c:ma:2019:lecturer
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| c:ma:2019:lecturer [2019/10/01 23:52] – [t.test: mtcars] hkimscil | c:ma:2019:lecturer [2019/10/04 11:28] (current) – [anova: mtcars] hkimscil | ||
|---|---|---|---|
| Line 230: | Line 230: | ||
| | | ||
| } | } | ||
| - | stats <- stats4each(mtcars$hp, mtcars$cyl) | + | |
| + | library(MASS) | ||
| + | |||
| + | tempd <- iris | ||
| + | x <- tempd$Species | ||
| + | y <- tempd$Sepal.Width | ||
| + | |||
| + | tempd <- mtcars | ||
| + | x <- tempd$gear | ||
| + | y <- tempd$mpg | ||
| + | |||
| + | tempd <- mtcars | ||
| + | x <- tempd$am | ||
| + | y <- tempd$mpg | ||
| + | |||
| + | |||
| + | x <- factor(x) | ||
| + | dfbetween <- nlevels(x)-1 | ||
| + | |||
| + | stats <- stats4each(y, | ||
| stats | stats | ||
| sswithin <- sum(stats[5, | sswithin <- sum(stats[5, | ||
| - | sstotal <- var(mtcars$hp)*(length(mtcars$hp)-1) | + | sstotal <- var(y)*(length(y)-1) |
| ssbetween <- sstotal-sswithin | ssbetween <- sstotal-sswithin | ||
| - | round(sswithin, | + | round(sswithin, |
| - | round(ssbetween, | + | round(ssbetween, |
| - | round(sstotal, | + | round(sstotal, |
| dfwithin <- sum(stats[4, | dfwithin <- sum(stats[4, | ||
| - | dfbetween <- 3-1 | + | dftotal <- length(y)-1 |
| - | dftotal <- length(mtcars$hp)-1 | + | |
| dfwithin | dfwithin | ||
| Line 253: | Line 271: | ||
| mstotal <- sstotal / dftotal | mstotal <- sstotal / dftotal | ||
| - | round(mswithin, | + | round(mswithin, |
| - | round(msbetween, | + | round(msbetween, |
| - | round(mstotal, | + | round(mstotal, |
| fval <- round(msbetween/ | fval <- round(msbetween/ | ||
| fval | fval | ||
| - | siglevel <- pf(q=36.18, df1=2, df2=29, lower.tail=FALSE) | + | siglevel <- pf(q=fval, df1=dfbetween, df2=dfwithin, lower.tail=FALSE) |
| siglevel | siglevel | ||
| - | mod <- aov(mtcars$hp~mtcars$cyl, data=mtcars) | + | mod <- aov(y~x, data=tempd) |
| summary(mod) | summary(mod) | ||
c/ma/2019/lecturer.1569941576.txt.gz · Last modified: by hkimscil
