8.4 Two samples

8.4.1 Comparing two variances

Before we can carry out a test to compare two sample means (see below), we need to test whether the sample
variances are significantly different (see p. 356). The test could not be simpler. It is called Fisher’s F test
after the famous statistician and geneticist R.A. Fisher, who worked at Rothamsted in south-east England

qf(0.975,9,9)

f.test.data <- read.table("c:\\temp\\f.test.data.txt",header = T)
attach(f.test.data)

names(f.test.data)

var(gardenB)

var(gardenC)

F.ratio <- var(gardenC)/var(gardenB)

F.ratio

2*(1-pf(F.ratio,9,9))


var.test(gardenB,gardenC)


refs <- read.table("c:\\temp\\refuge.txt",header=T)
attach(refs)

names(refs)


tapply(B,T,var)

bartlett.test(B[-31],T[-31])

fligner.test(B[-31],T[-31])


model <- lm(B~T)

plot(model)


ozone <- read.table("c:\\temp\\gardens.txt",header=T)
attach(ozone)

names(ozone)


y <- c(gardenA,gardenB,gardenC)

garden <- factor(rep(c("A","B","C"),c(10,10,10)))

var.test(gardenB,gardenC)


fligner.test(y~garden)

The reason for the difference is that Fisher and Bartlett are sensitive to outliers, whereas Fligner–Killeen is

not (i


There are two classical tests for comparing two sample means:
Student’s t test when the samples are independent, the variances constant, and the errors are normally
distributed;
Wilcoxon’s rank-sum test when the samples are independent but the errors are not normally distributed
(e.g. they are ranks or scores or some sort).
What to do when these assumptions are violated (e.g. when the variances are different) is discussed later on



qt(0.975,18)

t.test.data <- read.table("c:\\temp\\t.test.data.txt",header=T)
attach(t.test.data)

par(mfrow=c(1,1))



names(t.test.data)



ozone <- c(gardenA,gardenB)
label <- factor(c(rep("A",10),rep("B",10)))

boxplot(ozone~label,notch=T,xlab="Garden",ylab="Ozone") 


s2A <- var(gardenA)
s2B <- var(gardenB)

(mean(gardenA)-mean(gardenB))/sqrt(s2A/10+s2B/10)

2*pt(-3.872983,18)

t.test(gardenA,gardenB)

ozone <- c(gardenA,gardenB)

ozone

label <- c(rep("A",10),rep("B",10))

label


combined.ranks <- rank(ozone)

combined.ranks

tapply(combined.ranks,label,sum)


wilcox.test(gardenA,gardenB)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值