0

I'm currently trying to carry out a simulation study for Bernoulli Data to show that the sample proportion, ˆp, is also approximately normally distributed when the sample size is large.

From an exercise I'm told that the Bernoulli Data is generated by:

rbinom(n=50, size=1, prob=0.5)

as we're using a sample size as 50 and the true proportion to be 0.5.

We were given the code for a Simulation Study using Exponential Data but we have to change the code by using the code for Bernoulli Data above and not use the Exponential Data code, the sample code is as follows:

n = 10 # sample size
set.seed(142981)
simreps = 1000 # simulation replicates
# (just needs to be a big number)
xbar = rep(0, simreps)
for(i in 1:simreps){
xbar[i] = mean(rexp(n, rate=0.001))
}
hist(xbar, xlim=c(0,3000))
qqnorm(xbar, ylim=c(0,3000));qqline(xbar)

But the issue that arises is when I add in the code which is:

set.seed(142981)
simreps = 1000 # simulation replicates
# (just needs to be a big number)
xbar = rep(0, simreps)
for(i in 1:simreps){
xbar[i] = mean(rbinom(n=50, size=1, prob=0.5))
}
hist(xbar)
qqnorm(xbar);qqline(xbar)

I get a histogram result that has the values on it like this enter image description here

but for the Q-Q Plot, the result looks like this, which does not seem correct. I don't know what went wrong, any help at all would be greatly appreciated.

JamesR
  • 113
  • 1
  • 1
  • 8
  • What would "seem correct" to you? You are trying to compare an essentially discrete distribution to a continuous one. You get one of 51 values (0/50, 1/50, 2/50, ..., 50/50) – MrFlick Nov 26 '15 at 01:37
  • I thought the Q-Q Plot would result in something like [this](https://i.stack.imgur.com/NpI0O.png). This is the [sample question](https://i.imgur.com/3yV1RRH.png) I'm working off of. Which instructs me to use the code from the Simulation Study for the Exponential Data as posted in the Question but to change it for Bernoulli data. – JamesR Nov 26 '15 at 01:48
  • 1
    There's still no clear programming problem here. If you have questions about statistical plots like QQ plots, you might get help at [stats.se]. – MrFlick Nov 26 '15 at 01:49
  • Oh ok, thanks for the link! – JamesR Nov 26 '15 at 01:51

0 Answers0