Questions tagged [r-marginaleffects]

marginaleffects is an R package for computing and plotting adjusted predictions, contrasts, marginal effects, and marginal means.

marginaleffects is an R package for computing and plotting adjusted predictions, contrasts, marginal effects, and marginal means for 69 classes of statistical models in R. Conduct linear and non-linear hypothesis tests using the delta method.

19 questions
2
votes
3 answers

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 of the code block, how can I get the plot to…
Sandro
  • 101
  • 7
1
vote
1 answer

How does marginaleffects compute groupwise predictions in the presence of fixed effects?

I want to compute predictions for a fixed effects ols regression by group with the marginaleffects package. When I generate new data for the prediction and do not specify the specific level of the fixed effects variables that I want the prediction…
dameili
  • 35
  • 3
1
vote
1 answer

Join results of marginaleffects::predictions() back to main df?

I've run a lm model and then run predictions() from marginaleffects on the output. I want to join this back to by main df (that I fed into the lm) but I can't see what option is the right one to use in this case. Does anyone know what I need to do…
C.Robin
  • 1,085
  • 1
  • 10
  • 23
1
vote
2 answers

Is ther a way in R and modelsummary to stack a comparisons table produced by marginal effects

I ran several linear regressions and obtained comparisons from the avg_comparisons function of the marginaleffects package and then form it with the shape = term : contrast ~ model option parameters of the modelsummary package to concatenate the…
econgr
  • 129
  • 5
1
vote
0 answers

Simultaneous test for parameters with the marginaleffects package

Is it possible to do a simultaneous F-test, likelihood ratio test or Wald test with the marginaleffects::hypotheses function? I'm looking for similar behavior as car::linearHypothesis and multcomp:glht. Minimal…
Stefan Hansen
  • 499
  • 1
  • 3
  • 16
1
vote
1 answer

modelsummary and multiple comparisons from marginaleffects

dat <- mtcars dat$cyl <- as.factor(dat$cyl) dat$am <- as.logical(dat$am) dat$carb <- as.factor(dat$carb) mod <- lm(mpg ~ hp + cyl + am+carb, data = dat) mm_dat <- marginaleffects::comparisons(mod,variables = list(carb="pairwise"), …
Misha
  • 3,114
  • 8
  • 39
  • 60
1
vote
1 answer

Marginal effects/predictions at representative values (with other values at observed)

I have been looking around for a way to calculate marginal effects/predictions at specific values in R, while the remaining variables are kept as observed. I believe this is the default in Stata (for example, when using margins, at(age=(30 35 40 45…
edvinsyk
  • 160
  • 6
1
vote
1 answer

Plotting Population-level predictions with marginaleffects

I was trying to replicate this blog post from Vincent. to represent the "group" effect at population level of my model. Edit: I have now realized that I need to treat time as continuous…
jtjtjtjt
  • 105
  • 6
0
votes
1 answer

Forest Plot of Marginal Effects vs Full Model via marginaleffects and Converting to tidy()

For exposure_1, I am trying to calculate and display the marginal effects of binary exposure_2 against the full model. I am unsure how to obtain these values. Once I have them, I need to translate them into tidy() format to display in my forest…
0
votes
1 answer

Run iterative function for plotting marginal effect slopes of interaction effects (R)

I have code to generate plots of interaction effects such as the following: (modelled in MTcars) library(ggplot2) library(tidyverse) outcome_var_list = mtcars %>% select(qsec,hp) %>% names() var_list = mtcars %>% select(cyl,wt) %>%…
flâneur
  • 633
  • 2
  • 8
0
votes
1 answer

marginaleffects::plot_predictions, returning geom_point when I want geom_line

I have the following code: #R version 4.2.2 library(dplyr) library(marginaleffects) #version 0.12.0 model <- df %>% filter(!is.na(election)) %>% lm(as.numeric(election) ~ as.numeric(cat)*age_cat, data =…
C.Robin
  • 1,085
  • 1
  • 10
  • 23
0
votes
1 answer

Plotting Slopes of interaction effect from Fixed effects model with marginaleffects package (R)

I am running a regression with multiple interaction terms and multiple fixed effects. I am looking to plot the slope (derivative) of a variable, conditional upon it being interacted or not. I came across the marginaleffects package, which seems to…
flâneur
  • 633
  • 2
  • 8
0
votes
0 answers

marginal effects in R not producing std. error or confidence interval for first variable value

I am trying to calculate the average prediction for a regression that includes an interaction term. I am using the avg_prediction command from the marginal_effects package to do this. However, when I run the command with both variables included in…
sd3184
  • 69
  • 4
0
votes
1 answer

Does the `by` argument in `avg_comparisons` compute the strata specific marginal effect?

I'm analyzing data from an AB test we just finished running. Our outcome is binary, y, and we have stratified results by a third variable, g. Because the intervention could vary by g, I've fit a Poisson regression with robust covariance estimation…
Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73
0
votes
1 answer

Marginaleffects - obtaining contrasts and plotting predictions

Using marginaleffects, I was trying to obtain contrasts by "period" visualize the predictions by "period" visualize the predictions by "session" And failed in all! Any help is appreciated. Df in the…
jtjtjtjt
  • 105
  • 6
1
2