Different R2 from fitlm model from what I get from Ms. Excel linest model and SST not equal to SSE + SSR
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hello everyone,
I have created regression model of the form y~x1+x2+x3 using the fitlm function. However, the R2 predicted from the model is very different from what I get from Excel when i fit the same model using the Linest function in excel. Secondly I have noted that the fitlm function in matlab returns SST, SSE, and SST values that do not meet the statistical requirement of "SST = SSE + SSR". What could be the cause of this?  Below is part of the code I am using in Matlab. 
   mdl_SI = fitlm(GNTables{k}(:,end-3:end),'Intercept',false); 
   ModelCoeff{k} = mdl_SI.Coefficients;
   SSE = mdl_SI.SSE
   SSR = mdl_SI.SSR
   SST = mdl_SI.SST 
   mdl_SI.Rsquared
Any help will be grately appreciated.
Martin
1 Commento
  dpb
      
      
 il 10 Ott 2023
				
      Modificato: dpb
      
      
 il 11 Ott 2023
  
			load carsmall
X = [Weight,Horsepower,Acceleration];
mdl = fitlm(X,MPG)
[mdl.SSE mdl.SSR mdl.SST mdl.SSE+mdl.SSR]
mdl.SSE+mdl.SSR==mdl.SST
mdl.SST-(mdl.SSE+mdl.SSR)
The difference is in floating point rounding and is not significant either numerically nor statistically.
Now don't fit an intercept term...
mdl = fitlm(X,MPG,'intercept',false)
[mdl.SSE mdl.SSR mdl.SST mdl.SSE+mdl.SSR]
Now the model doesn't meet the needs of a full linear model -- and you note fitlm doesn't even try to compute the overall statistics including Rsq because they no longer apply.
Likely Excel doesn't pay attention to such niceties if it does return Rsq for such a model if it even can estimate one without the intercept term; I'm not about to go try to dig into that in a MATLAB forum.
(BTW, this thread was a smart link to another I happened to respond to that had no response -- on investigation it seemed worth noting the cause for the record)
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

