185 questions
0
votes
2
answers
57
views
Control levels the marginaleffects library uses when stratifying a numeric variable
I'm trying to use the marginaleffects library in R to get the estimates of a bunch of interaction effects from a bunch of different models. When I pass it an interaction that has a continuous ...
1
vote
1
answer
64
views
R marginaleffects::comparisons not generating expected outputs
I am sure this is either due to my density/some semantic thing I'm not getting, but I'm having trouble getting marginaleffects to produce what I expect when using its comparisons command.
What I am ...
-1
votes
1
answer
53
views
Replicate `avg_comparisons` by hand [closed]
I'm struggling replicating the results given by avg_comparisons.
What am I doing wrong?
library(marginaleffects)
dat <- get_dataset("thornton")
mod <- glm(outcome ~ incentive * (...
0
votes
1
answer
69
views
Replicate marginaleffects avg_predictions with "by" argument by hand
I cannot replicate marginaleffects::avg_predictions by hand when using the by argument.
In the following example, the coefficient returned by marginaleffects for the nodegree==0 condition equals 8290.
...
2
votes
1
answer
20
views
Marginal effects by group based on glm()
Trying to obtain marginal effects by group, simiar to Stata margins i.group, atmeans
Below is my code:
glm.model <- glm(y ~ factor(x1) + factor(x2) + x3 + x4, data = data, family = poisson(link = &...
1
vote
2
answers
107
views
estimate by weighted proportion in SAS, compared to R emmean's weights = "prop"
I am trying to replicate the R emmeans package's weight="prop" in SAS.
However, only reasonable method I could find was to explicitly state the average of one variable and the proportion of ...
1
vote
1
answer
130
views
How to obtain custom estimated marginal means from `emmeans`?
Let's say that I have the following linear model of the mpg as a function of gear (3, 4, and 5) and vs (0 or 1):
mod <- lm(mpg ~ factor(gear) * factor(vs), data = mtcars)
I know that I can obtain ...
1
vote
1
answer
139
views
NA values when using avg_predictions() from marginaleffects with a flexsurv model
I'm unsure why I do not get standard errors or confidence intervals when I fit parametric survival models and compute the predicted mean survival times using the avg_predictions(). I tried using ...
0
votes
1
answer
151
views
Marginal effects contrasts in R: replicating rms::contrast and simultaneous confidence intervals
Im trying to replicate the rms::contrast function using the marginaleffects package in R, but am having difficulties. Particularly, I would like to request simultaneous confidence intervals for ...
1
vote
1
answer
146
views
How to replicate Stata 'margins at' command to interpret interaction effects using marginaleffects package in R?
I am trying to replicate some Stata code that uses average marginal effects to interpret interaction effects in R.
Suppose I am using the mtcars dataset to estimate the average miles/gallon mpg of a ...
2
votes
1
answer
49
views
Using `inferences` with comparison and transform arguments
I'd like to use the inferences function to do some bootstrapping for a quantity which requires me to use comparison and transform arguments in avg_comparisons.
However, when I pass the output of ...
0
votes
0
answers
140
views
`marginaleffects::plot_comparisons()` for time-split survival data
Suppose I'm interested in estimating the effect of a binary variable for survival data as a hazard ratio. Before doing so, I want to split the observation period into two periods and estimate the ...
0
votes
2
answers
413
views
How to plot the marginal effect of a standard deviation increase and a standard deviation decrease both on the same plot?
I would like to plot the marginal effect of a standard deviation increase and a standard deviation decrease of a model on the same plot. I am using the marginaleffects package, but I am open to other ...
0
votes
1
answer
795
views
Display plm Model Results: Marginal Effects, p-Values for Interaction Terms, and Plots (Fixed Effects Method)
I'm working with panel data using the plm package in R to estimate a fixed effects model that includes interaction terms. I'm currently able to get my model results using plm and display them with ...
0
votes
1
answer
410
views
How to pool average predictions from a multinomial regression per category in R
I want to obtain pooled average predictions per level of a categorical variable using a multinomial regression on multiple imputed data. My problem is that the pool() function seems to collapse all ...
1
vote
1
answer
409
views
How to get out-of-sample predictions for specific subgroups, in Stata?
I have a mixed effects logistic regression model:
quietly melogit y i.x1 i.x2 || x3:
Variable x1 is coded 0/1. I create the predicted probabilities for both values of x1:
margins x1
Then I obtain ...
1
vote
1
answer
324
views
Marginaleffects package produces error with nlme
This question just migrated from crossvalidated, as it is indeed more a programming question.
I have tried a lot of things (all kind of way to provide info to the newdata-argument), from which I ...
2
votes
0
answers
70
views
How to specify two random intercepts in "random" argument of "mixed_model" function of "GLMMadaptive"?
I want to get marginal estimate and its confidence interval for a binomial model with two random intercepts, but I don't know how to specify the random argument of "mixed_model" function of &...
0
votes
1
answer
270
views
Predictive margins using R's "survey" package when I don't want to adjust for anything (simple GLM)
library(survey) # Analysis of Complex Survey Samples
library(srvyr) # 'dplyr' inspired syntactic style
# complex survey design
design <- data %>% as_survey_design(ids = HOSP_NRD, weights = ...
0
votes
1
answer
407
views
Plotting dynamic treatment effects using marginaleffects package in R
I am attempting to use the marginaleffects package in R to plot the effect of treatment on the outcome across time (i.e., dynamic treatment effects). My data consists of two groups (treated and ...
0
votes
1
answer
232
views
How can I prevent R from extrapolating the regression line outside the range of data points using a mixed model?
I am fitting a mixed model in R with an interaction term as follows: model <- lmer(y ~ x * z + (1|h), data = df). y and x are continuous variables and z is a categorical variable, and h is a random ...
3
votes
1
answer
233
views
Interaction plot using ggplot2 for hierarchical model (lmerMod) with statistical significance highlighting
I am working with a hierarchical model (lmerMod) that has an outcome and two categorical variables, cat1 and cat2. I want to make an interaction plot using ggplot2:: that visualizes the model ...
0
votes
1
answer
210
views
Generating a table with different probit marginal effect results
I generated three different marginal effect results using "probitmfx", but I am having a hard time generating one table with all the results in using Stargazer. Is there a simple way to get ...
2
votes
3
answers
618
views
Creating a 'marginsplot' in R
Inspired by this youtube https://www.youtube.com/watch?v=7maMbX_65b0 by the ever fantastic Chuck Huber, how can I recreate the marginsplot of Stata in R?
In other words, for my cplot() line at the end ...
0
votes
0
answers
120
views
NA problem in output of logmodel.get_margeff()
I have a logistic model which is created with statsmodel library. I want to get marginal effects, after that i will plot it. However, output of get_margeff() gives me table with all NA.
Xtrain = df_3[...