Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/predict.fRegress.R
Model predictions for object of class fRegress
.
1 2 3 4 |
object |
Object of class inheriting from |
newdata |
Either NULL or a list matching object\$xfdlist. If(is.null(newdata)) predictions <- object\$yhatfdobj If newdata is a list, predictions = the sum of either newdata[i] *
betaestfdlist[i] if object\$yfdobj has class |
se.fit |
a switch indicating if standard errors of predictions are required |
interval |
type of prediction (response or model term) |
level |
Tolerance/confidence level |
... |
additional arguments for other methods |
1. Without newdata
, fit <- object\$yhatfdobj.
2. With newdata
, if(class(object\$y) == 'numeric'), fit <- sum
over i of inprod(betaestlist[i], newdata[i]). Otherwise, fit <- sum
over i of betaestlist[i] * newdata[i].
3. If(se.fit | (interval != 'none')) compute se.fit
, then
return whatever is desired.
The predictions produced by predict.fRegress
are either a
vector or a functional parameter (class fdPar
) object, matching
the class of object\$y
.
If interval
is not "none", the predictions will be
multivariate for object\$y
and the requested lwr
and
upr
bounds. If object\$y
is a scalar, these predictions
are returned as a matrix; otherwise, they are a multivariate
functional parameter object (class fdPar
).
If se.fit
is TRUE
, predict.fRegress
returns a
list with the following components:
fit |
vector or matrix or univariate or multivariate functional parameter
object depending on the value of |
se.fit |
standard error of predicted means |
Spencer Graves
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | ###
###
### vector response with functional explanatory variable
###
###
##
## example from help('lm')
##
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
fRegress.D9 <- fRegress(weight ~ group)
pred.fR.D9 <- predict(fRegress.D9)
# Now compare with 'lm'
lm.D9 <- lm(weight ~ group)
pred.lm.D9 <- predict(lm.D9)
all.equal(as.vector(pred.fR.D9), as.vector(pred.lm.D9))
##
## vector response with functional explanatory variable
##
annualprec <- log10(apply(CanadianWeather$dailyAv[,,
"Precipitation.mm"], 2,sum))
smallbasis <- create.fourier.basis(c(0, 365), 25)
tempfd <- smooth.basis(day.5,
CanadianWeather$dailyAv[,,"Temperature.C"], smallbasis)$fd
precip.Temp.f <- fRegress(annualprec ~ tempfd)
#precip.Temp.p <- predict(precip.Temp.f, interval='confidence')
#class(precip.Temp.p) == 'matrix'
## ***** not yet implemented *****
##
## Example using se.fit
##
#precip.Temp.p <- predict(precip.Temp.f, se.fit=TRUE)
#class(precip.Temp.p) == 'list'
## ***** not yet implemented *****
###
###
### functional response with
### (concurrent) functional explanatory variable
###
###
##
## predict knee angle from hip angle; from demo('gait', package='fda')
##
(gaittime <- as.numeric(dimnames(gait)[[1]])*20)
gaitrange <- c(0,20)
gaitbasis <- create.fourier.basis(gaitrange, nbasis=21)
harmaccelLfd <- vec2Lfd(c(0, (2*pi/20)^2, 0), rangeval=gaitrange)
gaitfd <- smooth.basisPar(gaittime, gait,
gaitbasis, Lfdobj=harmaccelLfd, lambda=1e-2)$fd
hipfd <- gaitfd[,1]
kneefd <- gaitfd[,2]
knee.hip.f <- fRegress(kneefd ~ hipfd)
knee.hip.pred <- predict(knee.hip.f)
plot(knee.hip.pred)
|
Loading required package: splines
Loading required package: Matrix
Attaching package: 'fda'
The following object is masked from 'package:graphics':
matplot
Warning message:
In fRegress.formula(weight ~ group) :
No functions found; setting rangeval to 0:1
[1] TRUE
[1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5
[16] 15.5 16.5 17.5 18.5 19.5
[1] "done"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.