This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
power.anova.test(
groups = 4, n = NULL,
between.var = var(c(18, 19, 19, 20)),
within.var = 3.5,
sig.level = 0.05, power = 0.80
)
##
## Balanced one-way analysis of variance power calculation
##
## groups = 4
## n = 20.08368
## between.var = 0.6666667
## within.var = 3.5
## sig.level = 0.05
## power = 0.8
##
## NOTE: n is number in each group
power.anova.test(
groups = 4, n = NULL,
between.var = var(seq(18, 20, length.out = 4)),
within.var = 3.5,
sig.level = 0.05, power = 0.80
)
##
## Balanced one-way analysis of variance power calculation
##
## groups = 4
## n = 18.17867
## between.var = 0.7407407
## within.var = 3.5
## sig.level = 0.05
## power = 0.8
##
## NOTE: n is number in each group
power.anova.test(
groups = 4, n = NULL,
between.var = var(c(18, 18, 20, 20)),
within.var = 3.5,
sig.level = 0.05, power = 0.80
)
##
## Balanced one-way analysis of variance power calculation
##
## groups = 4
## n = 10.56952
## between.var = 1.333333
## within.var = 3.5
## sig.level = 0.05
## power = 0.8
##
## NOTE: n is number in each group
Fluid1 <- c(17.6, 18.9, 16.3, 17.4, 20.1, 21.6)
Fluid2 <- c(16.9, 15.3, 18.6, 17.1, 19.5, 20.3)
Fluid3 <- c(21.4, 23.6, 19.4, 18.5, 20.5, 22.3)
Fluid4 <- c(19.3, 21.1, 16.9, 17.1, 18.5, 19.8)
dat_wide <- data.frame(Fluid1, Fluid2, Fluid3, Fluid4)
dat <- pivot_longer(dat_wide, c(Fluid1, Fluid2, Fluid3, Fluid4),
names_to = "Fluid", values_to = "Life")
dat$Fluid <- as.factor(dat$Fluid)
# (a) ANOVA
aov.model <- aov(Life ~ Fluid, data = dat)
summary(aov.model)
## Df Sum Sq Mean Sq F value Pr(>F)
## Fluid 3 30.28 10.093 3.011 0.0543 .
## Residuals 20 67.03 3.352
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# (b) Diagnostic plots
par(mfrow = c(2, 2))
plot(aov.model)
par(mfrow = c(1, 1))
# (c) Tukey HSD at alpha = 0.10
tukey_result <- TukeyHSD(aov.model, conf.level = 0.90)
tukey_result
## Tukey multiple comparisons of means
## 90% family-wise confidence level
##
## Fit: aov(formula = Life ~ Fluid, data = dat)
##
## $Fluid
## diff lwr upr p adj
## Fluid2-Fluid1 -0.7000000 -3.2871676 1.8871676 0.9099601
## Fluid3-Fluid1 2.3000000 -0.2871676 4.8871676 0.1641697
## Fluid4-Fluid1 0.1333333 -2.4538342 2.7205009 0.9992575
## Fluid3-Fluid2 3.0000000 0.4128324 5.5871676 0.0461276
## Fluid4-Fluid2 0.8333333 -1.7538342 3.4205009 0.8588377
## Fluid4-Fluid3 -2.1666667 -4.7538342 0.4205009 0.2036744
plot(tukey_result)