Learn R Programming

Inflongitudinal (version 0.1.0)

wlm: Weighted Longitudinal Mean (WLM)

Description

This function identifies influential subjects in a longitudinal dataset based on their weighted mean response values. It computes weighted averages for each subject and detects anomalies by comparing them against an overall mean threshold.

Usage

wlm(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 dataframe of influential subjects' data.

non_influential_data

A dataframe of non-influential subjects' data.

weighted_plot

A ggplot object showing the weighted mean response for each subject.

longitudinal_plot

A ggplot object visualizing the longitudinal data with influential subjects highlighted.

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 longitudinal data.

subject_id

A column specifying the column name representing subject IDs.

time

A column specifying different time points that observations are measured.

response

A column specifying the column name representing the response variable.

k

A numeric value specifying the threshold multiplier for detecting influential subjects (default: 2).

verbose

Logical; if TRUE, prints informative messages during execution.

Details

The function follows these steps:

  • Computes the weighted mean response for each subject.

  • Calculates the overall mean and standard deviation of weighted responses.

  • Identifies subjects whose weighted mean response deviates beyond k standard deviations.

  • Separates data into influential and non-influential subjects.

  • Provides visualizations of the detected anomalies using ggplot2.

This method is beneficial for detecting influential subjects in longitudinal studies, where responses may vary over time and require weighted adjustments.

See Also

tvm, slm, sld, rld

Examples

Run this code
data(infsdata)
infsdata <- infsdata[1:5,]
result <- wlm(infsdata, "subject_id", "time", "response", k = 2)
print(result$influential_subjects)
head(result$influential_data)
head(result$non_influential_data)
print(result$weighted_plot)
print(result$longitudinal_plot)

Run the code above in your browser using DataLab