fregre.gsam | R Documentation |
Computes a functional GAM model between a functional covariate
(X^1(t_1), \dots, X^{q}(t_q))
and a non-functional
covariate (Z^1, ..., Z^p)
with a scalar response Y
.
This function extends functional generalized linear regression models (fregre.glm
)
where E[Y|X,Z]
is related to the linear predictor \eta
via a link function
g(\cdot)
with integrated smoothness estimation by the smooth
functions f(\cdot)
.
E[Y|X,Z]=\eta=g^{-1}\left(\alpha+\sum_{i=1}^{p}f_{i}(Z^{i})+\sum_{k=1}^{q}\sum_{j=1}^{k_q} f_{j}^{k}(\xi_j^k)\right)
where \xi_j^k
is the coefficient of the basis function expansion of
X^k
; in PCA analysis, \xi_j^k
is the score of the
j
-functional PC of X^k
.
fregre.gsam(
formula,
family = gaussian(),
data = list(),
weights = NULL,
basis.x = NULL,
basis.b = NULL,
...
)
formula |
an object of class |
family |
a description of the error distribution and link function to
be used in the model. This can be a character string naming a family
function, a family function or the result of a call to a family function.
(See |
data |
List that containing the variables in the model. |
weights |
weights |
basis.x |
List of basis for functional explanatory data estimation. |
basis.b |
List of basis for functional beta parameter estimation. |
... |
Further arguments passed to or from other methods. |
The smooth functions f(\cdot)
can be added to the right-hand
side of the formula to specify that the linear predictor depends on smooth
functions of predictors using smooth terms s
and
te
as in gam
(or linear functionals of these as
Z \beta
and \langle X(t), \beta \rangle
in
fregre.glm
).
The first item in the data
list is called "df" and is a data
frame with the response and non-functional explanatory variables, as in
gam
.
Functional covariates of class fdata
or fd
are introduced in
the following items of the data
list.
basis.x
is a list of
basis functions for representing each functional covariate. The basis object can be
created using functions such as create.pc.basis
, pca.fd
,
create.fdata.basis
, or create.basis
.
basis.b
is a list of basis functions for representing each functional beta parameter.
If basis.x
is a list of functional principal components basis functions
(see create.pc.basis
or pca.fd
), the argument basis.b
is ignored.
Return gam
object plus:
basis.x
: Basis used for fdata
or fd
covariates.
basis.b
: Basis used for beta parameter estimation.
data
: List containing the variables in the model.
formula
: Formula used in the model.
y.pred
: Predicted response by cross-validation.
If the formula only contains a non functional explanatory variables
(multivariate covariates), the function compute a standard glm
procedure.
Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@udc.es
Muller HG and Stadtmuller U. (2005). Generalized functional linear models. Ann. Statist.33 774-805.
Wood (2001) mgcv:GAMs and Generalized Ridge Regression for R. R News 1(2):20-25.
Ramsay, James O., and Silverman, Bernard W. (2006), Functional Data Analysis, 2nd ed., Springer, New York.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S, New York: Springer.
See Also as: predict.fregre.gsam
and
summary.gam.
Alternative methods: fregre.glm
and fregre.gkam
.
## Not run:
data(tecator)
x <- tecator$absorp.fdata
x.d1 <- fdata.deriv(x)
tt <- x[["argvals"]]
dataf <- as.data.frame(tecator$y)
nbasis.x <- 11
nbasis.b <- 5
basis1 <- create.bspline.basis(rangeval=range(tt),nbasis=nbasis.x)
basis2 <- create.bspline.basis(rangeval=range(tt),nbasis=nbasis.b)
f <- Fat ~ s(Protein) + s(x)
basis.x <- list("x"=basis1,"x.d1"=basis1)
basis.b <- list("x"=basis2,"x.d1"=basis2)
ldat <- ldata("df" = dataf, "x" = x , "x.d1" = x.d1)
res <- fregre.gsam(Fat ~ Water + s(Protein) + x + s(x.d1), ldat,
family = gaussian(), basis.x = basis.x,
basis.b = basis.b)
summary(res)
pred <- predict(res,ldat)
plot(pred-res$fitted)
pred2 <- predict.gam(res,res$XX)
plot(pred2-res$fitted)
plot(pred2-pred)
res2 <- fregre.gsam(Fat ~ te(Protein, k = 3) + x, data = ldat,
family=gaussian())
summary(res2)
## dropind basis pc
basis.pc0 <- create.pc.basis(x,c(2,4,7))
basis.pc1 <- create.pc.basis(x.d1,c(1:3))
basis.x <- list("x"=basis.pc0,"x.d1"=basis.pc1)
ldata <- ldata("df"=dataf,"x"=x,"x.d1"=x.d1)
res.pc <- fregre.gsam(f,data=ldata,family=gaussian(),
basis.x=basis.x,basis.b=basis.b)
summary(res.pc)
## Binomial family
ldat$df$FatCat <- factor(ifelse(tecator$y$Fat > 20, 1, 0))
res.bin <- fregre.gsam(FatCat ~ Protein + s(x),ldat,family=binomial())
summary(res.bin)
table(ldat$df$FatCat, ifelse(res.bin$fitted.values < 0.5,0,1))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.