swapcheck: Function to explore whether swapping the location of any two...

Description Usage Arguments Value Examples

Description

This function takes an existing set of X and Y estimates, a matrix of patterns, and the frequencies of the patterns and examines whether swapping the (X,Y) coordinates of any two patterns may improve the criterion value that POSAC attempts to optimise. As such this function can be used as one check of whether the results from the POSAC function itself are optimal.

Usage

1
swapcheck(X, Y, patmat, freqs)

Arguments

X

The initial X values assigned to each pattern.

Y

The initial Y values assigned to each pattern.

patmat

A matrix of patterns of values across. Each row of the matrix should represents a distinct pattern with no duplicates. The columns are the variables defining the patterns.

freqs

A vector of frequencies of each pattern. This should have the same length as nrow(patmat).

Value

The function returns a list with the following elements:

CurrentCorrect

The percentage of pairs correctly mapped by the POSAC function to begin with.

BestSwap

Details of the best possible swap including an updated per cent correct. This need not be above the current value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
posac2=POSAC(CRASdata[,1:5],CRASdata[,6])
swapcheck(posac2$X,posac2$Y,posac2$patmat,posac2$freqs)
#no improvement - however it is possible to swap some incomparable patterns without damaging criteria


#showing how successive looking for swaps could be used as a (very poor) alternative algorithm
randX=rank(rnorm(nrow(CRASdata)))
randY=rank(rnorm(nrow(CRASdata)))
swap1=swapcheck(randX,randY,CRASdata[,1:5],CRASdata[,6])
swap1
#make the suggested swaps
randX=replace(randX,sort(as.numeric(swap1$BestSwap[1,1:2])),randX[as.numeric(swap1$BestSwap[1,1:2])])
randY=replace(randY,sort(as.numeric(swap1$BestSwap[1,1:2])),randY[as.numeric(swap1$BestSwap[1,1:2])])
#check for any more
swap2=swapcheck(randX,randY,CRASdata[,1:5],CRASdata[,6])
swap2
#and so on...

CambridgeAssessmentResearch/POSAC documentation built on May 28, 2019, 12:16 p.m.