leeper / margins

An R Port of Stata's 'margins' Command
https://cloud.r-project.org/package=margins
Other
260 stars 40 forks source link

Support for mgcv::gam? #177

Open rokapre opened 3 years ago

rokapre commented 3 years ago

Please specify whether your issue is about:

Hi,

I was wondering is it possible at all to use margins with models from mgcv::gam() ? This is a common situation where I fit a penalized spline model and I would like to get the AME.

Below, I get the error "Error in J %*% vcov : non-conformable arguments"

Best,

Rohan

library(mgcv)
library(margins) 

x=rnorm(1000,0,0.1)
y = log(x+1) + rnorm(1000,0,0.2)
df = data.frame(x=x,y=y)
mod = gam(y~s(x),data=df)
margins(mod)