Question
set .seed( 1 ) # set.seed(1, sample.kind=Rounding) if using R 3.6 or later n
set.seed(1) # set.seed(1, sample.kind="Rounding") if using R 3.6 or later n <- 100 Sigma <- 9*matrix(c(1.0, 0.5, 0.5, 1.0), 2, 2) dat <- MASS::mvrnorm(n = 100, c(69, 69), Sigma) %>% data.frame() %>% setNames(c("x", "y"))
We will build 100 linear models using the data above and calculate the mean and standard deviation of the combined models. First,set the seed to 1 again(make sure to usesample.kind="Rounding"if your R is version 3.6 or later). Then, within areplicate()loop, (1) partition the dataset into test and training sets withp=0.5and usingdat$yto generate your indices, (2) train a linear model predictingyfromx, (3) generate predictions on the test set, and (4) calculate the RMSE of that model. Then, report the mean and standard deviation (SD) of the RMSEs from all 100 models.
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