3

I obtain an error when using stargazer in conjunction with polr from the MASS package in R. Here is an example:

library(MASS)
library(stargazer)

# Fake data
set.seed(1234)
fake_data <- data.frame(y = as.factor(sample.int(4, 20, replace = TRUE)),
                        x1 = rnorm(20, mean = 1, sd = 1),
                        x2 = rnorm(20, mean = -1, sd = 1))

# Ordered logistic regression
o_log <- MASS::polr(y ~ x1 + x2,
                    data = fake_data,
                    Hess = TRUE, method = "logistic")

summary(o_log)

# Create regression table
stargazer(o_log)

I receive the following error message:

% Error: Unrecognized object type.

Does anyone know how to solve this? Thanks in advance.

P.S.: I'm on OS X 10.13, using R 3.4.3, MASS 7.3.47, and stargazer 5.2.

EDIT: According to stargazer's vignette, objects from polr should be supported.

John Coleman
  • 51,337
  • 7
  • 54
  • 119
Dan
  • 57
  • 4
  • What line is throwing the error? – John Coleman Dec 11 '17 at 15:15
  • The last call, i.e. stargazer(o_log). – Dan Dec 11 '17 at 15:17
  • It does seem to be a bug in the stargazer package. I get the same error message when I run it on Windows, and you are correct that the documentation for `stargazer()` indicates that it should work with objects of class `polr`. I don't know enough about the package to suggest a work-around. – John Coleman Dec 11 '17 at 15:42
  • The bug here appears to be stargazer's use of `$call` to determine the object type. See https://stackoverflow.com/questions/27931317/using-stargazer-with-a-list-of-lm-objects-created-by-lapply-ing-over-a-split-dat – Frank Apr 07 '19 at 20:29

3 Answers3

1

I don't know the reason but when I change MASS::polr into plor, the error is removed and it works fine. It seems that it is a bug of package stargazer.

Dan
  • 57
  • 4
DavidYQY
  • 26
  • 2
1

I encountered the same problem. For some strange reason, this only happens when you call the function using :: (in your case: MASS::polr). It doesn't happen when you first load the package via library(MASS) and then call the specific function.

See: Why do I get different results when using library(MASS) vs. MASS::?

iunda
  • 89
  • 7
1

I guess it was because you didn't load the MASS library and instead called the function using ::. MASS library doing some updates on how summary works for polr, which is being used by stargazer to generate the table. By not loading the library, the update was not happened, hence bringing you some trouble with stargazer.

reksoadi
  • 11
  • 1