Question: Simulate ????=1000 values from the posterior predictive distribution for p at hours_star = 4.25 using the following steps: Generate a random vector (of length 2)
Simulate ????=1000 values from the posterior predictive distribution for p at hours_star = 4.25 using the following steps: Generate a random vector (of length 2) from the posterior distribution for the regression parameters, i.e., a multivariate normal distribution with mean mu_beta and variance-covariance matrix Sigma_beta. Use the random draw from the previous step, along with the variable x_star below (a vector that includes a intercept multiplier term and hours_star = 4.25), to generate a prediction from the likelihood function. Repeat the steps above ????=1000 times. For ????=1,...,???? , store the ???????? iteration of step 1 in the ???????? row of the ????2 matrix beta_star. Store the ???????? iteration of step 2 in the ???????? entry of the vector y_star. Finally, calculate the mean of the posterior predictive distribution and store it in a variable labeled pred_mean. HINTS: In step 2, the likelihood function will be normal, centered at ????0+????1hours , where ????0 and ????1 are the ???????? draws of the intercept and slope from step 1, hours is hours_star = 4.25, and ????2=0.1 . hours_star = 4.25 x_star = data.frame(cbind(1,hours_star)); names(x_star) = c("intercept", "hours"); x_star A data.frame: 1 2 intercept hours 1 4.25 set.seed(1899) m = 1000 #number of simulations beta_star = matrix(NA, nrow = m, ncol = 2) #matrix for posterior distribution draws y_star = matrix(NA,nrow = m, ncol = 1) # vector for posterior predictive distribution draws
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
