gam

Error returned predicting new data using GAM with periodic smoother

我只是一个虾纸丫 提交于 2019-12-08 04:07:38
问题 Apologies if this is better suited in CrossValidated. I am fitting GAM models to binomial data using the mgcv package in R. One of the covariates is periodic, so I am specifying the bs = "cc" cyclic cubic spline. I am doing this in a cross validation framework, but when I go to fit my holdout data using the predict function I get the following error: Error in pred.mat(x, object$xp, object$BD) : can't predict outside range of knots with periodic smoother Here is some code that should replicate

Getting adjusted r-squared value for each line in a geom_smooth gam

余生长醉 提交于 2019-12-04 18:24:28
I produced the below graph using ggplot2. PlotEchi = ggplot(data=Echinoidea, aes(x=Year, y=mean, group = aspect, linetype = aspect, shape=aspect)) + geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.025, position=pd) + geom_point(position=pd, size=2) + geom_smooth(method = "gam", formula = y~s(x, k=3), se=F, size = 0.5,colour="black") + xlab("") + ylab("Abundance (mean +/- SE)") + facet_wrap(~ species, scales = "free", ncol=1) + scale_y_continuous(limits=c(min(y=0), max(Echinoidea$mean+Echinoidea$se))) + scale_x_continuous(limits=c(min(Echinoidea$Year-0.125), max(Echinoidea$Year+0.125)))

Extract estimates of GAM

与世无争的帅哥 提交于 2019-12-04 08:21:33
I am fairly new to R and presently reading a book “Generalized Additive Models”, an Introduction with R by Wood (2006) and going through some of the exercises, particularly the part on air pollution and death which is my area of interest. Using the mgcv package I run the following model. library(gamair) library(mgcv) data(chicago) ap1<-gam(death ~ pm10median + so2median + o3median +s(time,bs="cr",k=200)+ s(tmpd,bs="cr"), data=chicago,family=poisson) How can I extract the effect estimates of pm10median and 95% CI of x and export the output to CSV or any other option? Save the summary of the

How to extract fitted values of GAM {mgcv} for each variable in R?

泄露秘密 提交于 2019-12-03 10:14:53
I'm searching for a method to add the predicted (real, not standardized) values of every single variable in my model > model<-gam(LN_Brutto~s(agecont,by=Sex)+factor(Sex)+te(Month,Age)+s(Month,by=Sex), data=bears) This is the summary of my model: > summary(m13) Family: gaussian Link function: identity Formula: LN_Brutto ~ s(agecont, by = Sex) + factor(Sex) + te(Month, Age) + s(Month, by = Sex) Parametric coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.32057 0.01071 403.34 <2e-16 *** factor(Sex)m 0.27708 0.01376 20.14 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0

Generalized additive model data.frame.default error: attempting to apply nonfunction

点点圈 提交于 2019-12-02 05:01:43
问题 I am trying to run a general additive model using the mgcv package, but I keep getting a model.frame.default error: Error in model.frame.default(formula = Presence ~ Sex + wind_speed + baro + : attempt to apply non-function Here is the code I am using (I am using "bam()" because of the size of the dataset): stormGAM <- bam(Presence~Sex+wind_speed+s(wind_direc)+baro+s(SST_C)+as.factor(daynight), data=PJstorm_alldata, family=binomial, na.action=TRUE) and here is what the data looks like: 'data

mgcv: Extract Knot Locations for `tp` smooth from a GAM model

南笙酒味 提交于 2019-12-02 02:51:31
I am trying to extract the placement of the knots from a GAM model in order to delineate my predictor variable into categories for another model. My data contains a binary response variable (used) and a continuous predictor (open). data <- data.frame(Used = rep(c(1,0,0,0),1250), Open = round(runif(5000,0,50), 0)) I fit the GAM as such: mod <- gam(Used ~ s(Open), binomial, data = data) I can get the predicted values, and the model matrix etc with either type=c("response", "lpmatrix") within the predict.gam function but I am struggling with out to extract the knot locations at which which the

Generalized additive model data.frame.default error: attempting to apply nonfunction

风流意气都作罢 提交于 2019-12-02 02:20:22
I am trying to run a general additive model using the mgcv package, but I keep getting a model.frame.default error: Error in model.frame.default(formula = Presence ~ Sex + wind_speed + baro + : attempt to apply non-function Here is the code I am using (I am using "bam()" because of the size of the dataset): stormGAM <- bam(Presence~Sex+wind_speed+s(wind_direc)+baro+s(SST_C)+as.factor(daynight), data=PJstorm_alldata, family=binomial, na.action=TRUE) and here is what the data looks like: 'data.frame': 31795 obs. of 25 variables: $ Con_hour : num 20127330 20127340 20127350 20127360 20127370 ... $

R plot.gam Error “Error in 1:object$nsdf : argument of length 0”

佐手、 提交于 2019-12-01 18:04:47
I am trying to plot a gam object in R, which I made with the gam package. I receive the same error reported in Error in 1:object$nsdf : argument of length 0 when using plot.gam . However, the solution found there, updating to the latest versions (I think), is not working for me. I am running R 3.3.1, gam 1.12, and mgcv 1.8.12 (mgcv is where the plot.gam function is from). Unfortunately, I cannot share the data I am working with. However, the following code -- pulled directly from the p.294 of Intro. to Statistical Learning with R -- reproduces the error for me: library(gam) library(ISLR) #

R Package conflict between gam and mgcv?

余生颓废 提交于 2019-11-30 21:19:21
Detaching packages in R isnt good practice (see ?detach ), but for some reasons I have to switch between the packages gam and mgcv . Once mgcv was attached and detached (and all the dependencies in the namespace unloaded!), functions of gam produce some strange errors (please forgive the terminology). It seems that - even though unloaded one step before - mgcv and friends are back in the namespace and function dispatching goes wrong. Does anyone had the same problem before? # fresh session t.s1 <- search() t.lN1 <- loadedNamespaces() # some dummy data data <-data.frame(is.exc=sample(x=c(0,1)

mgcv: how to specify interaction between smooth and factor?

天涯浪子 提交于 2019-11-30 15:15:26
In R, I would like to fit a gam model with categorical variables. I thought I could do it like with (cat is the categorical variable). lm(data = df, formula = y ~ x1*cat + x2 + x3); But I can't do things like : gam(data = df, formula = y ~ s(x1)*cat + s(x2) + x3) but the following works: gam(data = df, formula = y ~ cat + s(x1) + s(x2) + x3) How do I add a categorical variable to just one of the splines? One of the comments has more or less told you how. Use by variable: s(x1, by = cat) This creates the "factor smooth" smoothing class fs , where a smooth function of x1 is created for each

工具导航Map