Learn R Programming

klausuR (version 0.12-14)

nret.translator: Convert NRET/ET data between klausuR and other software

Description

This function should help to interchange answer data between R and other statistical software packages -- especially SPSS, but it's probably useful for other products as well.

Usage

nret.translator(
  dat,
  items = NULL,
  spss = "out",
  corr = FALSE,
  num.alt = NULL,
  klausuR.alt = c(is.true = "+", is.false = "-", missing = "0", err = "*"),
  spss.alt = c(is.true = "2", is.false = "1", missing = "0", err = "3"),
  rm.old.vars = TRUE,
  items.only = FALSE,
  klausuR.prefix = c(),
  spss.prefix = c()
)

Arguments

dat

A data.frame, the object to convert.

items

Optional vector defining the columns to convert. If NULL, the function will try to autodetect Items: klausuR type items are expected to be named "ItemXXX", with XXX indicating the item number, SPSS type items "itemXXXaYY", with XXX indicating the item number and YY the number of the answer alternative.

spss

Either "in" or "out", depending on the direction of conversion.

corr

Logical. Set to TRUE if dat is a vector with the correct answers. If corr=TRUE and spss="in", you must also set num.alt accordingly!

num.alt

A numeric value definig the number of answer alternatives for each item. Can be a vector, if items have different numbers of options. If it is shorter than the number of items, it will be repeated for all items.

klausuR.alt

A named vector defining the codes for klausuR type of answers.

spss.alt

A named vector defining the codes for SPSS type of answers.

rm.old.vars

Logical. If TRUE, the converted columns will not be returned. Only relevant if corr=FALSE.

items.only

Logical. If TRUE, only the converted columns will be returned. Only relevant if corr=FALSE.

klausuR.prefix

A named character vector with two optional elements, item and corr, defining the name prefix used for the items in the test data and the vector with correct answers, respectively. Defaults to item="Item" and corr="Item".

spss.prefix

Like klausuR.prefix, but for the SPSS data. Defaults to item="item" and corr="corr".

Value

If corr=FALSE, a data.frame with more or less columns (depending on rm.old.vars and items.only). If corr=TRUE, returns a named vector if spss="in" and a list if spss="out" (containing SPSS syntax in the element syntax and also a named vector, called answ).

Details

klausur expects data in a special format if it should be evaluated according to (Number Right) Elimination Testing (NRET/ET), only one variable per item. Other software products might not be able to process this rather condensed format. In that case, you will most likely need several variables for each item, i.e. one per answer alternative. Adding to that, the coding of answers is by default done with "+", "-", "0" and "*" in klausuR, again a solution that might confuse other products.

This function translates data in both directions, and does also convert vectors giving the correct answer. The latter will turn a klausuR type answer string into a number indicating the correct alternative (and the other way round). This means that it will only work if there's exactly one valid answer to each item. If you convert towards SPSS, the resulting list will also include SPSS syntax to define variables respectively.

See Also

klausur

Examples

Run this code
# NOT RUN {
# from SPSS to R
data(spss.data)
klausuR.data <- nret.translator(spss.data, spss="in")
spss.corr <- c(
   item01=2, item02=3, item03=3, item04=3, item05=2,
   item06=2, item07=3, item08=1, item09=1, item10=2)
klausuR.corr <- nret.translator(spss.corr, spss="in", corr=TRUE, num.alt=3)

# from R to SPSS
spss.data <- nret.translator(klausuR.data)
spss.corr <- nret.translator(klausuR.corr, corr=TRUE, num.alt=3)
# if you find the syntax useful
cat(spss.corr$syntax, file="~/somewhere/NRET.sps")
# }

Run the code above in your browser using DataLab