# using all defaults and properly formatted data
ds <- dscore(milestones)
head(ds)
# step-by-step example
data <- data.frame(
id = c(
"Jane", "Martin", "ID-3", "No. 4", "Five", "6",
NA_character_, as.character(8:10)
),
age = rep(round(21 / 365.25, 4), 10),
ddifmd001 = c(NA, NA, 0, 0, 0, 1, 0, 1, 1, 1),
ddicmm029 = c(NA, NA, NA, 0, 1, 0, 1, 0, 1, 1),
ddigmd053 = c(NA, 0, 0, 1, 0, 0, 1, 1, 0, 1)
)
items <- names(data)[3:5]
# third item is not part of the default key
get_tau(items, verbose = TRUE)
# calculate D-score
dscore(data)
# prepend id variable to output
dscore(data, prepend = "id")
# or prepend all data
# dscore(data, prepend = colnames(data))
# calculate full posterior
p <- dscore_posterior(data)
# check that rows sum to 1
rowSums(p)
# plot full posterior for measurement 7
barplot(as.matrix(p[7, 12:36]),
names = 1:25,
xlab = "D-score", ylab = "Density", col = "grey",
main = "Full D-score posterior for measurement in row 7",
sub = "D-score (EAP) = 11.58, SEM = 3.99")
# plot P10, P50 and P90 of D-score references
g <- expand.grid(age = seq(0.1, 4, 0.1), p = c(0.1, 0.5, 0.9))
d <- zad(z = qnorm(g$p), x = g$age, verbose = TRUE)
matplot(
x = matrix(g$age, ncol = 3), y = matrix(d, ncol = 3), type = "l",
lty = 1, col = "blue", xlab = "Age (years)", ylab = "D-score",
main = "D-score preliminary standards: P10, P50 and P90")
abline(h = seq(10, 80, 10), v = seq(0, 4, 0.5), col = "gray", lty = 2)
# add measurements made on very preterms, ga < 32 weeks
ds <- dscore(milestones)
points(x = ds$a, y = ds$d, pch = 19, col = "red")
Run the code above in your browser using DataLab