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
Requ... View full answer
Get step-by-step solutions from verified subject matter experts
