Académique Documents
Professionnel Documents
Culture Documents
One-sample t-tests
Lets generate an independent random sample of size 100 from
the N(mean=10, variance=9) distribution
set.seed(10)
sample1.100<- rnorm(100, mean=10, sd=3)
sample1.100
[1] 10.056239 9.447242 5.886008 8.202497 10.883635 11.169383 6.375771
[8] 8.908972 5.119982 9.230565 13.305339 12.267345 9.285299 12.962334
[15] 12.224170 10.268042 7.135168 9.414549 12.776564 11.448936 8.211068
[22] 3.444139 7.975402 3.642816 6.204406 8.879015 7.937334 7.383524
[29] 9.694717 9.238658 4.438779 9.766162 12.905699 10.554778 5.860169
[36] 5.693457 11.086262 4.722740 9.026368 8.045311 13.259654 7.712365
[43] 7.514012 12.503422 7.097044 9.913554 10.697575 9.096374 7.967156
[50] 11.965683 8.798087 8.996330 14.103862 16.413301 11.517458 12.359027
[57] 7.293364 11.598691 8.062317 10.872962 6.287217 8.631471 7.509032
[64] 11.020347 13.199129 13.648378 12.207072 8.556374 11.688234 6.261041
[71] 11.142767 5.708718 6.854663 9.344489 5.530191 13.518119 5.560519
[78] 8.708837 6.845084 14.567759 11.778484 9.332015 12.138683 12.149803
[85] 11.320726 10.476492 11.979292 16.661559 6.448165 9.778132 8.750936
[92] 9.425553 10.208634 13.466045 11.784872 5.741065 5.179968 12.678778
[99] 10.444504 13.681085
Suppose that I want to test whether or not the true mean is zero
or not. Of course, we know that the true mean is 10, so expect to
reject the null hypothesis (that the mean is equal to zero).
We choose a two-sided alternative that the mean is different
from zero!
t.test(sample1.100,alternative=c(two.sided))
One Sample t-test
data: sample1.100
t = 33.9637, df = 99, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
9.030068 10.150638
sample estimates:
mean of x
9.590353
Now, what if we want to choose a different alternative (onesided)? Such as, the mean is greater than zero?
t.test(sample1.100,alternative=c(greater))
One Sample t-test
data: sample1.100
t = 33.9637, df = 99, p-value < 2.2e-16
alternative hypothesis: true mean is greater than 0
95 percent confidence interval:
9.121507
Inf
sample estimates:
mean of x
9.590353
How about if we want to test that the mean is less than zero?
t.test(sample1.100,alternative=c(less))
One Sample t-test
data: sample1.100
t = 33.9637, df = 99, p-value = 1
alternative hypothesis: true mean is less than 0
95 percent confidence interval:
-Inf 10.0592
sample estimates:
mean of x
9.590353
Now, what if we want to choose a different alternative (onesided)? Such as, the mean is greater than 9?
3
Now, what if we want to choose a different alternative (onesided)? Such as, the mean is greater than 10?
t.test(sample1.100, mu=10, alternative=c(greater))
One Sample t-test
data: sample1.100
t = -1.4507, df = 99, p-value = 0.925
alternative hypothesis: true mean is greater than 10
95 percent confidence interval:
9.121507
Inf
sample estimates:
mean of x
9.590353
How about if we want to test that the mean is less than 10?
t.test(sample1.100, mu=10, alternative=c(less))
One Sample t-test
data: sample1.100
t = -1.4507, df = 99, p-value = 0.075
alternative hypothesis: true mean is less than 10
95 percent confidence interval:
-Inf 10.0592
sample estimates:
mean of x
9.590353
Two-sample T-tests
Paired T-tests
We now want to create a paired structure, so we will do it in a
simple way! To the first sample sample1.100, we will add
some noise N(mean=0, variance=0.1) and some signal
equal to 0.2. Call the resulting sample sample3.100.
Then, this latest sample comes from a population N(mean=10.2,
variance=9.1).
sample3.100 <-0.2+rnorm(100, mean=0,sd=sqrt(0.1))+
sample1.100
10
sample3.100
[1] 10.640618 9.751875 6.525652 8.678262 10.741851
11.526175 6.908642 8.705892 5.258739 9.021023 13.550205
12.866334 9.348847 12.585942 12.535655
[16] 10.041624 7.558959 9.484614 12.835512 11.319693
8.306958 3.554703 8.312148 3.745543 6.386496 9.310973
8.168106 8.099257 10.071998 9.859104
[31] 4.550607 9.565586 13.026911 10.760466 6.179410
6.145177 11.020416 4.225308 8.869645 7.821152 13.967236
8.147773 7.986627 12.828381 7.458042
[46] 10.074800 10.926853 9.183202 8.053423 12.490946
9.338947 9.490985 13.841918 16.326775 11.502313 12.895230
7.274404 11.440206 7.916169 10.752654
[61] 6.616958 8.982546 6.972259 11.225487 13.709144
14.103367 12.444893 7.985849 11.898044 6.354868 11.259353
5.796188 6.902509 9.614924 6.498596
[76] 14.191290 5.533718 8.761141 7.254719 15.495139
12.082052 9.552211 11.978322 12.723081 11.533814 10.292720
12.202439 16.780186 6.732536 10.416969
[91] 9.011993 9.812860 10.146173 13.790188 12.106578
6.273434 5.745464 12.551660 10.564034 14.283860
11