Displaying 20 results from an estimated 6000 matches similar to: "Gam() function in R"
2013 Mar 23
1
Time trends with GAM
Hi all,
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:
1) 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?
2) how can I extract the matrix
2007 Jun 11
1
Error using mgcv package
Hi all,
I need some solution in the following problem. The following error appears
when i use "mgcv" package for implementing GAM. But the same formula works
fine in "gam" package.
> model.gam <- gam(formula = RES ~
> CAT01+s(NUM01,5)+CAT02+CAT03+s(NUM02,5)+CAT04+
+ CAT05+s(NUM03,5)+CAT06+CAT07+s(NUM04,5)+CAT08+s(NUM05,5)+CAT09+
+
2012 Jul 30
1
te( ) interactions and AIC model selection with GAM
Hello R users,
I'm working with a time-series of several years and to analyze it, I?m using
GAM smoothers from the package mgcv. I?m constructing models where
zooplankton biomass (bm) is the dependent variable and the continuous
explanatory variables are:
-time in Julian days (t), to creat a long-term linear trend
-Julian days of the year (t_year) to create an annual cycle
- Mean temperature
2007 Aug 08
1
prediction using gam
I am fitting a two dimensional smoother in gam, say junk =
gam(y~s(x1,x2)), to a response variable y that is always positive and
pretty well behaved, both x1 and x2 are contained within [0,1].
I then create a new dataset for prediction with values of (x1,x2) within
the range of the original data.
predict(junk,newdata,type="response")
My predicted values are a bit strange
2005 Oct 05
3
testing non-linear component in mgcv:gam
Hi,
I need further help with my GAMs. Most models I test are very
obviously non-linear. Yet, to be on the safe side, I report the
significance of the smooth (default output of mgcv's summary.gam) and
confirm it deviates significantly from linearity.
I do the latter by fitting a second model where the same predictor is
entered without the s(), and then use anova.gam to compare the
2006 Jan 19
2
gam
Dear R users,
I'm new to both R and to this list and would like to get
advice on how to build generalized additive models in R.
Based on the description of gam, which I found on the R
website, I specified the following model:
model1<-gam(ST~s(MOWST1),family=binomial,data=strikes.S),
in which ST is my binary response variable and MOWST1 is a
categorical independent variable.
I get the
2010 Oct 27
1
GAM function in mgcv package
Hi R-users
I am trying to use the GAM function of the mgcv package. But I am having
problem trying to specify the k parameter.
Although I managed to run some models by giving to the parameter some
(random) value, and it is explained by Wood (2006) that it does not seem
to "really" affect the final result, I would like to grasp better its
meaning.
I understand that is the
2012 Nov 05
1
Post hoc tests in gam (mgcv)
Hi.
I'm analysing some fish biological traits with a gam in mgcv. After several
tries, I got this model
log(tle) = sexcolor + s(doy, bs = "cc", by = sexcolor) +log(tl)
sexcolor is a factor with 4 levels
doy is "day of year", which is modeled as a smoother
tl is "total length of the fish"
The summary of this models is (only parametric coefficientes):
Parametric
2004 Aug 06
2
gam --- a new contributed package
I have contributed a "gam" library to CRAN,
which implements "Generalized Additive Models".
This implementation follows closely the description in
the GAM chapter 7 of the "white" book "Statistical Models in S"
(Chambers & Hastie (eds), 1992, Wadsworth), as well as the philosophy
in "Generalized Additive Models" (Hastie & Tibshirani 1990,
2004 Aug 06
2
gam --- a new contributed package
I have contributed a "gam" library to CRAN,
which implements "Generalized Additive Models".
This implementation follows closely the description in
the GAM chapter 7 of the "white" book "Statistical Models in S"
(Chambers & Hastie (eds), 1992, Wadsworth), as well as the philosophy
in "Generalized Additive Models" (Hastie & Tibshirani 1990,
2012 Nov 27
1
interactions in GAMs
Hi all,
I wonder if it's possible to include a double interaction in a GAM formula.
Example:
If I do this:
mod=gam(energy~s(size, *by=color, by=sex*, k=5) + temperature, ...)
I get the interaction betwen size*color and size*sex.
But I need size*color*sex, being size a smoother.
I've created a new variable (colorsex) which combines all the level of both
color (2 levels) and sex (2
2010 Jun 03
4
gam error
Hi all,
I'm trying to use a gam (mgcv package) to analyse some data with a roughly U
shaped curve. My model is very simple with just one explanatory variable:
m1<-gam(CoT~s(incline))
However I just keep getting the error message
"Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
A term has fewer unique covariate combinations than specified maximum
degrees of
2008 May 06
1
mgcv::gam shrinkage of smooths
In Dr. Wood's book on GAM, he suggests in section 4.1.6 that it might be
useful to shrink a single smooth by adding S=S+epsilon*I to the penalty
matrix S. The context was the need to be able to shrink the term to zero if
appropriate. I'd like to do this in order to shrink the coefficients towards
zero (irrespective of the penalty for "wiggliness") - but not necessarily
all the
2009 Aug 24
2
Formulas in gam function of mgcv package
Dear R-experts,
I have a question on the formulas used in the gam function of the mgcv
package.
I am trying to understand the relationships between:
y~s(x1)+s(x2)+s(x3)+s(x4)
and
y~s(x1,x2,x3,x4)
Does the latter contain the former? what about the smoothers of all
interaction terms?
I have (tried to) read the manual pages of gam, formula.gam, smooth.terms,
linear.functional.terms but
2009 Aug 24
2
Formulas in gam function of mgcv package
Dear R-experts,
I have a question on the formulas used in the gam function of the mgcv
package.
I am trying to understand the relationships between:
y~s(x1)+s(x2)+s(x3)+s(x4)
and
y~s(x1,x2,x3,x4)
Does the latter contain the former? what about the smoothers of all
interaction terms?
I have (tried to) read the manual pages of gam, formula.gam, smooth.terms,
linear.functional.terms but
2010 Jul 27
0
gam (package gam) - diagonal of smoother matrix
Dear R-list members,
Once a gam (package gam) model has been fitted with family=poisson,
is there some R function that could extract the diagonal elements
of the smoother matrix S, to be used in a cross-validation for the
selection of the best smoothing parameter, following equation 3.19
on page 48 of the book T.J. Hastie and R.J. Tibshirani, Generalized
Additive Models, Chapman and Hall/CRC,
2012 Sep 11
1
plotting smoother function on raw data
Hi,
I have used the mgcv library to generate a simple additive model. I want to
know how to plot the function on the raw data with confidence intervals whan
I have TWO variables in the model. I get it to work with one variable but
not with two. I am on the limit for what I understand in R, so be gentle. I
have read the help file on predict.gam, but did not get any help out of it.
#My model:
2005 Mar 24
1
Prediction using GAM
Recently I was using GAM and couldn't help noticing
the following incoherence in prediction:
> data(gam.data)
> data(gam.newdata)
> gam.object <- gam(y ~ s(x,6) + z, data=gam.data)
> predict(gam.object)[1]
1
0.8017407
>
predict(gam.object,data.frame(x=gam.data$x[1],z=gam.data$z[1]))
1
0.1668452
I would expect that using two types of predict
arguments
2006 Dec 04
1
GAM model selection and dropping terms based on GCV
Hello,
I have a question regarding model selection and dropping of terms for GAMs fitted with package mgcv. I am following the approach suggested in Wood (2001), Wood and Augustin (2002).
I fitted a saturated model, and I find from the plots that for two of the covariates,
1. The confidence interval includes 0 almost everywhere
2. The degrees of freedom are NOT close to 1
3. The partial
2009 Oct 13
2
How to choose a proper smoothing spline in GAM of mgcv package?
Hi, there,
I have 5 datasets. I would like to choose a basis spline with same knots in
GAM function in order to obtain same basis function for 5 datasets.
Moreover, the basis spline is used to for an interaction of two covarites.
I used "cr" in one covariate, but it can only smooth w.r.t 1 covariate. Can
anyone give me some suggestion about how to choose a proper smoothing spline