# pffr

0th

Percentile

##### Penalized function-on-function regression

Implements additive regression for functional and scalar covariates and functional responses. This function is a wrapper for mgcv's gam and its siblings to fit models of the general form $E(Y_i(t)) = g(\mu(t) + \int X_i(s)\beta(s,t)ds + f(z_{1i}, t) + f(z_{2i}) + z_{3i} \beta_3(t) + \dots$ with a functional (but not necessarily continuous) response $Y(t)$, response function $g$, (optional) smooth intercept $\mu(t)$, (multiple) functional covariates $X(t)$ and scalar covariates $z_1$, $z_2$, etc.

##### Usage
pffr(formula, yind, data = NULL, ydata = NULL,
algorithm = NA, method = "REML",
tensortype = c("te", "t2"),
bs.yindex = list(bs = "ps", k = 5, m = c(2, 1)),
bs.int = list(bs = "ps", k = 20, m = c(2, 1)), ...)
##### Arguments
formula
a formula with special terms as for gam, with additional special terms ff() and c()
yind
a vector with length equal to the number of columns of the matrix of functional responses giving the vector of evaluation points $(t_1, \dots ,t_{G})$. If not supplied, yind is 1:ncol().
algorithm
the name of the function used to estimate the model. Defaults to gam if the matrix of functional responses has less than 2e5 data points and to bam
data
an (optional) data.frame or a named list containing the data. The functional response and functional covariates have to be supplied as n by matrices, i.e. each row is one functional observation. The model is then
ydata
an (optional) data.frame supplying functional responses that are not observed on a regular grid. See Details.
method
Defaults to "REML"-estimation, including of unknown scale. See gam for details.
bs.yindex
a named (!) list giving the parameters for spline bases on the index of the functional response. Defaults to list(bs="ps", k=5, m=c(2, 1)), i.e. 5 cubic B-splines bases with first order difference penalty.
bs.int
a named (!) list giving the parameters for the spline basis for the global functional intercept. Defaults to list(bs="ps", k=20, m=c(2, 1)), i.e. 20 cubic B-splines bases with first order difference penalty.
tensortype
which typ of tenor product splines to use. One of "te" or "t2", defaults to te
...
additional arguments that are valid for gam or bam. weights, subset, offset are not yet implemented!

##### References

Ivanescu, A., Staicu, A.-M., Scheipl, F. and Greven, S. (2012). Penalized function-on-function regression. (under revision) http://biostats.bepress.com/jhubiostat/paper240/

Scheipl, F., Staicu, A.-M. and Greven, S. (2012). Functional Additive Mixed Models. (submitted) http://arxiv.org/abs/1207.5947

smooth.terms for details of mgcv syntax and available spline bases and penalties.

• pffr
##### Examples
###############################################################################
# univariate model:
# Y(t) = f(t)  + \int X1(s)\beta(s,t)ds + eps
data1 <- pffrSim(scenario="1")
t <- attr(data1, "yindex")
s <- attr(data1, "xindex")
m1 <- pffr(Y ~ ff(X1, xind=s), yind=t, data=data1)
summary(m1)
plot(m1, pers=TRUE)

###############################################################################
# multivariate model:
# Y(t) = f0(t)  + \int X1(s)\beta1(s,t)ds + \int X2(s)\beta2(s,t)ds +
#		xlin \beta3(t) + f1(xte1, xte2) + f2(xsmoo, t) + beta4 xconst + eps
data2 <- pffrSim(scenario="2", n=200)
t <- attr(data2, "yindex")
s <- attr(data2, "xindex")
m2 <- pffr(Y ~  ff(X1, xind=s) + #linear function-on-function
ff(X2, xind=s) + #linear function-on-function
xlin  +  #varying coefficient term
c(te(xte1, xte2)) + #bivariate smooth term in xte1 & xte2, const. over Y-index
s(xsmoo) + #smooth effect of xsmoo varying over Y-index
c(xconst), # linear effect of xconst constant over Y-index
yind=t,
data=data2)
summary(m2)
plot(m2, pers=TRUE)

#############################################################################
# sparse data (keep only 20% of function evaluations):
set.seed(121456)
ydata1 <- data.frame(cbind(.obs=as.vector(row(data1$Y)), .index=rep(attr(data1, "yindex"), e=nrow(data1)), .value=as.vector(data1$Y)))
ydata1 <- ydata1[sample(1:nrow(ydata), 0.2*nrow(ydata)), ]

s <- attr(data1, "xindex")
t <- attr(data1, "yindex")
m1.sparse <- pffr(Y ~ ff(X1, xind=s), data=data1, ydata=ydata1, yind=t)
summary(m1.sparse)
plot(m1.sparse, pers=TRUE)
Documentation reproduced from package refund, version 0.1-9, License: GPL (>= 2)

### Community examples

Looks like there are no examples yet.