mgcv

How to get confidence interval for smooth.spline?

血红的双手。 提交于 2019-12-04 14:51:49
I have used smooth.spline to estimate a cubic spline for my data. But when I calculate the 90% point-wise confidence interval using equation, the results seems to be a little bit off. Can someone please tell me if I did it wrongly? I am just wondering if there is a function that can automatically calculate a point-wise interval band associated with smooth.spline function. boneMaleSmooth = smooth.spline( bone[males,"age"], bone[males,"spnbmd"], cv=FALSE) error90_male = qnorm(.95)*sd(boneMaleSmooth$x)/sqrt(length(boneMaleSmooth$x)) plot(boneMaleSmooth, ylim=c(-0.5,0.5), col="blue", lwd=3, type=

Determining derivatives from GAM smooth object

五迷三道 提交于 2019-12-04 10:54:13
I have a quite simple time series data set consisting of annual averages of a singe variable ("AVERAGE"). I wish to investigate the rate of change (1st derivative) and acceleration (2nd derivative) and associated standard errors of the "trend" component of the time series. I have obtained the "trend" using the GAM and PREDICT functions of MGCV simply as follows: A <- gam(AVERAGE ~ s(YEAR), data=DF, na.action=na.omit) B <- predict(A, type="response", se.fit=TRUE) I have determined derivatives through 2 separate methods, applying a high DoF cubic smooth spline and via first and second

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 get only the plots from gam.check

拜拜、爱过 提交于 2019-12-04 06:28:43
This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 5 years ago . Learn more . When applying gam.check in the mgcv package, R produces some residual plots and basis dimension output. Is there a way to only produce the plots and not the printed output? library(mgcv) set.seed(0) dat <- gamSim(1,n=200) b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3), data=dat) plot(b, pages=1) gam.check(b, pch=19, cex=.3) There are four plots, from top left, moving down and across we have: A QQ plot of the residuals A histogram of the residuals A plot of residuals vs 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)