dfrr: Dichotomized Functional Response Regression

Description Usage Arguments Details Examples

View source: R/dfrr.R

Description

Implementing Function-on-Scalar Regression model, in which the response function is dichotomized and observed sparsely.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
dfrr(
  formula,
  yind = NULL,
  data = NULL,
  ydata = NULL,
  method = c("REML", "ML"),
  rangeval = NULL,
  basis = NULL,
  times_to_evaluate = NULL,
  ...
)

Arguments

formula

an object of class "formula" (or one that can be coerced to that class with as.formula: a symbolic description of the model to be fitted.

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, yind is set to 1:ncol(<response>).

data

an (optional) data.frame containing the covariate data. the variable terms will be searched from the columns of data, covariates also can be read from the workspace if it is not available in data.

ydata

an (optional) data.frame consists of three columns .obs, .index and .value, supplying the functional responses that are not observed on a regular grid. ydata must be provided if the sampling design is irregular.

method

detrmines the estimation method of functional parameters. Defaults to "REML" estimation.

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 yind or .index column of ydata.

basis

an (optional) object of class 'basisfd'. Defaults to cubic bspline basis.

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 AMCEM.

Details

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

Examples

 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)

asgari-fatemeh/dfrr documentation built on Aug. 12, 2020, 3:06 a.m.