PsychInterpolate {MixedPsy} | R Documentation |
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)
Arguments
model_list |
A structured list of grouped models obtained from |
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.
Value
A data frame containing the interpolated independent variable, the corresponding predicted values from the GLM model, and columns for the grouping factors.
See Also
Examples
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))