Skip to content
WonderLand
Go back

Linear Regression Assignment 13

The thirteenth assignment of Linear Regression. The assignment is written in Rmarkdown, a smart syntax supported by RStudio helping with formula, plot visualization and plugin codes running.

most recommend: click here for html version of assignment, you can see codes as well as plots.

You may also find the PDF Version of this assignment from github. Or if you can cross the fire wall, just see below:

1

a

dat<-read.table("CH19PR10.txt")
names(dat)<-c('y','age','gender')
dat$age<-factor(dat$age)
dat$gender<-factor(dat$gender)
fit<-aov(data=dat,y~age*gender)
summary(fit)
library("ggpubr")
ggboxplot(dat, x = "age", y = "y", color = "gender",
          palette = c("#00AFBB", "#E7B800"))

b

for (i in c(1,2,3,4,5,6)){
  print (sum(fit$residuals[(6*(i-1)+1):(6*i)]))
}

Yes, they sum to zero for each treatment.

c

par(mfrow=c(1,2))
stripchart(split(resid(fit), dat$gender), method = "stack",  pch = 19)
abline(h = seq(2, 4)-0.1)
title("Aligned Residual Dot Plot gender")
stripchart(split(resid(fit), dat$age), method = "stack",  pch = 19)
abline(h = seq(2, 4)-0.1)
title("Aligned Residual Dot Plot age")

d

rq<-c()
for (i in c(1:36)) {
  qq<-qnorm((i-3/8)/(36+1/4))
  rq<-c(rq,qq)
}
plot(rq,sort(fit$residuals))
abline(0,1)
cor(rq,sort(fit$residuals))**2

when n = 36 and significance value = 0.05, the Critical Values for Coefficient of Correlation between Ordered Residuals and Expected Values under Normality is 0.97. And the correlation calculated is 0.9720399. So it appears reasonable.

e

par(mfrow=c(1,2))
arrofres = matrix(nrow = 6,ncol = 6)
for (i in c(1,2,3,4,5,6)){
  arrofres[i,]<-fit$residuals[(6*(i-1)+1):(6*i)]
}
matplot(arrofres)
plot(fit$residuals,type = 'b')

residuals in each treatment’s sum is equal to zero, and it seems that the residuals has no relation with treatments.

2

a

interaction.plot(dat$age,dat$gender,dat$y,type="b",col=c("red","blue"),pch=c(16,18))

age has larger effect and gender has small effect, since they are nearly parrallel, they have little interaction.

b

fit<-aov(data=dat,y~age*gender)
anova(fit)

age, it has the largest SSR.

c

fit<-aov(data=dat,y~age*gender)
anova(fit)
qf(0.95,2,30)
1-pf(1.0581,2,30)

d

qf(0.95,2,2)
qf(0.95,1,2)
1-pf(66.2907,2,2)
1-pf(2.2791,1,2)

i. Factor A (age) main effect

ii. Factor B (gender) main effect

f

Yes, age has large effect and gender has little effect, and there are no apparent interactions

g


Share this post on:

Previous Post
Artificial Intelligence and Wittgenstein's use theory of meaning
Next Post
Equilibrium inspiring AI