Kalkulator interval prediksi
Kalkulator ini membuat interval prediksi untuk nilai tertentu dalam analisis regresi.
Cukup masukkan daftar nilai untuk variabel prediktor, variabel respons, nilai individual untuk membuat interval prediksi dan tingkat kepercayaan, dan klik tombol “Hitung”:
Nilai prediktif:
Nilai respons:
Nilai X untuk prediksi:
Tingkat kepercayaan diri:
Interval prediksi 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