Diversity prediction theorem: Difference between revisions

m
→‎{{header|R}}: Improved syntax.
m (→‎{{header|R}}: Syntax highlighting.)
m (→‎{{header|R}}: Improved syntax.)
Line 1,328:
=={{header|R}}==
R's vectorisation shines here. The hardest part of this task was giving each estimate its own numbered column, which is little more than a printing luxury. The actual mathematics was trivial, with each part done in essentially one line.
<lang rsplus>diversityStats <- function(trueValue, estimates)
{
collectivePrediction <- mean(estimates)
data.frame("True Value" = trueValue,
as.list(setNames(estimates, paste("Guess", seq_along(estimates)))), #Guesses, each with a title and column.
"Average Error" = mean((trueValue - estimates)^2),
"Crowd Error" = (trueValue - collectivePrediction)^2,
"Prediction Diversity" = mean((estimates - collectivePrediction)^2))
}
diversityStats(49, c(48, 47, 51))
331

edits