SlideShare a Scribd company logo
1 of 45
R 統計軟體簡介(2)
常用統計分析
徐峻賢
中央研究院語言學研究所
大腦與語言實驗室
• What is central limit theorem?
x <- rnorm(30, mean = 1, sd = 2)
hist(x)
xmean <- numeric(100)
for (i in 1:100)
{
x <- rnorm(30, mean = 1, sd = 2)
xmean[i] <-mean(x)
}
hist(xmean)
• What is central limit theorem?
y <- rexp(100, rate = 1)
hist(y)
ymean <- numeric(100)
for (i in 1:100)
{
y <- rexp(100, rate = 1)
ymean[i] <-mean(y)
}
hist(ymean)
rnorm()  產生常態分布的隨機變數
dnorm()  probability density
pnorm()  cumulative probability function
qnorm()  the value of quantile
rnorm(n=30,mean=0,sd=1)
dnorm(1)== 1/sqrt(2*pi)*exp(-1/2)
pnorm(1.645, mean=0,sd=1)
qnorm(0.95,mean=0,sd=1)
建立 R documents 的好習慣
• R 軟體有很多細節,使用者偶而會出現失讀
症的徵狀…
建立 R documents 的好習慣
• 多做注解 (##)
• 留意套件和主程式的版本 (R-news)
• 在documents 的開頭交代基本環境
– e.g.:
### This is for …. By xxx at 2014/7/06
library(ez)
setwd(“c:/data/”)
load(“myexample.Rdata”)
rm(list=ls())
quasif data set in languageR package
Source: Raaijmakers et al., 1999, Table2
data(lexicalMeasures)
Lexical distributional measures for 2233 English
monomorphemic words. This dataset provides a
subset of the data available in the dataset
english.
Baayen, R.H., Feldman, L. and Schreuder, R.
(2006) Morphological influences on the
recognition of monosyllabic monomorphemic
words, Journal of Memory and Language, 53,
496-512.
data(lexicalMeasures)
head(lexicalMeasures)
lexicalMeasures.cor = cor(lexicalMeasures[,-1], method =
"spearman")^2
lexicalMeasures.dist = dist(lexicalMeasures.cor)
### Hierarchical Clustering
lexicalMeasures.clust = hclust(lexicalMeasures.dist)
plclust(lexicalMeasures.clust)
### or
### DIvisive ANAlysis Clustering
pltree(diana(lexicalMeasures.dist))
ffV
ffN
ffNonzero
spelV
friendsV
spelN
friendsN
fbV
fbN
phonV
phonN
Vf
Dent
NsyS
CelS
NsyC
Ncou
Len
Bigr
Ient
NVratio
Fdif
InBi
0.0 0.5 1.0 1.5 2.0hclust(*,"complete")
lexicalMeasures.dist
Height
CelS
NsyC
NsyS
Vf
Dent
Ient
NVratio
Fdif
InBi
Len
Bigr
Ncou
spelV
friendsV
spelN
friendsN
phonV
phonN
fbV
fbN
ffV
ffN
ffNonzero
0.0 0.5 1.0 1.5 2.0
Dendrogramofdiana(x=lexicalMeasures.dist)
diana(*,"NA")
lexicalMeasures.dist
Height
quasif data set in languageR package
> ldt=quasif
> detach(package:languageR)
> B=read.csv(file="Baayen2008C.csv")
> head(ldt, n=10)
> tail(ldt, n=10)
dataframe[r,c]
> B[1, 4]
[1] 466
> B[1:2, ]
Subj Item SOA RT
1 s1 w1 Long 466
2 s1 w2 Long 520
> B[,4]
[1] 466 520 502 475 …
dataframe$variable
> B$RT
[1] 466 520 502 475 …
> B[B$Subj=="s1", 4]
[1] 466 520 502 475 494 490
> B[B$RT<500, 4]
[1] 466 475 494 490 491 484 470
> B=B[order(B$Item, B$SOA), ];B
Subj Item SOA RT
1 s1 w1 Long 466
2 s1 w2 Long 520
3 s1 w3 Long 502
4 s1 w1 Short 475
5 s1 w2 Short 494
6 s1 w3 Short 490
7 s2 w1 Long 516
8 s2 w2 Long 566
9 s2 w3 Long 577
10 s2 w1 Short 491
11 s2 w2 Short 544
12 s2 w3 Short 526
13 s3 w1 Long 484
14 s3 w2 Long 529
15 s3 w3 Long 539
16 s3 w1 Short 470
17 s3 w2 Short 511
18 s3 w3 Short 528
> B$RT=B$RT/1000;B
Subj Item SOA RT
1 s1 w1 Long 0.466
2 s1 w2 Long 0.520
3 s1 w3 Long 0.502
4 s1 w1 Short 0.475
5 s1 w2 Short 0.494
6 s1 w3 Short 0.490
7 s2 w1 Long 0.516
8 s2 w2 Long 0.566
9 s2 w3 Long 0.577
10 s2 w1 Short 0.491
11 s2 w2 Short 0.544
12 s2 w3 Short 0.526
13 s3 w1 Long 0.484
14 s3 w2 Long 0.529
15 s3 w3 Long 0.539
16 s3 w1 Short 0.470
17 s3 w2 Short 0.511
18 s3 w3 Short 0.528
> B.xtab=xtabs(~ SOA+Item, data=B);B.xtab
Item
SOA w1 w2 w3
Long 3 3 3
Short 3 3 3
> B.xtab.g500=xtabs(~ SOA+Item,
+ data=B,subset=B$RT>500);B.xtab.g500
Item
SOA w1 w2 w3
Long 1 3 3
Short 0 2 2
> bysub=aggregate(B$RT, list(B$SOA, B$Subj),
+ mean); bysub
Group.1 Group.2 x
1 Long s1 496.0000
2 Short s1 486.3333
3 Long s2 553.0000
4 Short s2 520.3333
5 Long s3 517.3333
6 Short s3 503.0000
> colnames(bysub) = c(“SOA”, “Subj”, “meanRT”)
> bysub
SOA Subj meanRT
1 Long s1 496.0000
2 Short s1 486.3333
3 Long s2 553.0000
4 Short s2 520.3333
5 Long s3 517.3333
6 Short s3 503.0000
> byitem=aggregate(B$RT, list(B$SOA, B$Item),
+ mean); byitem
Group.1 Group.2 x
1 Long w1 488.6667
2 Short w1 478.6667
3 Long w2 538.3333
4 Short w2 516.3333
5 Long w3 539.3333
6 Short w3 514.6667
> colnames(byitem) = c(“SOA”, “Subj”, “meanRT”)
> byitem
SOA Subj meanRT
1 Long s1 496.0000
2 Short s1 486.3333
3 Long s2 553.0000
4 Short s2 520.3333
5 Long s3 517.3333
6 Short s3 503.0000
• By subject analysis
bysub=aggregate(B$RT, list(B$SOA, B$Subj), mean);
bysub
names(bysub) <- c("SOA", "Subj", "RT”)
rt_anova = ezANOVA(
data = B #### 用aggregate 之前的 data frames
, dv = RT
, wid = Subj
, within = .(SOA)
)
print(rt_anova)
rt_anova3 = ezANOVA(
data = bysub #### 用by subject mean 的 data frames
, dv = RT
, wid = Subj
, within = .(SOA)
)
print(rt_anova3)
• By item analysis
byitem=aggregate(B$RT, list(B$SOA, B$Item), mean);
byitem
names(byitem) <- c("SOA", "items", "RT")
rt_anova2 = ezANOVA(
data = byitem
, dv = RT
,wid = items
, between = SOA
)
print(rt_anova2)
• data(ANT)
– ANT{ez}
– Simulated data from the Attention Network Test
– J Fan, BD McCandliss, T Sommer, A Raz, MI Posner
(2002). Testing the efficiency and independence of
attentional networks. Journal of Cognitive
Neuroscience, 14, 340-347.
• 2 within-Ss variables (“cue” and “flank”)
• 1 between-Ss variable (“group”)
• 2 dependent variables (“rt”, and “error”)
> data(ANT) ### A data frame with 5760
observations on the following 10 variables
> head(ANT, 20)
aov.rt = ezANOVA(
data = ANT[ANT$error==0,]
, dv = rt
, wid = subnum
, within = .(cue,flank)
, between = group
)
print(aov.rt)
aov.rt = ezANOVA(
data = ANT[ANT$error==0,]
, dv = rt
, wid = subnum
, within = .(cue,flank)
, between = group
, detailed = T
)
print(aov.rt)
bt_descriptives = ezStats(
data = ANT[ANT$error==0,]
, dv = rt
, wid = subnum
, between = group
)
print(bt_descriptives)
所有獨變項組合的平均反應時間
all_descriptives = ezStats(
data = ANT[ANT$error==0,]
, dv = rt
, wid = subnum
, within = .(cue,flank)
, between = group
)
print(all_descriptives)
group_plot = ezPlot(
data = ANT[ANT$error==0,]
, dv = .(rt)
, wid = .(subnum)
, between = .(group)
, x = .(group)
, do_lines = FALSE
, x_lab = 'Group'
, y_lab = 'RT (ms)'
)
print(group_plot)
cue_by_flank_plot = ezPlot(
data = ANT[ANT$error==0,]
, dv = .(rt)
, wid = .(subnum)
, within = .(cue,flank)
, x = .(flank)
, split = .(cue)
, x_lab = 'Flanker'
, y_lab = 'RT (ms)'
, split_lab = 'Cue'
)
print(cue_by_flank_plot)
• 自我挑戰:
– (1) 用 aggregare 計算正確反應時間的by subject
mean
– (2) 用 (1) 的輸出執行 ezANOVA
– (3) 用 aggregate 計算每個人、每個 condition 的
錯誤率
– (4) 用 ezStats 計算每個人、每個 condition 的錯
誤率
– (5) 使用錯誤率分析、畫圖
各種常用的指令
運算子(operators)
Arithmetic Comparison Logical
+ addition < lesser than !x logical NOT
- subtraction > greater than x&y logical AND
* multiplication <= lesser than or equal to x&&y id.
/ division >= greater than or equal to x|y logical OR
^ power == equal x||y id.
%% modulo != different xor(x,y) exclusive OR
%/% integer division
x<-matrix(1:6,2,3) #製造一個2*3的矩陣x,其數值為1到6
x[2,3]==6 # x矩陣第2row第3column的值是否等於6
x[x<=3] # 列出x矩陣內小於或等於3的數值
x[x!=6] # 列出x矩陣內不等於6的數值
x[x<=3 & x!=2] #列出x矩陣內小於或等於3且不等於2的值
函數(function)
• function.name(object, argument, option)
函數名稱 物件 指令 選項
#args(function.name) 查詢該函數的指令
• 數學及簡單函數
sum(),mean(),max(),length()
• 產生隨機變數
rnorm(),runiform(),rbinom()
• 初統常用分析函數
t.test(),aova(),lm()
產生隨機序列
Graphing
> windows() #開啟一個繪圖視窗
> par(mfrow=c(m,n)) #將繪圖視窗切割成m*n區
> plot(x) #散佈圖
> hist(x) #直方圖
> boxplot(x) #箱型圖
> qqnorm(x);qqline(x) #QQ Plot
main=“titile”
xlab=“x lable name” ylab=“y lable name”
xlim=c(a,b) ylim=c(a,b)
Graphing
> windows()
> plot(B$RT, main="Scatter plot of B", ylab="B")
Graphing
> windows()
> hist(B$RT, main="Histogram of B", xlab="B")
Graphing
> windows()
> boxplot(B$RT, main="Boxplot of B")
Graphing
> windows()
> qqnorm(B$RT); qqline(B$RT)
Graphing
> windows()
> par(mfrow=c(2,2))
> plot(B$RT, main="Scatter plot of B", ylab="B")
> hist(B$RT, main="Histogram of B", xlab="B")
> boxplot(B$RT, main="Boxplot of B")
> qqnorm(B$RT); qqline(B$RT)
Graphing
Exercise 3
• 請依據MASS中leuk資料集內的time變項資料製作
下面這張圖,並儲存成MASSleuk.jpeg

More Related Content

What's hot

Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
Anderson Dantas
 

What's hot (20)

Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI
 
Rsplit apply combine
Rsplit apply combineRsplit apply combine
Rsplit apply combine
 
C Language Lecture 10
C Language Lecture 10C Language Lecture 10
C Language Lecture 10
 
Association Rule Mining with R
Association Rule Mining with RAssociation Rule Mining with R
Association Rule Mining with R
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Data Clustering with R
Data Clustering with RData Clustering with R
Data Clustering with R
 
An Introduction to Data Mining with R
An Introduction to Data Mining with RAn Introduction to Data Mining with R
An Introduction to Data Mining with R
 
Cheat sheet python3
Cheat sheet python3Cheat sheet python3
Cheat sheet python3
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
Python_ 3 CheatSheet
Python_ 3 CheatSheetPython_ 3 CheatSheet
Python_ 3 CheatSheet
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Pandas+postgre sql 實作 with code
Pandas+postgre sql 實作 with codePandas+postgre sql 實作 with code
Pandas+postgre sql 實作 with code
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
Clustering and Visualisation using R programming
Clustering and Visualisation using R programmingClustering and Visualisation using R programming
Clustering and Visualisation using R programming
 

Viewers also liked

Viewers also liked (18)

R intro 20140716-basic
R intro 20140716-basicR intro 20140716-basic
R intro 20140716-basic
 
Statistical computing 00
Statistical computing 00Statistical computing 00
Statistical computing 00
 
Chi square
Chi squareChi square
Chi square
 
Essentials of EEG/MEG
Essentials of EEG/MEGEssentials of EEG/MEG
Essentials of EEG/MEG
 
Statistical computing 03
Statistical computing 03Statistical computing 03
Statistical computing 03
 
Multiple regression
Multiple regressionMultiple regression
Multiple regression
 
Model III ANOVA & Simple Main Effects
Model III ANOVA & Simple Main EffectsModel III ANOVA & Simple Main Effects
Model III ANOVA & Simple Main Effects
 
Kirk' Experimental Design, Chapter 1
Kirk' Experimental Design, Chapter 1Kirk' Experimental Design, Chapter 1
Kirk' Experimental Design, Chapter 1
 
Kirk' Experimental Design, Chapter 4
Kirk' Experimental Design, Chapter 4Kirk' Experimental Design, Chapter 4
Kirk' Experimental Design, Chapter 4
 
APA style
APA styleAPA style
APA style
 
SQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQL
 
Kirk' Experimental Design, Chapter 2
Kirk' Experimental Design, Chapter 2Kirk' Experimental Design, Chapter 2
Kirk' Experimental Design, Chapter 2
 
repeated-measure-ANOVA
repeated-measure-ANOVArepeated-measure-ANOVA
repeated-measure-ANOVA
 
H2O World - Top 10 Deep Learning Tips & Tricks - Arno Candel
H2O World - Top 10 Deep Learning Tips & Tricks - Arno CandelH2O World - Top 10 Deep Learning Tips & Tricks - Arno Candel
H2O World - Top 10 Deep Learning Tips & Tricks - Arno Candel
 
初學R語言的60分鐘
初學R語言的60分鐘初學R語言的60分鐘
初學R語言的60分鐘
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to R intro 20140716-advance

Statistics and Data Mining with Perl Data Language
Statistics and Data Mining with Perl Data LanguageStatistics and Data Mining with Perl Data Language
Statistics and Data Mining with Perl Data Language
maggiexyz
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Vyacheslav Arbuzov
 

Similar to R intro 20140716-advance (20)

第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
Building Streaming Recommendation Engines on Apache Spark with Rui Vieira
Building Streaming Recommendation Engines on Apache Spark with Rui VieiraBuilding Streaming Recommendation Engines on Apache Spark with Rui Vieira
Building Streaming Recommendation Engines on Apache Spark with Rui Vieira
 
Crushing the Head of the Snake by Robert Brewer PyData SV 2014
Crushing the Head of the Snake by Robert Brewer PyData SV 2014Crushing the Head of the Snake by Robert Brewer PyData SV 2014
Crushing the Head of the Snake by Robert Brewer PyData SV 2014
 
Yoyak ScalaDays 2015
Yoyak ScalaDays 2015Yoyak ScalaDays 2015
Yoyak ScalaDays 2015
 
Bioinformatics t5-database searching-v2013_wim_vancriekinge
Bioinformatics t5-database searching-v2013_wim_vancriekingeBioinformatics t5-database searching-v2013_wim_vancriekinge
Bioinformatics t5-database searching-v2013_wim_vancriekinge
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOW
 
RではじめるTwitter解析
RではじめるTwitter解析RではじめるTwitter解析
RではじめるTwitter解析
 
2_EditDistance_Jan_08_2020.pptx
2_EditDistance_Jan_08_2020.pptx2_EditDistance_Jan_08_2020.pptx
2_EditDistance_Jan_08_2020.pptx
 
Comparative Genomics with GMOD and BioPerl
Comparative Genomics with GMOD and BioPerlComparative Genomics with GMOD and BioPerl
Comparative Genomics with GMOD and BioPerl
 
R Workshop for Beginners
R Workshop for BeginnersR Workshop for Beginners
R Workshop for Beginners
 
Statistics and Data Mining with Perl Data Language
Statistics and Data Mining with Perl Data LanguageStatistics and Data Mining with Perl Data Language
Statistics and Data Mining with Perl Data Language
 
Interpreting Logistic Regression.pptx
Interpreting Logistic Regression.pptxInterpreting Logistic Regression.pptx
Interpreting Logistic Regression.pptx
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Python memory management_v2
Python memory management_v2Python memory management_v2
Python memory management_v2
 
Top k string similarity search
Top k string similarity searchTop k string similarity search
Top k string similarity search
 
Graph Algebra
Graph AlgebraGraph Algebra
Graph Algebra
 
Boston Predictive Analytics: Linear and Logistic Regression Using R - Interme...
Boston Predictive Analytics: Linear and Logistic Regression Using R - Interme...Boston Predictive Analytics: Linear and Logistic Regression Using R - Interme...
Boston Predictive Analytics: Linear and Logistic Regression Using R - Interme...
 
Logisticregression
LogisticregressionLogisticregression
Logisticregression
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 

More from Kevin Chun-Hsien Hsu (10)

[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26
 
[1062BPY12001] Data analysis with R / April 19
[1062BPY12001] Data analysis with R / April 19[1062BPY12001] Data analysis with R / April 19
[1062BPY12001] Data analysis with R / April 19
 
[1062BPY12001] Data analysis with R / week 4
[1062BPY12001] Data analysis with R / week 4[1062BPY12001] Data analysis with R / week 4
[1062BPY12001] Data analysis with R / week 4
 
[1062BPY12001] Data analysis with R / week 3
[1062BPY12001] Data analysis with R / week 3[1062BPY12001] Data analysis with R / week 3
[1062BPY12001] Data analysis with R / week 3
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
語言議題
語言議題語言議題
語言議題
 
Regression 0410
Regression 0410Regression 0410
Regression 0410
 
Kirk' Experimental Design, Chapter 3
Kirk' Experimental Design, Chapter 3Kirk' Experimental Design, Chapter 3
Kirk' Experimental Design, Chapter 3
 
資料檢索
資料檢索資料檢索
資料檢索
 
Kirk' Experimental Design, Chapter 5
Kirk' Experimental Design, Chapter 5Kirk' Experimental Design, Chapter 5
Kirk' Experimental Design, Chapter 5
 

Recently uploaded

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 

Recently uploaded (20)

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 

R intro 20140716-advance

  • 2. • What is central limit theorem? x <- rnorm(30, mean = 1, sd = 2) hist(x) xmean <- numeric(100) for (i in 1:100) { x <- rnorm(30, mean = 1, sd = 2) xmean[i] <-mean(x) } hist(xmean)
  • 3. • What is central limit theorem? y <- rexp(100, rate = 1) hist(y) ymean <- numeric(100) for (i in 1:100) { y <- rexp(100, rate = 1) ymean[i] <-mean(y) } hist(ymean)
  • 4. rnorm()  產生常態分布的隨機變數 dnorm()  probability density pnorm()  cumulative probability function qnorm()  the value of quantile rnorm(n=30,mean=0,sd=1) dnorm(1)== 1/sqrt(2*pi)*exp(-1/2) pnorm(1.645, mean=0,sd=1) qnorm(0.95,mean=0,sd=1)
  • 5.
  • 6. 建立 R documents 的好習慣 • R 軟體有很多細節,使用者偶而會出現失讀 症的徵狀…
  • 7. 建立 R documents 的好習慣 • 多做注解 (##) • 留意套件和主程式的版本 (R-news) • 在documents 的開頭交代基本環境 – e.g.: ### This is for …. By xxx at 2014/7/06 library(ez) setwd(“c:/data/”) load(“myexample.Rdata”) rm(list=ls())
  • 8. quasif data set in languageR package Source: Raaijmakers et al., 1999, Table2
  • 9. data(lexicalMeasures) Lexical distributional measures for 2233 English monomorphemic words. This dataset provides a subset of the data available in the dataset english. Baayen, R.H., Feldman, L. and Schreuder, R. (2006) Morphological influences on the recognition of monosyllabic monomorphemic words, Journal of Memory and Language, 53, 496-512.
  • 10. data(lexicalMeasures) head(lexicalMeasures) lexicalMeasures.cor = cor(lexicalMeasures[,-1], method = "spearman")^2 lexicalMeasures.dist = dist(lexicalMeasures.cor) ### Hierarchical Clustering lexicalMeasures.clust = hclust(lexicalMeasures.dist) plclust(lexicalMeasures.clust) ### or ### DIvisive ANAlysis Clustering pltree(diana(lexicalMeasures.dist))
  • 12. CelS NsyC NsyS Vf Dent Ient NVratio Fdif InBi Len Bigr Ncou spelV friendsV spelN friendsN phonV phonN fbV fbN ffV ffN ffNonzero 0.0 0.5 1.0 1.5 2.0 Dendrogramofdiana(x=lexicalMeasures.dist) diana(*,"NA") lexicalMeasures.dist Height
  • 13. quasif data set in languageR package > ldt=quasif > detach(package:languageR) > B=read.csv(file="Baayen2008C.csv") > head(ldt, n=10) > tail(ldt, n=10)
  • 14. dataframe[r,c] > B[1, 4] [1] 466 > B[1:2, ] Subj Item SOA RT 1 s1 w1 Long 466 2 s1 w2 Long 520 > B[,4] [1] 466 520 502 475 …
  • 15. dataframe$variable > B$RT [1] 466 520 502 475 … > B[B$Subj=="s1", 4] [1] 466 520 502 475 494 490 > B[B$RT<500, 4] [1] 466 475 494 490 491 484 470
  • 16. > B=B[order(B$Item, B$SOA), ];B Subj Item SOA RT 1 s1 w1 Long 466 2 s1 w2 Long 520 3 s1 w3 Long 502 4 s1 w1 Short 475 5 s1 w2 Short 494 6 s1 w3 Short 490 7 s2 w1 Long 516 8 s2 w2 Long 566 9 s2 w3 Long 577 10 s2 w1 Short 491 11 s2 w2 Short 544 12 s2 w3 Short 526 13 s3 w1 Long 484 14 s3 w2 Long 529 15 s3 w3 Long 539 16 s3 w1 Short 470 17 s3 w2 Short 511 18 s3 w3 Short 528
  • 17. > B$RT=B$RT/1000;B Subj Item SOA RT 1 s1 w1 Long 0.466 2 s1 w2 Long 0.520 3 s1 w3 Long 0.502 4 s1 w1 Short 0.475 5 s1 w2 Short 0.494 6 s1 w3 Short 0.490 7 s2 w1 Long 0.516 8 s2 w2 Long 0.566 9 s2 w3 Long 0.577 10 s2 w1 Short 0.491 11 s2 w2 Short 0.544 12 s2 w3 Short 0.526 13 s3 w1 Long 0.484 14 s3 w2 Long 0.529 15 s3 w3 Long 0.539 16 s3 w1 Short 0.470 17 s3 w2 Short 0.511 18 s3 w3 Short 0.528
  • 18. > B.xtab=xtabs(~ SOA+Item, data=B);B.xtab Item SOA w1 w2 w3 Long 3 3 3 Short 3 3 3 > B.xtab.g500=xtabs(~ SOA+Item, + data=B,subset=B$RT>500);B.xtab.g500 Item SOA w1 w2 w3 Long 1 3 3 Short 0 2 2
  • 19. > bysub=aggregate(B$RT, list(B$SOA, B$Subj), + mean); bysub Group.1 Group.2 x 1 Long s1 496.0000 2 Short s1 486.3333 3 Long s2 553.0000 4 Short s2 520.3333 5 Long s3 517.3333 6 Short s3 503.0000 > colnames(bysub) = c(“SOA”, “Subj”, “meanRT”) > bysub SOA Subj meanRT 1 Long s1 496.0000 2 Short s1 486.3333 3 Long s2 553.0000 4 Short s2 520.3333 5 Long s3 517.3333 6 Short s3 503.0000
  • 20. > byitem=aggregate(B$RT, list(B$SOA, B$Item), + mean); byitem Group.1 Group.2 x 1 Long w1 488.6667 2 Short w1 478.6667 3 Long w2 538.3333 4 Short w2 516.3333 5 Long w3 539.3333 6 Short w3 514.6667 > colnames(byitem) = c(“SOA”, “Subj”, “meanRT”) > byitem SOA Subj meanRT 1 Long s1 496.0000 2 Short s1 486.3333 3 Long s2 553.0000 4 Short s2 520.3333 5 Long s3 517.3333 6 Short s3 503.0000
  • 21. • By subject analysis bysub=aggregate(B$RT, list(B$SOA, B$Subj), mean); bysub names(bysub) <- c("SOA", "Subj", "RT”) rt_anova = ezANOVA( data = B #### 用aggregate 之前的 data frames , dv = RT , wid = Subj , within = .(SOA) ) print(rt_anova) rt_anova3 = ezANOVA( data = bysub #### 用by subject mean 的 data frames , dv = RT , wid = Subj , within = .(SOA) ) print(rt_anova3)
  • 22. • By item analysis byitem=aggregate(B$RT, list(B$SOA, B$Item), mean); byitem names(byitem) <- c("SOA", "items", "RT") rt_anova2 = ezANOVA( data = byitem , dv = RT ,wid = items , between = SOA ) print(rt_anova2)
  • 23. • data(ANT) – ANT{ez} – Simulated data from the Attention Network Test – J Fan, BD McCandliss, T Sommer, A Raz, MI Posner (2002). Testing the efficiency and independence of attentional networks. Journal of Cognitive Neuroscience, 14, 340-347. • 2 within-Ss variables (“cue” and “flank”) • 1 between-Ss variable (“group”) • 2 dependent variables (“rt”, and “error”)
  • 24. > data(ANT) ### A data frame with 5760 observations on the following 10 variables > head(ANT, 20)
  • 25.
  • 26. aov.rt = ezANOVA( data = ANT[ANT$error==0,] , dv = rt , wid = subnum , within = .(cue,flank) , between = group ) print(aov.rt)
  • 27.
  • 28. aov.rt = ezANOVA( data = ANT[ANT$error==0,] , dv = rt , wid = subnum , within = .(cue,flank) , between = group , detailed = T ) print(aov.rt)
  • 29. bt_descriptives = ezStats( data = ANT[ANT$error==0,] , dv = rt , wid = subnum , between = group ) print(bt_descriptives)
  • 30. 所有獨變項組合的平均反應時間 all_descriptives = ezStats( data = ANT[ANT$error==0,] , dv = rt , wid = subnum , within = .(cue,flank) , between = group ) print(all_descriptives)
  • 31. group_plot = ezPlot( data = ANT[ANT$error==0,] , dv = .(rt) , wid = .(subnum) , between = .(group) , x = .(group) , do_lines = FALSE , x_lab = 'Group' , y_lab = 'RT (ms)' ) print(group_plot)
  • 32. cue_by_flank_plot = ezPlot( data = ANT[ANT$error==0,] , dv = .(rt) , wid = .(subnum) , within = .(cue,flank) , x = .(flank) , split = .(cue) , x_lab = 'Flanker' , y_lab = 'RT (ms)' , split_lab = 'Cue' ) print(cue_by_flank_plot)
  • 33. • 自我挑戰: – (1) 用 aggregare 計算正確反應時間的by subject mean – (2) 用 (1) 的輸出執行 ezANOVA – (3) 用 aggregate 計算每個人、每個 condition 的 錯誤率 – (4) 用 ezStats 計算每個人、每個 condition 的錯 誤率 – (5) 使用錯誤率分析、畫圖
  • 35. 運算子(operators) Arithmetic Comparison Logical + addition < lesser than !x logical NOT - subtraction > greater than x&y logical AND * multiplication <= lesser than or equal to x&&y id. / division >= greater than or equal to x|y logical OR ^ power == equal x||y id. %% modulo != different xor(x,y) exclusive OR %/% integer division x<-matrix(1:6,2,3) #製造一個2*3的矩陣x,其數值為1到6 x[2,3]==6 # x矩陣第2row第3column的值是否等於6 x[x<=3] # 列出x矩陣內小於或等於3的數值 x[x!=6] # 列出x矩陣內不等於6的數值 x[x<=3 & x!=2] #列出x矩陣內小於或等於3且不等於2的值
  • 36. 函數(function) • function.name(object, argument, option) 函數名稱 物件 指令 選項 #args(function.name) 查詢該函數的指令 • 數學及簡單函數 sum(),mean(),max(),length() • 產生隨機變數 rnorm(),runiform(),rbinom() • 初統常用分析函數 t.test(),aova(),lm()
  • 38. Graphing > windows() #開啟一個繪圖視窗 > par(mfrow=c(m,n)) #將繪圖視窗切割成m*n區 > plot(x) #散佈圖 > hist(x) #直方圖 > boxplot(x) #箱型圖 > qqnorm(x);qqline(x) #QQ Plot main=“titile” xlab=“x lable name” ylab=“y lable name” xlim=c(a,b) ylim=c(a,b)
  • 39. Graphing > windows() > plot(B$RT, main="Scatter plot of B", ylab="B")
  • 40. Graphing > windows() > hist(B$RT, main="Histogram of B", xlab="B")
  • 41. Graphing > windows() > boxplot(B$RT, main="Boxplot of B")
  • 43. Graphing > windows() > par(mfrow=c(2,2)) > plot(B$RT, main="Scatter plot of B", ylab="B") > hist(B$RT, main="Histogram of B", xlab="B") > boxplot(B$RT, main="Boxplot of B") > qqnorm(B$RT); qqline(B$RT)