Learn R Programming

Inflongitudinal (version 0.1.0)

tvm: Time-Varying Mean (TVM)

Description

This function detects influential subjects based on their response values at different time points. It calculates the mean and standard deviation of responses at each time point and flags subjects whose response values deviate significantly beyond a threshold. The function also generates plots to visualize influential observations and their trends over time. It also computes the Influence Score (IS) and Partial Influence Score (PIS) for each observation.

Usage

tvm(data, subject_id, time, response, k = 2, verbose = FALSE)

Value

A list containing:

influential_subjects

A vector of subject IDs identified as influential.

influential_data

A data frame containing data for influential subjects.

influential_time_data

A data frame containing data for influential subjects with only the influential time points.

non_influential_data

A data frame containing data for non-influential subjects.

mean_response_plot

A plot visualizing the mean response values across time points.

longitudinal_plot

A final plot highlighting influential subjects over time.

IS_table

A data frame containing the Influence Score (IS) and the Partial Influence Score (PIS) values for each subject at each time point.

Arguments

data

A dataframe containing the longitudinal data.

subject_id

A column specifying the column name for subject IDs.

time

A column specifying different time points that observations are measured.

response

A column specifying the column name for response values.

k

A numeric value specifying the number of standard deviations to use as the threshold (default = 2).

verbose

Logical; if TRUE, prints informative messages during execution.

Details

The function follows these steps:

  • Computes the mean and standard deviation of response values at each time point.

  • Calculates Influence Score (IS) and Partial Influence Score (PIS) for each observation.

  • Identifies subjects whose response values exceed the threshold based on k standard deviations.

  • Separates influential and non-influential subjects for further analysis.

  • Generates visualizations of mean responses and highlights influential subjects in a longitudinal plot.

This method is useful for identifying outliers and understanding variability in longitudinal studies.

See Also

slm, wlm, sld, rld

Examples

Run this code
data(infsdata)
infsdata <- infsdata[1:5,]
result <- tvm(infsdata, "subject_id", "time", "response", 2)
print(result$influential_subjects)
head(result$influential_data)
head(result$non_influential_data)
head(result$influential_time_data)
head(result$IS_table)
head(result$PIS_table)
result$mean_response_plot
result$longitudinal_plot

Run the code above in your browser using DataLab