Forked from russellpierce/errorInSSCalcDueToRounding.r
Created
August 18, 2017 17:40
-
-
Save Templier/127138f8dd69cfbe7e956d1cfaa2c40b to your computer and use it in GitHub Desktop.
What is the error in SS when rounding takes place prior to the calculation?
A simulation to address a comment here: http://stats.stackexchange.com/questions/65220/exception-for-sum-of-deviations-from-mean-being-0/65232#comment127480_65232
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sim <- function(places=3,N=20,FUN=round,...) { | |
| SSr <- function(x) {sum((FUN(x,places)-mean(FUN(x,places)))^2)} | |
| SS <- function(x) {sum((x-mean(x))^2)} | |
| y <- rnorm(N,...) | |
| return(abs(SSr(y)-SS(y))) | |
| } | |
| mean(replicate(20000,sim())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment