statistics - R dnorm result different between standardized and unstandardized values -


i ran confusing situation when calculating normal distribution density in r using standardized value vs. unstandardized value:

ds <- function(x, mu, var) {dnorm(x, mean = mu, sd = sqrt(var))} ds1 <- function(x, mu, var) {dnorm((x-mu)/sqrt(var), mean = 0, sd = 1)} 

these 2 should give identical results. however, don't:

> ds(0, 1, 2) [1] 0.2196956 > ds1(0, 1, 2) [1] 0.3106966 

it appears might because of numerical differences caused both sqrt , dnorm, because if set var = 1, result identical:

> ds(0, 1, 1) [1] 0.2419707 > ds1(0, 1, 1) [1] 0.2419707 > ds1(0, 1, 1.001) [1] 0.2420916 > ds(0, 1, 1.001) [1] 0.2419707 

could point out reason this?

in ds1, have forgotten 1/sqrt(var) term:

ds1 <- function(x, mu, var) {dnorm((x-mu)/sqrt(var), mean = 0, sd = 1)/sqrt(var)}  > ds(1,2,3) [1] 0.1949697 > ds1(1,2,3) [1] 0.1949697 

Comments