library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.3
library(lsmeans)
## Warning: package 'lsmeans' was built under R version 3.6.3
## Loading required package: emmeans
## Welcome to emmeans.
## NOTE -- Important change from versions <= 1.41:
## Indicator predictors are now treated as 2-level factors by default.
## To revert to old behavior, use emm_options(cov.keep = character(0))
## The 'lsmeans' package is now basically a front end for 'emmeans'.
## Users are encouraged to switch the rest of the way.
## See help('transition') for more information, including how to
## convert old 'lsmeans' objects and scripts to work with 'emmeans'.
h<-read.csv("C:/Users/User/Desktop/Helicopter - Sheet1.csv",header = T)
h$Wing.Length <- as.factor(h$Wing.Length)
#anova test
atest<-aov(Flight.Time..seconds.~Wing.Length, data = h)
summary(atest)
## Df Sum Sq Mean Sq F value Pr(>F)
## Wing.Length 3 6.143 2.0478 138.4 <2e-16 ***
## Residuals 28 0.414 0.0148
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#residual plot - check equal variance and residual normality
#plot(lm(Flight.Time..seconds.~Wing.Length, data = h),1)#Check linearity(not asked in the assignment)
plot(lm(Flight.Time..seconds.~Wing.Length, data = h),2)#Check normality of the residuals
plot(lm(Flight.Time..seconds.~Wing.Length, data = h),3)#Check homogeneity(equal variance)
#plot(lm(Flight.Time..seconds.~Wing.Length, data = h),5)#Check independence of error terms(not asked)
Based on the qq-plot, except for few points, the residuals approximately follow the diagonal line, which indicates that the residual normality holds.
The scale-location plot shows that the residuals seem to be equally spread along the scale of the predictors, thus the equal variance assumption holds.
#Doublecheck-qqplot
#themodel = lm(Flight.Time..seconds.~Wing.Length, data = h)
#stdres = rstandard(themodel)
#qqnorm(stdres)
#qqline(stdres)
#Check linear trend and quadratic trend
contrasts(h$Wing.Length) <- contr.poly(4)
summary.aov(atest,split=list(Wing.Length=list("Linear"=1, "Quadratic" = 2)))
## Df Sum Sq Mean Sq F value Pr(>F)
## Wing.Length 3 6.143 2.0478 138.37 < 2e-16 ***
## Wing.Length: Linear 1 0.735 0.7350 49.66 1.15e-07 ***
## Wing.Length: Quadratic 1 0.480 0.4800 32.43 4.17e-06 ***
## Residuals 28 0.414 0.0148
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The above table shows that the p-value for linear and quadratic trend is less than .05, meaning that,under .05 significance level, there is a significant linear and quadratic trend in flight times.