## Examples for sbchoice() are also based on a data set NaturalPark
## in the package Ecdat (Croissant 2011): so see the section Examples
## in the dbchoice() for details.
data(NaturalPark, package = "Ecdat")
## The variable answers are converted into a format that is suitable for
## the function sbchoice() as follows:
NaturalPark$R1 <- ifelse(substr(NaturalPark$answers, 1, 1) == "y", 1, 0)
NaturalPark$R2 <- ifelse(substr(NaturalPark$answers, 2, 2) == "y", 1, 0)
## We assume that the error distribution in the model is a log-logistic;
## therefore, the bid variables bid1 is converted into LBD1 as follows:
NaturalPark$LBD1 <- log(NaturalPark$bid1)
## The utility difference function is assumed to contain covariates
## (sex, age, and income) as well as the bid variable (LBD1) as follows
## (R2 is not used because of single-bounded dichotomous choice CV format):
fmsb <- R1 ~ sex + age + income | LBD1
if (FALSE) {
## The formula may be alternatively defined as
fmsb <- R1 ~ sex + age + income | log(bid1)
}
## The function sbchoice() with the function fmsb and the data frame NP
## is executed as follows:
NPsb <- sbchoice(fmsb, data = NaturalPark)
NPsb
NPsbs <- summary(NPsb)
NPsbs
if (FALSE) {
## Generic functions such as summary() and coefficients() work for glm.out
summary(NPsb$glm.out)
coefficients(NPsb$glm.out)
## The confidence intervals for these WTPs are calculated using the
## function krCI() or bootCI() as follows:
krCI(NPsb)
bootCI(NPsb)
## The WTP of a female with age = 5 and income = 3 is calculated
## using function krCI() or bootCI() as follows:
krCI(NPsb, individual = data.frame(sex = "female", age = 5, income = 3))
bootCI(NPsb, individual = data.frame(sex = "female", age = 5, income = 3))
}
## The variable age and income are deleted from the fitted model,
## and the updated model is fitted as follows:
update(NPsb, .~. - age - income |.)
## Respondents' utility and probability of choosing Yes under
## the fitted model and original data are predicted as follows:
head(predict(NPsb, type = "utility"))
head(predict(NPsb, type = "probability"))
## Utility and probability of choosing Yes for a female with age = 5
## and income = 3 under bid = 10 are predicted as follows:
predict(NPsb, type = "utility",
newdata = data.frame(sex = "female", age = 5, income = 3, LBD1 = log(10)))
predict(NPsb, type = "probability",
newdata = data.frame(sex = "female", age = 5, income = 3, LBD1 = log(10)))
## Plot of probabilities of choosing yes is drawn as drawn as follows:
plot(NPsb)
## The range of bid can be limited (e.g., [log(10), log(20)]):
plot(NPsb, bid = c(log(10), log(20)))
Run the code above in your browser using DataLab