[Rd] Bug in "stats4" package - "confint" method

Stefano de Pretis @te|@no@depret|@ @end|ng |rom ||t@|t
Wed Apr 24 16:51:07 CEST 2019


Dear R developers,

I noticed a bug in the stats4 package, specifically in the confint method applied to “mle” objects.
In particular, when some “fixed” parameters define the log likelihood, these parameters are stored within the mle object but they are not used by the “confint" method, which retrieves their value from the global environment (whenever they still exist). 

Sample code:

> ## Avoid printing to unwarranted accuracy
> od <- options(digits = 5)
> x <- 0:10
> y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
> 
> ## Easy one-dimensional MLE:
> nLL <- function(lambda, y) -sum(stats::dpois(y, lambda, log = TRUE))
> fit0 <- mle(nLL, start = list(lambda = 5), fixed=list(y=y), nobs = NROW(y))
> confint(fit0)
Profiling...
  2.5 %  97.5 % 
 9.6524 13.6716 
> rm(y)
> confint(fit0)
Profiling...
Error in eval(expr, p) : object 'y' not found

In this sample code, I’m showing that after the removal of y from the global environment the method ‘confint’ is not able anymore to act on the object ‘fit0’.

This retrieval from the global environment is actually dangerous because it’s silent and in case the user changes the value of ‘y’ for another purpose the method ‘confint’ will return a wrong evaluation of the confidence interval without throwing any warning.

I suggest to use the fixed values that are already contained within the mle object:

> fit0 using fullcoef[grep('y', names(fit0 using fullcoef))]
 y1  y2  y3  y4  y5  y6  y7  y8  y9 y10 y11 
 26  17  13  12  20   5   9   8   5   4   8 

Additionally, the method ‘coef’ returns both the coefficient and the fixed parameters - while should return only the parameters - , while the ‘fullcoef’ method is not implemented - while present in the documentation of 'mle-class’.

Best,
Stefano
 
Center for Genomic Science of IIT using SEMM

Stefano de Pretis, PhD
Postdoctoral fellow
stefano.depretis using iit.it <mailto:stefano.depretis using iit.it>
Via Adamello 16, 20139 Milan, Italy <http://maps.google.it/maps?q=Via+Adamello+16,+20139+Milan&oe=utf-8&client=firefox-a&ie=UTF8&hq=&hnear=Via+Adamello,+16,+20139+Milano,+Lombardia&gl=it&z=16>
t: +39 02 94375046



	[[alternative HTML version deleted]]



More information about the R-devel mailing list