二次回帰計算機
この計算機は、予測変数と応答変数の値に基づいて二次回帰式を生成します。
以下のボックスに予測変数と応答変数の値のリストを入力し、[計算] ボタンをクリックするだけです。
予測値:
応答値:
二次回帰式:
ŷ = -2.5475 + ( 3.7516 )x + ( -0.1704 ) x2
function calc() {
//get input data var x = document.getElementById('x').value.split(',').map(Number); var y = document.getElementById('y').value.split(',').map(Number);
//check that both lists are equal length if (x.length - y.length == 0) { document.getElementById('error_msg').innerHTML = '';
var xbar = math.mean(x); var ybar = math.mean(y);
let xbar2_hold = 0 for (let i = 0; i < x.length; i++) { xbar2_hold += Math.pow(x[i], 2); } var xbar2 = xbar2_hold / x.length; let sxx = 0 for (let i = 0; i < x.length; i++) { sxx += Math.pow(x[i] - xbar, 2); } let sxy = 0 for (let i = 0; i < x.length; i++) { sxy += (x[i] - xbar)*(y[i]-ybar); } let sxx2 = 0 for (let i = 0; i < x.length; i++) { sxx2 += (x[i] - xbar)*(Math.pow(x[i], 2)-xbar2); } let sx2x2 = 0 for (let i = 0; i < x.length; i++) { sx2x2 += Math.pow((Math.pow(x[i], 2)-xbar2), 2); } let sx2y = 0 for (let i = 0; i < x.length; i++) { sx2y += (Math.pow(x[i], 2)-xbar2)*(y[i]-ybar); } var b = ((sxy*sx2x2)-(sx2y*sxx2)) / ((sxx*sx2x2)-Math.pow(sxx2, 2)); var c = ((sx2y*sxx)-(sxy*sxx2)) / ((sxx*sx2x2)-Math.pow(sxx2, 2)); var a = ybar - (b*xbar) - (c*xbar2); document.getElementById('a').innerHTML = a.toFixed(4); document.getElementById('b').innerHTML = b.toFixed(4); document.getElementById('c').innerHTML = c.toFixed(4); } //output error message if boths lists are not equal else { //document.getElementById('out').innerHTML = ''; document.getElementById('error_msg').innerHTML = 'The two lists must be of equal length.'; } } //end calc function