       const lagMatrix = [];
            for (let i = 0; i < n - 1; i++) {
                lagMatrix.push([1, x[i]]);
                for (let j = 0; j < lag; j++) {
                    lagMatrix[i].push(i - j > 0 ? dy[i - j - 1] : 0);
                }
            }

            // Convert to math.js matrices
            const X = math.matrix(lagMatrix);
            const Y = math.matrix(dy);

            // Compute OLS estimates
            const XtX = math.multiply(math.transpose(X), X);
            cons