Closed vini-macuch-silva closed 5 years ago
Here's a more reproducible example of my workflow:
ggstatsplot::ggcoefstats(
x = RT_model_tidy)
#> Error in class(x)[[1]] %in% unsupported.mods: object 'RT_model_tidy' not found
Hi,
Your code is failing long before you get to ggstatsplot::ggcoefstats
. Both the examples you posted highlight the fact that your original model is not being found. Could be bad path information or something about your file structure.
You need to get rid of this error first.
`RT_model <- readRDS("model-outputs/RT_model.RDS")
When `RT_model <- readRDS("model-outputs/RT_model.RDS")
str(RT_model )` works you'll know you're on the right track
Hi Chuck,
Thanks very much for that. That was indeed the case when I imported the files in a wrong tab on RStudio (incomplete path information). Now that I'm doing it within the right path structure, I still get the error with ggstatsplot::ggcoefstats
. str(RT_model)
works fine.
I know why this is not working for you. For objects of class tbl
(or any other kind of dataframe), the statistic
argument should not be NULL
. This is a bug. Apologies!
I will push a change soon to solve this.
Right, thanks for the input, Indrajeet. However, I tried specifying that before, and there was still an error to do with factor levels, here:
Error in `levels<-`(`*tmp*`, value = as.character(levels)) :
factor level [5] is duplicated
Can you share what your output from brms
models look like? It's hard to diagnose what's going on without looking at the tbl
you are entering into the function.
Sure. Here's the whole thing:
# A tibble: 16 x 8
effect component group term estimate std.error conf.low conf.high
<chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 fixed cond NA (Intercept) 5.79 0.0340 5.73 5.86
2 fixed cond NA typeFal -0.0299 0.0102 -0.0503 -0.00970
3 fixed cond NA typeVer -0.000543 0.0105 -0.0218 0.0203
4 ran_pars cond item sd__(Intercept) 0.215 0.0219 0.176 0.261
5 ran_pars cond item sd__typeFal 0.0146 0.0110 0.000473 0.0399
6 ran_pars cond item sd__typeVer 0.0212 0.0133 0.00110 0.0492
7 ran_pars cond submission_id sd__(Intercept) 0.266 0.0159 0.236 0.299
8 ran_pars cond submission_id sd__typeFal 0.0268 0.0163 0.00168 0.0621
9 ran_pars cond submission_id sd__typeVer 0.0366 0.0134 0.0124 0.0642
10 ran_pars cond item cor__(Intercept).typeFal -0.0257 0.428 -0.817 0.804
11 ran_pars cond item cor__(Intercept).typeVer 0.266 0.370 -0.592 0.877
12 ran_pars cond item cor__typeFal.typeVer 0.0910 0.509 -0.858 0.910
13 ran_pars cond submission_id cor__(Intercept).typeFal 0.280 0.352 -0.506 0.887
14 ran_pars cond submission_id cor__(Intercept).typeVer 0.630 0.210 0.172 0.957
15 ran_pars cond submission_id cor__typeFal.typeVer 0.391 0.413 -0.608 0.942
16 ran_pars cond Residual sd__Observation 0.281 0.00283 0.275 0.286
structure(list(effect = c("fixed", "fixed", "fixed", "ran_pars",
"ran_pars", "ran_pars", "ran_pars", "ran_pars", "ran_pars", "ran_pars",
"ran_pars", "ran_pars", "ran_pars", "ran_pars", "ran_pars", "ran_pars"
), component = c("cond", "cond", "cond", "cond", "cond", "cond",
"cond", "cond", "cond", "cond", "cond", "cond", "cond", "cond",
"cond", "cond"), group = c(NA, NA, NA, "item", "item", "item",
"submission_id", "submission_id", "submission_id", "item", "item",
"item", "submission_id", "submission_id", "submission_id", "Residual"
), term = c("(Intercept)", "typeFal", "typeVer", "sd__(Intercept)",
"sd__typeFal", "sd__typeVer", "sd__(Intercept)", "sd__typeFal",
"sd__typeVer", "cor__(Intercept).typeFal", "cor__(Intercept).typeVer",
"cor__typeFal.typeVer", "cor__(Intercept).typeFal", "cor__(Intercept).typeVer",
"cor__typeFal.typeVer", "sd__Observation"), estimate = c(5.79418020957549,
-0.0299178294218983, -0.000543140330436366, 0.214901438289064,
0.0145870005142796, 0.0212152601138147, 0.265633253331641, 0.0268342032692802,
0.036577612834576, -0.0256856477612839, 0.266130254159324, 0.0910009988749176,
0.280384450435342, 0.629537299755329, 0.391078090510186, 0.280676574316031
), std.error = c(0.0340467311389221, 0.0102467481398605, 0.0105458815397743,
0.0218767813989946, 0.0109683166452514, 0.0133175131228213, 0.0159054036467544,
0.016340278071177, 0.013378593916756, 0.427895549336247, 0.370327479701484,
0.509081518250157, 0.352015939695904, 0.210406715087688, 0.412585303158786,
0.00283085864789277), conf.low = c(5.72869764343181, -0.0502841546638398,
-0.0217512012400585, 0.176442638000084, 0.000472546142398068,
0.00110340440165403, 0.236496895925071, 0.00168445484930733,
0.0123511951107462, -0.81651962728396, -0.592387172951057, -0.858480410089071,
-0.505662422408689, 0.172449614654224, -0.608014248669021, 0.275309086825284
), conf.high = c(5.86175766957825, -0.00969644072211255, 0.020340298583478,
0.261147443639607, 0.0398844979780345, 0.0491598171502455, 0.298768289857492,
0.0620956630791208, 0.0642347909939091, 0.804363992044674, 0.876577119518248,
0.910125087999616, 0.886647479360548, 0.956547406098323, 0.941858420921083,
0.286319019445041)), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"))
Ohhh. Now I see what the problem is. Every term in the term
column should have unique names. That is not the case in your dataframe. There are a number of repeated terms (e.g., "sd__(Intercept)"
, "sd__typeFal"
, etc.). Once you remove these repeated terms, the function works just fine. So the solution is to rename terms so that there unique term names.
# setup
set.seed(123)
library(tidyverse)
# data
df <- structure(
list(
effect = c(
"fixed",
"fixed",
"fixed",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars",
"ran_pars"
),
component = c(
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond",
"cond"
),
group = c(
NA,
NA,
NA,
"item",
"item",
"item",
"submission_id",
"submission_id",
"submission_id",
"item",
"item",
"item",
"submission_id",
"submission_id",
"submission_id",
"Residual"
),
term = c(
"(Intercept)",
"typeFal",
"typeVer",
"sd__(Intercept)",
"sd__typeFal",
"sd__typeVer",
"sd__(Intercept)",
"sd__typeFal",
"sd__typeVer",
"cor__(Intercept).typeFal",
"cor__(Intercept).typeVer",
"cor__typeFal.typeVer",
"cor__(Intercept).typeFal",
"cor__(Intercept).typeVer",
"cor__typeFal.typeVer",
"sd__Observation"
),
estimate = c(
5.79418020957549,
-0.0299178294218983,
-0.000543140330436366,
0.214901438289064,
0.0145870005142796,
0.0212152601138147,
0.265633253331641,
0.0268342032692802,
0.036577612834576,
-0.0256856477612839,
0.266130254159324,
0.0910009988749176,
0.280384450435342,
0.629537299755329,
0.391078090510186,
0.280676574316031
),
std.error = c(
0.0340467311389221,
0.0102467481398605,
0.0105458815397743,
0.0218767813989946,
0.0109683166452514,
0.0133175131228213,
0.0159054036467544,
0.016340278071177,
0.013378593916756,
0.427895549336247,
0.370327479701484,
0.509081518250157,
0.352015939695904,
0.210406715087688,
0.412585303158786,
0.00283085864789277
),
conf.low = c(
5.72869764343181,
-0.0502841546638398,
-0.0217512012400585,
0.176442638000084,
0.000472546142398068,
0.00110340440165403,
0.236496895925071,
0.00168445484930733,
0.0123511951107462,
-0.81651962728396,
-0.592387172951057,
-0.858480410089071,
-0.505662422408689,
0.172449614654224,
-0.608014248669021,
0.275309086825284
),
conf.high = c(
5.86175766957825,
-0.00969644072211255,
0.020340298583478,
0.261147443639607,
0.0398844979780345,
0.0491598171502455,
0.298768289857492,
0.0620956630791208,
0.0642347909939091,
0.804363992044674,
0.876577119518248,
0.910125087999616,
0.886647479360548,
0.956547406098323,
0.941858420921083,
0.286319019445041
)
),
row.names = c(NA, -16L),
class = c("tbl_df",
"tbl", "data.frame")
)
# checking how many times each term is repeated
df %>% dplyr::count(term)
#> # A tibble: 10 x 2
#> term n
#> <chr> <int>
#> 1 (Intercept) 1
#> 2 cor__(Intercept).typeFal 2
#> 3 cor__(Intercept).typeVer 2
#> 4 cor__typeFal.typeVer 2
#> 5 sd__(Intercept) 2
#> 6 sd__Observation 1
#> 7 sd__typeFal 2
#> 8 sd__typeVer 2
#> 9 typeFal 1
#> 10 typeVer 1
# creating a dataframe with only unique term names
unique_term_df <- df %>% dplyr::count(term) %>% dplyr::filter(n == 1L)
# subsetting dataframe to have unique term names
df1 <- dplyr::filter(df, term %in% c(unique_term_df$term))
# plot
ggstatsplot::ggcoefstats(df1)
#> Note: No model diagnostics information available for the object of class tbl_df .
#>
#> Note: For the object of class tbl_df , the argument `statistic` is not specified ('t', 'z', or 'f'),
#> so no labels will be displayed.
#>
#> Note: No p-values and/or statistic available for regression coefficients from tbl_df object, so skipping labels.
#>
Created on 2018-12-20 by the reprex package (v0.2.1)
Phew, glad to hear. Thanks a lot for your help. The interesting thing is that I initially tried filtering out the random effects, exactly so I would only have the 3 initial rows (no repeated terms), but that didn't work either.
Reopening because I think the documentation can be a bit better to help understand the user what this error is.
# data
df <- tibble::tribble(~term, ~estimate,
"x", 0.03,
"x", 0.05)
# attempt to create plot
ggstatsplot::ggcoefstats(df)
#> Note: No model diagnostics information available for the object of class tbl_df .
#>
#> Note: For the object of class tbl_df , the argument `statistic` is not specified ('t', 'z', or 'f'),
#> so no labels will be displayed.
#>
#> Error: All elements in the column `term` should be unique.
#>
#> Error:
Created on 2018-12-20 by the reprex package (v0.2.1)
Hi,
I tried displaying the output of a Bayesian regression model using
ggcoefstats
but I just can't manage to get it to work. I don't have reproducible code as it basically involves one function (ggcoefstats()
) and one line of code, but here's my workflow, described in words:After fitting my model using
brms()
and saving the output as an .RDS file, I load the .RDS file and convert it to a tidied tibble usingbroom.mixed::tidy()
, which supports brms;I then try displaying the tibble using
ggcoefstats
, but I get an error without any description. To be more precise, I'm tryingggstatsplot::ggcoefstats(x = RT_model_tidy)
, without any test statistic specification. Note that the tibble has all the appropriate columns, as required (i.e.,term
andestimate
).Thanks in advance for any tips!