Saturday, December 18, 2010

Reverse Statistics with R

Ask:

What I want to do sounds simple. I want to plot a normal IQ curve with R with a mean of 100 and a standard deviation of 15. Then, I'd like to be able to overlay a scatter plot of data on top of it.

Anybody know how to do this?

Answer:

Well, it's more like a histogram, since I think you are expecting these to be more like an integer rounded process:

x<-round(rnorm(1000, 100, 15))
y
<-table(x)
plot
(y)
par
(new=TRUE)
plot
(density(x), yaxt="n", ylab="", xlab="", xaxt="n")

If you want the theoretic value of dnorm superimposed, then use one of these:

lines(sort(x), dnorm(sort(x), 100, 15), col="red")

-or

points(x, dnorm(x, 100, 15))

No comments:

Post a Comment