User Tools

Site Tools


c:ms:2017:schedule:week15

This is an old revision of the document!


two sample t-test

x1 <- rnorm(10, mean=100, sd=15)
x1
t.test(x1, mu=95)
  1. What is the std error value?
  2. What if you have a sample with a large size?
    • How do you get your se?
ster <- sd(x1)/sqrt(length(x1))
difx <- mean(x1)-95
tvalue <- difx/ster

difx
ster
tvalue
x2 <- rnorm(100, mean=100, sd=15)
head(x2)
tail(x2)
t.test(x2, mu=95)

ster <- sd(x2)/sqrt(length(x2))
difx <- mean(x2)-95
tvalue <- difx/ster

difx
ster
tvalue
mtcars
mtcars$mpg
mtcars$am

t.test(mtcars$mpg~mtcars$am)

one sample t-test 2

a = c(65, 78, 88, 55, 48, 95, 66, 57, 79, 81)
mean(a)
sd(a)

t.test(a, mu=60)

Faired sample t-test

sleep

sleep.wide <- data.frame(
    ID=1:10,
    group1=sleep$extra[1:10],
    group2=sleep$extra[11:20]
)
sleep.wide

t.test(sleep.wide$group1 - sleep.wide$group2, mu=0, var.equal=TRUE)
t.test(sleep.wide$group1, sleep.wide$group2, paired=TRUE)

ANOVA

Oneway

<code>
data(InsectSprays)
str(InsectSprays)

attach(InsectSprays)
tapply(count, spray, mean)
tapply(count, spray, var)
tapply(count, spray, length)

boxplot(count ~ spray) # boxplot(count~spray, data=InsectSprays) if not attached

one ← oneway.test(count ~ spray) # oneway.test(count~spray, data=InsectSprays) if not attached
summary(one)

aov.out ← aov(count ~ spray, data=InsectSprays)
summary(aov.out)

pairwise.t.test(InsectSprays$count, InsectSprays$spray)
TukeyHSD(aov.out)

Twoway

c/ms/2017/schedule/week15.1497403549.txt.gz · Last modified: 2017/06/14 09:55 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki