[R] negative log likelihood
Bernardo Rangel Tura
tura at centroin.com.br
Mon Nov 9 09:49:45 CET 2009
On Sun, 2009-11-08 at 11:12 -0800, mat7770 wrote:
> I have two related variables, each with 16 points (x and Y). I am given
> variance and the y-intercept. I know how to create a regression line and
> find the residuals, but here is my problem. I have to make a loop that uses
> the seq() function, so that it changes the slope value of the y=mx + B
> equation ranging from 0-5 in increments of 0.01. The loop also needs to
> calculate the negative log likelihood at each slope value and determine the
> lowest one. I know that R can compute the best regression line by using
> lm(y~x), but I need to see if that value matches the loop functions.
Hi
If I understand your question you need extract log-likelihood for a
linear model, so you need using logLik command, see example:
set.seed(1)
x<-rpois(16,6)
y<-2*x+3+rnorm(16,sd=3)
model<-lm(y~x)
logLik(model)
'log Lik.' -40.1177 (df=3)
--
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil
More information about the R-help
mailing list