Re: [R] negative log likelihood

2009-11-09 Thread Bernardo Rangel Tura
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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] negative log likelihood

2009-11-09 Thread Colin Millar
Sounds like a homework question ...
 
if y = a + bx + e,  where e ~ N(0, sigma^2)
 
the log likelihood of the slope parameter and intercept parameters, a and b, 
and variance sigma^2 given n data points y and covariates x is
 
f(a,b, sigma; y, x) = -0.5*n*log(2 * pi) - n*log(sigma) - 0.5 / sigma^2 * sum_i 
[ (y_i - (a + b*x_i))^2 ]
 
You can simplyfiy this function if you condition on the variance and intercept. 
 
You are then left with a simple function coresponding to the log-likelihood 
curve.
This function is trivial to minimise.
 
Hope this helps.
Colin.
 



From: r-help-boun...@r-project.org on behalf of mat7770
Sent: Sun 08/11/2009 19:12
To: r-help@r-project.org
Subject: [R] negative log likelihood




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.
--
View this message in context: 
http://old.nabble.com/negative-log-likelihood-tp26256881p26256881.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
__



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] negative log likelihood

2009-11-08 Thread mat7770

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. 
-- 
View this message in context: 
http://old.nabble.com/negative-log-likelihood-tp26256881p26256881.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.