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
Error: package or namespace load failed for ‘survival’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/hornik/tmp/R.check/r-patched-gcc/Work/build/Packages/Matrix/libs/Matrix.so':
  /home/hornik/tmp/R.check/r-patched-gcc/Work/build/Packages/Matrix/libs/Matrix.so: failed to map segment from shared object
> 
> 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)
> dim(scores)
[1] 240  51
> names(scores)
 [1] "id"          "b.milking"   "b.feeding"   "b.nursing"   "b.butter"   
 [6] "b.ice"       "b.caramel"   "b.wool"      "b.wood"      "b.flower"   
[11] "b.horse"     "b.tractor"   "b.cow"       "w.milking"   "w.feeding"  
[16] "w.nursing"   "w.butter"    "w.ice"       "w.caramel"   "w.wool"     
[21] "w.wood"      "w.flower"    "w.horse"     "w.tractor"   "w.cow"      
[26] "bw.milking"  "bw.feeding"  "bw.nursing"  "bw.butter"   "bw.ice"     
[31] "bw.caramel"  "bw.wool"     "bw.wood"     "bw.flower"   "bw.horse"   
[36] "bw.tractor"  "bw.cow"      "sbw.milking" "sbw.feeding" "sbw.nursing"
[41] "sbw.butter"  "sbw.ice"     "sbw.caramel" "sbw.wool"    "sbw.wood"   
[46] "sbw.flower"  "sbw.horse"   "sbw.tractor" "sbw.cow"     "gender"     
[51] "age"        
> 
> # The scores for each level were aggregated among all respondents using
> # sum() and bar plots of the scores were drawn using barplot():
> sum(scores, "level")
          B   W   BW     stdBW
milking 131 129    2  0.002778
feeding 106 156  -50 -0.069444
nursing 157 109   48  0.066667
butter  358  51  307  0.426389
ice     354  58  296  0.411111
caramel 349  65  284  0.394444
wool     79 297 -218 -0.302778
wood     63 362 -299 -0.415278
flower   34 428 -394 -0.547222
horse   272  75  197  0.273611
tractor 135 235 -100 -0.138889
cow     122 195  -73 -0.101389
> barplot(scores, "bw", "level")
> 
> # If we only need aggregated B and W scores, these can be calculated from
> # the dataset for a paired model as follows:
> apply(pr.data1[pr.data1$RES == 1, c("BEST.LV", "WORST.LV")], 2, table)
        BEST.LV WORST.LV
butter      358       51
caramel     349       65
cow         122      195
feeding     106      156
flower       34      428
horse       272       75
ice         354       58
milking     131      129
nursing     157      109
tractor     135      235
wood         63      362
wool         79      297
> 
> # BW scores can be calculated according to groups of respondents. 
> # For example, the scores for male and those for female are given as follows:
> sum(scores[agritourism$gender == 1, ], "level")
          B   W   BW    stdBW
milking  62  62    0  0.00000
feeding  51  78  -27 -0.07500
nursing  72  56   16  0.04444
butter  179  23  156  0.43333
ice     178  32  146  0.40556
caramel 169  43  126  0.35000
wool     30 168 -138 -0.38333
wood     36 173 -137 -0.38056
flower    4 247 -243 -0.67500
horse   151  29  122  0.33889
tractor  83  92   -9 -0.02500
cow      65  77  -12 -0.03333
> sum(scores[agritourism$gender == 2, ], "level")
          B   W   BW     stdBW
milking  69  67    2  0.005556
feeding  55  78  -23 -0.063889
nursing  85  53   32  0.088889
butter  179  28  151  0.419444
ice     176  26  150  0.416667
caramel 180  22  158  0.438889
wool     49 129  -80 -0.222222
wood     27 189 -162 -0.450000
flower   30 181 -151 -0.419444
horse   121  46   75  0.208333
tractor  52 143  -91 -0.252778
cow      57 118  -61 -0.169444
> 
> # Bar plots for respondents in their 20s and those in their 50s can also be
> # drawn using the following lines of code:
> barplot(scores[agritourism$age == 2, ], "bw", "level")
> barplot(scores[agritourism$age == 5, ], "bw", "level")
> 
> # We fitted the conditional logit model to the Case 2 BWS responses 
> # on the basis of the paired and marginal models with both attribute
> # and attribute-level variables. The systematic component of the utility
> # function for the example is
> #    v = b1 chore + b2 food + b3 outdoor + 
> #        b4 milking + b5 feeding + b6 butter + b7 ice +
> #        b8 wool + b9 wood + b10 horse + b11 tractor
> # where chore, food, and outdoor are attribute variables (craft has been
> # omitted); and milking, feeding, butter, ice, wool, wood, horse, and
> # tractor are attribute-level variables (nursing has been omitted for chore,
> # caramel has been omitted for food, flower has been omitted for craft,
> # and cow has been omitted for outdoor); bs are coefficients to be estimated.
> #
> # The model formula for clogit(), corresponding to the systematic component
> # mentioned above, is described as:
> mf <- RES ~ chore + food + outdoor + 
+             milking + feeding + butter + ice + 
+             wool + wood + horse + tractor +
+             strata(STR)
> 
> # We fitted the paired model using clogit() with the dataset pr.data1:
> pr.out <- clogit(formula = mf, data = pr.data1)
Error in clogit(formula = mf, data = pr.data1) : 
  could not find function "clogit"
Execution halted