[R] pglm package: fitted values and residuals

Achim Zeileis Achim.Zeileis at uibk.ac.at
Wed Apr 24 23:37:07 CEST 2013


On Wed, 24 Apr 2013, Paul Johnson wrote:

> On Wed, Apr 24, 2013 at 3:11 AM,  <alfonso.carfora at uniparthenope.it> wrote:
>
>> I'm using the package pglm and I'have estimated a "random probit 
>> model". I need to save in a vector the fitted values and the residuals 
>> of the model but I can not do it.
>>
>> I tried with the command fitted.values using the following procedure 
>> without results:
>>
> This is one of those "ask the pglm authors" questions. You should take 
> it up with the authors of the package.  There is a specialized email 
> list R-sig-mixed where you will find more people working on this exact 
> same thing.
>
> pglm looks like fun to me, but it is not quite done, so far as I can 
> tell. Well, the authors have not gone the "extra step" to make their 
> regression objects behave like other R regression objects.  In case you 
> need alternative software, ask in R-sig-mixed. You'll learn that most of 
> these can be estimated with other packages. But I really like the 
> homogeneous user interface that is spelled out in pglm, and I expect my 
> students will run into the same questions that you have..
>
> I just downloaded their source code, you probably ought to do that so
> you can understand what they are doing.   They provide the fitting
> functions, but they do not do any of the other work necessary to make
> these functions fit together with the R class framework.  There are no
> methods for "predict", anova, and so forth.

This is only partially true. In fact, "pglm" employs the framework 
provided by the "maxLik" (by Ott Toomet and Arne Henningsen) and hence it 
inherits some of the methods that "maxLik" provides for all of its fitted 
model objects. So there is summary(), coef(), vcov(), AIC() work and you 
can leverage tools like coeftest() from "lmtest", linearHypothesis() from 
"car" or sandwich() from "sandwich" do work.

But it is certainly true that even more features would be desirable and I 
think that Yves always planned on enhancing "pglm" at some point. (After 
all it's still the initial version 0.1-0 on CRAN...)

> I'm in their R folder looking for implementations:
>
> pauljohn at pols110:/tmp/pglm/R$ grep summary *
> pauljohn at pols110:/tmp/pglm/R$ grep predict *
> pauljohn at pols110:/tmp/pglm/R$ grep class *
> pauljohn at pols110:/tmp/pglm/R$ grep fitted *
> pglm.R:  # glm models can be fitted
>
> Run
>
>> example(pglm)
>
> what can we do after that?
>
>> plot(anb)
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>  'x' is a list, but does not have components 'x' and 'y'
>
> ## Nothing.
> ## We do get a regression summary object, that's better than some
> packages provide:
>
>> anbsum <- summary(anb)
>
> ## And a coefficient table
>
>> coef(anbsum)
>                 Estimate  Std. error       t value      Pr(> t)
> (Intercept) -6.933764e-01 0.061391429 -11.294351205 1.399336e-29
> wage         1.517009e-02 0.006375966   2.379261231 1.734738e-02
> exper        1.314229e-03 0.007400129   0.177595444 8.590407e-01
> ruralyes    -8.594328e-05 0.051334716  -0.001674175 9.986642e-01
>
>> model.matrix(anb)
> Error in terms.default(object) : no terms component nor attribute
>> anova(anb)
> Error in UseMethod("anova") :
>  no applicable method for 'anova' applied to an object of class
> "c('maxLik', 'maxim')"
>> predict(anb)
> Error in UseMethod("predict") :
>  no applicable method for 'predict' applied to an object of class
> "c('maxLik', 'maxim')"
>
> So, if you want those features with these models, you'll have to get
> busy and do a lot of coding!
>
> While working on regression support lately, I've reached the conclusion 
> that if an R package that claims to "do regression" but does not provide 
> methods for summary, predict, anova, nobs, fitted, logLik, AIC, and so 
> forth, then it is not done yet. Otherwise, users like you who expect to 
> be able to run methods like fitted or such have a bad experience, as you 
> are having now.
>
> Maybe somebody reading this will remind us where the common list of R
> regression methods is listed. I know for sure I've seen a document
> about these things, but I'm baffled now trying to find it. But I'm
> sure there is one.

I'm sure that there are many. One of my attempts to write up a list is in 
Table 1 of vignette("betareg", package = "betareg").

Personally, I don't write anova() methods for my model objects because I 
can leverage lrtest() and waldtest() from "lmtest" and linearHypothesis() 
and deltaMethod() from "car" as long as certain standard methods are 
available, including coef(), vcov(), logLik(), etc.

Similarly, an AIC() method is typically not needed as long as logLik() is 
available. And BIC() works if nobs() is available in addition.

Best,
Z

>
> pj
>
>> library(pglm)
>>
>> m1_S<-pglm(Feed ~ Cons_PC_1 + imp_gen_1 + LGDP_PC_1 + lnEI_1 +
>> SH_Ren_1,data,family=binomial(probit),model="random",method="bfgs",index=c("Year","IDCountry"))
>>
>> m1_S$fitted.values
>> residuals(m1)
>>
>>
>> Can someone help me about it?
>>
>> Thanks
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list