How sum of squares is calculated by R ANOVA function fo non-factor variables in linear model > d = data.table(a = rnorm(40), b = rnorm(40), c = rnorm(40))
> summary(aov(a ~ b + c, d))
            Df Sum Sq Mean Sq F value Pr(>F)
b            1   1.17  1.1707   0.836  0.367
c            1   0.07  0.0677   0.048  0.827
Residuals   37  51.84  1.4011 

I understand how it's done for factor variables, as those divide whole dataset into groups. But how is it calculated for numerical variables b and c?
 A: One method (the easiest to grasp in one sentence) is to look at the increment in sums of squares due to regression when a covariate is added. This is R's ANOVA (or AOV) strategy, which implies that the order of addition of variables is important:
> anova( lm(mpg ~ cyl, mtcars))
Analysis of Variance Table

Response: mpg
          Df Sum Sq Mean Sq F value    Pr(>F)    
cyl        1 817.71  817.71  79.561 6.113e-10 
Residuals 30 308.33   10.28                      
---

When we add another variable the regression sums of squares stays the same for the cyl variable:
> anova( lm(mpg ~ cyl+disp, mtcars))
Analysis of Variance Table

Response: mpg
          Df Sum Sq Mean Sq F value    Pr(>F)    
cyl        1 817.71  817.71 87.5883 2.903e-10 
disp       1  37.59   37.59  4.0268   0.05419  
Residuals 29 270.74    9.34                  

If disp is added first, its SS-regression is maintained and the incremental SS-regression is attributed to the next covariate, this time to cyl.
> anova( lm(mpg ~ disp+cyl, mtcars))
Analysis of Variance Table

Response: mpg
          Df Sum Sq Mean Sq F value    Pr(>F)    
disp       1 808.89  808.89  86.643 3.271e-10 ***
cyl        1  46.42   46.42   4.972   0.03366 *  
Residuals 29 270.74    9.34                   

There is ongoing holy-war between the proponents of this method as default and the SAS authors who want to use a method that allocates sums-of-squares differently (and I don't think I can state in one sentence what they do do except to say that the sums of squares regression using so-called "type-III" ANOVA for each variable at any given level of complexity are not affected by the order of addition or removal of variables.)
The proponents of the R approach think that the theory-agnostic application of stepwise methods is bad statistics. They think you should be setting up yur models based on what is known or established by existing science and then adding variables that represent any new hypotheses. I'm not sure who invented the "typing" system for sums-of-squares strategies but R uses type II while SAS uses type III sums of squares in their respective default regression methods. There are R packages that can provide a type III calculation if that's what you need to attempt replication of SAS results. My memory is the the car package has an Anova function that will allow specification of the desired type.
