0
$\begingroup$

I have just started learning R and am studying some probability and statistics examples.

I have the following code snippet, which produces a vector x of length 100000 and sample means of $\text{Unif}(−3, 3)$ with a random sample of size 100:

samplemean <- function() {
  return(mean(runif(100, -3, 3))) } 

x <- replicate(100000, samplemean())

I determined the sample average and sample variance of x as follows:

(mean(x)) #sample mean 
(var(x)) #sample variance

Let mux and sig2x be the expected value and variance, respectively, of a $\text{Unif}(−3,3)$ random variable. I'm trying to use the central limit theorem to calculate the probability that the sample average is less than 0.44, which is given by $P(Y < 0.44)$ where $Y$ is a $\text{N}(\text{`mux`}, \text{`sig2x`}/100)$ random variable.

I tried to use the function convolve to achieve this, but this is my first time using it, so I really don't know what I'm doing here:

pX2fold <- convolve(x, rev(x), type = "o")
pX3fold <- convolve(pX2fold, rev(x), type = "o")
pX4fold <- convolve(pX3fold, rev(x), type = "o")
pX5fold <- convolve(pX4fold, rev(x), type = "o")
pX6fold <- convolve(pX5fold, rev(x), type = "o")
pX7fold <- convolve(pX6fold, rev(x), type = "o")
pX8fold <- convolve(pX7fold, rev(x), type = "o")

(pX8fold < 0.44)

Despite my best efforts, none of this seems correct.

I would greatly appreciate it if people could please take the time to explain my errors and show me how to do this.

$\endgroup$
3
  • $\begingroup$ You say you want to use the central limit theorem but instead of using it, you then attempt to do numerical convolution. Why? $\endgroup$
    – Glen_b
    Commented Oct 24, 2019 at 0:38
  • $\begingroup$ @Glen_b I was under the impression that this is how you do it? Would you mind please demonstrating how it’s supposed to be done? $\endgroup$ Commented Oct 24, 2019 at 0:40
  • $\begingroup$ Typically what people mean when they say they will "use the central limit theorem" for a problem like this is they compute the mean and variance of the required quantity and then treat that as approximately normal with that mean and variance (just in the way you describe Y). So $P(Y<y)=P(Y\leq y) = $ $ F_Y(y)$ $ = \Phi(\frac{y-\mu_Y}{\sigma_Y})$ ... which in programs like R is a single function call (see ?pnorm). $\endgroup$
    – Glen_b
    Commented Oct 24, 2019 at 7:58

1 Answer 1

0
$\begingroup$

It is not clear to me what you are trying to do, or why. Maybe I can say something useful anyhow.

First, if $X \sim \mathsf{Unif}(-3, 3)$ and you seek $P(X < 0.44) = 0.5733,$ then you can do the exact computation easily in R (or, in this particular case, with simple arithmetic):

punif(0.44, -3, 3)
[1] 0.5733333
(.44 + 3)/6
[1] 0.5733333

If somehow you are able to take many samples of size $n = 100$ from the same unknown population and you want to know the percentage of the population below 44, you can average the results from many such samples to get 0.1958 as a good approximation.

set.seed(1023)
b.44 = replicate(10^5, mean(rnorm(100, 50, 7) < 44))
mean(b.44)
[1] 0.1957673

Here we are pretending you don't know the population distribution. But if you did, you'd know that this probability is exactly 0.1957, to four places.

pnorm(44, 50, 7)
[1] 0.195683
$\endgroup$
2
  • $\begingroup$ Thanks for the answer, Bruce. How did you get 50 and 7 in rnorm(100, 50, 7)? Is that the sample mean and sample variance? $\endgroup$ Commented Oct 24, 2019 at 2:11
  • $\begingroup$ Just an example for purposes of illustration. If you want heights of US adult men below 67" you might use $X \sim \mathsf{Norm}(69, 3.5)$ and evaluate $P(X < 67) = 0.2839.$ $\endgroup$
    – BruceET
    Commented Oct 24, 2019 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.