SampleItemsToHitTarget | R Documentation |
This function finds a random selection of indices within a matrix of items scores so that the sum of the maximum scores available on these items meets a predefined total. This is done using brute computing power to solve an extremely simple version of the famous Knapsack problem where all the values we need to consider (the maximum item scores) are (fairly) small integers. The function will print the number of selected items with each number of marks in the chosen solution.
SampleItemsToHitTarget(itemat, targtot, chooseclosestproportional = TRUE)
itemat |
Matrix of item scores. |
targtot |
The target sum of maximum scores on selected items. |
chooseclosestproportional |
Logical value indicating whether the proportion of items with each number of available marks be chosen so as to match the proportions for the overall test as closely as possible (default=TRUE). |
The function returns a vector denoting which items should be included.
library(KernEqWPS)
summary(mathsdata)
maxes=apply(mathsdata,2,max,na.rm=TRUE)
sum(maxes)
#make form X with 50 marks
itesX=SampleItemsToHitTarget(as.matrix(mathsdata),50)
formX=mathsdata[,itesX]
#note difference in selected item totals if we set chooseclosestproportional=FALSE
SampleItemsToHitTarget(as.matrix(mathsdata),50,chooseclosestproportional=FALSE)
#make form Y with 50 marks from the remainder
remain=mathsdata[,-itesX]
itesY=SampleItemsToHitTarget(as.matrix(remain),50)
formY=remain[,itesY]
#make form A with 10 marks from the remainder
remain=remain[,-itesY]
itesA=SampleItemsToHitTarget(as.matrix(remain),10)
formA=remain[,itesA]
length(itesX)
length(itesY)
length(itesA)
#check
x=rowSums(formX)
y=rowSums(formY)
a=rowSums(formA)
summary(x)
summary(y)
summary(a)
cor(cbind(x,y,a))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.