[R] Integrate to 1? (gauss.quad)

Doran, Harold HDoran at air.org
Sun Nov 14 18:18:58 CET 2010


Does anyone see why my code does not integrate to 1?

library(statmod)

mu <- 0
s <- 1
Q <- 5
qq <- gauss.quad(Q, kind='hermite')
sum((1/(s*sqrt(2*pi)))  * exp(-((qq$nodes-mu)^2/(2*s^2))) * qq$weights)

### This does what's it is supposed to
myNorm <- function(theta) (1/(s*sqrt(2*pi)))  * exp(-((theta-mu)^2/(2*s^2))) 
integrate(myNorm, -Inf, Inf)


More information about the R-help mailing list