Coefficient Plot in r for mixed model - r

I have fitted a three level model looking at political trust using multiple waves of survey data. Individuals nested in country-waves nested in countries. Now that I have my results, I want to present them in a coefficient plot. I have fitted a coefficient plot using the sjPlot function below. I am only interested in presenting the higher level variables (growth,inflation,unemployment,corruption) as the individual level variables are controls, but the plot puts all the predictors in. I also want to edit the names of certain variables so its clearer. How can I do this? I don't mind suggestions using ggplot or the base r coefplot function.
plot_model(fullmodel, transform = NULL, show.values = TRUE)

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!

How can I get log-likelihoods in mitools (survey design with multiple imputed datasets)?

I've run successfully a logistic regression for a complex design survey where data were imputed in multiple datasets with mitools.
Although I can get the confidence interval and the significance of each variable, I'm interested in studying the significance of a block of variables (dummy variables that represent a categorical variable with several categories). That could be accomplished subtracting the log-likelihoods of models with and without this block of variables.
Can this be accomplished with mitools?
Thank you.

Regression model with missing data in dependant variable

modelo <- lm( P3J_IOP~ PräOP_IOP +OPTyp + P3J_Med, data = na.omit(df))
summary(modelo)
Error:
Fehler in step(modelo, direction = "backward") :
Number of lines used has changed: remove missing values?
I have a lot of missing values in my dependent variable P3J_IOP.
Has anyone any idea how to create the model?
tl;dr unfortunately, this is going to be hard.
It is fairly difficult to make linear regression work smoothly with missing values in the predictors/dependent variables (this is true of most statistical modeling approaches, with the exception of random forests). In case it's not clear, the problem with stepwise approaches with missing data in the predictor is:
incomplete cases (i.e., observations with missing data for any of the current set of predictors) must be dropped in order to fit a linear model;
models with different predictor sets will typically have different sets of incomplete cases, leading to the models being fitted on different subsets of the data;
models fitted to different data sets aren't easily comparable.
You basically have the following choices:
drop any predictors with large numbers of missing values, then drop all cases that have missing values in any of the remaining predictors;
use some form of imputation, e.g. with the mice package, to fill in your missing data (in order to do proper statistical inference, you need to do multiple imputation, which may be hard to combine with stepwise regression).
There are some advanced statistical techniques that will allow you to simultaneously do the imputation and the modeling, such as the brms package (here is some documentation on imputation with brms), but it's a pretty big hammer/jump in statistical sophistication if all you want to do is fit a linear model to your data ...

How can I plot my lmer() mixed model growth curves in r?

I have constructed a mixed effect model using lmer() with the aim of comparing the growth in reading scores for four different groups of children as they age.
I would like to plot a graph of the 4 different slopes with confidence intervals in R in order to visualize this relationship but I keep getting stuck.
I have tried to use the plot function and some versions of the ggplot as I have done for previous lm() models but it isn't working so far. Here is my attempted model which I hope looks at how the change in reading scores over time(age) interacts with a child's SESDLD grouping (this indicated whether a child has a language problem and whether or not they are high or low income).
AgeSES.model <- lmer(ReadingMeasure ~ Age.c*SESDLD1 + (1|childid), data = reshapedomit, REML = FALSE)
The ReadingMeasure is a continuous score, age.c is centered age measured in months. SESDLD1 is a categorical measure which has 4 levels. I would expect four positive slopes of ReadingMeasure growth with different intercepts and probably differing slopes.
I would really appreciate any pointers on how to do this!
Thank you so much!!
The type of plot I would like to achieve - this was done in Stata

visreg package for R: conditional plots

The visreg package in R can produce plots for various regression models. When creating conditional plots for each predictor, the other predictors are — by default — held at their median values, although this value can be changed by the user. In the documentation, an example is given (Fig. 5) that shows the effect of choosing values other than the median. The model's predictions change depending on the chosen value, as do the data that are plotted. My question is this: how are the data transformed between these plots? Are they simply adjusted according to the model?
The conditional plot shows partial residuals and not the original data as I thought. Consequently, the points that are plotted are determined according to the equation given in that URL.

Resources