Since Aug 11, 2014
Last update
May 19, 2017
This is the website for Stated Preference Methods Using R (SPMUR) published as a title of Chapman & Hall/CRC The R Series.
install.packages("DCchoice", repos = c("http://www.bioconductor.org/packages/release/bioc", "https://cran.rstudio.com/"), dep = TRUE)
SPMUR explains how to apply stated preference (SP) methods such as contingent valuation (CV), discrete choice experiments (DCEs), and best-worst scaling (BWS) to elicit people's preferences using R. SPMUR focuses on introductory-level variants of three methods: single-bounded dichotomous choice and double-bounded dichotomous choice CV based on parametric and nonparametric approaches for analyzing responses; DCEs based on orthogonal main-effect designs (OMEDs) for designing choice situations and conditional and binary logit models for analyzing responses; and object case (case 1) BWS based on OMED or balanced incomplete block design for designing choice situation and counting and modeling approaches for analyzing responses. For the table of contents, refer the SPMUR page on the publisher's website.
Supplementary materials on SPMUR such as Errata, FAQs, reproduction of examples, contact, and site policy are given below.
R is a free environment for statistical computing and graphics (http://www.R-project.org). R runs on operating systems such as Windows, Mac OS X, and Linux. R can extend its functionality by installing various add-on packages. More than 5,000 packages are distributed from the Comprehensive R Archive Network (CRAN). R enables us to learn statistical techniques such as SP methods with limited cost. For detailed information, refer the website for R.
R is available from CRAN. CRAN also provides steps for installing R on your computer based on the operating system, such as Windows, Mac OS X, and Linux. Since there are many mirror sites for CRAN, first, access the CRAN page on the R website, and then search mirror sites closest to your location.
We recommend that R beginners first attempt Chapter 5 of SPMUR, or one of the R manuals, such as "An Introduction to R." The R manuals may be available in your R, or can be downloaded from CRAN or the R website. After understanding the basic usage, attempt Chapters 2, 3, and 4 of SPMUR. In addition to informative R manuals, many books, documents, and websites explain how to use R. Books and documents related to R are listed in CRAN and the R website. The R series also provides titles for basic topics on R, as well as ones for specific statistical techniques such as SPMUR. Since R users are worldwide, information on R is available, through the web, in English, as well as other languages. For example, RjpWiki provides a place for the exchange of information on R in Japanese, and thus, it is of help to Japanese R beginners.
The authors' packages related to SPMUR are available from CRAN and R-Forge. After installing R onto your computer and then starting an R session, the following code is executed (or copy and paste) on the R console to install packages needed for each chapter (the other packages on which each package depends may be installed simultaneously). For general and detailed information on installing packages, see R FAQ, R Mac OS X FAQ, and R Windows FAQ that are provided through the R website and CRAN.
This is the R code for installing the DCchoice package in Chapter 2
install.packages("DCchoice", repos = c("http://R-Forge.R-project.org", "http://www.bioconductor.org/packages/release/bioc", "http://cran.rstudio.com/"), dep = TRUE)Note that the third repository in
repos
above,
http://cran.rstudio.com/
,
can be replaced by any other CRAN mirror site. This modification is
also available for Mac and Linux below.
This is the R code for installing the DCchoice package in Chapter 2
install.packages("DCchoice", repos = c("http://R-Forge.R-project.org", "http://www.bioconductor.org/packages/release/bioc", "http://cran.rstudio.com/"), dep = TRUE, type = "source")Some Mac OS X (in particular Mavericks) users will encounter an error when trying the above command. If this is the case, the following steps may solve the problem.
(1) Upgrade R to the latest release (version 3.1.1 as of August 2014).
(2) Start an R session and type (or copy and paste) the above command.
If you still encounter error messages, you need to install a suitable version of the gfortran complier as follows (The following steps can be risky to carry out because it may cause irreversible damage to your system. Please be aware of the risks before you decide to proceed. See also site policy.):
(3) Download the compressed file for gfortran from http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2 and save it in an accessible location, such as Downloads, on your machine.
(4) Double-click the icon labeled "Terminal" in your Utilities folder at Launchpad. A new window opens with the prompt
your_machine:~ your_name$
(5) Assume that the downloaded file is saved in your "Downloads" folder. Type the following command at the command prompt
cd ./DownloadsThe prompt now appears as
your_machine:Downloads your_name$
(6) Type the following command, and when you are asked for a password, enter the one you use for the startup.
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /Then, the installation starts and several lines appear as:
x usr/local/bin/gfortran x usr/local/bin/gfortran-4.8 x usr/local/bin/x86_64-apple-darwin13.0.0-gfortran ...
(7) After a short while, the prompt will start again. This indicates a successful installation of gfortran.
(8) Start an R session again and carry out
the install.packages()
command shown in the beginning.
This is the R code for installing the DCchoice package in Chapter 2
install.packages("DCchoice", repos = c("http://R-Forge.R-project.org", "http://www.bioconductor.org/packages/release/bioc", "http://cran.rstudio.com/"), dep = TRUE, type = "source")
install.packages(c("support.CEs", "mded"), dep = TRUE)
install.packages(c("support.BWS", "DoE.base", "crossdes"), dep = TRUE)
See the section Reproduction of Examples below.
Examples in Chapters 2, 3, and 4 of SPMUR can be reproduced
on your R. Note that some lines of code may not return outputs
that are the same in SPMUR, because random numbers are generated
without the set.seed()
function.
Dataset examples in Chapters 2, 3, and 4 are stored in
the following packages:
• For Chapter 2,
DCchoice and
Ecdat packages.
• For Chapter 3,
support.CEs package.
• For Chapter 4,
support.BWS package.
Note that datasets used in Sections 3.3 and 4.3 are embedded
in example codes that are explained below.
The R code for examples in Chapters 2, 3, and 4 are contained
in the following:
• For Chapter 2,
examples_ch2.R
• For Chapter 3,
examples_ch3.R
• For Chapter 4,
examples_ch4.R
These files are licensed under
the GNU GPLv2 or
later.
Note that these files are saved as a text file, and that
some lines of code in these files are not shown in SPMUR explicitly.
For example, the plot()
function was used in SPMUR
implicitly to draw some figures, and a comment
"not shown in SPMUR"
is added to such lines.
Before reproducing examples, first, type and execute the following code on the R console:
options(prompt = "R> ", continue = " ", width = 60, digits = 4, show.signif.stars = FALSE)This sets the appearance format for R that is used in SPMUR.
When executing all lines of code at once, the file assumed
to be examples_ch2.R
is stored in the current
working directory. Then, type and execute the following code
on the R console, after executing the code using
options()
given above.
source(file = "examples_ch2.R", echo = TRUE, max.deparse.length = Inf)Note that this code executes all lines of code for Chapter 2 simultaneously. When executing those for Chapters 3 or 4, the argument
file
is set as "examples_ch3.R"
or
"examples_ch4.R"
.
We welcome your comments, suggestions, or error reports.
Our e-mail address is spmur_at_agecon.agr.hokudai.ac.jp
(_at_
should be replaced with @
).
While reasonable efforts have been made to provide reliable information, we are not responsible for any errors in the material provided on this website and shall not be liable for any damages of any kind arising from the use of any material found on this website.