Description Usage Arguments Note Author(s) References See Also Examples
View source: R/GA4StratificationP3fitt.R
This is the fitness function in Genetic Algorithm that calculates the variance of the estimate according to the boundaries obtained with GA and sample sizes obtained with Neyman Allocation for the final chromosome.
1 | GA4StratificationP3fitt(bestGeneration, dataName, numberOfStrata, sampleSize, bestValue, cumTotal, sumSquares)
|
bestGeneration |
The generation that has the smallest fitness value is the best generation that will be delivered to the next step. |
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. |
bestValue |
A numeric: The best fitness value that is the minimum variance of the estimate for the best generation. |
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 |
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
GA4StratificationP3
GA4StratificationP3fit
GA4StratificationP3m
GA4StratificationP3x
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 41 42 43 44 | ## The function is currently defined as
function(bestGeneration,dataName,numberOfStrata,sampleSize,bestValue,cumTotal,sumSquares)
{
c=nrow(dataName)
nocrom=length(bestGeneration)/c
bestGeneration=array(bestGeneration,dim=c(length(bestGeneration)/c,c))
fitp1=array(0,dim=c(1,nocrom))
fit=array(0,dim=c(nocrom,1))
N=means=s=n=vars=mas=NN=k=p=t=array(0,dim=c(nocrom,numberOfStrata))
dd=array(0,dim=c(nocrom,1))
for ( i in 1:nocrom )
{
mas[i,]=which(bestGeneration[i,]==1,arr.ind=TRUE)
N[i,1]=min(mas[i,])
means[i,1]=cumTotal[mas[i,1],]/N[i,1]
s[i,1]=((N[i,1]/(N[i,1]-1))*(sumSquares[N[i,1]]/N[i,1]-means[i,1]^2))^.5
for ( j in 2:numberOfStrata )
{
N[i,j]=mas[i,j]-mas[i,(j-1)]
means[i,j]=(cumTotal[mas[i,j],]-cumTotal[mas[i,j-1],])/N[i,j]
s[i,j]=((N[i,j]/(N[i,j]-1))*((sumSquares[mas[i,j]]-sumSquares[mas[i,j-1]])/N[i,j]-means[i,j]^2))^.5
}
for ( j in 1:numberOfStrata )
{
n[i,j]=max(1,round(sampleSize*N[i,j]*s[i,j]/sum(N[i,]*s[i,])))
n[i,j]=min(n[i,j],N[i,j])
}
if ( (sampleSize-sum(n[i,]))>0 )
{
k[i,]=N[i,]-n[i,]
t[i,]=max(k[i,])
p[i,]=which(k[i,]==t[i,],arr.ind=TRUE)[1]
n[i,p[i,1]]=min(n[i,p[i,1]]+sampleSize-sum(n[i,]),N[i,p[i,1]])
}
}
return(array(c(N,n,bestValue),dim=c(numberOfStrata,3)))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.