Description Usage Arguments Note Author(s) References See Also Examples
View source: R/GA4StratificationP2x.R
This is the crossover operation in the Genetic Algorithm approach for the determination of the stratum boundaries and sample sizes in each stratum in stratified sampling with an Proportional Sample Allocation Scheme.
1 | GA4StratificationP2x(crossoverGeneration,bestGeneration,dataName,numberOfStrata,sampleSize,fitnessValueGeneration,cumTotal,sumSquares,lengthData,dd,nocrom,fitp1,fit,N,means,s,n,vars,mas,NN,k,p,t)
|
crossoverGeneration |
The generation that will be crossovered and transfered to the next generation. |
bestGeneration |
The generation that has the best fitness value after the selection process. |
dataName |
A string: The name of any type of numeric data containing the values of a univariate stratification variable. |
numberOfStrata |
An integer: The number of strata. |
sampleSize |
An integer: The total sample size. |
fitnessValueGeneration |
The fitness value -the variance of the estimate- of the best generation after selection |
cumTotal |
An array: The cumulative total of the data elements from i=1 to i=N |
sumSquares |
An array: The cumulative total of the squares of the data elements from i=1 to i=N |
lengthData |
An integer: The size of the data. |
dd |
An array (nocrom X 1): The minimum of the difference in between the size of each stratum and the sample size to be drawn from that stratum. |
nocrom |
An integer: The number of the chromosomes in the generation. |
fitp1 |
An array (1 X nocrom): The fitness value for each chromosome in the generation. |
fit |
An array (nocrom X 1): The fitness value for each chromosome in the generation. |
N |
An array (nocrom X nofstrata): The number of the elements in each stratum for each chromosome in the generation. |
means |
An array (nocrom X nofstrata): The mean of the elements in each stratum for each chromosome in the generation. |
s |
An array (nocrom X nofstrata): The standart deviation of the elements in each stratum for each chromosome in the generation. |
n |
An array (nocrom X nofstrata): The number of the sample size to be drawn from each stratum for each chromosome in the generation. |
vars |
An array (nocrom X nofstrata): The variance of the estimate in each stratum for each chromosome in the generation. |
mas |
An array (nocrom X nofstrata): The indice of each stratum for each chromosome in the generation. |
NN |
An array (nocrom X nofstrata): The cumulative sum of the number of the elements in each stratum. |
k |
An array (nocrom X nofstrata): The difference between the number of the elements and the sample sizes in each stratum. |
t |
An array (nocrom X nofstrata): The maximum of the |
p |
An array (nocrom X nofstrata): The indice of the element where |
This study is part of a project supported by the Scientific and Technological Research Council of Turkey (TUBITAK).
Sebnem Er, Timur Keskinturk, Charlie Daly
Maintainer: Sebnem Er <er.sebnem@gmail.com>
http://ideas.repec.org/a/eee/csdana/v52y2007i1p53-67.html
http://www.sciencedirect.com/science/article/B6V8V-4NHM520-1/2/a21e0295aa1616ff56da1ddf2c0ba1ac
GA4StratificationP2
GA4StratificationP2fit
GA4StratificationP2fitt
GA4StratificationP2m
GA4StratificationSelection
randomnumGenerator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ## The function is currently defined as
function(crossoverGeneration,bestGeneration,dataName,numberOfStrata,sampleSize,fitnessValueGeneration,cumTotal,sumSquares,lengthData,dd,nocrom,fitp1,fit,N,means,s,n,vars,mas,NN,k,p,t)
{
fitnessValueParents=fitnessValueGeneration
parents=cbind(crossoverGeneration,fitnessValueParents)
crossoverGenerationp=crossoverGeneration
rowCrossoverGenerationp=nocrom
tableData=as.data.frame(table(dataName))
randomnumRange=cumsum(tableData[,2])
lengthRandomnum=length(randomnumRange)
randomNumbers=array(0,dim=c(rowCrossoverGenerationp,2))
for (i in 1:rowCrossoverGenerationp)
{
randomNumbers[i,]=randomnumGenerator((1:rowCrossoverGenerationp),(rowCrossoverGenerationp+1),2)
}
mother=father=NULL
for (i in 1:rowCrossoverGenerationp)
{
mother=randomNumbers[i,1]
father=randomNumbers[i,2]
crossoverPoint=sample((randomnumRange[1:lengthRandomnum-1]),1)
while ( sum(crossoverGenerationp[mother,c(1:crossoverPoint)])!=sum(crossoverGenerationp[father,c(1:crossoverPoint)]) )
{
crossoverPoint=sample((randomnumRange[1:lengthRandomnum-1]),1)
}
crossoverGeneration[i,c(1:crossoverPoint)]=crossoverGenerationp[mother,c(1:crossoverPoint)]
crossoverGeneration[i,c((crossoverPoint+1):lengthData)]=crossoverGenerationp[father,c((crossoverPoint+1):lengthData)]
}
s=GA4StratificationP2fit(crossoverGeneration,dataName,numberOfStrata,sampleSize,cumTotal,sumSquares,lengthData,dd,nocrom,fitp1,fit,N,means,s,n,vars,mas,NN,k,p,t)
crossoverGenerationx=cbind(crossoverGeneration,s)
GA4StratificationP2x=rbind(parents, crossoverGenerationx)
GA4StratificationP2x=GA4StratificationP2x[order(GA4StratificationP2x[,(lengthData+1)]),]
GA4StratificationP2x=GA4StratificationP2x[c((rowCrossoverGenerationp+1):(rowCrossoverGenerationp*2)),c(1:lengthData)]
return(GA4StratificationP2x)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.