Question
a. Write an R function to: (i) simulate n data points from the model, y = a + bx + error, with data points x
a. Write an R function to:
(i) simulate n data points from the model, y = a + bx + error, with data points x uniformly sampled from the range (0, 100) and with errors drawn independently from the normal distribution with mean 0 and standard deviation σ;
(ii) fit a linear regression to the simulated data; and
(iii) make a scatterplot of the data and fitted regression line. Your function should take as arguments, a, b, n, σ, and it should return the data, print out the fitted regression, and make the plot. Check your function by trying it out on some values of a, b, n, σ.
b. Repeat the example , varying the number of data points, n. What happens to the parameter estimates and uncertainties when you increase the number of observations?
c. Simulation study: Perform the previous exercise more systematically, trying out a sequence of values of n, for each simulating fake data and fitting the regression to obtain estimate and uncertainty (median and mad sd) for each parameter. Then plot each of these as a function of n and report on what you find
Step by Step Solution
3.43 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
Requ...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