Skip to content

Commit 79b8026

Browse files
committed
add comments
1 parent ab74f98 commit 79b8026

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

R/get_predicted_bayesian.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ get_predicted.stanreg <- function(x,
103103
# Handle special cases
104104
if (!my_args$predict %in% c("expectation", "response", "link") && inherits(model_family, "brmsfamily")) {
105105
if (is_wiener) {
106+
# Wiener (Drift Diffusion) Models --------------------
107+
# ----------------------------------------------------
106108
# Separate RT from Choice and assemble into 3D matrix (as if it was a multivariate)
107109
response <- as.numeric(draws >= 0)
108110
draws <- abs(draws)
@@ -112,6 +114,8 @@ get_predicted.stanreg <- function(x,
112114
dimnames = list(NULL, NULL, c("rt", "response"))
113115
)
114116
} else if (is_rtchoice) {
117+
# Reaction time and Choice Models --------------------
118+
# ----------------------------------------------------
115119
# LogNormal Race models (cogmod package) return RT and Choice as odd and even columns
116120
response <- as.matrix(draws[, seq(2, ncol(draws), 2)])
117121
draws <- as.matrix(draws[, seq(1, ncol(draws), 2)])
@@ -121,9 +125,14 @@ get_predicted.stanreg <- function(x,
121125
dimnames = list(NULL, NULL, c("rt", "response"))
122126
)
123127
} else if (is_mixture && identical(my_args$predict, "classification")) {
128+
# Mixture (multi membership) Models --------------------
129+
# ------------------------------------------------------
124130
# for mixture models, which predict the class membership, we stop
125131
# here and just return the predicted class membership
126132
mixture_output <- do.call(brms::pp_mixture, fun_args)
133+
# pp_mixture() returns an array with predicted probability for class
134+
# assignment for each observation. we here return the class definition
135+
# with the highest probability per observation
127136
out <- data.frame(Predicted = apply(mixture_output[, 1, ], 1, which.max))
128137
return(out)
129138
}

0 commit comments

Comments
 (0)