gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

Error showing parametric terms in draw(parametric=T) #221

Closed dsmi313 closed 1 year ago

dsmi313 commented 1 year ago

I have a data set:

df<-structure(list(Landings = c(97109, 167, 568, 953, 493, 8235, 
27, 3063, 4001, 5321, 107, 4325, 39, 1191, 3467, 20936, 11702, 
1241, 12575, 3075, 19305, 10830, 2896, 3334, 16566, 10084, 20724, 
1080, 2598, 5395), year.y = c(2007L, 2007L, 2010L, 2014L, 2007L, 
2017L, 2006L, 2003L, 2010L, 2014L, 2017L, 2019L, 2007L, 2015L, 
2006L, 2007L, 2008L, 2009L, 2010L, 2015L, 2005L, 2012L, 2004L, 
2006L, 2008L, 2012L, 2016L, 2006L, 2016L, 2005L), survey_type = structure(c(1L, 
2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L), levels = c("accesspoint", 
"roving"), class = c("ordered", "factor")), spreg2 = structure(c(1L, 
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L), levels = c("0", 
"1"), class = c("ordered", "factor"))), row.names = c(NA, 30L
), class = "data.frame")

and I am running a gam with that data set and trying to draw it in gratia:

gam<-gam(Landings~s(year.y)+survey_type+spreg2,data=df)
draw(gam, parametric = T)

I get the error: ! Can't combinex[[1]]$level<ordered<7ed0c>> andx[[3]]$level<ordered<8fa51>>. However when I call the parametric terms individually:

draw(parametric_effects(gam,terms = "survey_type")) image

I do not get the error.

What is going on here? I have gratia_0.7.3.18

gavinsimpson commented 1 year ago

Confirmed this remains a bug in the current development version too

gavinsimpson commented 1 year ago

Thanks @dsmi313 this is now fixed in the version on GitHub

dsmi313 commented 1 year ago

It works with the small data set but with my larger data set I get this error:

Error in bind_cols(): ! Can't recycle level (size 2128) to match partial (size 237).

The same thing listed on this post: https://github.com/gavinsimpson/gratia/issues/219

dsmi313 commented 1 year ago

Sorry I am realizing its a problem with my NAs after reading that post more carefully.