3
$\begingroup$

I have a problem with calculating ANOVA with my data in R. The R reports an error when I run ANOVA, it shows"Residual sum squares is 0". How can I solve this problem? By the way, my data is unbalanced data, so I want to try type II or type III ANOVA. This is my data for your reference.

library(car)
#read data
input <- read.csv("input.csv",sep=",",header=TRUE)

#This is my data for ANOVA
treatment   fraction    data
trt1    F45 -4.15E-05
trt1    F78 -7.24E-05
trt1    F45 -1.65E-05
trt1    F57 -2.22E-06
trt1    F78 -2.78E-05
trt1    F45 -5.13E-05
trt1    F57 -5.96E-05
trt1    F78 -4.09E-05
control F45 -4.42E-05
control F57 -1.11E-05
control F45 -2.73E-06
control F57 -9.02E-07
control F78 -6.37E-06
control F45 -4.70E-06
control F57 -2.73E-06

mod.1 <- lm( data ~ fraction * treatment, input )
Anova( mod.1, type=3 )
Anova( mod.1, type=2 )

Yes, some cells have only one replication, but I can run successfully in other data columns with the same operation, but it reports an error in this data column. I'm strange about this.

Any leads will be appreciated. Mengying

$\endgroup$
2
  • $\begingroup$ Please edit your question so we can copy-paste it into R. Define input as the output of what dput(input) gives you, so we have the exact data you are working with. Check that your code runs in a completely new console (which package does Anova() come from?). Thank you! $\endgroup$ Commented Jul 28, 2020 at 8:07
  • $\begingroup$ Ok, I have completed the information. Thank you. $\endgroup$ Commented Jul 28, 2020 at 8:48

1 Answer 1

3
$\begingroup$

The car:::ANOVA.lm function tests if the model's deviance (its residual sum of squares) is below a precision limit:

input <- read.table(text = "treatment   fraction    data
trt1    F45 -4.15E-05
trt1    F78 -7.24E-05
trt1    F45 -1.65E-05
trt1    F57 -2.22E-06
trt1    F78 -2.78E-05
trt1    F45 -5.13E-05
trt1    F57 -5.96E-05
trt1    F78 -4.09E-05
control F45 -4.42E-05
control F57 -1.11E-05
control F45 -2.73E-06
control F57 -9.02E-07
control F78 -6.37E-06
control F45 -4.70E-06
control F57 -2.73E-06", header = TRUE)

mod.1 <- lm( data ~ fraction * treatment, input )
Anova( mod.1, type=2 )
#Error in Anova.lm(mod.1, type = 2) : 
#  residual sum of squares is 0 (within rounding error)

deviance(mod.1) < sqrt(.Machine$double.eps)
#[1] TRUE

This test is probably done to avoid numeric issues due to floating point precision.

I suggest you simply rescale your dependent variable. This also rescales the residuals and the resulting sum of squares.

mod.2 <- lm( I(data * 1e6) ~ fraction * treatment, input )
library(car)
Anova( mod.2, type=2 )
#Anova Table (Type II tests)
#
#Response: I(data * 1e+06)
#                   Sum Sq Df F value  Pr(>F)  
#fraction            360.1  2  0.3605 0.70697  
#treatment          2375.6  1  4.7566 0.05709 .
#fraction:treatment  229.9  2  0.2302 0.79891  
#Residuals          4495.0  9                  
#---
#Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
$\endgroup$
2
  • $\begingroup$ Thanks for your nice and immediate reply! I will take a try! $\endgroup$ Commented Jul 28, 2020 at 8:50
  • $\begingroup$ Roland beat me to it. This is precisely the right answer. Mengying, please consider upvoting it (click the little triangle point up next to the answer) and/or accepting it (click the little checkmark under the vote totals). $\endgroup$ Commented Jul 28, 2020 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.