Convert a data frame in contingency-table format into a simple data frame of individual observations

Share:

Description

A convinience function converting a data frame object in contingency-table format of bid(s) and responses of dichotomous choice CV into a simple data frame of individual observations. The outcome is suitable for the analysis using functions in the package.

Usage

1
2
ct2df(x, bid1 = "bid1", bid2h = "bidh", bid2l = "bidl", 
    yy = "yy", yn = "yn", ny = "ny", nn = "nn", y = "y", n = "n", type = "double")

Arguments

x

a data frame object in contingency-table format containing bid(s) and responses

bid1

a character string showing the bid (for "single") or the bid in the first stage (for "double")

bid2h

a character string showing the second (higher) bid when respondents answer "Yes" in the first stage

bid2l

a character string showing the second (lower) bid when respondents answer "No" in the first stage

yy

a character string showing a number of respondents accepting both the first and the second bids

yn

a character string showing a number of respondents accepting only the first bid

ny

a character string showing a number of respondents accepting only the second bid

nn

a character string showing a number of respondents not accepting the first nor the second bids

y

a character string showing a number of respondents accepting the bid

n

a character string showing a number of respondents not accepting the bid

type

a character string setting the elicitation format, which takes one of "single" (single-bounded dichotomous choice format) or "double" (double-bounded dichotomous choice format)

Details

The function ct2df implements a conversion of a data frame containing bid(s) and responses regarding dichotomous choice CV in contingency-table format into a data frame suitable for use by the functions sbchoice, dbchoice, kristrom, turnbull.sb, and turnbull.db. See CarsonSB and CarsonDB for dataset in contingency-table format. Arguments from bid2h to nn are only valid for double-bounded dichotomous choice format, while arguments y and n are only valid for single-bounded dichotomous choice format.

See the examples, for usage in detail.

Value

The function returns a data frame, in which each row shows a single respondent. It contains the following variables.

For "single",

R1

a response to a bid: 1 for "Yes", 0 for "No"

bid1

the bid

For "double",

B1

a bid in the first stage

B2H

a (higher) bid in the second stage when the response is "Yes" in the first stage

B2L

a (lower) bid in the second stage when the response is "No" in the first stage

R

a combination of responses in the first and second stages, which takes yy for "Yes" and "Yes", yn for "Yes" and "No", ny for "No" and "Yes", or nn for "No" and "No"

R1

the response in the first stage, which takes 1 for "Yes", 0 for "No"

R2

the response in the second stage, which takes 1 for "Yes", 0 for "No"

bid1

the bid in the first stage

bid2

the bid in the second stage the respondent faced

References

Aizaki H, Nakatani T, Sato K (2014). Stated Preference Methods Using R. CRC Press, Boca Raton, FL.

See Also

sbchoice, dbchoice, kristrom, turnbull.sb, turnbull.db

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
27
# Single-bounded dichotomous choice CV format
data(CarsonSB)
CarsonSB
CarsonSB.dat <- ct2df(
  x    = CarsonSB,
  bid1 = "T1",
  y    = "Y",
  n    = "N",
  type = "single")
head(CarsonSB.dat)
summary(turnbull.sb(R1 ~ bid1, data = CarsonSB.dat))

# Double-bounded dichotomous choice CV format
data(CarsonDB)
CarsonDB
CarsonDB.dat <- ct2df(
  x     = CarsonDB,
  bid1  = "T1",
  bid2h = "TU",
  bid2l = "TL",
  yy    = "yy",
  yn    = "yn",
  ny    = "ny",
  nn    = "nn",
  type  = "double")
head(CarsonDB.dat)
summary(turnbull.db(R1 + R2 ~ bid1 + bid2, data = CarsonDB.dat))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.