Learn R Programming

cSFM (version 1.1)

cSFM.est.parallel: Knots Selection by AIC

Description

Select the best number of knots to minimize AIC. This is a convinient function to implement cSFM.est for different combination of knots by allowing parallel computing.

Usage

cSFM.est.parallel(data, tp, cp, nknots.tp = NULL, nknots.cp = NULL, max.knots = NULL, parallel = TRUE, num.core = NULL, method = c("cSFM", "cSFM0", "2cSFM"), bi.level = 2, degree.poly = c(3, 3, 3), nbasis.mean = 10, gam.method = "REML")

Arguments

data
The fully observed data matrix $n$ by $m$. The number of row $n$ is the number of subjects; the number of columns $m$ is the number of time points for each subject.

tp
The timepoint vector of length $m$, shared by each subject

cp
The covariate vector of length $n$ corresponding to $n$ subjects

nknots.tp
knots matrix with each row to be a vector (k1,k2,k3) for the number of knots (mean, variance, skewness) in the time direction

nknots.cp
knots matrix with each row to be a vector (s1,s2,s3) for the number of knots (mean, variance, skewness) in the covariant direction; the effective length is bi.level. For example, if bi.level = 2, only the first two numbers (s1, s2) are used
max.knots
the maximum number of knots to be considerred; nknots.tp and nknots.cp are not used if max.knots is provided; See "Details"
parallel
logical indicator; whether parallel computing will be used or not
num.core
number of cores to be used when parallel = TRUE; default to be the total available cores
method
Estimation method for the model. See cSFM.est
bi.level
Bivariate level taking values at 0, 1, 2, 3. See cSFM.est.

degree.poly
The vector (d1,d2,d3) for the degree of B-splines (mean, variance, skewness) in both the time and covariant direction; the cubic splines are the default splines.

nbasis.mean
Number of basis functions to smooth the mean; only applicable when method is "2cSFM".

gam.method
Method to smooth the mean; only applicable when method is "2cSFM".

Value

best.cSFM
cSFM object with the minimal AIC value; see cSFM.est for a complete explanation of HAC object
knots.mat
matrix for knots to be considerred; each row is a vector with length 6: first three are knots for time direction, while the last three are knots for covariate direction
AIC
AIC vector for all sets of knots

Details

This function is mainly based on cSFM.est, except that different sets of knots are considerred here. The parallel computing is based on the package parallel.

When supplied, max.kntos will determine (knots.tp, knots.cp) as follows. For each direction (time and covariate) and each parameter (mean, variance and skewness), the number of knots is from 1 to max.knots; we enforce the lower moments have more knots than higher moments (for example, mean has more knots than variance), therefore delete those exceptions to give (knots.tp, knots.cp).

See Also

cSFM.est, clusterMap

Examples

Run this code
## Not run: 
# data(data.simulation)
# # Example 1: use the convinient default to generate knots 
# ret <- cSFM.est.parallel(DST$obs, DST$tp, DST$cp, max.knots = 4)
# # AIC vector
# ret$AIC
# # best number of knots
# ret$knots.mat[which.min(ret$AIC), ]
# # Example 2: assign combinations of knots subjectively
# nknots.tp = rbind(c(3,2,1), c(6,5,4))
# nknots.cp = nknots.tp
# ret2 <- cSFM.est.parallel(DST$obs, DST$tp, DST$cp, 
#                           nknots.tp = nknots.tp, nknots.cp = nknots.cp)
#                           ## End(Not run)

Run the code above in your browser using DataLab