Datatrans: Data transformation.

View source: R/estimation_support.R

DatatransR Documentation

Data transformation.

Description

Transforms the data into the desired data format required by different estimation packages.

Usage

Datatrans(
  pkg,
  des,
  y,
  n.alts,
  n.sets,
  n.resp,
  bin,
  alt.names = NULL,
  coding = NULL,
  lvls = NULL
)

Arguments

pkg

Indicates the desired estimation package. Options are RSGHB = doHB, bayesm = rhierMnlRwMixture, bayesm::rbprobitGibbs = rbprobitGibbs (previously, in package Mixed.Probit), mlogit = mlogit, logitr = logitr, Rchoice = Rchoice, gmnl = gmnl, ChoiceModelR = choicemodelr.

des

A design matrix in which each row is a profile.

y

A numeric vector containing binary or discrete responses. See bin argument.

n.alts

Numeric value indicating the number of alternatives per choice set.

n.sets

Numeric value indicating the number of choice sets.

n.resp

Numeric value indicating the number of respondents.

bin

Logical value indicating whether the response vector contains binary data (TRUE) or discrete data (FALSE). See y argument.

alt.names

A character vector containing the names of the alternatives. The default = NULL.

coding

Type of coding that needs to be used for each attribute. To be used only for package "ChoiceModelR". The default = NULL.

lvls

A numeric vector which contains for each attribute the number of levels. To be used only for package "ChoiceModelR". The default = NULL.

Details

The design (des) specified should be the full aggregated design. Thus, if all participants responded to the same design, des will be a repetition of that design matrix.

The responses in y should be successive when there are multiple respondents. There can be n.sets elements for each respondent with discrete values indicating the chosen alternative for each set. Or there can be n.sets * n.alts elements for each respondent with binary values indicating for each alternative whether it was chosen or not. In the latter case the bin argument should be TRUE.

n.sets indicates the number of sets each respondent responded to. It is assumed that every responded responded to the same number of choice sets.

Value

The data ready to be used by the specified package.

Examples

idefix.data <- aggregate_design 
des <- as.matrix(idefix.data[, 3:8], ncol = 6)
y <- idefix.data[, 9]
bayesm.data <- Datatrans(pkg = "bayesm", des = des, y = y, 
n.alts = 2, n.sets = 8, n.resp = 7, bin = TRUE)
rbprobit.data <- Datatrans(pkg = "bayesm::rbprobitGibbs", des = des, y = y,
 n.alts = 2, n.sets = 8, n.resp = 7, bin = TRUE)
mlogit.data <- Datatrans(pkg = "mlogit", des = des, y = y,
 n.alts = 2, n.sets = 8, n.resp = 7, bin = TRUE)
ChoiceM.data <- Datatrans(pkg = "ChoiceModelR", des = des, y = y,
 n.alts = 2, n.sets = 8, n.resp = 7, bin = TRUE, coding = c("D", "D", "D"), lvls = c(3, 3, 3))
 

idefix documentation built on April 4, 2025, 1:51 a.m.