ns = Inputs.text().classList[0]
// custom css to override some ojs defaults for inputs
html`<style>
.${ns} {
--label-width: 80px;
}
form.${ns} {
flex-wrap: wrap;
}
/* label above options -- add stacked-input to an input elsewhere to get this */
.plot-inputs form.${ns},
form.${ns}.stacked-input {
flex-direction: column;
}
/* inputs' forms center their items, which in a column centers the options */
form.${ns}.stacked-input {
align-items: flex-start;
}
.${ns} div label {
background-color: #f4f4f4;
padding: 0.25rem 0.5rem;
border-radius: 0.5rem;
margin-right: 0.25rem;
margin-bottom: 0.25rem;
width: auto;
}
.${ns} div label:hover,
.${ns} div label:active,
.${ns} div label:focus {
background-color: #fbe4b4;
}
.${ns} input[type="checkbox"] {
accent-color: black;
margin-bottom: 0;
}
.${ns} div input[type="number"] {
background-color: #f4f4f4;
padding: 0.25rem 0.5rem;
border-radius: 0.5rem;
flex-shrink: 3;
border: none;
}
/* wide enough for 3-4 digit values, which the shrink above would cut off */
.${ns} div input[type="number"] {
flex-shrink: 0;
width: 4.5em;
}
/* single ended sliders, styled to match the double ended ones in _interval:
the track is filled up to the thumb centre, given by --fill (0 to 1), which
has to be set from js since browsers other than firefox have no fill element */
.${ns} input[type="range"] {
-webkit-appearance: none;
appearance: none;
height: 7px;
border-radius: 4px;
--fill-px: calc(7.5px + var(--fill, 0) * (100% - 15px));
background: linear-gradient(to right, #f7ca69 var(--fill-px), hsl(0, 0%, 80%) var(--fill-px));
}
.${ns} input[type="range"]::-moz-range-track {
background: transparent;
}
.${ns} input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 15px;
height: 15px;
border-radius: 100%;
background: #fcfcfc;
border: 1px solid hsl(0, 0%, 55%);
}
.${ns} input[type="range"]::-moz-range-thumb {
box-sizing: border-box;
width: 15px;
height: 15px;
border-radius: 100%;
background: #fcfcfc;
border: 1px solid hsl(0, 0%, 55%);
}
.${ns} select {
background-color: #f4f4f4;
border: none;
border-radius: 0.5rem;
padding: 0.25rem 0.5rem;
//width: auto;
}
.${ns} .hist {
width: 100%;
display: flex;
flex-direction: column;
row-gap: 0em;
}
</style>`// keeps an input's value in a URL parameter, so that links to the page can
// share its state. on creation the input is set from the parameter (if valid),
// and the parameter is updated whenever the input changes, with it left out
// when the input is at its default value
//
// choices: Map of option labels to values for radio/select/checkbox inputs,
// which are stored by label (their values can be null or data), comma separated
// for checkboxes; otherwise the value is stored as a number, or as comma
// separated numbers for intervals
url_bound = (key, input, { choices } = {}) => {
const is_number = s => s !== "" && Number.isFinite(+s)
const label_of = v => [...choices].find(([label, value]) => value === v)?.[0]
// checkbox values are arrays, but so can be the values of other inputs
const multiple = choices && input.querySelector("input[type=checkbox]") !== null
const encode = multiple
? v => v.map(label_of).join(",")
: choices
? label_of
: v => String(v)
const decode = multiple
? s => { const v = s === "" ? [] : s.split(","); return v.every(l => choices.has(l)) ? { value: v.map(l => choices.get(l)) } : null }
: choices
? s => choices.has(s) ? { value: choices.get(s) } : null
: Array.isArray(input.value)
? s => { const v = s.split(","); return v.length === 2 && v.every(is_number) ? { value: v.map(Number) } : null }
: s => is_number(s) ? { value: +s } : null
const default_param = encode(input.value)
const param = new URLSearchParams(location.search).get(key)
const decoded = param === null ? null : decode(param)
if (decoded !== null) {
input.value = decoded.value
// the value setter alone is silent, so let the input's own listeners (e.g.
// slider fill) know
input.dispatchEvent(new Event("input", { bubbles: true }))
}
input.addEventListener("input", () => {
const url = new URL(location.href)
const p = encode(input.value)
if (p === undefined || p === default_param) url.searchParams.delete(key)
else url.searchParams.set(key, p)
history.replaceState(history.state, "", url)
})
return input
}Plot = import("https://esm.sh/@observablehq/plot@0.6.17")
// defined in _load-data-items.qmd
items = transpose(items_)
models = transpose(models_)
// create combined item_group and language, sort by task
task_order = ([ "hf", "sds", "mg", "math", "matrix", "mrot", "trog", "vocab", "tom", "pa", "sre", "swr" ])
items_coded = items
.map(d => ({...d, lang_group_label: `${d.item_group_label} | ${d.language}` }))
.sort((a, b) => {
return task_order.indexOf(a.task_code) - task_order.indexOf(b.task_code)
})
// group items by task for task selector
tasks = d3.group(items_coded, d => d.task_label)This Items tab shows estimated difficulty by item group. Item groups are clusters of items defined a priori based on conceptual similarity, and were not used to estimate the scores themselves.
item_vars = ["item_group_label", "item_uid", "n_responses", "guessing"]
item_channels = Object.fromEntries(item_vars.map(k => [k, k]))
task = task_items[0].task_code // current items' task code
model = models.filter(t => t.task_code === task)[0] // current items' model type
by_lang = model.language !== undefined // whether items' model is by language
// sort order of languages -- alpha
langs = d3.sort(new Set(task_items.map(d => d.language)))
// sort order of item groups -- median difficulty (in first language)
l0_items = task_items.filter(d => d.language === langs[0])
groups = d3.groupSort(l0_items, g => d3.median(g, d => d.difficulty), d => d.item_group_label)
// sort order of language + item group -- above combined
indeces = d3.groups(task_items, d => d.lang_group_label)
.map(([lang_group_label, vals]) =>
[lang_group_label, langs.indexOf(vals[0].language), groups.indexOf(vals[0].item_group_label)])
lang_groups = d3.sort(indeces, d => d[1], d => d[2]).map(d => d[0])heights = ({
"hf": 180,
"sds": 240,
"mg": 220,
"math": 490,
"matrix": 220,
"mrot": 150,
"trog": 690,
"vocab": 340,
"tom": 300,
"pa": 320,
"swr": 600
})
// shared options for both parameter plots
item_opts = ({
style: { fontFamily: "var(--sans-serif)", fontSize: 12, overflow: "visible" },
width: 800,
height: heights[task],
marginLeft: 200,
marginTop: 50,
marginBottom: 40,
grid: true,
facet: { label: null, grid: true },
x: { line: true },
r: { range: [1, 4] },
fy: { domain: by_lang ? lang_groups : groups },
color: { domain: groups.length > 1 ? groups : langs, legend: false, scheme: "viridis" },
})
// dot mark for each plot, depending on x variable
item_dots = (x_var) => {
return Plot.marks(
Plot.dot(task_items, Plot.dodgeY("middle", {
x: x_var,
fy: by_lang ? "lang_group_label" : "item_group_label",
fill: groups.length > 1 ? "item_group_label" : "language",
r: "n_responses",
tip: { format: { fy: false } }, //, anchor: "left"
channels: item_channels
}))
)
}plot_d = Plot.plot({
...item_opts,
marks: item_dots("difficulty")
})
// item discriminations plot -- hide if model isn't 2PL
plot_a = model.itemtype !== "2PL" ? html`<div></div>` :
Plot.plot({
...item_opts,
marks: item_dots("discrimination")
})
Plot.plot({
style: { fontFamily: "var(--sans-serif)", fontSize: 12, overflow: "visible" },
className: "icc-plot",
width: 250,
height: 250,
marginBottom: 40,
x: {
line: true,
label: "ability",
domain: [theta_min, theta_max],
ticks: d3.range(theta_min, theta_max, 2.5).concat(theta_max)
},
y: {
line: true,
label: "probability correct",
domain: [0, 1],
ticks: d3.range(0, 1, 0.25).concat(1)
},
color: plot_d.scale("color"), // use color scale from difficulty plot
subtitle: item ? item_label(item) : "",
marks: [
Plot.ruleY([item?.guessing || null], {
stroke: "lightgrey",
strokeDasharray: "4 3",
strokeLinecap: "round"
}),
Plot.line(item_icc, {
x: "theta",
y: "p",
stroke: groups.length > 1 ? "item_group_label" : "language"
})
]
})
item_label = (item) => item.language ? `${item.item_uid} (${item.language})`: item.item_uidirf = (theta, a, b, c) => c + (1 - c) / (1 + Math.exp(-a * (theta - b)))
// theta array
theta_min = -5
theta_max = 5
thetas = d3.range(theta_min, theta_max, 0.01)
// ICC (item characteristic curve)
icc = (thetas, a, b, c) => thetas.map(t => ({theta: t, p: irf(t, a, b, c)}))
icc_item = (thetas, item) => icc(thetas, item.discrimination, item.difficulty, item.guessing)
// instantiate item object and its ICC array
mutable item = null
item_icc = item ? icc_item(thetas, item).map(d => ({...d, ...item})) : []
// find selected item in item data -- match by item_uid, then by language if defined
match_item = (vals) => vals ? task_items.filter(d => d.item_uid === vals.item_uid && (d.language === undefined || d.language === vals.language))[0] : null
// add event listeners to parameter plots that set item object based on hovered point
plot_d.addEventListener("input", (event) => mutable item = match_item(plot_d.value))