You have an identification study: each row is a trial, with the stimulus shown and the response given. This turns that into a fitted perceptual space with intervals, and into the construct probabilities a GRT analysis usually reports. All outputs were generated by executing this code on the example file.
-
Start from trial-level data
One row per trial. The only columns that matter are
stimulusandresponse. Aparticipantcolumn lets you split a sample. To follow along, download the example file, my_experiment.csv.my_experiment.csvparticipant trial stimulus response p01 1 a2/b2 a2/b1 p01 2 a2/b1 a2/b1 p01 3 a2/b2 a2/b2 p01 4 a1/b2 a1/b2 p01 5 a2/b2 a1/b1 p01 6 a2/b2 a2/b2Levels are written as
a1/b2: the level on each dimension, separated by a character you choose. Order carries meaning that a bare label cannot express, so the packages will not guess it: you say which levels belong to which factor and they do the placement.import pandas as pd, grintools as gt trials = pd.read_csv("my_experiment.csv") one = trials[trials.participant == "p01"] ci = gt.to_confusion( one, long=True, factor_a=("a1", "a2"), factor_b=("b1", "b2"), sep="/", ) print(ci.counts)library(grin) trials <- read.csv("my_experiment.csv") one <- trials[trials$participant == "p01", ] ci <- grin_to_confusion( one, factor_a = c("a1", "a2"), factor_b = c("b1", "b2"), sep = "/" ) print(ci$counts)counts, canonical order[[29 2 3 6] [ 1 32 0 2] [ 2 3 36 4] [ 2 6 3 29]]
Rows are stimuli and columns responses, both ordered
A1B1, A1B2, A2B1, A2B2. If your file already has a 4×4 matrix in that order, skip this step and pass it straight in. -
Fit it
One call, well under a millisecond.
fit, con = gt.infer(ci.counts) print(fit.summary())fit <- grin_infer(ci$counts) print(fit)consoleGRIN inference (onnx) ---------------------------------------------- zx_0 = -0.77 +/- 0.27 [90% -1.20, -0.33] zx_1 = -1.61 +/- 0.39 [90% -2.26, -0.97] zx_2 = +1.15 +/- 0.28 [90% +0.69, +1.62] zx_3 = +0.88 +/- 0.25 [90% +0.47, +1.30] zy_0 = -0.86 +/- 0.24 [90% -1.26, -0.46] zy_1 = +1.77 +/- 0.37 [90% +1.16, +2.37] zy_2 = -0.88 +/- 0.24 [90% -1.27, -0.49] zy_3 = +1.26 +/- 0.27 [90% +0.81, +1.72] rho_0 = +0.54 +/- 0.32 [90% +0.01, +1.07] rho_1 = +0.21 +/- 0.58 [90% -0.75, +1.16] rho_2 = -0.19 +/- 0.40 [90% -0.85, +0.47] rho_3 = +0.29 +/- 0.39 [90% -0.36, +0.93] ---------------------------------------------- componentwise modal structure : free + !PS(A) + PS(B) intervals are the network's own; pass calibrated=True for width-corrected intervals (see the package documentation)
Note
rho_0: the interval runs past 1.0. The point estimate of a correlation is always valid, but the shipped interval is a symmetric Gaussian one in parameter space and is not clipped to (−1, 1). Read such an interval as “everything up to the boundary”. -
Read the constructs
for k, dk in (("p_PI", "decision_PI"), ("p_sep_A", "decision_sep_A"), ("p_sep_B", "decision_sep_B")): print(f"{k:9s} {con[k]:.3f} decision: {con[dk]}")con <- fit$constructs for (k in c("PI", "sep_A", "sep_B")) { cat(sprintf("%-9s %.3f decision: %s\n", paste0("p_", k), con[[paste0("p_", k)]], con[[paste0("decision_", k)]])) }consolep_PI 0.019 decision: against p_sep_A 0.184 decision: against p_sep_B 0.646 decision: undecided
The direction-explicit
decisionis the useful part. Here independence is clearly rejected, and so is separability on factor A. Separability on factor B is left undecided: 0.646 is not far enough from one half to report either way. A mix like this is a legitimate outcome, not a failed fit, and it matches the modal structure printed above (free + !PS(A) + PS(B)). -
Report it
The perceptual space is the conventional way to present a GRT result. All four plots come straight off the fitted object and default to a greyscale-safe style.
from grintools.plot import (plot_space, plot_params, plot_constructs, plot_diagnostics) plot_space(fit)res <- fit$result grin_plot_space(res)plot_space(fit)
plot_params(fit)grin_plot_params(res)plot_params(fit)
plot_constructs(fit, con)grin_plot_constructs(res, con)plot_constructs(fit, con)
plot_diagnostics(fit, ci.counts)grin_plot_diagnostics(res, ci$counts)plot_diagnostics(fit, cm)
Read the diagnostics plot carefully. A poor reconstruction is a real warning, but a good one does not validate the GRT assumptions: the unconstrained model can reproduce any pattern of response proportions, so fitting well is not evidence that the model is right.
-
Do the whole sample
for pid, sub in trials.groupby("participant"): cm = gt.to_confusion(sub, long=True, factor_a=("a1", "a2"), factor_b=("b1", "b2"), sep="/") _, cc = gt.infer(cm.counts) print(f"{pid} p_PI = {cc['p_PI']:.3f} p_sep_A = {cc['p_sep_A']:.3f}")for (pid in unique(trials$participant)) { sub <- trials[trials$participant == pid, ] cm <- grin_to_confusion(sub, factor_a = c("a1","a2"), factor_b = c("b1","b2"), sep = "/") f <- grin_infer(cm$counts) cat(sprintf("%s p_PI = %.3f p_sep_A = %.3f\n", pid, f$constructs$p_PI, f$constructs$p_sep_A)) }consolep01 p_PI = 0.019 p_sep_A = 0.184 p02 p_PI = 0.003 p_sep_A = 0.857 p03 p_PI = 0.080 p_sep_A = 0.879
In R,
grin_tidy()returns one row per parameter per person, and the_groupplotting functions take a list of fitted objects. -
Know what the intervals mean
The interval on a marginal sensitivity is close to its stated level, if slightly too wide. The interval on a within-stimulus correlation is narrower than nominal. Across large held-out sets a 90% interval covers about 84% of the time. Both packages ship an optional correction, off by default:
fit, con = gt.infer(ci.counts, calibrated=True) fit.std # corrected widths fit.std_raw # what the network returnedfit <- grin_infer(ci$counts, calibrated = TRUE) fit$result$std # corrected widths fit$result$std_raw # what the network returnedPoint estimates, construct probabilities and model selection are identical either way. Only the stated uncertainty changes.
Next: stop when the estimate is precise enough, or set stimulus levels.