ct2df: Convert a data frame in contingency-table format into a...

Description Usage Arguments Details Value References See Also Examples

View source: R/ct2df.R

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))

Example output

   T1   Y   N
1  10 178  86
2  30 138 129
3  60 129 126
4 120  88 169
  R1 bid1
1  1   10
2  1   10
3  1   10
4  1   10
5  1   10
6  1   10
Survival probability: 
   Upper   Prob.
1      0  1.0000
2     10  0.6742
3     30  0.5169
4     60  0.5059
5    120  0.3424
6    Inf  0.0000

WTP estimates:
 Mean: 52.800720  (Kaplan-Meier)
 Mean: 61.072064  (Spearman-Karber)
 Median in: [      60 ,     120 ] 
   T1  TU TL  yy yn ny  nn
1  10  30  5 119 59  8  78
2  30  60 10  69 69 31  98
3  60 120 30  54 75 25 101
4 120 250 60  35 53 30 139
  B1 B2H B2L  R R1 R2 bid1 bid2
1 10  30   5 yy  1  1   10   30
2 10  30   5 yy  1  1   10   30
3 10  30   5 yy  1  1   10   30
4 10  30   5 yy  1  1   10   30
5 10  30   5 yy  1  1   10   30
6 10  30   5 yy  1  1   10   30
Survival probability: 
   Upper    Prob.
1      0  1.00000
2      5  0.72057
3     10  0.69191
4     30  0.54122
5     60  0.38390
6    120  0.22070
7    250  0.08778
8    Inf  0.00000

WTP estimates:
 Mean: 54.057648  (Kaplan-Meier)
 Mean: 72.230589  (Spearman-Karber)
 Median in: [      30 ,      60 ] 

DCchoice documentation built on May 2, 2019, 4:44 p.m.