incorrect dimensions in data set
Show older comments
Hi,
I keep running into an error for incorrect dimensions and not sure on how to fix it.
%% Generate the data set
m_true = [10; 100; 9.8];
sigma = 8;
t = linspace(0, 10, 10);
y = m_true(1) + m_true(2)*t - m_true(3)*t^2/2 + sigma*randn(10, 1);
% Construct the G matrix
G = [ones(10, 1), t, -(1/2)*t.^2];
% Solve for the least squares parameters
m_L2 = (G'*G)\G'*y;
% Calculate the model covariance matrix
cov_m_L2 = (G'*G)\sigma^2;
% Calculate the 95% confidence intervals for the model parameters
alpha = 0.05;
t_crit = tinv(1 - alpha/2, 10 - 3);
chi_m_L2 = m_L2 +- t_crit * sqrt(diag(cov_m_L2));
% Calculate the p-value for the regression
chi2_stat = sum((y - G*m_L2).^2 / sigma^2);
p_value = chi2cdf(chi2_stat, 10 - 3);
% Display the results
fprintf('Model parameters: %f %f %f\n', m_L2);
fprintf('Confidence intervals: [%f %f] [%f %f] [%f %f]\n', ci_m_L2(1, :));
fprintf('p-value: %f\n', p_value);
Accepted Answer
More Answers (0)
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!