View source: R/cluster.samplesize.R
cluster.samplesize | R Documentation |
Calculates the required sample size in order to achieve an absolute sampling error less or equal to the specified for an specific estimator and an optional confidence interval in cluster sampling.
cluster.samplesize(
N,
data,
error,
alpha,
estimator = c("total", "mean", "proportion", "class total"),
replace = FALSE
)
N |
Number of clusters in the population. |
data |
Dataset. |
error |
Sampling error. |
alpha |
Significance level to obtain confidence intervals. |
estimator |
The estimator to be estimated. Default is "total". |
replace |
Whether the samples to be taken can have repeated instances or not. |
This function admits both grouped and non-grouped by cluster data.
Non-grouped data must have interest variable data in the first column and cluster
name each individual belongs to in the last column.
Grouped by cluster data must have interest variable data in the first column,
cluster size in the second and the cluster name in the last column. Interest
values of grouped data must reflect the total value of each cluster.
Number of clusters to be taken.
d<-cbind(rnorm(500, 50, 20), rep(c(1:50),10)) #Non-grouped data
sample<-cluster.sample(d, n=10) #Non-grouped sample
sampleg<-aggregate(sample[,1], by=list(Category=sample[,2]), FUN=sum)
sampleg<-cbind(sampleg[,2], rep(10,10), sampleg[,1]) #Sample sample with grouped data
#Cluster size to be taken for estimation
cluster.samplesize(N=50, data=sample, error=500, estimator="total", replace=TRUE)
newsample<-cluster.sample(d, n=26) #New sample for estimation
sum(d[,1])
cluster.estimator(N=50, data=newsample, estimator="total", alpha=0.05, replace=TRUE)
cluster.estimator(N=50, data=sampleg, estimator="total", alpha=0.05)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.