I used a Monte carlo algorithm to generate data samples of size 100 of a geometric distribution using inversion sampling:
gi.cdf.geom <- function(p,u){
k <- c()
k <- ceiling(log(1-u)/log(1-p)) - 1
return(k)
}
The function above is the inverse of the CDF of a geometric distribution
u1 <- runif(100)
gen.gi.cdf1 <- gi.cdf.geom(50/239,u1)
as.data.frame(table(gen.gi.cdf1))
What I do not know how to do is randomly simulate a 1000 data samples of size 100 and to calculate the chi-square test statistic for each sample. My attempt at creating the samples is the following:
for(i in 1:1000){
n=100
p=50/239
{
u=runif(n)
values <- gi.cdf.geom(p,u)
}
print(values)
}
However this gives me all the samples of my console with no way of referring to them later.
I would really appreciate some help.
Thank you
Use
replicate
. For example:You can test on them using
apply