www.gusucode.com > stats 源码程序 matlab案例代码 > stats/DisplayCoefficientofDeterminationExample.m

    %% Display Coefficient of Determination  
% This example shows how to display R-squared (coefficient of determination)
% and adjusted R-squared.   Load the sample data and define the response
% and independent variables. 

% Copyright 2015 The MathWorks, Inc.

load hospital
y = hospital.BloodPressure(:,1);
X = double(hospital(:,2:5)); 

%% 
% Fit a linear regression model. 
mdl = fitlm(X,y) 

%%
% The R-squared and adjusted R-squared values are 0.508 and 0.487, respectively.
% Model explains about 50% of the variability in the response variable.  

%% 
% Access the R-squared and adjusted R-squared values using the property
% of the fitted |LinearModel| object. 
mdl.Rsquared.Ordinary  

%%  
mdl.Rsquared.Adjusted 

%%
% The adjusted R-squared value is smaller than the ordinary R-squared value.