Re: [R] Trying to write a linear regression using MLE and optim()

2005-05-31 Thread Gabor Grothendieck
On 5/30/05, Ajay Shah [EMAIL PROTECTED] wrote: I wrote this: # Setup problem x - runif(100) y - 2 + 3*x + rnorm(100) X - cbind(1, x) # True OLS -- lm(y ~ x) # OLS likelihood function -- ols.lf - function(theta, K, y, X) { beta - theta[1:K] sigma - exp(theta[K+1]) e - (y -

[R] Trying to write a linear regression using MLE and optim()

2005-05-30 Thread Ajay Shah
I wrote this: # Setup problem x - runif(100) y - 2 + 3*x + rnorm(100) X - cbind(1, x) # True OLS -- lm(y ~ x) # OLS likelihood function -- ols.lf - function(theta, K, y, X) { beta - theta[1:K] sigma - exp(theta[K+1]) e - (y - X%*%beta)/sigma logl - sum(log(dnorm(e))) return(logl) }