Description Usage Arguments Details Examples
Implementing Function-on-Scalar Regression model, in which the response function is dichotomized and observed sparsely.
1 2 3 4 5 6 7 8 9 10 11 |
formula |
an object of class " |
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,...,t_{G}).
If not supplied, |
data |
an (optional) |
ydata |
an (optional) |
method |
detrmines the estimation method of functional parameters. Defaults to " |
rangeval |
an (optional) vector of length two, indicating the lower and upper limit of the domain of
latent functional response. If not specified, it will set by minimum and maximum of |
basis |
an (optional) object of class |
times_to_evaluate |
a numeric vector indicating the set of time points for evaluating the functional regression coefficients and principal components. |
... |
other arguments that can be passed to the inner function |
The output is a dfrr
-object, which then can be injected into other methods/functions
to postprocess the fitted model, including:
coef.dfrr
,fitted.dfrr
, basis
, residuals.dfrr
, predict.dfrr
,
fpca
, summary.dfrr
, model.matrix.dfrr
,
plot.coef.dfrr
, plot.fitted.dfrr
, plot.residuals.dfrr
,
plot.predict.dfrr
, plot.fpca.dfrr
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 | set.seed(2000)
N<-50;M<-24
X<-rnorm(N,mean=0)
time<-seq(0,1,length.out=M)
Y<-simulate_simple_dfrr(beta0=function(t){cos(pi*t+pi)},
beta1=function(t){2*t},
X=X,time=time)
dfrr_fit<-dfrr(Y~X,yind=time)
plot(dfrr_fit)
##### Fitting dfrr model to the Madras Longitudinal Schizophrenia data
data(madras)
ids<-unique(madras$id)
N<-length(ids)
ydata<-data.frame(.obs=madras$id,.index=madras$month,.value=madras$y)
xdata<-data.frame(Age=rep(NA,N),Gender=rep(NA,N))
for(i in 1:N){
dt<-madras[madras$id==ids[i],]
xdata[i,]<-c(dt$age[1],dt$gender[1])
}
rownames(xdata)<-ids
madras_dfrr<-dfrr(Y~Age+Gender+Age*Gender, data=xdata, ydata=ydata, J=11)
coefs<-coef(madras_dfrr)
plot(coefs)
fpcs<-fpca(madras_dfrr)
plot(fpcs)
plot(fpcs,plot.eigen.functions=FALSE,plot.contour=TRUE,plot.3dsurface = TRUE)
par(mfrow=c(2,2))
fitteds<-fitted(madras_dfrr) #Plot first four fitted functions
plot(fitteds,id=c(1,2,3,4))
resids<-residuals(madras_dfrr)
plot(resids)
newdata<-data.frame(Age=c(1,1,0,0),Gender=c(1,0,1,0))
preds<-predict(madras_dfrr,newdata=newdata)
plot(preds)
newdata<-data.frame(Age=c(1,1,0,0),Gender=c(1,0,1,0))
newydata<-data.frame(.obs=rep(1,5),.index=c(0,1,3,4,5),.value=c(1,1,1,0,0))
preds<-predict(madras_dfrr,newdata=newdata,newydata = newydata)
plot(preds)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.