Question: Using R: What is the best polynomial order (1-20) modeling the structure of the following dataset (`x` vs `y`)? Your answer should include a numerical
Using R:
What is the best polynomial order (1-20) modeling the structure of the following dataset (`x` vs `y`)?
Your answer should include a numerical approach (e.g. MSE estimates) along with a convincing set of visuals supporting your answer.
```{r} set.seed(4) n <- 1000 x <- runif(n, -4, 4) mu <- ifelse(x > 0, cos(4*x), 1-sin(x)) y <- mu + rnorm(n) data <- data.frame(x=x, y=y) plot(x, y, col="black", pch=21, bg="steelblue", ylab = "y") lines(x[order(x)], mu[order(x)], col="red", lwd=3, type="l") legend("bottomleft", legend=c("E[Y|X=x], truth", "Data"), cex=.8, lty=c(1, NA), col=c("red","steelblue"), pch=c(NA, 21), pt.bg=c(NA, "steelblue")) ```
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
