Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Defining arrays for the values
- const x = [128, 125, 122, 100, 109, 126, 124, 106, 131, 120, 103, 110, 130, 111, 102];
- const y = [59, 40, 38, 11, 56, 36, 47, 58, 60, 13, 20, 20, 45, 29, 49, 53, 37, 54, 35, 23];
- const z = [130, 118, 145, 157, 132, 124, 147, 149, 123, 148, 156, 159, 137, 158, 117];
- // Calculating the mean
- let sum_x = 0, sum_y = 0, sum_z = 0;
- for (let i = 0; i < x.length; ++i) {
- sum_x += x[i];
- sum_y += y[i];
- sum_z += z[i];
- }
- const mean_x = sum_x / x.length;
- const mean_y = sum_y / y.length;
- const mean_z = sum_z / z.length;
- // Calculating the variance
- let variance_x = 0, variance_y = 0, variance_z = 0;
- for (let i = 0; i < x.length; ++i) {
- variance_x += Math.pow(x[i] - mean_x, 2);
- variance_y += Math.pow(y[i] - mean_y, 2);
- variance_z += Math.pow(z[i] - mean_z, 2);
- }
- variance_x /= x.length - 1;
- variance_y /= y.length - 1;
- variance_z /= z.length - 1;
- // Calculating the standard deviation
- const std_dev_x = Math.sqrt(variance_x);
- const std_dev_y = Math.sqrt(variance_y);
- const std_dev_z = Math.sqrt(variance_z);
- // Calculating the correlation coefficients
- let sum_xy = 0, sum_xz = 0, sum_yz = 0;
- for (let i = 0; i < x.length; ++i) {
- sum_xy += (x[i] - mean_x) * (y[i] - mean_y);
- sum_xz += (x[i] - mean_x) * (z[i] - mean_z);
- sum_yz += (y[i] - mean_y) * (z[i] - mean_z);
- }
- const correlation_coefficient_xy = sum_xy / (std_dev_x * std_dev_y * (x.length - 1));
- const correlation_coefficient_xz = sum_xz / (std_dev_x * std_dev_z * (x.length - 1));
- const correlation_coefficient_yz = sum_yz / (std_dev_y * std_dev_z * (x.length - 1));
- // Printing the results
- console.log("Математическо очакване за x: " + mean_x);
- console.log("Математическо очакване за y: " + mean_y);
- console.log("Математическо очакване за z: " + mean_z);
- console.log("Дисперсия за x: " + variance_x);
- console.log("Дисперсия за y: " + variance_y);
- console.log("Дисперсия за z: " + variance_z);
- console.log("Средноквадратично отклонение за x: " + std_dev_x);
- console.log("Средноквадратично отклонение за y: " + std_dev_y);
- console.log("Средноквадратично отклонение за z: " + std_dev_z);
- console.log("Коефициент на корелация между x и y: " + correlation_coefficient_xy);
- console.log("Коефициент на корелация между x и z: " + correlation_coefficient_xz);
- console.log("Коефициент на корелация между y и z: " + correlation_coefficient_yz);
- // Confidence intervals for the mean
- console.log("Доверителни интервали за математическото очакване:");
- console.log("x: [" + (mean_x - (1.76131 * std_dev_x / 2)) + ", " + (mean_x + (1.76131 * std_dev_x / 2)) + "]");
- console.log("y: [" + (mean_y - (1.729133 * std_dev_y / 2)) + ", " + (mean_y + (1.729133 * std_dev_y / 2)) + "]");
- console.log("z: [" + (mean_z - (1.76131 * std_dev_z / 2)) + ", " + (mean_z + (1.76131 * std_dev_z / 2)) + "]");
- // Confidence intervals for the variance
- console.log("Доверителни интервали ДИСПЕРСИЯ:");
- console.log("x: [" + (variance_x * 3) / 9.348 + ", " + (variance_x * 3) / 0.2158 + "]");
- console.log("y: [" + (variance_y * 3) / 9.348 + ", " + (variance_y * 3) / 0.2158 + "]");
- console.log("z: [" + (variance_z * 3) / 9.348 + ", " + (variance_z * 3) / 0.2158 + "]");
- // Confidence intervals for the mean changes
- console.log("Доверителни интервали ИЗМЕНЕНИЕ НА ВЕЛИЧИНАТА:");
- console.log("x: [" + (mean_x - 3 * std_dev_x) + ", " + (mean_x + 3 * std_dev_x) + "]");
- console.log("y: [" + (mean_y - 3 * std_dev_y) + ", " + (mean_y + 3 * std_dev_y) + "]");
- console.log("z: [" + (mean_z - 3 * std_dev_z) + ", " + (mean_z + 3 * std_dev_z) + "]");
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement