Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi this is a regression analysis. Below is a example about model selection #####

ID: 2925731 • Letter: H

Question

hi

this is a regression analysis.

Below is a example about model selection

###########################And code is

rm(list = ls())
set.seed(61)
x <- seq(1,10,by=0.09)
true <- exp(0.1+0.02*x^2)
y <- true+rnorm(length(x),0,1.5)


fit <- lm(y~poly(x,6))


plot(fitted(fit),x,type="l",xlim = c(0,10),ylim = c(-2,10))
par(new=TRUE)
plot(y,x,xlim = c(0,10),ylim = c(-2,10))
par(new=TRUE)
plot(true,x,xlim = c(0,10),ylim = c(-2,10),type = "l",lty=2)

#######!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

But problem is that

if i make R-codes like

fit1 <- lm(y~poly(x,1)) ; fit2 <- lm(y~poly(x,2)) ; fit3 <- lm(y~poly(x,3)) ; fit4 <- lm(y~poly(x,4)) ; fit5 <- lm(y~poly(x,5)) ; fit6 <- lm(y~poly(x,6)) ; fit7 <- lm(y~poly(x,7))

then how do i make below box graph at x=5 ??

In graph xlab is model, and ylab is fitted value...

(the middle dotted line is a value exp(0.1+0.02*x^2) at x=5)

=exp (0.1 +0.020 ?), n= 100, (zi,Vi ),i-1, , 100, x-1 (0.09) 10g ~ M(0.1.52) set the model : f6(x)- 3 1-0

Explanation / Answer

Just run the following code:

##############################################################
rm(list = ls())
set.seed(61)
x <- seq(1,10,by=0.09)
true <- exp(0.1+0.02*x^2)
y <- true+rnorm(length(x),0,1.5)

mt <- numeric(length(x))
for(i in 1:7)
{
fit <- lm(y~poly(x,i))
fitted(fit)
mt <- rbind(mt,fitted(fit))
}

mt <- mt[-1,]

boxplot.matrix(mt,use.cols = FALSE)

##############################################################