05/6/2019The statistical model:
yt=β0+β1∗(Elevations)t+β2∗Slopet+(bs)t+ϵt
Where: -β0 is the mean response when both Elevation and Slope are 0 -β1 is the change in mean response for a 1-unit change in -elevation. Elevation is measured at the stand level, so all -plots in a stand share a single value in elevation. -β2 is the change in mean response for a 1-unit change in slope. Slope is measured at the plot level, so every plot potentially has a unique value of slope. Let’s define the parameters:
the intercept (β0) will be -1 the coefficient for elevation (β1) will be set to 0.005 the coefficient for slope (β2) will be set to 0.1
nstand = 5
nplot = 4
b0 = -1
b1 = .005
b2 = .1
sds = 2
sd = 1
Simulate other variables:
set.seed(16)
stand = rep(LETTERS[1:nstand], each = nplot)
standeff = rep( rnorm(nstand, 0, sds), each = nplot)
ploteff = rnorm(nstand*nplot, 0, sd)
Simulate elevation and slope:
elevation = rep( runif(nstand, 1000, 1500), each = nplot)
slope = runif(nstand*nplot, 2, 75)
Simulate response variable:
resp2 = b0 + b1*elevation + b2*slope + standeff + ploteff
Your tasks (complete each task in its’ own code chunk, make sure to use echo=TRUE so I can see your code):
Fit a linear mixed model with the response variable as a function of elevation and slope with stand as a random effect. Are the estimated parameters similar to the intial parameters as we defined them?
Create a function for your model and run 1000 simulations of that model.
Extract the stand and residual variances from this simulation run. Print the first 6 rows of the data.
Choose three different sample sizes (your choice) and run 1000 model simulations with each sample size. Create 3 visualizations that compare distributions of the variances for each of the 3 sample sizes. Make sure that the axes are labelled correctly. What do these graphs say about the relationship between sample size and variance?
Plot the coefficients of the estimates of elevation and slope. Hint: the x-axis should have 1000 values. Discuss the graphs.
Submit a link to this document in R Pubs to your Moodle.