5

var, sd, cor functions in {stats} use n-1 as a denominator (where n the number of observations). Out of curiosity, are there equivalent function that use n as a denominator?

smci
  • 32,567
  • 20
  • 113
  • 146
ECII
  • 10,297
  • 18
  • 80
  • 121
  • 1
    maybe in some package somewhere, but I think people just generally multiply by the appropriate correction factor, or write their own utility function that does it .... http://r.789695.n4.nabble.com/population-variance-and-sample-variance-td904148.html – Ben Bolker Jan 25 '14 at 22:27
  • 5
    Usually just multiply by `(n-1)/n` if I'm working with pop data. I think the answer might actually be just plain "no" here. – Brandon Bertelsen Jan 25 '14 at 22:41

1 Answers1

3

Try this:

library(RH2) # needs Java
library(sqldf)

n <- length(BOD$demand)

sd(BOD$demand)
sqrt((n-1)/n) * sd(BOD$demand)
sqldf("select stddev_samp(demand) as samp, stddev_pop(demand) as pop from BOD")

var(BOD$demand)
(n-1)/n * var(BOD$demand)
sqldf("select var_samp(demand) as samp, var_pop(demand) as pop from BOD")    
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341