[R] Error in pglm function when performing logit regression on Panel Data
Marc Schwartz
m@rc_@chw@rtz @end|ng |rom me@com
Tue Apr 23 21:23:42 CEST 2019
> On Apr 23, 2019, at 2:43 PM, Paul Bernal <paulbernal07 using gmail.com> wrote:
>
> Dear friends,
>
> The following error is generated when trying to fit a logistic regression
> with the pglm function:
>
>> PGLM_Model2 <-
> pglm(dataframe2$TRANSIT~dataframe2$Draft+dataframe2$TOTALCOST+dataframe2$BUNKER+dataframe2$CHARTERVALUE,
> effect=c("twoways"), family=binomial('logit'), index=dataframe2$ID,
> data=dataframe2)
> Error in pdata.frame(data, index) :
> 'index' can be of length 3 at the most (one index variable for
> individual, time, group)
>
> This doesn´t make sense to me because the maximum length for ID is 3 and I
> checked it twice.
>
> A few things to keep in mind:
> 1. I am using R version 3.5.3
> 2. My worstation has Windows 8 and it is a 64-bit OS
>
> I would like to know what I´m doing wrong and how to solve this issue (if
> possible). I provide a dput() of my dataset below:
>
> dput(dataframe2)'
<snip of dput output>
> Any guidance will be greatly appreciated,
>
> Best regards,
>
> Paul
Hi Paul,
I do not use pglm, but installed it.
Thanks for providing the dput() output of your data frame.
As is typical with R modeling functions, there is a reason for the 'data' argument, rather than specifying the 'dataframe$' prefix syntax for each DV and IV.
It shortens the code required to specify the formula, but perhaps more importantly, it defines the environment within which the function can find the variables to be used by the function, as specified by the various arguments.
In this case, that is critical, since, as per the examples in ?pglm, the 'index' argument is to be specified as a character vector and not as the vector objects themselves. That is, use "ID" and not ID. Therefore, the function will search for the vector/column named "ID" within the dataframe2 object, which is the argument to 'data'.
Unfortunately, the help for the function does not make it clear that the value for 'index' should be a character vector, it simply says 'the index'. Thus one needs to look at the examples for some guidance.
You might want to point that out to the maintainer of the package (copied here now) as an improvement in the documentation.
Thus:
> pglm(TRANSIT ~ Draft + TOTALCOST + BUNKER + CHARTERVALUE, data = dataframe2, effect = "twoways", family = binomial("logit"), index = "ID")
Maximum Likelihood estimation
Newton-Raphson maximisation, 0 iterations
Return code 100: Initial value out of range.
You now have other issues to deal with, which appear to be coming from the maxLik() function used from the package of the same name, which is a dependency for pglm, and I will leave those to you to resolve, probably using the 'start' argument to pglm().
Regards,
Marc Schwartz
More information about the R-help
mailing list