This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(DescTools)
## Warning: package 'DescTools' was built under R version 4.1.3
library(ggplot2)
library(lattice)
library(grid)
crack.data <- read.table(header=TRUE, text="
Roadway cracks Treatment Concentration
1 37 NaCl Low
1 49 NaCl High
1 43 CaCl Low
1 47 CaCl High
1 27 Sand Low
1 33 Sand High
2 39 NaCl Low
2 50 NaCl High
2 42 CaCl Low
2 48 CaCl High
2 27 Sand Low
2 31 Sand High
3 48 NaCl Low
3 52 NaCl High
3 47 CaCl Low
3 50 CaCl High
3 36 Sand Low
3 37 Sand High
4 44 NaCl Low
4 57 NaCl High
4 45 CaCl Low
4 54 CaCl High
4 34 Sand Low
4 37 Sand High
5 54 NaCl Low
5 68 NaCl High
5 56 CaCl Low
5 63 CaCl High
5 45 Sand Low
5 44 Sand High
")
ggplot(crack.data, aes(x=interaction(Treatment,Concentration, sep=":"),
y=cracks,
fill=interaction(Treatment,Concentration, sep=":"))) +
geom_boxplot(show.legend = FALSE) +
theme_minimal()
interaction.plot(x.factor=crack.data$Treatment,
trace.factor=crack.data$Concentration,
response=crack.data$cracks,
fun=mean,
xlab="Treatment", ylab="cracks",
trace.label = "Concentration",
col=c("red", "blue", "orange"), lty=1, lwd=2)
Roadway <- factor( c(rep("1", 6), rep("2", 6), rep("3", 6), rep("4", 6), rep("5", 6)), levels=c("1", "2", "3", "4","5"))
Concentration <- factor(rep( c(rep("Low", 1), rep("Hi", 1)),1),
levels=c("Low", "Hi"))
Treatment<- factor( c(rep("NaCl", 2), rep("CaCl", 2), rep("Sand", 2)),
levels=c("NaCl","CaCl","Sand"))
cracks <- crack.data$cracks %>% c(1:30)
crack.data <- data.frame(Roadway=Roadway, Treatment=Treatment, Concentration=Concentration, cracks=cracks)
groadway <- ggplot(data=crack.data, aes(x=Roadway, y=cracks, fill=Roadway) ) +
geom_boxplot(show.legend = FALSE) +
labs(title="Cracks", subtitle="by Block (Roadway)") +
theme_minimal()
gconcentration <- ggplot(data=crack.data, aes(x=Concentration, y=cracks, fill=Concentration) ) +
geom_boxplot(show.legend = FALSE) +
labs(title="Cracks", subtitle="by Concentration") +
theme_minimal()
gtreatmeant <- ggplot(data=crack.data, aes(x=Treatment, y=cracks, fill=Treatment) ) +
geom_boxplot(show.legend = FALSE) +
labs(title="Cracks", subtitle="by Treatment") +
theme_minimal()
summary(
RCB.model <- aov(cracks ~ Treatment*Concentration, data=crack.data)
)
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 452 225.9 0.706 0.498
## Concentration 1 205 205.4 0.642 0.427
## Treatment:Concentration 2 43 21.3 0.067 0.936
## Residuals 54 17278 320.0
summary(
RCB.model2 <- aov(cracks ~ ., data=crack.data)
)
## Df Sum Sq Mean Sq F value Pr(>F)
## Roadway 4 2899 724.6 2.613 0.0458 *
## Treatment 2 452 226.0 0.815 0.4483
## Concentration 1 205 205.3 0.740 0.3935
## Residuals 52 14422 277.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library("car")
## Warning: package 'car' was built under R version 4.1.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.1.3
##
## Attaching package: 'car'
## The following object is masked from 'package:DescTools':
##
## Recode
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
qqPlot(crack.data$cracks)
## [1] 26 28
library(postHoc)
## Warning: package 'postHoc' was built under R version 4.1.3
## Loading required package: igraph
## Warning: package 'igraph' was built under R version 4.1.3
##
## Attaching package: 'igraph'
## The following object is masked from 'package:DescTools':
##
## %c%
## The following objects are masked from 'package:dplyr':
##
## as_data_frame, groups, union
## The following objects are masked from 'package:purrr':
##
## compose, simplify
## The following object is masked from 'package:tidyr':
##
## crossing
## The following object is masked from 'package:tibble':
##
## as_data_frame
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
## Loading required package: multcomp
## Warning: package 'multcomp' was built under R version 4.1.3
## Loading required package: mvtnorm
## Loading required package: survival
##
## Attaching package: 'survival'
## The following object is masked _by_ '.GlobalEnv':
##
## cracks
## Loading required package: TH.data
## Warning: package 'TH.data' was built under R version 4.1.3
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
PostHocTest(RCB.model, which=c("Treatment:Concentration"), method="hsd", conf.level=NA)
##
## Posthoc multiple comparisons of means : Tukey HSD
##
## $`Treatment:Concentration`
## NaCl:Low CaCl:Low Sand:Low NaCl:Hi CaCl:Hi
## CaCl:Low 1.00 - - - -
## Sand:Low 1.00 0.98 - - -
## NaCl:Hi 0.98 1.00 0.86 - -
## CaCl:Hi 0.98 1.00 0.88 1.00 -
## Sand:Hi 1.00 1.00 1.00 0.94 0.95