mgcv

Extracting data used to make a smooth plot in mgcv

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 03:15:46
问题 This thread from a couple of years ago describes how to extract data used to plot the smooth components of a fitted gam model. It works, but only when there is one smooth variable. I've got more than one smooth variable, and unfortunately I can only extract the smooths from the last of the series. Here is an example: library(mgcv) a = rnorm(100) b = runif(100) y = a*b/(a+b) mod = gam(y~s(a)+s(b)) summary(mod) plotData <- list() trace(mgcv:::plot.gam, at=list(c(25,3,3,3)), #this gets you to

How to extract fitted splines from a GAM (`mgcv::gam`)

不想你离开。 提交于 2019-11-26 22:20:21
问题 I am using GAM to model time trends in a logistic regression. Yet I would like to extract the the fitted spline from it to add it to another model, that cannot be fitted in GAM or GAMM. Thus I have 2 questions: How can I fit a smoother over time so that I force one knot to be at a particular location while letting the model to find the other knots? How can I extract the matrix from the fitted GAM so that I can use it in as an impute for a different model? The types of models I am running are

Error in model.frame.default: variable lengths differ

半腔热情 提交于 2019-11-26 16:34:40
问题 On running a gam model using the mgcv package, I encountered a strange error message which I am unable to understand: “Error in model.frame.default(formula = death ~ pm10 + Lag(resid1, 1) + : variable lengths differ (found for 'Lag(resid1, 1)')”. The number of observations used in model1 is exactly the same as the length of the deviance residual, thus I think this error is not related to difference in data size or length. I found a fairly related error message on the web here, but that post