I have followed the code on this solution to plot multiple regressions using dot-and-whiskers, but receive the following error when trying to replicate results and when running the code with my own data and models:
Error in match.arg(tolower(centrality), c("median", "mean", "map", "trimmed", :
'arg' should be one of “median”, “mean”, “map”, “trimmed”, “all"
I am running the following code:
nblaborforcer <- glm.nb(asylum~laborforcerl + hr_scoreL + warL + asylumL + origin-1 + offset(log(population)), data = dissertation2, control = glm.control(maxit = 500))
nb1 <- tidy(nblaborforcer)
nblaborforcefpercent<- glm.nb(asylum~laborforcefpercentL + hr_scoreL + warL + asylumL + origin-1 + offset(log(population)), data = dissertation2, control = glm.control(maxit = 500))
nb2 <- tidy(nblaborforcefpercent)
dwplot(list(nb1, nb2))+ ylim(breaks = c("laborforcerl", "laborforcefpercentL"))
When I run the following code found here to solve this problem:
dwplot(list(nb1, nb2), centrality = NULL)+ ylim(breaks = c("laborforcerl", "nblaborforcefpercent"))
I receive this error:
Error in `$<-.data.frame`(`*tmp*`, "estimate", value = numeric(0)) : replacement has 0 rows, data has 8
Here is my traceback
> traceback()
5: stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
"replacement has %d rows, data has %d"), N, nrows), domain = NA)
4: `$<-.data.frame`(`*tmp*`, "estimate", value = numeric(0))
3: `$<-`(`*tmp*`, "estimate", value = numeric(0))
2: add_NAs(df, n_models, mod_names)
1: dwplot(list(nb1, nb2), centrality = NULL)
Here is my session info:
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] broom.mixed_0.2.7 glmmTMB_1.1.2.3 lme4_1.1-26 Matrix_1.3-4 broom_0.7.6
[6] dotwhisker_0.7.4 jtools_2.1.4 boot_1.3-28 pscl_1.5.5 MASS_7.3-54
[11] plyr_1.8.6 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.5 purrr_0.3.4
[16] readr_1.4.0 tidyr_1.1.4 tibble_3.1.1 ggplot2_3.3.5 tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] httr_1.4.2 pkgload_1.1.0 jsonlite_1.7.2 splines_4.0.2
[5] modelr_0.1.8 datawizard_0.2.1 assertthat_0.2.1 statmod_1.4.35
[9] pander_0.6.4 ggstance_0.3.5 cellranger_1.1.0 bayestestR_0.11.0
[13] numDeriv_2016.8-1.1 pillar_1.6.0 backports_1.2.1 lattice_0.20-44
[17] glue_1.4.2 digest_0.6.27 rvest_1.0.0 minqa_1.2.4
[21] colorspace_2.0-0 pkgconfig_2.0.3 haven_2.4.1 scales_1.1.1
[25] generics_0.1.0 farver_2.0.3 ellipsis_0.3.1 withr_2.3.0
[29] TMB_1.7.22 cli_2.5.0 magrittr_2.0.1 crayon_1.4.1
[33] readxl_1.3.1 fs_1.5.0 fansi_0.4.1 nlme_3.1-148
[37] xml2_1.3.2 tools_4.0.2 hms_1.0.0 lifecycle_1.0.0
[41] munsell_0.5.0 reprex_2.0.0 compiler_4.0.2 rlang_0.4.10
[45] grid_4.0.2 nloptr_1.2.2.2 parameters_0.14.0 rstudioapi_0.13
[49] labeling_0.4.2 testthat_3.0.0 gtable_0.3.0 DBI_1.1.1
[53] R6_2.5.0 lubridate_1.7.10 utf8_1.1.4 rprojroot_2.0.2
[57] insight_0.14.5 desc_1.2.0 stringi_1.5.3 Rcpp_1.0.5
[61] vctrs_0.3.7 dbplyr_2.1.1 tidyselect_1.1.0
I would ideally like to have a plot with 5+ regressions.
Update
When I run the code with sample data mtcars, I get the desired result. When I use my data with negative binomial models, I get the same error.
options("install.lock"=FALSE)
install.packages("ggplot2")
library(dotwhisker)
library(dplyr)
install.packages("tidyr")
library(tidyverse)
data("mtcars")
m1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
dwplot(m1) + ylim(c("wt"))
m2 <- update(m1, . ~ . + hp) # add another predictor
m3 <- update(m2, . ~ . + am) # and another
summary(m1)
summary(m2)
dwplot(list(m1, m2, m3)) + ylim(c("wt", "cyl"))
dissertation2<-read.csv("C:/Users/diron/Google Drive/Vanderbilt/R working directory/dissertation2.csv")
library(MASS)
install.packages("pscl")
library(pscl)
install.packages("boot")
library(boot)
install.packages("jtools")
library(jtools)
nblaborforcer <- glm.nb(asylum~laborforcerl + hr_scoreL + warL + asylumL + origin-1 + offset(log(population)), data = dissertation2, control = glm.control(maxit = 500))
nb1 <- tidy(nblaborforcer)
dwplot(nb1) + ylim(c("laborforcerl"))
nblaborforcefpercent<- glm.nb(asylum~laborforcefpercentL + hr_scoreL + warL + asylumL + origin-1 + offset(log(population)), data = dissertation2, control = glm.control(maxit = 500))
nb2<-tidy(nblaborforcefpercent)
dwplot(nb2) + ylim(c("laborforcefpercentL"))
dwplot(list(nb1,nb2))
Error in match.arg(tolower(centrality), c("median", "mean", "map", "trimmed", :
'arg' should be one of “median”, “mean”, “map”, “trimmed”, “all”
What am I doing wrong? Is there a different package I have to use since I am using negative binomial models?