Title: | Dichotomized Functional Response Regression |
---|---|
Description: | Implementing Function-on-Scalar Regression model in which the response function is dichotomized and observed sparsely. This package provides smooth estimations of functional regression coefficients and principal components for the dfrr model. |
Authors: | Fatemeh Asgari [aut, cre], Saeed Hayati [aut, ctb] |
Maintainer: | Fatemeh Asgari <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2025-02-20 04:15:27 UTC |
Source: | https://github.com/asgari-fatemeh/dfrr |
Implementing Function-on-Scalar Regression model in which the response function is dichotomized and observed sparsely. This package provides smooth estimations of functional regression coefficients and principal components for the dfrr model.
Implementing Function-on-Scalar Regression model in which the response function is dichotomized and observed sparsely. This package provides smooth estimations of functional regression coefficients and principal components for the dfrr model. The main function in the dfrr-package is dfrr().
Maintainer: Fatemeh Asgari [email protected]
Authors:
Saeed Hayati [email protected] [contributor]
Fatemeh Asgari, Alamatsaz Mohammad Hossein, Hayati Saeed (2021). Dichotomized Functional Response Regression Model. <http://arxive.org/adress_to_paper>
Useful links:
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) coefs<-coef(dfrr_fit) plot(coefs) fitteds<-fitted(dfrr_fit) plot(fitteds) resids<-residuals(dfrr_fit) plot(resids) fpcs<-fpca(dfrr_fit) plot(fpcs,plot.contour=TRUE,plot.3dsurface = TRUE) newdata<-data.frame(X=c(1,0)) preds<-predict(dfrr_fit,newdata=newdata) plot(preds) newdata<-data.frame(X=c(1,0)) newydata<-data.frame(.obs=rep(1,5),.index=c(0.0,0.1,0.2,0.3,0.7),.value=c(1,1,1,0,0)) preds<-predict(dfrr_fit,newdata=newdata,newydata = newydata) plot(preds)
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) coefs<-coef(dfrr_fit) plot(coefs) fitteds<-fitted(dfrr_fit) plot(fitteds) resids<-residuals(dfrr_fit) plot(resids) fpcs<-fpca(dfrr_fit) plot(fpcs,plot.contour=TRUE,plot.3dsurface = TRUE) newdata<-data.frame(X=c(1,0)) preds<-predict(dfrr_fit,newdata=newdata) plot(preds) newdata<-data.frame(X=c(1,0)) newydata<-data.frame(.obs=rep(1,5),.index=c(0.0,0.1,0.2,0.3,0.7),.value=c(1,1,1,0,0)) preds<-predict(dfrr_fit,newdata=newdata,newydata = newydata) plot(preds)
Returns the basis functions employed in fitting a dfrr-object.
basis(object)
basis(object)
object |
a fitted |
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) coefs<-coef(dfrr_fit,return.fourier.coefs=TRUE) basis<-basis(dfrr_fit) evaluated_coefs<-coefs%*%t(fda::eval.basis(time,basis)) #Plotting the regression coefficients par(mfrow=c(1,2)) plot(time,evaluated_coefs[1,],'l',main="Intercept") plot(time,evaluated_coefs[2,],'l',main="X")
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) coefs<-coef(dfrr_fit,return.fourier.coefs=TRUE) basis<-basis(dfrr_fit) evaluated_coefs<-coefs%*%t(fda::eval.basis(time,basis)) #Plotting the regression coefficients par(mfrow=c(1,2)) plot(time,evaluated_coefs[1,],'l',main="Intercept") plot(time,evaluated_coefs[2,],'l',main="X")
Returns estimations of the smooth functional regression coefficients .
The result is a matrix of either Fourier coefficients or evaluations. See Details.
## S3 method for class 'dfrr' coef( object, standardized = NULL, unstandardized = !standardized, return.fourier.coefs = NULL, return.evaluations = !return.fourier.coefs, time_to_evaluate = NULL, ... )
## S3 method for class 'dfrr' coef( object, standardized = NULL, unstandardized = !standardized, return.fourier.coefs = NULL, return.evaluations = !return.fourier.coefs, time_to_evaluate = NULL, ... )
object |
a |
standardized , unstandardized
|
a |
return.fourier.coefs , return.evaluations
|
a |
time_to_evaluate |
a numeric vector indicating the set of time points for evaluating the functional regression coefficients, for the case of |
... |
dot argument, just for consistency with the generic function |
This function will return either the Fourier coefficients or the evaluation of
estimated coefficients. Fourier coefficients which are reported are
based on the a set of basis which can be determined by basis(dfrr_fit)
.
Thus the evaluation of regression coefficients on the set of time points specified by vector time
,
equals to fitted(dfrr_fit)%*%t(eval.basis(time,basis(dfrr_fit)))
.
Consider that the unstandardized estimations are not identifiable. So, it is recommended to extract and report the standardized estimations.
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) coefs<-coef(dfrr_fit) plot(coefs)
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) coefs<-coef(dfrr_fit) plot(coefs)
Implementing Function-on-Scalar Regression model, in which the response function is dichotomized and observed sparsely.
dfrr( formula, yind = NULL, data = NULL, ydata = NULL, method = c("REML", "ML"), rangeval = NULL, basis = NULL, times_to_evaluate = NULL, ... )
dfrr( formula, yind = NULL, data = NULL, ydata = NULL, method = c("REML", "ML"), rangeval = NULL, basis = NULL, times_to_evaluate = NULL, ... )
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 |
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
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)
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)
Fitted curves refer to the estimations of latent functional response curves. The results can be either the Fourier coefficients or evaluation of the fitted functions. See Details.
## S3 method for class 'dfrr' fitted( object, return.fourier.coefs = NULL, return.evaluations = !return.fourier.coefs, time_to_evaluate = NULL, standardized = NULL, unstandardized = !standardized, ... )
## S3 method for class 'dfrr' fitted( object, return.fourier.coefs = NULL, return.evaluations = !return.fourier.coefs, time_to_evaluate = NULL, standardized = NULL, unstandardized = !standardized, ... )
object |
a fitted |
return.fourier.coefs , return.evaluations
|
a |
time_to_evaluate |
a numeric vector indicating the set of time points for evaluating the fitted latent functions, for the case of |
standardized , unstandardized
|
a |
... |
dot argument, just for consistency with the generic function |
This function will return either the Fourier coefficients or the evaluation of
fitted curves to the binary sequences. Fourier coefficients which are reported are
based on the a set of basis which can be determined by basis(dfrr_fit)
.
Thus the evaluation of fitted latent curves on the set of time points specified by vector time
,
equals to fitted(dfrr_fit)%*%t(eval.basis(time,basis(dfrr_fit)))
.
Consider that the unstandardized estimations are not identifiable. So, it is recommended to extract and report the standardized estimations.
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) fitteds<-fitted(dfrr_fit) plot(fitteds)
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) fitteds<-fitted(dfrr_fit) plot(fitteds)
fpca()
returns estimations of the smooth principal components/eigen-functions
and the corresponding eigen-values of the residual function in the dfrr
model.
The result is a named list containing the vector of eigen-values and the matrix of Fourier coefficients. See Details.
fpca(object, standardized = NULL, unstandardized = !standardized)
fpca(object, standardized = NULL, unstandardized = !standardized)
object |
a fitted |
standardized , unstandardized
|
a |
Fourier coefficients which are reported are
based on the a set of basis which can be determined by basis(dfrr_fit)
.
Thus the evaluation of pricipal component/eigen-function on the set of time points specified by vector time
,
equals to fpca(dfrr_fit)%*%t(eval.basis(time,basis(dfrr_fit)))
.
Consider that the unstandardized estimations are not identifiable. So, it is recommended to extract and report the standardized estimations.
fpca(dfrr_fit)
returns a list containtng the following components:
values |
a vector containing the eigen-values of the standaridized/unstandardized covariance operator of
the residual function term in |
vectors |
a matrix whose columns contain the Fourier coefficients of the
principal components/eigen-functions of the standaridized/unstandardized covariance operator of
the residual function term in |
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) fpcs<-fpca(dfrr_fit) plot(fpcs,plot.eigen.functions=TRUE,plot.contour=TRUE,plot.3dsurface = TRUE)
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) fpcs<-fpca(dfrr_fit) plot(fpcs,plot.eigen.functions=TRUE,plot.contour=TRUE,plot.3dsurface = TRUE)
Monthly records of presence/abscence of psychiatric symptom 'thought disorder' of 86 patients over the first year after initial hospitalisation for disease.
madras
madras
A data frame with 1032 observations and 5 variables
identification number of a patient
response 'thought disorder': 0 = absent, 1 = present
month since hospitalisation
age indicator: 0 = less than 20 years, 1 = 20 or over
sex indicator: 0 = male, 1 = female
Diggle PJ, Heagerty P, Liang KY, Zeger SL (2002). The analysis of Longitudinal Data, second ed., pp. 234-43. Oxford University Press, Oxford.
<http://faculty.washington.edu/heagerty/Books/AnalysisLongitudinal/datasets.html>
Jokinen J. Fast estimation algorithm for likelihood-based analysis of repeated categorical responses. Computational Statistics and Data Analysis 2006; 51:1509-1522.
Obtain model matrix for a dfrr fit
## S3 method for class 'dfrr' model.matrix(object, ...)
## S3 method for class 'dfrr' model.matrix(object, ...)
object |
a |
... |
dot argument, just for consistency with the generic function |
Plot a coef.dfrr
object. The output is the plot of regression coefficients.
## S3 method for class 'coef.dfrr' plot(x, select = NULL, ask.hit.return = TRUE, ...)
## S3 method for class 'coef.dfrr' plot(x, select = NULL, ask.hit.return = TRUE, ...)
x |
a |
select |
a vector of length one or more of indices of regression coefficients to plot. |
ask.hit.return |
a boolean indicating whether to wait for interaction of the user between any two plots. |
... |
graphical parameters passed to |
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) coefs<-coef(dfrr_fit) plot(coefs)
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) coefs<-coef(dfrr_fit) plot(coefs)
Plot the regression coefficients, principal components, kernel function and residuals of a dfrr
-object.
## S3 method for class 'dfrr' plot(x, plot.kernel = TRUE, ...)
## S3 method for class 'dfrr' plot(x, plot.kernel = TRUE, ...)
x |
the output of the function fitted.dfrr |
plot.kernel |
a boolean indicating whether plots the kernel function or not.
|
... |
graphical parameters passed to |
The contour plot of the kernel function is produced if the package ggplot2
is installed.
Plotting the 3d surface of the kernel function is also depends on the package plotly
.
To produce the qq-plot, the package car
must be installed.
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)
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)
Plot a fitted.dfrr
object.
## S3 method for class 'fitted.dfrr' plot( x, id = NULL, main = NULL, col = "blue", lwd = 2, lty = "solid", cex.circle = 1, col.circle = "black", ylim = NULL, ... )
## S3 method for class 'fitted.dfrr' plot( x, id = NULL, main = NULL, col = "blue", lwd = 2, lty = "solid", cex.circle = 1, col.circle = "black", ylim = NULL, ... )
x |
the output of the function fitted.dfrr |
id |
a vector of length one or more containing subject ids to plot. Must be matched with
|
main |
a vector of length one or |
col , lwd , lty , ...
|
graphical parameters passed to |
cex.circle , col.circle
|
size and color of circles and filled circles. |
ylim |
a vector of length two indicating the range of y-axis of the plot. |
The output is the plot of latent curves over the observed binary sequence. The binary sequence is illustrated with circles and filled circles for the values of zero and one, respectively.
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) fitteds<-fitted(dfrr_fit) plot(fitteds)
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) fitteds<-fitted(dfrr_fit) plot(fitteds)
Plot a fpca.dfrr
object.
## S3 method for class 'fpca.dfrr' plot( x, plot.eigen.functions = TRUE, select = NULL, plot.contour = FALSE, plot.3dsurface = FALSE, plot.contour.pars = list(breaks = NULL, minor_breaks = NULL, n.breaks = NULL, labels = NULL, limits = NULL, colors = NULL, xlab = NULL, ylab = NULL, title = NULL), plot.3dsurface.pars = list(xlab = NULL, ylab = NULL, zlab = NULL, title = NULL, colors = NULL), ask.hit.return = TRUE, ... )
## S3 method for class 'fpca.dfrr' plot( x, plot.eigen.functions = TRUE, select = NULL, plot.contour = FALSE, plot.3dsurface = FALSE, plot.contour.pars = list(breaks = NULL, minor_breaks = NULL, n.breaks = NULL, labels = NULL, limits = NULL, colors = NULL, xlab = NULL, ylab = NULL, title = NULL), plot.3dsurface.pars = list(xlab = NULL, ylab = NULL, zlab = NULL, title = NULL, colors = NULL), ask.hit.return = TRUE, ... )
x |
a |
plot.eigen.functions |
a |
select |
a vector of length one or more of indices of eigenfunctions to be plotted. |
plot.contour |
a |
plot.3dsurface |
a |
plot.contour.pars |
a named list of graphical parameters passed to the function |
plot.3dsurface.pars |
a named list of graphical parameters passed to the function |
ask.hit.return |
a boolean indicating whether to wait for interaction of the user between any two plots. |
... |
graphical parameters passed to |
This function plots the functional principal components, contour plot and 3d surface of the kernel function.
If ggplot2-package
is installed, the contour plot of
the kernel function is produced by setting the argument plot.contour=TRUE
.
Some graphical parameters of the contour plot can be modified by setting the (optional) argument
plot.contour.pars
.
If the package plotly
is installed, the 3d surface of
the kernel function is produced by setting the argument plot.3dsurface=TRUE
.
Some graphical parameters of the 3d surface can be modified by setting the (optional) argument
plot.3dsurface.pars
.
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) fpcs<-fpca(dfrr_fit) plot(fpcs,plot.eigen.functions=TRUE,plot.contour=TRUE,plot.3dsurface=TRUE)
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) fpcs<-fpca(dfrr_fit) plot(fpcs,plot.eigen.functions=TRUE,plot.contour=TRUE,plot.3dsurface=TRUE)
Plot a predict.dfrr
object.
## S3 method for class 'predict.dfrr' plot( x, id = NULL, main = id, col = "blue", lwd = 2, lty = "solid", cex.circle = 1, col.circle = "black", ylim = NULL, ... )
## S3 method for class 'predict.dfrr' plot( x, id = NULL, main = id, col = "blue", lwd = 2, lty = "solid", cex.circle = 1, col.circle = "black", ylim = NULL, ... )
x |
a |
id |
a vector of length one or more containing subject ids to plot. Must be matched with
|
main |
a vector of length one or |
col , lwd , lty , ...
|
graphical parameters passed to |
cex.circle , col.circle
|
size and color of circles and filled circles. |
ylim |
a vector of length two indicating the range of y-axis of the plot. |
The output is the plot of predictions of latent functions given the new covariates.
For the case in which newydata
is also given, the predictions are plotted
over the observed binary sequence.
The binary sequence is illustrated with circles and filled circles for the values
of zero and one, respectively.
Choi, H., & Reimherr, M. A geometric approach to confidence regions and bands for functional parameters . Journal of the Royal Statistical Society, Series B Statistical methodology 2018; 80:239-260.
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) newdata<-data.frame(X=c(1,0)) preds<-predict(dfrr_fit,newdata=newdata) plot(preds) newdata<-data.frame(X=c(1,0)) newydata<-data.frame(.obs=rep(1,5),.index=c(0.0,0.1,0.2,0.3,0.7),.value=c(1,1,1,0,0)) preds<-predict(dfrr_fit,newdata=newdata,newydata = newydata) plot(preds)
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) newdata<-data.frame(X=c(1,0)) preds<-predict(dfrr_fit,newdata=newdata) plot(preds) newdata<-data.frame(X=c(1,0)) newydata<-data.frame(.obs=rep(1,5),.index=c(0.0,0.1,0.2,0.3,0.7),.value=c(1,1,1,0,0)) preds<-predict(dfrr_fit,newdata=newdata,newydata = newydata) plot(preds)
The output gives the qq-plot of estimated measurment error.
## S3 method for class 'residuals.dfrr' plot(x, ...) ## S3 method for class 'dfrr' qq(x, ...)
## S3 method for class 'residuals.dfrr' plot(x, ...) ## S3 method for class 'dfrr' qq(x, ...)
x |
a |
... |
graphical parameters passed to |
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) resid<-residuals(dfrr_fit) plot(resid) #qq(dfrr_fit)
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) resid<-residuals(dfrr_fit) plot(resid) #qq(dfrr_fit)
Takes a dfrr
-object created by dfrr()
and returns predictions
given a new set of values for a model covariates and an optional ydata
-like
data.frame
of observations for the dichotomized response.
## S3 method for class 'dfrr' predict( object, newdata, newydata = NULL, standardized = NULL, unstandardized = !standardized, return.fourier.coefs = NULL, return.evaluations = !return.fourier.coefs, time_to_evaluate = NULL, ... )
## S3 method for class 'dfrr' predict( object, newdata, newydata = NULL, standardized = NULL, unstandardized = !standardized, return.fourier.coefs = NULL, return.evaluations = !return.fourier.coefs, time_to_evaluate = NULL, ... )
object |
a fitted |
newdata |
a |
newydata |
(optional) a |
standardized , unstandardized
|
a |
return.fourier.coefs , return.evaluations
|
a |
time_to_evaluate |
a numeric vector indicating the set of time points for evaluating the predictions, for the case of |
... |
dot argument, just for consistency with the generic function |
This function will return either the Fourier coefficients or the evaluation of
predictions. Fourier coefficients which are reported are
based on the a set of basis which can be determined by basis(dfrr_fit)
.
Thus the evaluation of predictions on the set of time points specified by vector time
,
equals to fitted(dfrr_fit,return.fourier.coefs=T)%*%t(eval.basis(time,basis(dfrr_fit)))
.
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) newdata<-data.frame(X=c(1,0)) preds<-predict(dfrr_fit,newdata=newdata) plot(preds) newdata<-data.frame(X=c(1,0)) newydata<-data.frame(.obs=rep(1,5),.index=c(0.0,0.1,0.2,0.3,0.7),.value=c(1,1,1,0,0)) preds<-predict(dfrr_fit,newdata=newdata,newydata = newydata) plot(preds)
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) newdata<-data.frame(X=c(1,0)) preds<-predict(dfrr_fit,newdata=newdata) plot(preds) newdata<-data.frame(X=c(1,0)) newydata<-data.frame(.obs=rep(1,5),.index=c(0.0,0.1,0.2,0.3,0.7),.value=c(1,1,1,0,0)) preds<-predict(dfrr_fit,newdata=newdata,newydata = newydata) plot(preds)
This is a generic function for qq() method.
qq(x, ...)
qq(x, ...)
x |
an object |
... |
extra parameters passed to S3 methods |
Returns the residuals of a fitted dfrr
model.
A dfrr
model is of the form:
in which is the indicator function and
, where
is the functional part of the model and
is the measurement error.
The functional part of the model, consisting a location and a residual function of the form:
and are iid standard normal for each
and
.
The residuals reported in the output of this functions is the estimation of the
measurement error of the model i.e.
, which is estimated by:
## S3 method for class 'dfrr' residuals(object, standardized = NULL, unstandardized = !standardized, ...)
## S3 method for class 'dfrr' residuals(object, standardized = NULL, unstandardized = !standardized, ...)
object |
a fitted |
standardized , unstandardized
|
a |
... |
dot argument, just for consistency with the generic function |
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) resid<-residuals(dfrr_fit) plot(resid) #qq(dfrr_fit)
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) resid<-residuals(dfrr_fit) plot(resid) #qq(dfrr_fit)
dfrr
ModelSimulation from a simple dfrr model:
where is the indicator function,
is a Gaussian random function, and
are iid standard normal for each
and
independent of
.
For demonstration purpose only.
simulate_simple_dfrr( beta0 = function(t) { cos(pi * t + pi) }, beta1 = function(t) { 2 * t }, X = rnorm(50), time = seq(0, 1, length.out = 24), sigma2 = 0.2 )
simulate_simple_dfrr( beta0 = function(t) { cos(pi * t + pi) }, beta1 = function(t) { 2 * t }, X = rnorm(50), time = seq(0, 1, length.out = 24), sigma2 = 0.2 )
beta0 , beta1
|
(optional) functional intercept and slope parameters |
X |
an (optional) vector consists of scalar covariate |
time |
an (optional) vector of time points for which, each sample curve is observed at. |
sigma2 |
variance of the measurement error in the |
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)
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)
Summarise a fitted dfrr
-object. Not implemented.
## S3 method for class 'dfrr' summary(object, ...)
## S3 method for class 'dfrr' summary(object, ...)
object |
a |
... |
dot argument, just for consistency with the generic function |