GA4StratificationP1fitt: The genetic algorithm fitness function to calculate the...

Description Usage Arguments Note Author(s) References See Also Examples

View source: R/GA4StratificationP1fitt.R

Description

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 Equal Allocation for the final chromosome.

Usage

1
GA4StratificationP1fitt(bestGeneration, dataName, numberOfStrata, sampleSize, bestValue, cumTotal, sumSquares)

Arguments

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

Note

This study is part of a project supported by the Scientific and Technological Research Council of Turkey (TUBITAK).

Author(s)

Sebnem Er, Timur Keskinturk, Charlie Daly

Maintainer: Sebnem Er <er.sebnem@gmail.com>

References

http://ideas.repec.org/a/eee/csdana/v52y2007i1p53-67.html

http://www.sciencedirect.com/science/article/B6V8V-4NHM520-1/2/a21e0295aa1616ff56da1ddf2c0ba1ac

See Also

GA4StratificationP1 GA4StratificationP1fit GA4StratificationP1m GA4StratificationP1x

GA4StratificationSelection randomnumGenerator

Examples

 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
## 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)]
			N
	      	means[i,j]=(cumTotal[mas[i,j],]-cumTotal[mas[i,j-1],])/N[i,j]
			means
      		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
			s
		}   

    	for ( j in 1:numberOfStrata )
		{
      	n[i,j]=(sampleSize/numberOfStrata)
        	}
  }

   return(array(c(N,n,bestValue),dim=c(numberOfStrata,3)))
}

GA4Stratification documentation built on May 30, 2017, 1:22 a.m.