I have the following randomly generated distribution:
set.seed(1) mean=100; sd=15 x <- seq(-4,4,length=100)*sd + mean hx <- dnorm(x,mean,sd) plot(x, hx, type="l", lty=2, xlab="x value", ylab="Density", main="Some random distribution")
And a "non-random" value
set.seed(1) x <- seq(-4,4,length=100)*10 + 100 ux <- dunif(x = x, min=10, max=100) non_random_value <- ux[1] non_random_value # [1] 0.01111111
I'd like to have the statistic that show non_random_value
is significant and doesn't come up by chance with respect to hx
. How can I do that in R?
1 Answers
Answers 1
The function you want is pnorm(x, mean, sd). It returns the proportion of values in the normal distribution, defined by mean and sd, that are less than x.
You can use pnorm in a two-tailed test to get the proportion of values that are more extreme than x (i.e. farther from the mean in either direction).
p <- 2*pnorm(x, mean, sd, lower.tail=x<mean)
Now interpret p to mean p% of potential values are farther away from the mean than x is. Keep in mind that any value of x can come up by chance from a normal distribution. You can't say that x is not random, merely that it seems unlikely to have come from the specified distribution.
Here's a nice site describing this is more detail.
0 comments:
Post a Comment