Package 'npmlda'

Title: Non-Parametric Models for Longitudinal Data Analysis
Description: Support the book: Wu CO and Tian X (2018). Nonparametric Models for Longitudinal Data: With Implementation in R. (Chapman & Hall/CRC Monographs on Statistics & Applied Probability); Present global and local smoothing methods for the conditional-mean and conditional-distribution based nonparametric models with longitudinal Data.
Authors: Xin Tian, Colin Wu
Maintainer: Xin Tian <[email protected]>
License: GPL (>= 2)
Version: 1.2.0
Built: 2025-02-16 04:00:47 UTC
Source: https://github.com/npmldabook/npmlda

Help Index


BDIdata dataset

Description

This dataset includes 557 depressed patients (total 7117 observations) in the cognitive behavior therapy arm in the Enhancing Recovery in Coronary Heart Disease Patients (ENRICHD) study.

Usage

data(BDIdata)

Format

A data frame with 7117 rows and 5 variables.

Details

  • ID. Subject ID

  • time. Study visit time (in days) since randomization

  • BDI. Beck Depression Inventory (BDI) score

  • med. Antidepressant medication use

  • med.time. The starting time of medication

References

  1. Wu, C. O., Tian, X. and Bang, H. A varying-coefficient model for the evaluation of time-varying concomitant intervention effects in longitudinal studies. Statistics in Medicine, 27:3042-3056, 2008.

  2. Wu, C. O., Tian, X. and Jiang, W. A shared parameter model for the estimation of longitudinal concomitant intervention effects. Biostatistics, 12(4):737-749, 2011.


BMACS CD4 dataset

Description

This dataset is from the Baltimore site of the Multi-center AIDS Cohort Study (BMACS), which included 400 homosexual men who were infected by the human immunodeficiency virus (HIV) between 1984 and 1991.

Usage

data(BMACS)

Format

A data frame with 1817 rows and 6 variables.

Details

  • ID. Subject ID

  • Time. Subject's study visit time

  • Smoke. Cigarette baseline smoking status

  • age. Age at study enrollment

  • preCD4. Pre-infection CD4 percentage

  • CD4. CD4 percentage at the time of visit

References

Kaslow, R. A., Ostrow, D. G., Detels, R., Phair, J. P., Polk, B. F. and Rinaldo, C. R. The Multicenter AIDS Cohort Study: rationale, organization and selected characteristics of the participants. American Journal of Epidemiology, 126:310-318, 1987.


Leave one-subject out Cross-validation score for local linear fit

Description

Leave one-subject out Cross-validation score for local linear fit

Usage

CVlm(Xvec, Yvec, bw, ID, Wt)

Arguments

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

bw

a bandwidth of the Epanechnikov kernel

ID

subject ID of the data value

Wt

a weight vector, may be subject-specific. a weight vector or a constant. For longitudinal data, Wt=1/N corresponds to measurement uniform weight and Wt=1/(nni) corresponds subject uniform weight.


Leave one-subject out Cross-validation score for spline fit

Description

Leave one-subject out Cross-validation score for spline fit

Usage

CVspline(Xvec, Yvec, ID, nKnots, Degree, Wt)

Arguments

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

ID

subject ID of the data value

nKnots

number of equally-spaced knots

Degree

degree of polynomial splines

Wt

a weight vector. For longitudinal data, Wt=1/N corresponds to measurement uniform weight and Wt=1/(nni) corresponds subject uniform weight.

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


Derivative of the function Xi(s)

Description

Derivative of the function Xi(s)

Usage

DXi(s)

Arguments

s

a number or a vector

Value

value of the function DXi with give s

Examples

DXi(c(-1000, -10,-5, 0, 5,10, 1000 ))

HSCT dataset

Description

This dataset consists of 20 patients with hematologicmalignancies who had allogeneic hematopoietic stem cell transplantation (HSCT) between 2006 and 2009 at the National Institutes of Health (NIH). The variables are as follows:

Usage

data(HSCT)

Format

A data frame with 271 rows and 8 variables.

Details

  • ID. Subject ID

  • Days. Subject's study visit time relative to time of transplant (day 0)

  • Granu. Granulocytes (K/uL)

  • LYM. Lymphocytes (K/uL)

  • MON. Monocytes (K/uL)

  • G-CSF. Granulocyte colony-stimulating factor level (pg/mL)

  • IL-15. IL-15 level (pg/mL)

  • MCP-1. monocyte chemotactic protein-1 level (pg/mL)

References

Melenhorst, J.J., Tian, X., Xu, D., Sandler, N.G., Scheinberg, P., Biancotto, A., et al. Cytopenia and leukocyte recovery shape cytokine fluctuations after myeloablative allogeneic hematopoietic stem cell transplantation. Haematologica, 97(6):867-73, 2012.


Nadaraya-Watson Kernel estimator

Description

Nadaraya-Watson Kernel estimator

Usage

kernel.fit(Xint, Xvec, Yvec, bw, Kernel = "Ep", Wt = 1)

Arguments

Xint

a vector of x interval to generate the local linear fit

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

bw

a bandwidth of the kernel

Kernel

a character string indicating which kernel function is to be used. Use of "Ep", "Bw", or "Nm" for Epanechnikov, Biweight or Normal kernel function.

Wt

a weight vector

References

  1. Fan, J. and Gijbels, I. Local Polynomial Modeling and Its Applications. Chapman & Hall, London, United Kingdom, 1996.

  2. Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018

Examples

X <- seq(0, 1, len=100)
Y <- (X- 0.5)^3 - 2*(X-0.5)^2+ rnorm(100, 0, 0.1)
kernel.fit(seq(0,1,0.1), X, Y, Kernel="Ep", bw=0.1, Wt=1   )

2-dim Kernel function for longitudinal data

Description

2-dim Kernel function for longitudinal data

Usage

Kernel2D(IDls, Xvec, Yvec, X01, X02, Bndwdth1, Bndwdth2)

Arguments

IDls

the vector of subject ID in a longitudinal sample

Xvec

Yvec numeric vectors of data values, Xvec and Yvec must have the same length

X01

X02 two given values of Xvec

Bndwdth1, Bndwdth2

two given bandwidths

Value

2-dim kernel fit result

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


3-dim Kernel function for longitudinal data to get Pr(y1(t1),y2(t2)|x(t1))

Description

3-dim Kernel function for longitudinal data to get Pr(y1(t1),y2(t2)|x(t1))

Usage

Kernel3D(IDls = ID, Y, Time, X, T1, T2, X0, Bndwdth1, Bndwdth2, Bndwdth3)

Arguments

IDls

the vector of subject ID in a longitudinal sample

Y, X, Time

numeric vectors of outcome, covariate and time of the the same length

T1, T2

twp given time points

X0

a given covariate value

Bndwdth1, Bndwdth2, Bndwdth3

three bandwidths around two time and one covariate value

Value

3-dim Kernel function results

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


3-dim Kernel function for longitudinal data to get Pr(y2(t2)|x(t1))

Description

3-dim Kernel function for longitudinal data to get Pr(y2(t2)|x(t1))

Usage

Kernel3D.S2(IDls = ID, Y, Time, X, T1, T2, X0, Bndwdth1, Bndwdth2, Bndwdth3)

Arguments

IDls

the vector of subject ID in a longitudinal sample

Y, X, Time

numeric vectors of outcome, covariate and time of the the same length

T1, T2

twp given time points

X0

a given covariate value

Bndwdth1, Bndwdth2, Bndwdth3

three bandwidths around two time and one covariate value

Value

3-dim Kernel function results

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


Biweight kernel

Description

Biweight kernel

Usage

Kh.Bw(datavec, Bndwdth)

Arguments

datavec

a numeric vector

Bndwdth

a bandwidth of the kernel

Value

kernel function result

Examples

# same usage as Kh.Ep

Epanechnikov Kernel

Description

Epanechnikov Kernel

Usage

Kh.Ep(datavec, Bndwdth)

Arguments

datavec

a numeric vector

Bndwdth

a bandwidth

Value

kernel function result

Examples

Kh.Ep(2:7,5)

Normal kernel

Description

Normal kernel

Usage

Kh.Nm(datavec, Bndwdth)

Arguments

datavec

a numeric vector

Bndwdth

a bandwidth of the kernel

Value

kernel function result

Examples

Kh.Nm(2:7,5)

Multiplicative Epanechnikov Kernel (2-dim)

Description

Multiplicative Epanechnikov Kernel (2-dim)

Usage

Kh2D(datavec1, datavec2, Bndwdth1, Bndwdth2)

Arguments

datavec1

datavec2 two numeric vectors of same length

Bndwdth1

Bndwdth2 two bandwidths for two vectors

Value

2-dim kernel function result

Examples

Kh2D(2:7, 2:7, 5, 5)

Multiplicative Epanechnikov Kernel (3-dim)

Description

Multiplicative Epanechnikov Kernel (3-dim)

Usage

Kh3D(datavec1, datavec2, datavec3, Bndwdth1, Bndwdth2, Bndwdth3)

Arguments

datavec1

datavec2, datavec3 three numeric vectors of same length

Bndwdth1

Bndwdth2, Bndwdth3 three bandwidths for three vectors

Value

3-dim kernel function result


Local linear fit with Epanechnikov kernel

Description

Local linear fit with Epanechnikov kernel

Usage

LocalLm(Xint, Xvec, Yvec, bw, Wt = 1)

Arguments

Xint

a vector of x interval to generate the local linear fit

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

bw

a bandwidth of the kernel

Wt

a weight vector

Examples

data(BMACS)
Time.int<- seq(0.1,5.9,  by=0.1)
LocalFit.Y <- with(BMACS, LocalLm(Time.int, Time, CD4, bw=0.9, Wt=1))

Least square local linear fit

Description

Least square local linear fit

Usage

LocalLm.Beta(Tint, Tvec, X1, X2, X3, Yvec, Bndwdth, Weight)

Arguments

Tint

a time interval

Tvec, Yvec

numeric vectors of time and outcome values, Tvec and Yvec must have the same length.

X1, X2, X3

three covariate vectors

Bndwdth

a bandwidth of the Epanechnikov kernel

Weight

the weight vector

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.

Examples

data(NGHS)
NGHS$Black <- (NGHS$RACE==2)*1
NGHS<- NGHS[!is.na(NGHS$SBP) & !is.na(NGHS$BMIPCT) & !is.na(NGHS$HTPCT ),]
Ct <-   data.frame(table(NGHS$ID))
names(Ct)<- c('ID', 'ni')
NGHS<- merge(NGHS, Ct, by= 'ID')
nID<- dim(Ct)[1]
Age.grid <- seq(9, 19, by=0.5) #21
NGHS$HTPCTc<- NGHS$HTPCT-50
NGHS$BMIPCTc<- NGHS$BMIPCT-50
Beta <- with(NGHS, LocalLm.Beta(Age.grid, AGE, X1=Black, X2=HTPCTc, X3=BMIPCTc, SBP, Bndwdth=3.5, Weight=1/ni))

Least square local linear fit at t0

Description

Least square local linear fit at t0

Usage

LocalLm.Beta.t0(t0, Tvec, X1, X2, X3, Yvec, Bndwdth, Weight)

Arguments

t0

a given time point

Tvec, Yvec

numeric vectors of time and outcome values, Tvec and Yvec must have the same length.

X1, X2, X3

three covariate vectors

Bndwdth

a bandwidth of the Epanechnikov kernel

Weight

the weight vector

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.

Examples

# see usage of LocalLm.Beta

Local linear fit at X0 with Epanechnikov kernel

Description

Local linear fit at X0 with Epanechnikov kernel

Usage

LocalLm.X0(Xvec, Yvec, X0, Bndwdth, Wt = 1)

Arguments

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

X0

a given value

Bndwdth

a bandwidth of the kernel

Wt

a weight vector or a constant. For longitudinal data, Wt=1/N corresponds to measurement uniform weight and Wt=1/(nni) corresponds subject uniform weight.

Examples

# see usage of LocalLm

An equation solver with Newton's method with 1 variable

Description

An equation solver with Newton's method with 1 variable

Usage

Newton1var(Z12vec, h0, Vh, HZB, Ind.Y, Diff = 1e-08, ORR, MaxIter = 100)

Arguments

Z12vec

2-dim covariate vector

h0, Vh, HZB

inital values

Ind.Y

outcome inidicator

Diff

limit to stop the interations

ORR

estimate of the odds ratio vector

MaxIter

maximum no. of interations

Value

The root of the equation

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


An equation solver with Newton's method with 2 variables

Description

An equation solver with Newton's method with 2 variables

Usage

Newton2var(Zij, b0, Ub, Indicator, difflmt = 1e-14, MaxIter = 100)

Arguments

Zij

2-dim covariate vector

b0, Ub

inital values

Indicator

Indicator of Yi1> Yi2

difflmt

limit to stop the interations

MaxIter

maximum no. of interations

Value

The root of the equation

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


NGHS dataset

Description

This dataset includes 2378 girls (total 19701 observations) enrolled in the National Heart, Lung, and Blood Institute's Growth and Health Study (NGHS). NGHS is a multicenter population-based cohort study aimed at evaluating the racial differences and longitudinal changes in childhood cardiovascular risk factors between Caucasian and African American girls during childhood and adolescence.

Usage

data(NGHS)

Format

A data frame with 19701 rows and 12 variables.

Details

  • ID. Subject ID

  • RACE. Subject's race (1=Caucasian, 2= African American)

  • AGE,HEIGHT,WEIGHT,BMI. Age, height, weight and BMI at study visit

  • BMIPCT, HTPCT. CDC Age-adjusted BMI percentile and height percentile at study visit

  • SBP,DBP. Systolic and diastolic blood pressure at study visit

  • TG,LDL. Triglyceride and Low-density lipoprotein (LDL) cholesterol at study visit

References

  1. National Heart, Lung, and Blood Institute Growth and Health Research Group (NGHSRG). Obesity and cardiovascular disease risk factors in black and white girls: the NHLBI Growth and Health Study. American Journal of Public Health, 82:1613-1620, 1992.

  2. Wu, C. O. and Tian, X. Nonparametric estimation of conditional distributions and rank-tracking probabilities with time-varying transformation models in longitudinal studies. Journal of the American Statistical Association, 108:971-982, 2013.


Title Nadaraya-Watson Kernel estimator at x0

Description

Title Nadaraya-Watson Kernel estimator at x0

Usage

NW.Kernel(Xvec, Yvec, X0, Kernel = "Ep", Bndwdth, Wt = 1)

Arguments

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

X0

a given value

Kernel

a character string indicating which kernel function is to be used. Use of "Ep", "Bw", or "Nm" for Epanechnikov, Biweight or Normal kernel function.

Bndwdth

a bandwidth of the kernel

Wt

a weight vector or a constant. For longitudinal data, Wt=1/N corresponds to measurement uniform weight and Wt=1/(nni) corresponds subject uniform weight.

Value

The kernel estimator at x0

References

  1. Fan, J. and Gijbels, I. Local Polynomial Modeling and Its Applications. Chapman & Hall, London, United Kingdom, 1996.

  2. Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data. Chapman & Hall/CRC. To appear.

Examples

X <- seq(0, 1, len=100)
Y <- (X- 0.5)^3 - 2*(X-0.5)^2+ rnorm(100, 0, 0.1)
NW.WtKernel(X, Y,  X0=0.5, Kernel="Ep", Bndwdth=0.3, Wt=1 )
NW.WtKernel(X, Y,  X0=0.5, Kernel="Nm", Bndwdth=0.3, Wt=1 )

Title Nadaraya-Watson Kernel estimator at x0

Description

Title Nadaraya-Watson Kernel estimator at x0

Usage

NW.WtKernel(Xvec, Yvec, X0, Kernel = "Ep", Bndwdth, Wt = 1)

Arguments

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

X0

a given value

Kernel

a character string indicating which kernel function is to be used. Use of "Ep", "Bw", or "Nm" for Epanechnikov, Biweight or Normal kernel function.

Bndwdth

a bandwidth of the kernel

Wt

a weight vector or a constant. For longitudinal data, Wt=1/N corresponds to measurement uniform weight and Wt=1/(nni) corresponds subject uniform weight.

Value

The kernel estimator at x0

References

  1. Fan, J. and Gijbels, I. Local Polynomial Modeling and Its Applications. Chapman & Hall, London, United Kingdom, 1996.

  2. Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018

Examples

X <- seq(0, 1, len=100)
Y <- (X- 0.5)^3 - 2*(X-0.5)^2+ rnorm(100, 0, 0.1)
NW.WtKernel(X, Y,  X0=0.5, Kernel="Ep", Bndwdth=0.3, Wt=1 )
NW.WtKernel(X, Y,  X0=0.5, Kernel="Nm", Bndwdth=0.3, Wt=1 )

Polynomial-spline fit with equally-spaced knots

Description

Polynomial-spline fit with equally-spaced knots

Usage

spline.fit(Xint, Xvec, Yvec, nKnots = 2, Degree = 3, Wt = 1)

Arguments

Xint

a vector of x interval to generate the local linear fit

Xvec, Yvec

numeric vectors of data values, Xvec and Yvec must have the same length.

nKnots

number of equally-spaced knots

Degree

degree of polynomial splines

Wt

a weight vector or a constant. For longitudinal data, Wt=1/N corresponds to measurement uniform weight and Wt=1/(nni) corresponds subject uniform weight.

References

Wu, C.O. and Tian, X. Nonparametric Models for Longitudinal Data: With Implementation in R. Chapman & Hall/CRC. 2018.


Function Xi(s)

Description

Function Xi(s)

Usage

Xi(s)

Arguments

s

a number or a vector

Value

value of the function with give s

Examples

Xi(0)
Xi(c(-1000, -10,-5, 0, 5,10, 1000 ))