Reputation: 87
I'm trying to change my confidence intervals in stargazer()
with ci.custom
but it's not possible.
Using this exemple (used here):
library(dplyr)
library(nnet)
# create sample data
data <- tibble(
choice = rep(c("strawberry", "mango", "orange"), 100),
likes_kiwi = rbinom(300, size = 1, prob = 0.3),
inner_beauty = rnorm(n = 300, mean = 5, sd = 2)
)
m1 <- multinom(choice ~ likes_kiwi + inner_beauty, data = data)
I have :
stargazer(m1, type = "text", ci = TRUE)
# =================================================
# Dependent variable:
# -------------------------------
# orange strawberry
# (1) (2)
# -------------------------------------------------
# likes_kiwi 0.166 -0.571*
# (-0.403, 0.735) (-1.180, 0.038)
#
# inner_beauty -0.029 -0.062
# (-0.178, 0.120) (-0.212, 0.087)
#
# Constant 0.085 0.493
# (-0.767, 0.936) (-0.345, 1.332)
#
# -------------------------------------------------
# Akaike Inf. Crit. 664.198 664.198
# =================================================
# Note: *p<0.1; **p<0.05; ***p<0.01
But if I try to change the intervals with ci.custom
, it shows :
stargazer(m1, type = "text", ci.custom = list(confint(m1)))
# Error in ci.custom[[1]][, 1] : incorrect number of dimensions
Looking into .stargazer.wrap()
function, I found (~L 3891) :
user.ci.lb=ci.custom[[1]][,1], user.ci.rb=ci.custom[[1]][,2]
and then :
.get.ci.lb.1 <- function(object.name, user.given=NULL, model.num=1) {
if (!is.null(user.given)) {
if (.model.identify(object.name) == "multinom") {
if (!is.null(nrow(user.given))) { user.given <- as.vector(user.given[model.num,]) }
}
return(user.given)
}
return(NULL)
}
.get.ci.lb <- function(object.name, user.given=NULL, model.num=1) {
out <- .get.ci.lb.1(object.name, user.given, model.num)
coef.vars <- .coefficient.variables(object.name)
if (is.null(names(out))) {
if (length(out) < length(coef.vars)) {
out.temp <- rep(NA, times=length(coef.vars)-length(out))
out <- c(out, out.temp)
}
else if (length(out) > length(coef.vars)) {
out <- out[1:length(coef.vars)]
}
names(out) <- coef.vars
}
else {
out.temp <- rep(NA, times = length(coef.vars))
names(out.temp) <- coef.vars
for (i in 1:length(out)) {
name <- names(out)[i]
if (name %in% coef.vars) {
out.temp[name] <- out[i]
}
}
out <- out.temp
}
return(out)
}
(and the same form rb) where user.given
takes user.ci.lb
value ie ci.custom[[1]][,1]
.
The problem is that confidence intervals are arrays with 3 dimensions in multinom
:
confint(m1)
# , , orange
#
# 2.5 % 97.5 %
# (Intercept) -0.7666906 0.9364189
# likes_kiwi -0.4032031 0.7350409
# inner_beauty -0.1779730 0.1200524
#
# , , strawberry
#
# 2.5 % 97.5 %
# (Intercept) -0.3452642 1.33184380
# likes_kiwi -1.1797179 0.03782021
# inner_beauty -0.2115865 0.08737243
but it wants only 2 dimensions. By the way, stargazer uses .get.ci.lb
and .get.ci.lb.1
for one part of the model at the time (orange, strawberry), so I cannot give a big matrix to it.
At first I thought that making array transpositions would help but it doesn't. Do you have any idea of how to resolve the problem ?
Thanks,
Upvotes: 1
Views: 128