Running examples in ‘support.BWS2-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: agritourism
> ### Title: Potential tourists' valuation of agritourism
> ### Aliases: agritourism
> ### Keywords: datasets
> 
> ### ** Examples
> 
> # Agritourism refers to various activities offered by farms and ranches
> # to visitors, such as hands-on farm work or outdoor recreation.
> #
> # In the Case 2 BWS questions, respondents were asked to evaluate 
> # agritourism packages provided by dairy farms (ranches) in Hokkaido, Japan. 
> # We assumed that the agritourism package consists of the following four
> # types of activities, each with three activity items:
> #  1. Hands-on ranch chores
> #    (1) Milking a cow
> #    (2) Feeding a cow
> #    (3) Nursing a calf
> #  2. Hands-on food processing
> #    (1) Butter making
> #    (2) Ice-cream making
> #    (3) Creamy caramel making
> #  3. Hands-on craft making
> #    (1) Making a product from wool
> #    (2) Making a product from wood
> #    (3) Making a product from pressed flowers
> #  4. Outdoor activities
> #    (1) Horse riding
> #    (2) Tractor riding
> #    (3) Walking with cows
> #
> # As there are four activities and each activity has three items, 
> # a total of nine BWS questions were created using a three-level OMED
> # with four columns. Each BWS question asked respondents to select
> # the most and least interesting of the four activities shown 
> # in the question.
> #
> # In the following, we assume that the paired and marginal models with
> # both attribute and attribute-level variables (Flynn et al. 2007; 2008)
> # are fitted to the responses using the conditional logit model, 
> # with clogit() in the survival package.
> 
> # Load the package needed for the example:
> require(survival)
Loading required package: survival
> 
> options(digits = 4)
> 
> # The following OMED is generated using oa.design() in the DoE.base package:
> # require(DoE.base)
> # des <- data.matrix(
> #    oa.design(nl = c(3,3,3,3), randomize = FALSE))
> des <- cbind(
+   c(1, 1, 1, 2, 2, 2, 3, 3, 3),
+   c(1, 2, 3, 1, 2, 3, 1, 2, 3),
+   c(1, 3, 2, 3, 2, 1, 2, 1, 3),
+   c(1, 2, 3, 3, 1, 2, 2, 3, 1))
> 
> # The names of the attributes (activities) and attribute levels 
> # (activity items) were stored in the list attr.lev:
> attr.lev <- list(
+    chore = c("milking", "feeding", "nursing"),
+    food = c("butter", "ice", "caramel"),
+    craft = c("wool", "wood", "flower"),
+    outdoor =c("horse", "tractor", "cow"))
> 
> # A series of Case 2 BWS questions were converted from the OMED using 
> # bws2.questionnaire():
> bws2.questionnaire(choice.sets = des, attribute.levels = attr.lev,
+   position = "left")

Q1
 Attribute Best Worst
 milking   [ ]  [ ]  
 butter    [ ]  [ ]  
 wool      [ ]  [ ]  
 horse     [ ]  [ ]  

Q2
 Attribute Best Worst
 milking   [ ]  [ ]  
 ice       [ ]  [ ]  
 flower    [ ]  [ ]  
 tractor   [ ]  [ ]  

Q3
 Attribute Best Worst
 milking   [ ]  [ ]  
 caramel   [ ]  [ ]  
 wood      [ ]  [ ]  
 cow       [ ]  [ ]  

Q4
 Attribute Best Worst
 feeding   [ ]  [ ]  
 butter    [ ]  [ ]  
 flower    [ ]  [ ]  
 cow       [ ]  [ ]  

Q5
 Attribute Best Worst
 feeding   [ ]  [ ]  
 ice       [ ]  [ ]  
 wood      [ ]  [ ]  
 horse     [ ]  [ ]  

Q6
 Attribute Best Worst
 feeding   [ ]  [ ]  
 caramel   [ ]  [ ]  
 wool      [ ]  [ ]  
 tractor   [ ]  [ ]  

Q7
 Attribute Best Worst
 nursing   [ ]  [ ]  
 butter    [ ]  [ ]  
 wood      [ ]  [ ]  
 tractor   [ ]  [ ]  

Q8
 Attribute Best Worst
 nursing   [ ]  [ ]  
 ice       [ ]  [ ]  
 wool      [ ]  [ ]  
 cow       [ ]  [ ]  

Q9
 Attribute Best Worst
 nursing   [ ]  [ ]  
 caramel   [ ]  [ ]  
 flower    [ ]  [ ]  
 horse     [ ]  [ ]  

> 
> # The responses to the questions were stored in the dataset agritourism
> # in the support.BWS2 package:
> data(agritourism)
> dim(agritourism)
[1] 240  21
> colnames(agritourism)
 [1] "id"     "b1"     "w1"     "b2"     "w2"     "b3"     "w3"     "b4"    
 [9] "w4"     "b5"     "w5"     "b6"     "w6"     "b7"     "w7"     "b8"    
[17] "w8"     "b9"     "w9"     "gender" "age"   
> 
> # The names of the response variables used in the dataset agritourism
> # were stored in the vector response.vars:
> response.vars <- colnames(agritourism)[2:19]
> response.vars
 [1] "b1" "w1" "b2" "w2" "b3" "w3" "b4" "w4" "b5" "w5" "b6" "w6" "b7" "w7" "b8"
[16] "w8" "b9" "w9"
> 
> # The base level in each attribute was stored in the object base.lev
> # in list format:
> base.lev <- list(
+   chore = c("nursing"),
+   food = c("caramel"),
+   craft = c("flower"),
+   outdoor =c("cow"))
> 
> # The datasets for the paired model and the marginal model were created
> # using bws2.dataset() and then stored in the objects pr.data1 and mr.data1,
> # respectively:
> pr.data1 <- bws2.dataset(
+    data = agritourism,
+    id = "id",
+    response = response.vars,  
+    choice.sets = des,        
+    attribute.levels = attr.lev,
+    attribute.variables = c("reverse"),
+    effect = base.lev,
+    type = "paired") 
> mr.data1 <- bws2.dataset(
+    data = agritourism,
+    id = "id",
+    response = response.vars,
+    choice.sets = des,
+    attribute.levels = attr.lev,
+    attribute.variables = c("reverse"),
+    effect = base.lev,
+    delete.best = FALSE,
+    type = "marginal")
> dim(pr.data1)
[1] 25920    27
> names(pr.data1)
 [1] "id"       "Q"        "PAIR"     "BEST"     "WORST"    "BEST.AT" 
 [7] "WORST.AT" "BEST.LV"  "WORST.LV" "chore"    "food"     "craft"   
[13] "outdoor"  "milking"  "feeding"  "butter"   "ice"      "wool"    
[19] "wood"     "horse"    "tractor"  "RES.B"    "RES.W"    "RES"     
[25] "STR"      "gender"   "age"     
> dim(mr.data1)
[1] 17280    26
> names(mr.data1)
 [1] "id"      "Q"       "ALT"     "BW"      "ATT.cha" "ATT"     "LEV.cha"
 [8] "LEV"     "chore"   "food"    "craft"   "outdoor" "milking" "feeding"
[15] "butter"  "ice"     "wool"    "wood"    "horse"   "tractor" "RES.B"  
[22] "RES.W"   "RES"     "STR"     "gender"  "age"    
> 
> # The BWS scores were calculated using bws2.count() with the dataset for
> # the marginal model:
> scores <- bws2.count(mr.data1)
Error in nrow(B[, c(id.variable, variableNames)]) : object 'B' not found
Calls: bws2.count ... by.data.frame -> structure -> eval -> eval -> tapply -> nrow
Execution halted