简体   繁体   中英

Stargazer error with polr in R

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.

PS: 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.

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.

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::?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM