Learn R Programming

MixedPsy (version 1.2.0)

PsychInterpolate: Interpolate Predictions from a List of GLM Models

Description

This function generates an interpolated dataset by predicting values across a range of an independent variable from a list of generalized linear models (GLMs).

Usage

PsychInterpolate(model_list, n_points = 100)

Value

A data frame containing the interpolated independent variable, the corresponding predicted values from the GLM model, and columns for the grouping factors.

Arguments

model_list

A structured list of grouped models obtained from PsychModels.

n_points

An integer number. It specifies the number of points to interpolate along the independent variable range. Default is 100.

Details

The function takes a structured list of models, as produced by PsychModels, and generates a new dataset with interpolated values for the independent variable. Predictions are computed at evenly spaced points across the observed range for each model, and the results are returned in a long-format data frame.

See Also

PsychModels, predict.

Examples

Run this code
model_list <- PsychModels(formula = cbind(Longer, Total - Longer) ~ X,
data = simul_data,
group_factors = "Subject")

longData <- PsychInterpolate(model_list)

# use the interpolated dataset to plot model:
library(ggplot2)
ggplot(longData, aes(X, prediction, color = Subject)) +
geom_line() +
geom_point(data = simul_data, aes(X, Longer/Total))

Run the code above in your browser using DataLab