Mary
Mary

Reputation: 13

Calculating MSS and RSS in R

I am trying to calculate the MSS and RSS using the output and the components of the regression model that I have created (model.1)

 model.1<-glm(wbw.df$x.percap ~ wbw.df$y.percap,family=gaussian)

Which part of the output do I need to be focusing on? For ex:

Call:
glm(formula = wbw.df$x.percap ~ wbw.df$y.percap, family = gaussian)

Deviance Residuals: 
      Min         1Q     Median         3Q        Max  
-0.061191  -0.006350  -0.005931  -0.003722   0.275066  

Coefficients:
                      Estimate Std. Error t value Pr(>|t|)    
(Intercept)           0.006458   0.002766   2.334 0.021022 *  
wbw.df$totwlth.percap 0.030566   0.008933   3.422 0.000819 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 0.001005281)

    Null deviance: 0.15050  on 139  degrees of freedom
Residual deviance: 0.13873  on 138  degrees of freedom
  (1 observation deleted due to missingness)
AIC: -565.06

Number of Fisher Scoring iterations: 2

Thanks in advance.

Upvotes: 1

Views: 4914

Answers (2)

Towsif Ahamed Labib
Towsif Ahamed Labib

Reputation: 686

As you are using glm, qpcR library can calculate the residual sum-of-squares of nls, lm, glm, drc or any other models from which residuals can be extacted. Here RSS(fit) function returns the RSS value of the model.

install.packages('qpcR')
library(qpcR)
model.1<-glm(wbw.df$x.percap ~ wbw.df$y.percap,family=gaussian)
RSS(model.1)

check the link to see other functions of qpcR

Upvotes: 0

Fred Boehm
Fred Boehm

Reputation: 668

I'm not sure that I understand why you're fitting the model with glm. I suggest using ordinary least squares for model fitting:

lm(wbw.df$x.percap ~ wbw.df$y.percap)

You could then use the function residuals

residuals(lm(wow.df$x.percap ~ wbw.df$y.percap))

to get the vector of residuals. With it, square each and sum the result.

I hope that this is helpful.

Upvotes: 2

Related Questions