By using R language, the le indexnger.txt records the length and width of the in
ID: 3863879 • Letter: B
Question
By using R language, the le indexnger.txt records the length and width of the index finger of 8
adults.(Length is explanatory variable)
(a) Read in the data set indexnger.txt" and print it out.
(b) Draw a scatterplot of the width and length.
(c) Find out the longest finger lengths of both male and female. Then mark this
two points in the scatterplot in (a). You can use any aesthetic feature you like
as long as these two points can be distinguished from other points.
(d) Draw a new scatterplot, but substitute all the points with letter F" or M"
according to the gender.(Hint: pch = as.character(sex)). For male the female,
conduct the linear regression separately to determine the relationship of width
and length of fingers. Calculate the coefficients of these two models. Then you
can use the results from the linear regression to draw two predicted lines on
the scatterplot above by different line types (One line for male and the other
for female).
Explanation / Answer
First of all, do you really need R to compute the MLE? Please note that MLE in many cases have explicit formula. Second of all, for some common distributions even though there are no explicit formula, there are standard (existing) routines that can compute MLE. Example of this catergory include Weibull distribution with both scale and shape parameters, logistic regression, etc. If you still cannot nd anything usable then the following notes may be useful. We start with a simple example so that we can cross check the result. Suppose the observations X1,X2,...,Xn are from N(µ,2) distribution (2 parameters: µ and 2). The log likelihood function is X(Xi µ)2 22 1/2log21/2log2 + logdXi (actually we do not have to keep the terms 1/2log2 and logdXi since they are constants. In R software we rst store the data in a vector called xvec
xvec <- c(2,5,3,7,-3,-2,0) # or some other numbers
then dene a function (which is negative of the log lik)
fn <- function(theta) { sum ( 0.5*(xvec - theta[1])^2/theta[2] + 0.5* log(theta[2]) ) }
where there are two parameters: theta[1] and theta[2]. They are components of a vector theta. then we try to nd the max (actually the min of negative log lik)
nlm(fn, theta <- c(0,1), hessian=TRUE)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.