Package 'IIVpredictor'

Title: Modeling Within Individual Variability as Predictor
Description: Time parceling method and Bayesian variability modeling methods for modeling within individual variability indicators as predictors.For more details, see <https://github.com/xliu12/IIVpredicitor>.
Authors: Lijuan Wang [aut, cph], Xiao Liu [aut, cre, cph], Miao Yang [aut, cph]
Maintainer: Xiao Liu <[email protected]>
License: GPL-2
Version: 0.1.0
Built: 2024-12-03 06:31:36 UTC
Source: CRAN

Help Index


Bayesian variability modeling method for modeling intraindividual standard deviation as a predictor

Description

Intraindividual mean and standard deviation are modeled as predictors of an outcome variable using Bayesian approach, where hyper priors are specified for the true (i.e., latent) intraindividual mean and standard deviation.

Usage

ISD.BV(
  compx,
  y,
  ReMeasure
  , nchains=2, niter=8000
)

Arguments

compx

an N*T (N: number of individuals; T: number of measurement occasions) matrix containing wide format repeated measures of a time varying independent variable X

y

a column vector of length N containing a single measurement of the outcome variable y

ReMeasure

measurement scale reliability of the time varying independent variable X

nchains

number of Markov chains (default: 2)

niter

number of total iterations per chain (including burn in; default: 8000)

Details

For each individual, the predictor score at occasion t is assumed to follow a normal distribution:

x_it : N( mux_i, (sigmav_i)^2 + sigmaex^2 ),

where the intraindividual variance (sigmav_i)^2 is modeled as sigmav_i^2 : Gamma(location, scale) with unknown location and scale parameters; and the intraindividual mean (mux_i) as mux_i : N(mu_mux, sigma_mux^2). The measurement scale reliability of X ("ReMeasure") is used to help identify the model, where we set sigmaex^2 = (1– ReMeasure )*(sigma_mux^2+location*scale)/ReMeasure.

For predicting outcome Y, we assume y_i : N( beta_0+beta_IM*mux_i+beta_IIV*sigmav_i, sigmay^2 ).

Half Cauchy priors are used as a weakly informative prior for location, 1/scale, sigma_mux, and sigmay. Noninformative normal priors,N(0,0.001^2) are used for the regression coefficients. R JAGS is used to implement the MCMC sampling.

Value

IVAR.BV returns a data.frame named "res" containing the mean("Estimate"), standard deviation ("Std.err"), 0.025 and 0.975 quantiles of the posterior distributions of the effects of the intraindividual standard deviation ("beta_IIV") and intraindividual mean ("beta_IM") of X (the time varying indenpendent variable) on Y (the outcome variable), , and their corresponding Rhat (the potential scale reduction factor of the Gelman Rubin convergence diagnositic) values.

Examples

#  Population Values
# IM: mux_i : N(0, var=9)
sigma_mu=sqrt(9);
# IIV: sigmasqx_i : Gamma(shape=0.25, scale=17)
shape=0.25;
scale=17;
# measurement error
sigma_e=sqrt(1.8) # such that the measurement scale reliability is .88
# y_i = beta_mu*IM_i + beta_IIV*ISD_i + epsilon_i
# epsilon_i : N(0,1)
beta_mu=1;
sigma_ep=1

# beta_IIV is beta2 for ISD
beta_IIV=c(0,0.3,0.8,1.50)[2]
N=c(200,500)[1]
T=c(6,9,12)[2]


#  Data Generation
set.seed(12)
mu=rnorm(N,0,sigma_mu)
IIV=rgamma(N,shape=shape,scale=scale) #sigmasq_vi
isd=sqrt(IIV)
# population regression model
# y=0+beta_mu*mu+beta_IIV*IIV+rnorm(N,0,sigma_ep)
# use ISD as predictor
y=0+beta_mu*mu+beta_IIV*isd+rnorm(N,0,sigma_ep)

x=v=compx=array(0,c(N,T))
for (i in 1:N) {
  v[i,]=mu[i]+rnorm(T,0,isd[i])
  x[i,]=v[i,]+rnorm(T,0,sigma_e)
  compx[i,]=x[i,]
}


ISD.BV(
  compx,
  y,
  ReMeasure=0.88
  , nchains=2, niter=10
)

Bayesian variability modeling method for modeling intraindividual variance as a predictor

Description

Intraindividual mean and variance are modeled as predictors of an outcome variable using Bayesian approach, where hyper priors are specified for the true (i.e., latent) intraindividual mean and variance.

Usage

IVAR.BV(
  compx,
  y,
  ReMeasure
  , nchains=2, niter=8000
)

Arguments

compx

an N*T (N: number of individuals; T: number of measurement occasions) matrix containing wide format repeated measures of a time varying independent variable X.

y

a column vector of length N containing a single measurement of the outcome variable y.

ReMeasure

measurement scale reliability of the time varying independent variable X.

nchains

number of Markov chains (default: 2).

niter

number of total iterations per chain (including burn in; default: 8000).

Details

For each individual, the predictor score at occasion t is assumed to follow a normal distribution:

x_it : N( mux_i, (sigmav_i)^2 + sigmaex^2 ),

where the intraindividual variance (sigmav_i)^2 is modeled as sigmav_i^2 : Gamma(location, scale) with unknown location and scale parameters; and the intraindividual mean (mux_i) as mux_i : N(mu_mux, sigma_mux^2). The measurement scale reliability of X ("ReMeasure") is used to help identify the model, where we set sigmaex^2 = (1– ReMeasure )*(sigma_mux^2+location*scale)/ReMeasure.

For predicting outcome Y, we assume y_i : N( beta_0+beta_IM*mux_i+beta_IIV*(sigmav_i)^2, sigmay^2 ).

Half Cauchy priors are used as a weakly informative prior for location, 1/scale, sigma_mux, and sigmay. Noninformative normal priors,N(0,0.001^2) are used for the regression coefficients. R JAGS is used to implement the MCMC sampling.

Value

IVAR.BV returns a data.frame named "res" containing the mean("Estimate"), standard deviation ("Std.err"), 0.025 and 0.975 quantiles of the posterior distributions of the effects of the intraindividual variance ("beta_IIV") and intraindividual mean ("beta_IM") of X (the time varying indenpendent variable) on Y (the outcome variable), and their corresponding Rhat (the potential scale reduction factor of the Gelman Rubin convergence diagnositic) values.

Examples

#  Population Values
# IM: mux_i : N(0, var=9)
sigma_mu=sqrt(9);
# IIV: sigmasqx_i : Gamma(shape=0.25, scale=17)
shape=0.25;
scale=17;
# measurement error
sigma_e=sqrt(1.8) # such that the measurement scale reliability is .88
# y_i = beta_mu*IM_i + beta_IIV*ISD_i + epsilon_i
# epsilon_i : N(0,1)
beta_mu=1;
sigma_ep=1

# beta_IIV is beta2 for ISD
beta_IIV=c(0,0.3,0.8,1.50)[2]
N=c(200,500)[1]
T=c(6,9,12)[2]


#  Data Generation
set.seed(12)
mu=rnorm(N,0,sigma_mu)
IIV=rgamma(N,shape=shape,scale=scale) #sigmasq_vi
isd=sqrt(IIV)
# population regression model
# y=0+beta_mu*mu+beta_IIV*IIV+rnorm(N,0,sigma_ep)
# use ISD as predictor
y=0+beta_mu*mu+beta_IIV*isd+rnorm(N,0,sigma_ep)

x=v=compx=array(0,c(N,T))
for (i in 1:N) {
  v[i,]=mu[i]+rnorm(T,0,isd[i])
  x[i,]=v[i,]+rnorm(T,0,sigma_e)
  compx[i,]=x[i,]
}


IVAR.BV(
  compx,
  y,
  ReMeasure=0.88
  , nchains=2, niter=10
)

Time parceling (with bootstrap) method for modeling intraindividual variance as a predictor

Description

Use observed intraindividual means and variances of multiple (e.g., 3) time parcels as manifest indicators of true (latent) intraindividual mean and variance respectively to predict an outcome variable in a structural equation model (SEM).

Usage

IVAR.TPB(
  compx,
  y,
  nB=1000
)

Arguments

compx

an N*T (N: number of individuals; T: number of measurement occasions) matrix containing wide format repeated measures of a time varying independent variable X.

y

a column vector of length N containing the outcome variable Y.

nB

number of bootstrap samples (default: 1000).

Details

A fixed number (numpar = 3) of time parcels are formed for each individual using the individual's repeated measures of the independent variable X at T occasions. The time parcels are created by cutting the sequence 1,2,...,T into three intervals of (approximately) equal length (about T/numpar). Then for each individual, sample intraindividual means and variances of the created time parcels are computed and used as manifest indicators of the individual's true (latent) intraindividual mean and variance respectively to predict the individual's outcome score in a structural equation model (SEM). Sampling (i.e., sampling individuals from population) variablility of the parameter estimates is accounted for using the Bootstrap approach. #nB bootstrap samples are drawn to estimate the standard errors and 0.95 confidence intervals.

Value

IVAR.TPB returns a list "reslist" containing two components.

res

a data.frame named "res" containing the estimates ("Estimate"), standard error estimates ("Std.err"), and lower and upper bounds of 0.95 confidence intervals of the effects of the intraindividual variance ("beta_IIV") and intraindividual mean ("beta_IM") of X (the time varying indenpendent variable) on Y (the outcome variable).

convergence

convergence rate of the bootstrap samples.

Examples

#  Population Values
# IM: mux_i  N(0, var=9)
sigma_mu=sqrt(9);
# IIV: sigmasqx_i  Gamma(shape=0.25, scale=17)
shape=0.25;
scale=17;
# measurement error
sigma_e=sqrt(1.8) # such that the measurement scale reliability is .88
# y_i = beta_mu*IM_i + beta_IIV*ISD_i + epsilon_i
# epsilon_i  N(0,1)
beta_mu=1;
sigma_ep=1

# beta_IIV is beta2 for ISD
beta_IIV=c(0,0.3,0.8,1.50)[2]
N=c(200,500)[1]
T=c(6,9,12)[2]

#  Data Generation
set.seed(12)
mu=rnorm(N,0,sigma_mu)
IIV=rgamma(N,shape=shape,scale=scale) #sigmasq_vi
isd=sqrt(IIV)
# population regression model
# y=0+beta_mu*mu+beta_IIV*IIV+rnorm(N,0,sigma_ep)
# use ISD as predictor
y=0+beta_mu*mu+beta_IIV*isd+rnorm(N,0,sigma_ep)

x=v=compx=array(0,c(N,T))
for (i in 1:N) {
  v[i,]=mu[i]+rnorm(T,0,isd[i])
  x[i,]=v[i,]+rnorm(T,0,sigma_e)
  compx[i,]=x[i,]
}

IVAR.TPB(
  compx,
  y,
  nB=10
)