Learn R Programming

joineR (version 1.0-2)

variogram: Empirical variogram for longitudinal data

Description

Calculates the variogram for observed measurements, with two components, the total variability in the data, and the variogram for all time lags in all individuals.

Usage

variogram(indv, time, Y)

Arguments

indv
vector of individual identification, as in the longitudinal data, repeated for each time point
time
vector of observation time, as in the longitudinal data
Y
vector of observed measurements. This can be a vector of longitudinal data, or residuals after fitting a model for the mean response

Value

  • The function returns a list with two elements. The first svar is a matrix with columns for all values $(u_{ijk},v_{ijk})$, and the second sigma2 is the total variability in the data. This is an object of class vargm

Details

The empirical variogram in this function is calculated from observed half-squared-differences between pairs of measurements, $$v_{ijk} = 0.5 * (r_{ij}-r_{ik})^2$$ and the corresponding time differences $$u_{ijk}=t_{ij}-t_{ik}$$. The variogram is plotted for averages of each time lag for the $v_{ijk}$ for all $i$

Examples

Run this code
data(mental)
mental.unbalanced <- to.unbalanced(mental, id.col = 1, 
                                   times = c(0,1,2,4,6,8),
                                   Y.col = 2:7, 
                                   other.col = c(8,10,11))
names(mental.unbalanced)[3] <- "Y"
vgm <- variogram(indv = mental.unbalanced[, 1],
                 time = mental.unbalanced[, 2],
                 Y = mental.unbalanced[, 3])

Run the code above in your browser using DataLab