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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started