View source: R/psych_utils_multi.R
PsychInterpolate | R Documentation |
This function generates an interpolated dataset by predicting values across a range of an independent variable from a list of generalized linear models (GLMs).
PsychInterpolate(model_list, n_points = 100)
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. |
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.
A data frame containing the interpolated independent variable, the corresponding predicted values from the GLM model, and columns for the grouping factors.
PsychModels
, predict
.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.