Learn R Programming

DCchoice (version 0.0.15)

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

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

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)

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

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.

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

Run this code
# 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))

Run the code above in your browser using DataLab