Question: Please solve it by using R. This code is supposed to evaluate the log likelihood for the iid multivariate normal model. = logL function(Y, mu,

Please solve it by using R. This code is supposed to evaluatePlease solve it by using R.

This code is supposed to evaluate the log likelihood for the iid multivariate normal model. = logL function(Y, mu, Sigma) { n = nrow(Y); p=ncol(Y) ds = det (Sigma) retval = -.5*n* log(ds) Si = solve (Sigma) for(i in 1:n) { yi = matrix(y[i,]-mu, ncol=1) retval = retval - .5 * t(yi) %*% Si %*% yi } return(retval) } Is the code correct? This code will be slow for large n because of the loop over observations. "Vectorize the code by writing everything using matrix operations. Check that your code is faster than the simple code above. Again simulate data but just use p = 2 so that we have 5 parameters (2 in u and 3 in ). Plot the log likelihood versus each of the 5 parameters. in u and one at a time keeping the other 4 parameters fixed at the mle values. You want to see that the max is indeed obtained at the mle. Note that when you vary an element of , keeping the others fixed, you need to limit the range so that stays positive definite. This code is supposed to evaluate the log likelihood for the iid multivariate normal model. = logL function(Y, mu, Sigma) { n = nrow(Y); p=ncol(Y) ds = det (Sigma) retval = -.5*n* log(ds) Si = solve (Sigma) for(i in 1:n) { yi = matrix(y[i,]-mu, ncol=1) retval = retval - .5 * t(yi) %*% Si %*% yi } return(retval) } Is the code correct? This code will be slow for large n because of the loop over observations. "Vectorize the code by writing everything using matrix operations. Check that your code is faster than the simple code above. Again simulate data but just use p = 2 so that we have 5 parameters (2 in u and 3 in ). Plot the log likelihood versus each of the 5 parameters. in u and one at a time keeping the other 4 parameters fixed at the mle values. You want to see that the max is indeed obtained at the mle. Note that when you vary an element of , keeping the others fixed, you need to limit the range so that stays positive definite

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!