Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function confidenceInterval95(
{mean, variance}: Distribution, size: number): ConfidenceInterval {
// http://www.stat.yale.edu/Courses/1997-98/101/confint.htm
const t = jstat.studentt.inv(1 - (.05 / 2), size - 1);
const stdDev = Math.sqrt(variance);
const margin = t * stdDev;
return {
low: mean - margin,
high: mean + margin,
};
}
mean: _ => _,
prediction: x => (MSE * 1 / (m || 1)) + x,
}[type]).map(Math.sqrt);
let g = values.length;
let statValue = {
// simultaneous region over regression surface
workingHotelling: Math.sqrt(ddof * jStat.centralF.inv(1 - alpha, ddof, n - ddof)),
// simultaneous set
scheffe: Math.sqrt(g * jStat.centralF.inv(1 - alpha, g, n - ddof)),
bonferroni: jStat.studentt.inv(1 - alpha / (2 * g), n - ddof),
// pointwise
t: jStat.studentt.inv(1 - alpha / 2, n - ddof)
}[statistic];
let invLink = {
gaussian: _ => _,
poisson: x => Math.exp(x),
exponential: x => -1 / x,
gamma: x => -1 / x,
binomial: x => 1 / (1 + Math.exp(x))
}[family];
return values
.map((val, i) => [-1, 1].map(sign => invLink(val + sign * statValue * stdErr[i])).sort())
};
// MSE is already included in the coefficient variance-covariance matrix
let stdErr = variances.map({
mean: _ => _,
prediction: x => (MSE * 1 / (m || 1)) + x,
}[type]).map(Math.sqrt);
let g = values.length;
let statValue = {
// simultaneous region over regression surface
workingHotelling: Math.sqrt(ddof * jStat.centralF.inv(1 - alpha, ddof, n - ddof)),
// simultaneous set
scheffe: Math.sqrt(g * jStat.centralF.inv(1 - alpha, g, n - ddof)),
bonferroni: jStat.studentt.inv(1 - alpha / (2 * g), n - ddof),
// pointwise
t: jStat.studentt.inv(1 - alpha / 2, n - ddof)
}[statistic];
let invLink = {
gaussian: _ => _,
poisson: x => Math.exp(x),
exponential: x => -1 / x,
gamma: x => -1 / x,
binomial: x => 1 / (1 + Math.exp(x))
}[family];
return values
.map((val, i) => [-1, 1].map(sign => invLink(val + sign * statValue * stdErr[i])).sort())
};
exports.T.INV['2T'] = function(probability, df) {
probability = parseNumber(probability);
df = parseNumber(df);
if (probability <= 0 || probability > 1 || df < 1) {
return Error(ERROR_NUM);
}
if (anyIsError(probability, df)) {
return Error(ERROR_VALUE);
}
return Math.abs(jStat.studentt.inv(probability/2, df));
};
exports.T.DIST = function (x, df, cumulative) {
cumulative = parseBool(cumulative)
x = parseNumber(x);
df = parseNumber(df);
if (anyIsError(x, df)) {
return Error(ERROR_VALUE);
}
return (cumulative) ? jStat.studentt.cdf(x, df) : jStat.studentt.pdf(x, df);
};
exports.T.DIST.RT = function(x, df) {
if (arguments.length !== 2) {
return Error(ERROR_NA);
}
if (x < 0 || df < 1) {
return Error(ERROR_NUM);
}
if ((typeof x !== 'number') || (typeof df !== 'number')) {
return Error(ERROR_VALUE);
}
return 1 - jStat.studentt.cdf(x , df);
};