Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using R, Exercise 3 (Simulating SLR) Consider the model with en N where Bo-3 and B1-7 Before answering the following parts, set a seed value

Using R,

image text in transcribed

image text in transcribed

Exercise 3 (Simulating SLR) Consider the model with en N where Bo-3 and B1-7 Before answering the following parts, set a seed value equal to your birthday, as was done in the previous assignment birthday18760613 set.seed (birthday) (a) Use R to simulate n 50 observations from the above model. For the remainder of this exercise, use the following "known" values of a x - runif(n -50, 0, 10) You may use the sim_slr function provided in the text. Store the data frame this function returns in a variable of your choice. Note that this function calls y response and r predictor (b) Fit a model to your simulated data. Report the estimated coefficients. Are they close to what you would expect? Briefly explain. (c) Plot the data you simulated in part (a). Add the regression line from part (b). Hint: Keep the two commands in the same chunk, so R knows what plot to add the line to when knitting your .Rmd file. (d) Use R to repeat the process of simulating n-50 observations from the above model 2000 times. Each time fit a SLR model to the data and store the value of B1 in a variable called beta hat 1. Some hints: .Use a for loop . Create beta_hat_1 before writing the for loop. Make it a vector of length 2000 where each element is Inside the body of the for loop, simulate new y data each time. Use a variable to temporarily store this data together with the known z data as a data frame .After simulating the data, use 1mC) to fit a regression. Use a variable to temporarily store this output . Use the coef ) function and [] to extract the correct estimated coefficient Use beta_hat 1[i] to store in elements of beta_hat 1 . See the notes on Distribution of a Sample Mean for some inspiration You can do this differently if you like. Use of these hints is not required. (e) Report the mean and standard deviation of beta_hat_1. Do either of these look familiar? (f) Plot a histogram of beta_hat_1. Comment on the shape of this histogram. Exercise 3 (Simulating SLR) Consider the model with en N where Bo-3 and B1-7 Before answering the following parts, set a seed value equal to your birthday, as was done in the previous assignment birthday18760613 set.seed (birthday) (a) Use R to simulate n 50 observations from the above model. For the remainder of this exercise, use the following "known" values of a x - runif(n -50, 0, 10) You may use the sim_slr function provided in the text. Store the data frame this function returns in a variable of your choice. Note that this function calls y response and r predictor (b) Fit a model to your simulated data. Report the estimated coefficients. Are they close to what you would expect? Briefly explain. (c) Plot the data you simulated in part (a). Add the regression line from part (b). Hint: Keep the two commands in the same chunk, so R knows what plot to add the line to when knitting your .Rmd file. (d) Use R to repeat the process of simulating n-50 observations from the above model 2000 times. Each time fit a SLR model to the data and store the value of B1 in a variable called beta hat 1. Some hints: .Use a for loop . Create beta_hat_1 before writing the for loop. Make it a vector of length 2000 where each element is Inside the body of the for loop, simulate new y data each time. Use a variable to temporarily store this data together with the known z data as a data frame .After simulating the data, use 1mC) to fit a regression. Use a variable to temporarily store this output . Use the coef ) function and [] to extract the correct estimated coefficient Use beta_hat 1[i] to store in elements of beta_hat 1 . See the notes on Distribution of a Sample Mean for some inspiration You can do this differently if you like. Use of these hints is not required. (e) Report the mean and standard deviation of beta_hat_1. Do either of these look familiar? (f) Plot a histogram of beta_hat_1. Comment on the shape of this histogram

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions