予測間隔計算ツール
この計算機は、回帰分析で指定された値の予測区間を作成します。
予測変数、応答変数、予測区間と信頼水準を作成するための個別の値の値のリストを入力し、[計算] ボタンをクリックするだけです。
予測値:
応答値:
予測の X 値:
自信のレベル:
90 % 予測区間: ( 74.643 , 86.903 )
function calc() {
//get input data var x = document.getElementById('x').value.split(',').map(Number); var y = document.getElementById('y').value.split(',').map(Number); var xpred = +document.getElementById('xpred').value; var CI = +document.getElementById('CI').value;
//check that both lists are equal length if (x.length - y.length == 0) { document.getElementById('error_msg').innerHTML = '';
function linearRegression(y,x){ var lr = {}; var n = y.length; var sum_x = 0; var sum_y = 0; var sum_xy = 0; var sum_xx = 0; var sum_yy = 0;
for (var i = 0; i < y.length; i++) { sum_x += x[i]; sum_y += y[i]; sum_xy += (x[i]*y[i]); sum_xx += (x[i]*x[i]); sum_yy += (y[i]*y[i]); } lr['slope'] = (n * sum_xy - sum_x * sum_y) / (n*sum_xx - sum_x * sum_x); lr['intercept'] = (sum_y - lr.slope * sum_x)/n; lr['r2'] = Math.pow((n*sum_xy - sum_x*sum_y)/Math.sqrt((n*sum_xx-sum_x*sum_x)*(n*sum_yy-sum_y*sum_y)),2); lr['sum_y'] = sum_y; lr['sum_xx'] = sum_xx; return lr; } //create regression variables var lr = linearRegression(y, x); var a = lr.slope; var b = lr.intercept; var r2 = lr.r2; var r2p = r2*100; var sxx = lr.sum_xx; //create sse variable var my = lr.sum_y / y.length; let sst = 0; for (let i = 0; i < y.length; i++) { sst += Math.pow((y[i] - my), 2); } var CI_out = CI*100 var sse = sst - r2*sst; var n = y.length; var var2 = sse/(n-2); var xbar = math.mean(x); var ypred = b - (-1*a*xpred); var df = n-2; var tcrit = -1*jStat.studentt.inv((1-CI)/2, df); //calculate lower and upper bounds of prediction interval var lowCI = ypred-tcrit*Math.sqrt(var2*(1-(-1*(1/n))-(-1*Math.pow(xpred-xbar,2)/sxx))); var highCI = ypred-(-1*(tcrit*Math.sqrt(var2*(1-(-1*(1/n))-(-1*Math.pow(xpred-xbar,2)/sxx))))); //output results document.getElementById('lowCI').innerHTML = lowCI.toFixed(3); document.getElementById('highCI').innerHTML = highCI.toFixed(3); document.getElementById('CI_out').innerHTML = CI_out.toFixed(0); } //output error message if boths lists are not equal else { document.getElementById('error_msg').innerHTML = 'The two lists must be of equal length.'; } } //end calc function