Displaying 2 results from an estimated 2 matches for "llsum".
Did you mean:
lsum
2006 Aug 26
1
problems with loop
...lihood of this model given a data set "new". This
works fine if it is used in the optim() routine with only one data set.
NLL=function(coef)
{
beta0=coef[1]
mu=coef[2]
k=coef[3]
I=coef[4]
data_sim=Model_1(beta0,mu,k,I)
LLsum=0 #log likelihood sum
for (j in 1:length(data_sim[,1]))
{
if (data_sim[j,2]<0 || data_sim[j,3]<0)
{return(1500)}
for (i in 1:length(new[,1]))
{
if (new[i,1]==data_sim[j,1] && is.na(n...
2007 Feb 17
1
Constraint maximum (likelihood) using nlm
...minimize the negative likelihood function:
# params: vector containing values of mu and sigma
# params[1] - mu, params[2]- sigma
# dat: matrix of data pairs y_i and s_i
# dat[,1] - column of y_i , dat[,2] column of s_i
negll <- function(params,dat,constant=0)
{
for(i in 1:length(dat[,1]))
{
llsum <- log( params[2]^2 + dat[i,2]^2) +
(( dat[i,1] - params[1])^2/ (params[2]^2 + dat[i,2]^2))
}
ll <- -0.5 * llsum + constant
return(-ll)
}
Using (find data attached):
data.osl <- read.table("osl.dat",header=TRUE)
data.matrix <- as.matrix(data.frame(data.osl$de,data.osl$s...