library(GAD)
## Warning: package 'GAD' was built under R version 4.1.3
## Loading required package: matrixStats
## Warning: package 'matrixStats' was built under R version 4.1.3
## Loading required package: R.methodsS3
## Warning: package 'R.methodsS3' was built under R version 4.1.3
## R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
obs <- c(570,1063,565,565,1080,510,583,1043,590,528,988,526,547,1026,538,521,1004,532)
Temp <- c(rep(seq(1,3),6))
position <- c(rep(1,9),rep(2,9))
Assume both factors as fixed.
Temp <-as.fixed(Temp) # is what sets as fixed
position <- as.fixed(position)
model <-lm(obs~Temp+position+Temp*position)
gad(model)
## Analysis of Variance Table
##
## Response: obs
## Df Sum Sq Mean Sq F value Pr(>F)
## Temp 2 945342 472671 1056.117 3.25e-14 ***
## position 1 7160 7160 15.998 0.001762 **
## Temp:position 2 818 409 0.914 0.427110
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
With both factors as fixed, the main effects of Temperture and postion are significant with P- values of 3.25e-14, and 0.001762.
The interaction is not significant with a p-value of 0.42411
## Part B Assume both factors are random
Temp <-as.random(Temp) # is what sets as random
position <- as.random(position)
model <-lm(obs~Temp+position+Temp*position)
gad(model)
## Analysis of Variance Table
##
## Response: obs
## Df Sum Sq Mean Sq F value Pr(>F)
## Temp 2 945342 472671 1155.518 0.0008647 ***
## position 1 7160 7160 17.504 0.0526583 .
## Temp:position 2 818 409 0.914 0.4271101
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
With both factors as random, only the main effect of temperture is significant at an alpha of .05, with a p-value of 0.0008647.
Postion and the interaction are both not significant with p- values of 0.0526583 and 0.42711
Temp <-as.random(Temp) # is what sets as random
position <- as.fixed(position)# sets as fixed
model <-lm(obs~Temp+position+Temp*position)
gad(model)
## Analysis of Variance Table
##
## Response: obs
## Df Sum Sq Mean Sq F value Pr(>F)
## Temp 2 945342 472671 1056.117 3.25e-14 ***
## position 1 7160 7160 17.504 0.05266 .
## Temp:position 2 818 409 0.914 0.42711
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
In this setting only Temperture is significant with a p-value of 3.25e-14.
The postion and 2- factor interaction are not significant with p-values of 0.05266 and 0.42711.
As we move from fixed effects to random effects the p-values get less significant. When both factors were set to random, only one effects was sognificant. When both factors were fixed, both of the main effects were significant.