Skip to content

Instantly share code, notes, and snippets.

@CerebralMastication
Created January 25, 2011 13:09
Show Gist options
  • Save CerebralMastication/794883 to your computer and use it in GitHub Desktop.
Save CerebralMastication/794883 to your computer and use it in GitHub Desktop.
example of converting a non-normal dist to normal
## make some non norm data
d1 <- rnorm(20, 5, 1)
d2 <- rnorm(5, 10, 2)
d <- c(d1,d2)
hist(d)
## no mean adjustment
myUniform <- ecdf( d )( d )
mean( myUniform )
## hey that mean's not .5!
myNorm <- qnorm( myUniform ) ## whoops.. inf value
## mean adjust
myUniform <- ecdf( d )( d )
mean( myUniform )
myUniform <- myUniform - (mean( myUniform ) - .5)
mean( myUniform )
myNorm <- qnorm( myUniform )
mean(myNorm)
sd(myNorm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment