search for: llik

Displaying 13 results from an estimated 13 matches for "llik".

Did you mean: lli
2011 Jul 01
2
Help fix last line of my optimization code
Hi I need help figure out how to fix my code. When I call into R >optimize(llik,init.params=F) I get this error message ####Error in optimize(llik, init.params = F) : element 1 is empty; the part of the args list of 'min' being evaluated was: (interval)#### My data and my code looks like below. R_j R_m 0.002 0.026567296 0.01 0.003194435 . . . . . . ....
2007 Apr 18
3
Problems in programming a simple likelihood
...ion, I am trying to learn to program likelihoods in R. I started with a simple probit model but am unable to get the code to work. Any help or suggestions are most welcome. I give my code below: ************************************ mlogl <- function(mu, y, X) { n <- nrow(X) zeta <- X%*%mu llik <- 0 for (i in 1:n) { if (y[i]==1) llik <- llik + log(pnorm(zeta[i,], mean=0, sd=1)) else llik <- llik + log(1-pnorm(zeta[i,], mean=0, sd=1)) } return(-llik) } women <- read.table("~/R/Examples/Women13.txt", header=TRUE) # DATA # THE DATA SET CAN BE ACCE...
2009 Jul 19
1
trouble using optim for maximalisation of 2-parameter function
...am having trouble using "optim". I want to maximalise a function to its parameters [kind of like: univariate maximum likelihood estimation, but i wrote the likelihood function myself because of data issues ] When I try to optimize a function for only one parameter there is no problem: llik.expo<-function(x,lam){(length(x)*log(lam))-(length(x)*log(1-exp(-1*lam* *cons*)))-lam*sum(x)} cons<- data<-c(.............) expomx<-optimize(llik.expo,c(0,100),maximum=TRUE,tol=0.0001,x=data) expomx To optimize to two parameters you can't use "optimize", so I tried t...
2011 Jul 03
3
Hint improve my code
Hi I have developed the code below. I am worried that the parameters I want to be estimated are "not being found" when I ran my code. Is there a way I can code them so that R recognize that they should be estimated. This is the error I am getting. > out1=optim(llik,par=start.par) Error in pnorm(au_j, mean = b_j * R_m, sd = sigma_j) : object 'au_j' not found #Yet al_j,au_j,sigma_j and b_j are just estimates that balance the likelihood function? llik=function(R_j,R_m) if(R_j< 0) { sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_...
2011 Jul 04
3
loop in optim
...rect my loop function. I want optim to estimates al_j; au_j; sigma_j; b_j by looking at 0 to 20, 21 to 40, 41 to 60 data points. The final result should have 4 columns of each of the estimates AND 4 rows of each of 0 to 20, 21 to 40, 41 to 60. ###MY code is n=20 runs=4 out=matrix(0,nrow=runs) llik = function(x) { al_j=x[1]; au_j=x[2]; sigma_j=x[3]; b_j=x[4] sum(na.rm=T, ifelse(a$R_j< 0, -log(1/(2*pi*(sigma_j^2)))- (1/(2*(sigma_j^2))*(a$R_j+al_j-b_j*a$R_m))^2, ifelse(a$R_j>0 , -log(1/(2*pi*(sigma_j^2)))-...
2005 Oct 07
2
AIC in lmer
Hello all, Is AIC calculated incorrectly in lmer? It appears as though it uses AIC = -2*logLik - 2*#parms, instead of -2*LogLik + 2*#parms? Below is output from one of many models I have tried: Generalized linear mixed model fit using PQL Formula: cswa ~ pcov.ess1k + (1 | year) Data: ptct50.5 Family: poisson(log link) AIC BIC logLik deviance 224.8466 219.19 -114.4233 228.8466
2011 Jun 14
1
Using MLE Method to Estimate Regression Coefficients
...ces for the MLE procedure # I will try the first-model first to see if I can get it to work... x<- cbind(1,x1,x2,x3) y<- as.vector(y) ones<- x[,1] # Calculate K and n for later use K <- ncol(x) K [1] 4 K1 <- K + 1 n <- nrow(x) n [1] 81 # Define the function to be optimized llik.regress <- function(par,X,Y) { X <- as.matrix(x) Y <- as.vector(y) xbeta <- X%*%par[1:K] Sig <- par[K1:K1] sum(-(1/2)*log(2*pi)-(1/2)*log(Sig^2)-(1/(2*Sig^2))*(Y-xbeta)^2) } llik.regress # Now let's use the above function to estimate the model. model <- optim(c(1,1,1,1...
2011 Jul 23
1
Extend my code to run several data at once.
...current state, it means I will have to run it 200 times manually. May you help me adjust it to accomodate several rows of R_j and print the 200 results. ***Please do not get intimidated by the maths in the code.*** my code ###### afull=read.table("D:/hope.txt",header=T) library(optimx) llik = function(x) { al_j=x[1]; au_j=x[2]; sigma_j=x[3]; b_j=x[4] sum(na.rm=T, ifelse(a$R_j< 0, log(1 / ( sqrt(2*pi) * sigma_j) )- (1/( 2*sigma_j^2 ) ) * ( (a$R_j+al_j-b_j*a$R_m)^2 ) , ifelse(a$R_j>0 , log(1 / ( sqrt(2*pi) * sigma_j) )-...
2003 Sep 08
1
Probit and optim in R
...<- 1.0 + 2.0 * x1 - 3.0 * x2 + rnorm(1000) y <- latentz y[latentz < 1] <- 0 y[latentz >=1] <- 1 #Option export of data to check estimates in STATA #SimProbit <- data.frame(y, x1, x2) #write.table(SimProbit, 'a:/SimProbit') x <- cbind(1, x1 ,x2) #Define Likelihood llik.probit<-function(par, X, Y){ Y <- as.matrix(y) X <- as.matrix(x) K <- ncol(X) b <-as.matrix(par[1:K]) phi<-pnorm(X%*%b, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) sum(Y*log(phi)+(1-Y)*log(1-phi)) } grad <-function(par,X,Y){ Y <- as.matrix(y) X <- as.matrix(...
2004 Jun 17
0
beta regression in R
...However, the results returned by optim in R are not reasonable in terms of the value of the log likelihood and parameter estimates. Here is my code. Does anyone see a problem with what I'm doing here? Any advice would be appreciated. Thanks. B. Dan Wood # Define the function to be optimized llik.beta <- function(par,X,YP) { X <- as.matrix(x) YP <- as.vector(y) xbeta <- X %*% par[1:K] p <- par[K1:K1] sum( -lgamma(p) +lgamma(p+(p/xbeta-p)) -lgamma(p/xbeta-p) +(p-1)*log(YP) +log(1-YP)*(p/xbeta-p-1) ) } llik.beta # Now use the above function to estimate the model. First, creat...
2011 Jul 06
1
Group Data indexed by n Variables
...au_j; sigma_j; b_j by looking at 0 to 20, > 21 to 40, 41 to 60 data points. > > The final result should have 4 columns of each of the estimates AND 4 rows > of each of 0 to 20, 21 to 40, 41 to 60. > > ###MY code is > > n=20 > runs=4 > out=matrix(0,nrow=runs) > > llik = function(x) > { > al_j=x[1]; au_j=x[2]; sigma_j=x[3]; b_j=x[4] > sum(na.rm=T, > ifelse(a$R_j< 0, -log(1/(2*pi*(sigma_j^2)))- > (1/(2*(sigma_j^2))*(a$R_j+al_j-b_j*a$R_m))^2, > ifelse(a$R_j>0 , -log(1/(2*pi*(sigma_j^2)))- &gt...
2012 May 29
1
model frame and formula mismatch with latent class analysis poLCA
...s ll=rep(0,Kmax) #vector of loglikelihood values for (j in 1:Kmax){ #fits for #classes=1,2,...,Kmax cat(j,"\n") #print current analysis number fit[[j]]<-poLCA(f,data.int,nclass=j,nrep=20,verbose=FALSE) #20 random starts bic[j]<-fit[[j]]$bic #collect BICs ll[j] <- fit[[j]]$llik #collect logliks } Then I get an ERROR saying " Error in model.matrix.default(formula, mframe) : model frame and formula mismatch in model.matrix() " What is confusing me is that the macro runs just fine when the number of items is restricted to 63 or less. I have checked this for...
2008 Jan 24
0
(lme4: lmer) mcmcsamp: Error in if (var(y) == 0)
...: initialize(value, ...) 4: initialize(value, ...) 3: new(if (is(object, "glmer")) "summary.glmer" else { if (is(object, "lmer")) "summary.lmer" else "summary.mer" }, object, isG = glz, methTitle = methTitle, logLik = llik, ngrps = sapply(object at flist, function(x) length(levels(x))), sigma = .Call(mer_sigma, object, REML), coefs = coefs, vcov = vcov, REmat = REmat, AICtab = AICframe) 2: summary(emnlp.m1) 1: summary(emnlp.m1) -- David Reitter ICCS/HCRC, Informatics, University of Edinbur...