How to get P value for coefficient of determination in the form of single answer (not in the matrix form)

10 views (last 30 days)
Hi,
I wanted to calculate p value for R2 which i have obtained byusing this code.
yfit = polyval(p,W);
yresid = Wsim(:) - yfit;
SSresid = sum(yresid.^2);
SStotal = (length(Wsim(:))-1) * var(Wsim(:));
R(nok) = 1 - SSresid/SStotal;
I need code after this to calculate p value and i need in the form of single answer (not in the matrix)
I would be extremely gareful if somebody can help.

Answers (1)

Vatsal
Vatsal on 17 Oct 2023
Hi,
I understand that you would like to calculate the p-value for 'R2' based on the provided code. To calculate the p-value for ‘R2’ in MATLAB, you can use utilize the following code:
df_regression = 1; % Linear model.
df_residual = length(Wsim(:)) - 2; % N - 2 degrees of freedom for residuals
F_statistic = (R(nok) / df_regression) / ((1 - R(nok)) / df_residual);
p_value = 1 - fcdf(F_statistic, df_regression, df_residual);
To learn more about “fcdf” usage and syntax, you may refer to the MathWorks documentation link below:
I hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!