Question: R code assignment STAT 231 Assignment 3 Download the Assignment 3 Template which is posted as a Word document on Learn. Your assignment submission must

R code assignment
R code assignment STAT 231 Assignment 3 Download the Assignment 3 Template

STAT 231 Assignment 3 Download the Assignment 3 Template which is posted as a Word document on Learn. Your assignment submission must be typed and follow the template exactly. If you wish you may create your own document in Google Docs or LaTeX or using another word processor but it must follow the same layout as in the provided Word document. This requirement is to help the TAs mark your assignment more easily. Create a .pdf file of your assignment. Crowdmark only accepts .pdf files. Upload your assignment to Crowdmark. Here is a useful link for all information related to Crowdmark assessments: https://crowdmark.com/help/ The code for this assignment is posted both as a text file called RCodeAssignment3.txt and an R file called RCodeAssignment3R.R which are posted in the Assignment 3 folder under Content on Learn. Problem 1 - Binomial approximate confidence intervals The purpose of this problem is to use the software R to calculate approximate confidence intervals for the unknown parameter theta in a Binomial experiment using both the approximate confidence interval based on the asymptotic Gaussian pivotal quantity and the 15% likelihood interval which is also an approximate 95% confidence interval based on the Likelihood Ratio statistic. As well the sampling distribution of the likelihood ratio statistic is examined by using simulation. Run the following R code. ################################################################################### # Run this code only once library(MASS) # truehist is in the library MASS ################################################################################### ################################################################################### # Problem 1: Binomial confidence intervals and sampling distribution of likelihood ratio statistic id0.9) {theta=li[,1] & theta=li[,1] & theta cat("n = ",n," theta = ",theta,"\ ") n = 30 theta = 0.8336096 # display values > cibi[1:10,1:2] # Look at first 10 approximate 95% confidence intervals [,1] [,2] [1,] 0.6999722 0.9666944 [2,] 0.6568618 0.9431382 [3,] 0.4979767 0.8353566 [4,] 0.7926464 1.0073536 [5,] 0.6568618 0.9431382 [6,] 0.7450226 0.9883107 [7,] 0.7926464 1.0073536 [8,] 0.6999722 0.9666944 [9,] 0.7450226 0.9883107 [10,] 0.6153150 0.9180183 > prop cat("proportion of approximate 95% confidence intervals which contain true value of theta = ",prop,"\ ") proportion of approximate 95% confidence intervals which contain true value of theta = 0.8914 > li[1:10,1:2] [,1] [1,] 0.6764578 [2,] 0.6367535 [3,] 0.4903719 [4,] 0.7618115 [5,] 0.6367535 [6,] 0.7179737 [7,] 0.7618115 [8,] 0.6764578 [9,] 0.7179737 [10,] 0.5984359 # Look at first ten 15% likelihood intervals [,2] 0.9363108 0.9146738 0.8159170 0.9738560 0.9146738 0.9562090 0.9738560 0.9363108 0.9562090 0.8916837 > prop=li[,1] & that cat("proportion of 15% likelihood intervals which contain true value of theta = ",prop,"\ ") proportion of 15% likelihood intervals which contain true value of theta = 0.9544 > cat("n = ",n," theta = ",theta,"\ ") n = 100 theta = 0.8336096 # display values > cibi[1:10,1:2] # Look at first 10 approximate 95% confidence intervals [,1] [,2] [1,] 0.7446993 0.8953007 [2,] 0.8163075 0.9436925 [3,] 0.7919905 0.9280095 [4,] 0.7563760 0.9036240 [5,] 0.7563760 0.9036240 [6,] 0.6988077 0.8611923 [7,] 0.7331090 0.8868910 [8,] 0.8163075 0.9436925 [9,] 0.7446993 0.8953007 [10,] 0.7331090 0.8868910 > prop cat("proportion of approximate 95% confidence intervals which contain true value of theta = ",prop,"\ ") proportion of approximate 95% confidence intervals which contain true value of theta = 0.9436 > li[1:10,1:2] [,1] [1,] 0.7376807 [2,] 0.8074470 [3,] 0.7837396 [4,] 0.7490357 [5,] 0.7490357 [6,] 0.6929403 [7,] 0.7263601 [8,] 0.8074470 [9,] 0.7376807 [10,] 0.7263601 # Look at first ten 15% likelihood intervals [,2] 0.8863831 0.9335610 0.9182707 0.8944542 0.8944542 0.8530908 0.8781662 0.9335610 0.8863831 0.8781662 > prop=li[,1] & that cat("proportion of 15% likelihood intervals which contain true value of theta = ",prop,"\ ") proportion of 15% likelihood intervals which contain true value of theta = 0.9538 Run the R code for this problem again except modify the line "id=li[,1] & theta cat("n = ",n," theta = ",theta,"\ ") n = 20 theta = 8 # display values > ciexp[1:10,1:2] # Look at first 10 approximate 95% confidence intervals [,1] [,2] [1,] 5.566600 14.252862 [2,] 5.280761 13.520992 [3,] 2.667126 6.828977 [4,] 3.874224 9.919661 [5,] 5.992533 15.343433 [6,] 3.120172 7.988966 [7,] 4.192294 10.734054 [8,] 4.614491 11.815057 [9,] 4.196023 10.743603 [10,] 4.966030 12.715147 > prop cat("proportion of approximate 95% confidence intervals which contain true value of theta = ",prop,"\ ") proportion of approximate 95% confidence intervals which contain the true value of theta = 0.9246 > li[1:10,1:2] [,1] [1,] 6.602221 [2,] 6.263204 [3,] 3.163324 [4,] 4.594993 [5,] 7.107457 [6,] 3.700655 [7,] 4.972236 [8,] 5.472980 [9,] 4.976660 [10,] 5.889920 # Look at first ten 15% likelihood intervals [,2] 15.849327 15.035480 7.593868 11.030757 17.062053 8.883794 11.936374 13.138463 11.946993 14.139372 > prop=li[,1] & that cat("proportion of 15% likelihood intervals which contain true value of theta = ",prop,"\ ") proportion of 15% likelihood intervals which contain true value of theta = 0.9442 Run the R code for this problem again except modify the line "id=cisig[,1] & sig cat("mu = ", mu, ", sigma = ", sig,"\ ") mu = 8 , sigma = 5 #display values of mu and sigma > cimu[1:10,1:2] #Look at first ten 95% confidence intervals for mu [,1] [,2] [1,] 6.244030 10.164982 [2,] 6.697515 9.783502 [3,] 6.212403 9.020471 [4,] 4.624907 9.944456 [5,] 7.704320 11.294890 [6,] 6.578151 11.437126 [7,] 5.346232 9.403112 [8,] 5.838531 9.540677 [9,] 5.704073 9.729931 [10,] 5.110502 9.524473 > prop cat("proportion of 95% confidence intervals which contain true value of mu = ",prop,"\ ") proportion of 95% confidence intervals which contain true value of mu = 0.9454 > cisig[1:10,1:2] #Look at first ten 95% confidence intervals for sigma [,1] [,2] [1,] 3.708505 6.607207 [2,] 2.918779 5.200203 [3,] 2.655918 4.731881 [4,] 5.031321 8.963985 [5,] 3.396023 6.050478 [6,] 4.595703 8.187871 [7,] 3.837067 6.836258 [8,] 3.501554 6.238495 [9,] 3.807726 6.783983 [10,] 4.174810 7.437994 > prop=cisig[,1] & sig cat("proportion of 95% confidence intervals which contain true value of sigma = ",prop,"\ ") proportion of 95% confidence intervals which contain true value of sigma = 0.9492 Problem 4: Tests of hypotheses The purpose of this problem is to use the software R to test the hypothesis H0 : = 0 for Binomial, Poisson and Exponential data using the likelihood ratio statistic and the approximate Normal test statistic. Run the following R code. ################################################################################### # Problem 4: id

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 Mathematics Questions!