Decode: Coded design to readable design.

Description Usage Arguments Details Value Examples

View source: R/shiny_support.R

Description

Transforms a coded design matrix into a design containing character attribute levels, ready to be used in a survey. The frequency of each attribute level in the design is also included in the output.

Usage

1
2
Decode(des, n.alts, lvl.names, coding, alt.cte = NULL, c.lvls = NULL,
  no.choice = NULL)

Arguments

des

A numeric matrix which represents the design matrix. Each row is a profile.

n.alts

Numeric value indicating the number of alternatives per choice set.

lvl.names

A list containing character vectors with the values of each level of each attribute.

coding

A character vector denoting the type of coding used for each attribute. See also Profiles.

alt.cte

A binary vector indicating for each alternative if an alternative specific constant is present. The default is NULL.

c.lvls

A list containing numeric vectors with the attribute levels for each continuous attribute. The default is NULL.

no.choice

An integer indicating the no choice alternative. The default is NULL.

Details

des A design matrix, this can also be a single choice set. See for example the output of Modfed or CEA.

In lvl.names, the number of character vectors in the list should equal the number of attributes in de choice set. The number of elements in each character vector should equal the number of levels for that attribute.

Valid arguments for coding are C, D and E. When using C the attribute will be treated as continuous and no coding will be applied. All possible levels of that attribute should then be specified in c.lvls. If D (dummy coding) is used contr.treatment will be applied to that attribute. The first attribute wil be used as reference level. For E (effect coding) contr.sum is applied, in this case the last attribute level is used as reference level.

If des contains columns for alternative specific constants, alt.cte should be specified. In this case, the first column(s) (equal to the number of nonzero elements in alt.cte) will be removed from des before decoding the alternatives.

Value

design

A character matrix which represents the design.

lvl.balance

A list containing the frequency of appearance of each attribute level in the design.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Not run: 
# Example without continuous attributes.
design <- example_design 
coded <- c("D", "D", "D") # Coding.
# Levels as they should appear in survey. 
al <- list(
  c("$50", "$75", "$100"), # Levels attribute 1.
  c("2 min", "15 min", "30 min"), # Levels attribute 2.
  c("bad", "moderate", "good") # Levels attribute 3.
) 
# Decode
Decode(des = design, n.alts = 2, lvl.names = al, coding = coded) 

# Example with alternative specific constants
design <- example_design2 
coded <- c("D", "D", "D") # Coding.
# Levels as they should appear in survey. 
al <- list(
  c("$50", "$75", "$100"), # Levels attribute 1.
  c("2 min", "15 min", "30 min"), # Levels attribute 2.
  c("bad", "moderate", "good") # Levels attribute 3.
) 
# Decode
Decode(des = design, n.alts = 3, lvl.names = al, coding = coded, alt.cte = c(1, 1, 0)) 

## End(Not run)

Example output

Loading required package: shiny
$design
            V1     V2       V3
set1.alt1  $75 15 min      bad
set1.alt2 $100  2 min moderate
set2.alt1  $50  2 min moderate
set2.alt2  $75 15 min      bad
set3.alt1 $100  2 min     good
set3.alt2  $50 30 min      bad
set4.alt1 $100  2 min      bad
set4.alt2  $75 15 min moderate
set5.alt1  $50 30 min     good
set5.alt2 $100 30 min      bad
set6.alt1  $75 30 min moderate
set6.alt2 $100 15 min      bad
set7.alt1  $50 15 min     good
set7.alt2  $75  2 min moderate
set8.alt1 $100 15 min moderate
set8.alt2  $75 30 min     good

$lvl.balance
$lvl.balance$`attribute 1 `

$100  $50  $75 
   6    4    6 

$lvl.balance$`attribute 2 `

15 min  2 min 30 min 
     6      5      5 

$lvl.balance$`attribute 3 `

     bad     good moderate 
       6        4        6 


$design
            V1     V2       V3
set1.alt1  $50 30 min moderate
set1.alt2  $75  2 min      bad
set1.alt3 $100  2 min     good
set2.alt1 $100 15 min     good
set2.alt2  $50  2 min moderate
set2.alt3  $75 30 min      bad
set3.alt1  $75 15 min moderate
set3.alt2 $100  2 min      bad
set3.alt3  $50 30 min     good
set4.alt1  $50  2 min      bad
set4.alt2  $75 30 min     good
set4.alt3 $100 30 min moderate
set5.alt1 $100  2 min moderate
set5.alt2  $50 30 min      bad
set5.alt3  $75 15 min     good
set6.alt1 $100 30 min      bad
set6.alt2  $50 15 min moderate
set6.alt3  $75  2 min moderate
set7.alt1  $50  2 min     good
set7.alt2 $100 30 min moderate
set7.alt3  $75 15 min      bad
set8.alt1  $75 30 min      bad
set8.alt2 $100 15 min      bad
set8.alt3  $50  2 min moderate

$lvl.balance
$lvl.balance$`attribute 1 `

$100  $50  $75 
   8    8    8 

$lvl.balance$`attribute 2 `

15 min  2 min 30 min 
     6      9      9 

$lvl.balance$`attribute 3 `

     bad     good moderate 
       9        6        9 

idefix documentation built on Nov. 27, 2020, 1:07 a.m.