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

4 visualizzazioni (ultimi 30 giorni)
shagun chaudhary il 20 Gen 2022
Risposto: Vatsal il 17 Ott 2023
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.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Vatsal il 17 Ott 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);
I hope this helps!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Special Functions in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by