Issue with including p-value stars using sjPlot tab_model - r

I am plotting the results of multiple regressions in R using tab_model from sjPlot. The regression results are produced, however, I am now trying to add simultaneous displays of the numeric p-values and their corresponding stars for significance. By default the plot only renders the numeric values, so I added the term p.style = "scientific_stars". This generated the following error:
Warning: Could not access model information.Error in fam.info$is_linear || identical(fam.info$link_function, "identity") :
invalid 'x' type in 'x || y'
Unfortunately, due to the nature of the data, I cannot provide the exact data I am working with. However, the models are both basic OLS models produced using the lm function. The two models have the exact same variables, and number of observations.
The code for the function is the following:
tab_model(model_1, model_2, auto.label = TRUE, show.se = TRUE, show.ci = FALSE, show, p.style = "scientific_stars")
I have tried plotting a signle model, and chainging the other labels, but the same error is generated.
Is there anyway to fix this problem and include both the numeric values and the stars in the rendering?

Related

How can I display all my model predicted values using whisker plots?

I'm working with a linear mixed model with sex and diel (day/night) as my predictors and depth displacement as my response in R. Here is the model:
displacement_lmm_hour <- lmer(Displacement~sex*Light + (1|Hour), data = avg_depth_df_hour)
I want to create a whisker plot displaying each predicted value for each of my predictors from the model. So, I tried using dwplot from the dotwhisker() library in R.
dwplot(displacement_lmm_hour, effects = "fixed")
This is what it came out with:
As you can see, it is only showing the first 'sets' (if you will) of predicted values. Ie. there's no males, or day time values shown. I realize this comes from the model itself and the summary() table of the model only shows those as well. But, how can I show these values for the 'hidden' predicted values that also come from the model?
I also tried using '''plot_model''', which allowed me to separate my predicted values, but I don't think the error bars are correct (why I tried the whisker plots instead)
plot_model(displacement_lmm_hour, type = "pred", terms = c("sex","Light"), axis.title = c("Sex", "Displacement")
Do you have an idea how to accomplish this using the dwplot function? Or another way to accomplish this in general?
Thanks!

GAM residuals missing in plot

I am applying a GAM model to my data: cell abundance over time.
The model works just fine (although I am aware of a pattern in my resiudals, but this is a different issue not relevant here).
It just fails to display the partial residuals in the final plot, although i set residuals = TRUE. Here is my output:
https://i.stack.imgur.com/C1MlY.png
also I used mgcv package.
Previously this code worked as I wanted, but on different data. Any ideas on why it is not working are welcome!
GAM_EA <- mgcv::gam(EUB_FISH ~ s(Day, by = Heatwave), data = HnH, method = "REML")
gam.check(GAM_EA) #Checking the model
mgcv::anova.gam(GAM_EA) #Retrieving the statistical results. See ?anova.gam
summary.gam(GAM_EA)
plot(GAM_EA, shift = coef(GAM_EA)[1], residuals = TRUE)
See argument by.resid in ?plot.gam. They way these are used in plot.gam would been meaningless for factor by terms unless you were to subset the partial residuals and plot only the residuals for observations in the specific level of the by factor.

Use plot_model to produce confidence intervals plot for multiple models

I am using the function plot_model from the sjPlot package to generate a confidence interval plot for a fixed effect linear model (felm). For the individual base model, I encountered no issues, and generated the confidence interval plot effectively. Now, however, I am attempting to do this for multiple similarly-constructed models, but cannot make it work.
An individual model's code is as simple as the following:
plot <- plot_model(model1, show.values = TRUE)
Using the lapply function I generated the multiple models, which are now stored as a list object. However, I cannot find the way to put this list object (or its multiple individual models) into the plot_model (or plot_models) function. I have received various errors, including this one:
Warning: Could not access model information.Error in if (fam.info$is_linear) transform <- NULL else transform <- "exp" : argument is of length zero
Is there a way to place multiple similar models from a list into the plot_model function, so that the resulting confidence interval plots can be readily compared?
Update: with sample code and error:
plots <- plot_models(modellist[[1]], modellist[[2]], show.values = TRUE)
Warning: Could not access model information.Error: Sorry, `model_parameters()` failed with the following error (possible class 'numeric' not supported): $ operator is invalid for atomic vectors

How to make GAM work with binary variables?

I am running this piece of code:
model.runs <- BIOMOD_Modeling(run.data,
models = models,
NbRunEval = runs.CV,
DataSplit = 80,
VarImport = 20,
SaveObj = T,
Yweights = NULL,
rescal.all.models = FALSE,
do.full.models = FALSE,
models.options = BIOMOD_ModelingOptions(
GAM = list(k=3),
MAXENT.Phillips = list(path_to_maxent.jar = "F:/xxx/xxx/")))
save(model.runs, file = "model.runs")
and I had this error:
Error in smooth.construct.tp.smooth.spec(object, data, knots) :
A term has fewer unique covariate combinations than specified maximum
degrees of freedom
After some research, I understood that GAM did not like my binary variables, so I took them out, and it worked fine.
Therefore, my question is simple: I would like to keep my environmental variables, is this doable in some way?
Sorry if it is trivial, but I do not use GAM often and I did not find the answer anywhere else.
Cheers.
You can’t smooth binary or categorical variables, only continuous ones.
You can create and interaction between a smooth and a categorical variable, and you could use random effects “smooths” for categorical variables. But you can’t just smooth binary or categorical variables. You would need to arrange for biomod to include those variables as linear factor terms. If you codes them as 0,1 then R, biomod, and mgcv will think those variables are numeric. Make sure they are coerced to be factors and then retry.

How to create partial dependence plots for multinomial gbm?

I am trying to create partial dependence plots for my multinomial gbm predictions but I haven't been able to figure out how to produce the correct plots, the ones that I am getting have a single line instead of a line for every level of my response variable (in my case are 3 different species names). I have seen several examples but they require objects created with other packages (not gbm objects) and most of the examples don't include multinomial variables.
gbm fit
gbm.fit.final<-readRDS(file = "gbm_fit_final1_organism.rds")
getting table with variable importance
summary.gbm<-summary(
gbm.fit.final,
cBars = 10,
method = relative.influence,
las = 2)
The table looks like this:
var rel.inf
MA0356.1 22.641689
MA1071.1 21.707397
MA0311.1 16.010605
MA0210.1 7.249431
MA0271.1 4.958186
I used the following code to generate the partial dependence plot for the most important predictor variable:
gbm.fit.final %>%
partial(pred.var = "MA0356.1", n.trees = gbm.fit.final$n.trees, grid.resolution = 100, prob=T) %>%
autoplot(rug = TRUE, train = motifs_train.100) +
scale_y_continuous()
motifs_train.100 is the training data that I used to create the gbm fit (gbm.fit.final), I am not sure if it is necessary to add the training data.
I got the following plot:
plot with single line
I would like to get a plot like this one (I think I need to get marginal probabilities):
plot with a line for each level of response variable
I am very new to gbm package. I don't know if there is an argument of the function partial that I am omitting, or if there is a better function to do this. Any help would be appreciated. Thanks!

Resources