search for: loglik

Displaying 20 results from an estimated 857 matches for "loglik".

2004 Jul 01
2
Individual log likelihoods of nlsList objects.
Hello all. I was wondering if the logLike.nls() and logLike.nlme() functions are still being used. Neither function seems to be available in the most recent release of R (1.9.1). The following is contained in the help file for logLik(): "classes which already have methods for this function include: 'glm', 'lm', 'n...
2011 Jan 24
2
how to get loglik parameter from splm package?
splm package is a r implemention of spatial panel data models. and the loglik paremeter is most important infomation for splm methods. but i found the loglik always been null ,it's craze to get right estimation in splm with null loglik. Any one knows the splm package and can get the right loglik ? please help me. thanks -- View this message in context: http://r.7896...
2009 Sep 23
1
Strange behaviour with global variable in C
...## DESCRIPTION OF PROGRAM ### ...I have a strange bug on a global variable in some C code which I am compiling using $ MAKEFLAGS="CFLAGS=-g -O0" R CMD SHLIB myProgram.c the global variable in question is the log likelihood. In an old version of the program I initialized this as double loglik = -999999999999999 and in current versions I initialize this as double loglik = 0.0 and long sequences of 9s do not appear anywhere in the program now (I confirmed this using the grep command in bash) A function called update_loglik() exists in the file loglik.c and so myProgram.c includes the...
2023 Aug 29
1
logLIk(lme(...))?
...nk I should be able to use lme to do that, e.g., lme(y~gp, random=y~1|gp, method='ML'). I think I should get the same answer as from lm(y~1, ...) within each level of group. I can get the same means, but I don't know how to extract the within-gp standard deviations, and the sum of logLik for the latter two does not equal the former. TOY EXAMPLE: library(nlme) set.seed(1) lmePblm <- data.frame(y=c(rnorm(5, 1, 2), rnorm(5,3,5)), gp=factor(rep(1:2, each=5))) fit22 <- lme(y~gp, lmePblm, random=~1|gp, method='ML') fitGp1 <- lm(y~1, lm...
2011 Oct 06
1
sum of functions
...s for each i and so to get another function that is a function only of betas and so to maximize it through maxLik for instance. Is that possible? In order to be more clear I give an example of how it could be: Prob1 <- function(b, i) g.yj(b,y=1,h.np,i)/(g.yj(b,y=1,h.np,i)+g.yj(b,y=0,h.np,i)) loglik.i<- function(b, i) Y[i,]*log(Prob1(b,i))+(1-Y[i,])*log(1-Prob1(b,i)) where b denotes the betas, i the observations, Y is the response vector and g.yj(b,1,h.np,i) a function that I created previously, Prob1(b,i) is a function that gives the conditional probability for observation i and loglik.i(...
2008 Mar 20
1
logLik calculations
Does the ?logLik? function applied to a ?glm? and ?glm.nb? (from MASS package) calculate the complete log-likelihoods, or does it drop the constant terms of the equation? (It?s not clear from the associated help pages, and I?ve found no reference from searching the R help mailing list) Thank you, Kelly Young
2006 Feb 22
2
does multinomial logistic model from multinom (nnet) has logLik?
I want to get the logLik to calculate McFadden.R2 ,ML.R2 and Cragg.Uhler.R2, but the value from multinom does not have logLik.So my quetion is : is logLik meaningful to multinomial logistic model from multinom?If it does, how can I get it? Thank you! ps: I konw VGAM has function to get the multinomial logistic model wit...
2011 Apr 11
1
pseudo-R by hand
...a function that computes either nagelkerkes normed pseudo-R or cox & snells pseudo-R. however, i am not clear as in the decisive step, i need to calculate the log of (maximum likelihood estimates of model divided by mle of null model). i am well aware of the functions stats::mle and stats::logLik as well as of Design::lrm. however, I'm not sure wheter mle helps me at all and I am uncertain about the logLik call I have implemented: #cox&snell lambda<- -2*log((logLik(null.model)[1]/logLik(model)[1])) out<-1-exp(-lambda/n) #nagelkerke lambda<- -2*log( logLik(model)[1]/logL...
2001 Aug 28
2
fitting a mixture of distributions with optim and max log likelihood ?
...seq(1:npnt)){ if(runif(1,0,1)<=p2){ rv[i]<-rnorm(1,m2,s2) } else{ rv[i]<-rnorm(1,m1,s1) } } return(rv) } x <- rtwonormals(50000,0,100,500,500,0.05) #and I try to fit these with (based on thread: [R] Estimating Weibull Distribution Parameters - very basic question) loglike<-function(p) -2*sum(log((1-p[5])*dnorm(x,p[1],p[2])+p[5]*dnorm(x,p[3],p[4]))) optim(c(-20,150,400,600,.035),loglike) optim(c(20,70,600,400,.095),loglike) optim(c(0,100,500,500,.05),loglike) optim(c(-20,150,400,600,.035),loglike) # three different starting values (1 and 4 the same to check repr...
2006 Dec 30
3
wrapping mle()
...)? The call in this code fails because the "ll" function cannot find the object 'y'. Modifying from the example in ?mle: library(stats4) ll <- function(ymax=15, xhalf=6) { -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE)) } fit.mle <- function(FUN, x, y) { loglik.fun <- match.fun(FUN) mle(loglik.fun, method="L-BFGS-B", lower=c(0, 0)) } fit.mle("ll", x=0:10, y=c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)) How should "fit.mle" be constructed so that "ll" works on the appropriate environment? Thanks in advance for a...
2005 Apr 19
1
behaviour of logLik and lme
Dear all, when performing a meta analysis I have two results obtained with logLik and lme, which I do not quite understand. The results are based on these data: study or var 1 0.10436 0.299111 2 -0.03046 0.121392 3 0.76547 0.319547 4 -0.19845 0.025400 5 -0.10536 0.025041 6 -0.11653 0.040469 7 0.09531 0.026399 8 0.26236 0.017918 9 -0.26136 0.020901 10 0.4574...
2006 Jun 05
2
Calculation of AIC BIC from mle
...ackages up to date Linux, SuSE 10.0 Hi I want to calculate AIC or BIC from several results from mle calculation. I found the AIC function, but it does not seem to work with objects of class mle - If I execute the following: ml1 <- mle(...) AIC(ml1) I get the following error messale: Error in logLik(object) : no applicable method for "logLik" Therefore I am using the following to calculate the AIC: #AICmle calculate AIC from mle object AICmle <- function( m, k=2) { lL <- logLik(m) edf <- attr(lL, "df") LL <- lL[1] - 2 * LL + k * edf } 1) Why is AIC not wo...
2010 May 18
1
BIC() in "stats" {was [R-sig-ME] how to extract the BIC value}
...t; core of R, as AIC is already, and then various packages could define GaGr> methods for it. MM> Well, if you look at help(AIC): >> Usage: >> AIC(object, ..., k = 2) >> Arguments: >> object: a fitted model object, for which there exists a ?logLik? >> method to extract the corresponding log-likelihood, or an >> object inheriting from class ?logLik?. >> ...: optionally more fitted model objects. >> k: numeric, the _penalty_ per parameter to be used; the default >> ?k = 2? is the classical AI...
2009 Jul 15
1
GLM Gamma Family logLik formula?
Hello all, I was wondering if someone can enlighten me as to the difference between the logLik in R vis-a-vis Stata for a GLM model with the gamma family. Stata calculates the loglikelihood of the model as (in R notation) some equivalent function of -1/scale * sum(Y/mu+log(mu)+(scale-1)*log(Y)+log(scale)+scale*lgamma(1/scale)) where scale (or dispersion) = 1, Y = the response variable, an...
2002 Sep 27
2
question regarding lm and logLik in R
It appears that the degrees of freedom reported by logLik changed between R 1.4.1 and R 1.5.1. Is this true? Detail: > I have been using the lm and logLik functions in R to develop code using > version 1.4.1. When I run it on version 1.5.1, I'm getting different > degrees of freedom with the logLik function. Version 1.5.1 seems to give...
2003 Mar 17
1
help with likelihood contour plot
Can some kind person point out my error here? I'm trying to set up a grid for a countour plot of a likelihood function. > u <- rnorm(20,9.5,2.5) > # sample of size 20 from N(9.5,2.5^2) > loglik <- function(th1,th2) { + n <- length(u) + -(n/2)*log(2*pi*th2^2)-0.5*sum((u-th1)^2/th2^2) + } > x <- seq(4.5,14.5,len=50) > y <- seq(0.5,6,len=50) > f <- outer(x, y, loglik(x,y)) Error in match.fun(FUN) : not function, character, or symbol: "loglik(x, y)" In add...
2013 Jan 31
1
LogLik of nls
Hello there, Can anyone point me to the code for logLik of an nls object? I found the code for logLik of an lm but could not find exactly what function is used for calculating the logLik of nls function? I am using the nls to fit the following model to data - Model 1: y ~ Ae^(-mx) + Be^(-nx) +c and want to understand what is the likelihood function us...
2012 Jan 20
1
nobs() and logLik()
Dear all, I am studying a bit the various support functions that exist for extracting information from fitted model objects. From the help files it is not completely clear to me whether the number returned by nobs() should be the same as the "nobs" attribute of the object returned by logLik(). If so, then there is a slight inconsistency in the methods for 'nls' objects with logLik.nls() taking zero weights into account while nobs.nls() does not. Admittedly, the help page of nobs() states that: For 'lm' and 'glm' fits, observations with zero weight are not...
2009 Feb 02
2
logLik for poisson models
Dear all, I have a very basic question: how does the logLik function work for poisson models? Example: I simulate 20 observations from a Poisson distribution with mean 800. y <- rpois(20,800) model <- glm(y ~ 1, family=poisson()) logLik(model) I would like to know what's the exact formula the function logLik uses. I looked at ?extractAIC but...
2008 Oct 16
1
lmer for two models followed by anova to compare the two models
Dear Colleagues, I run this model: mod1 <- lmer(x~category+subcomp+category*subcomp+(1|id),data=impchiefsrm) obtain this summary result: Linear mixed-effects model fit by REML Formula: x ~ category + subcomp + category * subcomp + (1 | id) Data: impchiefsrm AIC BIC logLik MLdeviance REMLdeviance 4102 4670 -1954 3665 3908 Random effects: Groups Name Variance Std.Dev. id (Intercept) 0.11562 0.34003 Residual 0.22765 0.47713 number of obs: 2568, groups: id, 107 run this model (only difference is I've removed the interact...