R/bws.questionnaire.R

Defines functions bws.questionnaire

Documented in bws.questionnaire

bws.questionnaire <- function(choice.sets, design.type, item.names)
{
# Name : bws.questionnaire
# Title: Converting a two-level OMED/BIBD into BWS questions
# Arguments:
#  choice.sets   a data frame or matrix containing choice sets
#  design.type   a value describing how to design the choice sets
#                  = 1 if a OMED is used
#                  = 2 if a BIBD is used
#  item.names    a vector containing the names of items shown in the questions


# set variable and matrix

  numQuestions <- nrow(choice.sets)
  design <- data.matrix(choice.sets)


# store items contained in each choice set in each element of itemsInSet 

  itemsInSet <- vector("list", numQuestions) # list
  if(design.type == 1)   # OMED
  {
    for(i in 1:numQuestions)
    {
      itemsInSet[[i]] <- which(design[i, ] == 2)
    }
  }
  else                   # BIBD
  {
    for(i in 1:numQuestions)
    {
      itemsInSet[[i]] <- design[i, ]
    }
  }


# display BWS questions

  numItemsInSet <- sapply(itemsInSet, length)  # number of items in each choice set

  for(i in 1:numQuestions) {
    cat("\n")
    cat("Q", i, "\n", sep ="")
    dsp           <- matrix(c("[ ]"), nrow = numItemsInSet[i], ncol = 3)
    dsp[, 2]      <- item.names[itemsInSet[[i]]]
    colnames(dsp) <- c("Best", "Items", "Worst")
    rownames(dsp) <- rep(c(""), numItemsInSet[i])
    print(noquote(dsp))
  }
  cat("\n")

}

Try the support.BWS package in your browser

Any scripts or data that you put into this service are public.

support.BWS documentation built on March 31, 2023, 8:12 p.m.