strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
606 stars 91 forks source link

get_model_data / tab_model / etc fails for gam models with no smooth terms #847

Open alansz opened 2 years ago

alansz commented 2 years ago

tab_model is now working great with mcgv::gam again, but fails in the case where there are no smooths in the gam:

Replicable example:

df<-data.frame(x=rnorm(100),y=rnorm(100),z=rnorm(100))
m1<-mgcv::gam(y~x + s(z),data=df)
m2<-mgcv::gam(y~s(z),data=df)
m3<-mgcv::gam(y~x,data=df)

# Works:

tab_model(m1,m2)

# Fails: Error in rep("smooth_terms", nrow(cs.smooth)) : invalid 'times' argument

tab_model(m3)

Should be an easy fix (testing nrow(cs.smooth)>0 ?)