檢定平均數是否為16
x<-c(16.3,16.2,15.8,15.4,16.0,15.6,15.5,16.1,15.9,16.1)
t.test(x,mu=16)

獨立樣本T檢定(Two sample t test)
library(lawstat) #載入Levene test 的套件
sleep #範例資料
a<-levene.test(sleep$extra,sleep$group);a #檢定變異數是否相等
b<-t.test(extra~group,sleep,var.equal=TRUE);b #獨立樣本T檢定
c<-t.test(extra~group,sleep);c #預設值是假設變異數不相等
cbind(rbind(a[1:2],c("","")),rbind(b[1:3],c[1:3])) #弄的跟SPSS一樣

相依樣本T檢定(Paired t test)
檢定補習前後成績是否有差異
補習前 52 61 58 57 59 62 56 57 61 58 55 60
補習後 67 59 71 58 70 67 66 60 66 61 66 68
old<-c(52,61,58,57,59,62,56,57,61,58,55,60)
new<-c(67,59,71,58,70,67,66,60,66,61,66,68)
t.test(old,new,paired=T)

t.test(x,mu=16)

獨立樣本T檢定(Two sample t test)
library(lawstat) #載入Levene test 的套件
sleep #範例資料
a<-levene.test(sleep$extra,sleep$group);a #檢定變異數是否相等
b<-t.test(extra~group,sleep,var.equal=TRUE);b #獨立樣本T檢定
c<-t.test(extra~group,sleep);c #預設值是假設變異數不相等
cbind(rbind(a[1:2],c("","")),rbind(b[1:3],c[1:3])) #弄的跟SPSS一樣

相依樣本T檢定(Paired t test)
檢定補習前後成績是否有差異
補習前 52 61 58 57 59 62 56 57 61 58 55 60
補習後 67 59 71 58 70 67 66 60 66 61 66 68
old<-c(52,61,58,57,59,62,56,57,61,58,55,60)
new<-c(67,59,71,58,70,67,66,60,66,61,66,68)
t.test(old,new,paired=T)

沒有留言:
張貼留言