–//– Load R Packages –//–


Install and/or load all required R Packages

knitr::opts_chunk$set(echo = TRUE)

if(!require("tidyverse")) {install.packages("tidyverse"); library("tidyverse")}
if(!require("pROC")) {install.packages("pROC"); library("pROC")}
if(!require("broom")) {install.packages("broom"); library("broom")}
if(!require("car")) {install.packages("car"); library("car")}
if(!require("lmtest")) {install.packages("lmtest"); library("lmtest")}
if(!require("Hmisc")) {install.packages("Hmisc"); library("Hmisc")}
if(!require("sjlabelled")) {install.packages("sjlabelled"); library("sjlabelled")}
if(!require("DescTools")) {install.packages("DescTools"); library("DescTools")}
if(!require("cowplot")) {install.packages("cowplot"); library("cowplot")}
if(!require("dplyr")) {install.packages("dplyr"); library("dplyr")}
if(!require("nnet")) {install.packages("nnet"); library("nnet")}
if(!require("stats")) {install.packages("stats"); library("stats")}

–//– Clean-Up Working Emvironment –//–


Removes all objects from the current working environment

# clean up working environment
rm(list = ls())

–//– Chapter 05 - Logistic Regression –//–


[=> Case Study] | 5.4 | Case Study

(-) Table 5.21 - Chocolate flavors and perceived attributes examined in the case study

Chocolate_flavor <- factor(levels = c(1:11),
                           labels = c("Milk", 
                                      "Espresso",
                                      "Biscuit",
                                      "Orange",
                                      "Strawberry",
                                      "Mango",
                                      "Cappuccino",
                                      "Mousse",
                                      "Caramel",
                                      "Nougat",
                                      "Nut"))

Perceived_attributes <- factor(levels = c(1:10),
                               labels = c("Price",
                                          "Refreshing",
                                          "Delicious",
                                          "Healthy",
                                          "Bitter",
                                          "Light",
                                          "Crunchy",
                                          "Exotic",
                                          "Sweet",
                                          "Fruity"))


print(Chocolate_flavor); print(Perceived_attributes)
## factor(0)
## 11 Levels: Milk Espresso Biscuit Orange Strawberry Mango Cappuccino ... Nut
## factor(0)
## 10 Levels: Price Refreshing Delicious Healthy Bitter Light Crunchy ... Fruity

(-) Table 5.22 - Definition of the segments (groups) for multinomial logistic regression

Seg_1_Classic <- c("Milk", "Biscuit", "Mousse", "Caramel", "Nougat", "Nut")
Seg_2_Fruit <- c("Orange", "Strawberry", "Mango")
Seg_3_Coffee <- c("Espresso", "Cappuccino")

(-) Create exemplary data set.

datlogreg_127cases <- data.frame(
"ID"    = c(    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, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,    101,    102,    103,    104,    105,    106,    107,    108,    109,    110,    111,    112,    113,    114,    115,    116,    117,    118,    119,    120,    121,    122,    123,    124,    125,    126,    127 ),
"Price" = c(    3,  6,  2,  4,  7,  5,  6,  3,  7,  3,  7,  7,  6,  3,  4,  4,  3,  6,  7,  5,  3,  6,  4,  6,  6,  6,  5,  6,  3,  7,  2,  6,  5,  5,  4,  7,  5,  4,  2,  3,  3,  7,  3,  6,  4,  2,  3,  4,  6,  1,  2,  2,  3,  2,  5,  1,  3,  3,  5,  7,  3,  2,  3,  2,  6,  2,  3,  7,  5,  3,  6,  5,  6,  6,  4,  5,  5,  5,  6,  7,  5,  7,  5,  7,  6,  6,  6,  6,  7,  6,  5,  5,  4,  7,  7,  7,  5,  5,  6,  5,  2,  6,  5,  5,  4,  4,  6,  5,  5,  5,  6,  6,  5,  4,  5,  4,  7,  4,  5,  5,  3,  5,  6,  4,  5,  3,  5   ),
"Refreshing"    = c(    3,  6,  3,  3,  5,  4,  5,  3,  6,  4,  1,  7,  5,  3,  6,  3,  4,  3,  7,  2,  4,  2,  3,  2,  5,  2,  2,  5,  4,  7,  2,  5,  3,  4,  6,  4,  5,  5,  2,  6,  7,  7,  5,  2,  5,  7,  7,  6,  7,  7,  2,  4,  6,  4,  4,  3,  6,  7,  4,  5,  5,  7,  1,  2,  4,  1,  4,  4,  3,  4,  2,  3,  3,  4,  2,  3,  3,  5,  4,  5,  4,  6,  2,  5,  2,  4,  6,  2,  6,  6,  4,  4,  5,  6,  4,  7,  2,  4,  4,  2,  2,  4,  6,  4,  3,  7,  5,  5,  1,  4,  NA, 5,  3,  1,  3,  4,  5,  4,  3,  3,  3,  5,  7,  3,  4,  4,  4   ),
"Delicious" = c(    5,  5,  3,  3,  5,  5,  6,  3,  6,  4,  4,  3,  4,  4,  2,  4,  4,  5,  3,  3,  4,  5,  4,  4,  7,  6,  4,  6,  6,  4,  5,  4,  4,  4,  4,  6,  4,  4,  2,  3,  3,  7,  3,  3,  4,  5,  5,  6,  5,  1,  2,  4,  2,  3,  5,  3,  4,  3,  4,  6,  5,  3,  3,  2,  4,  2,  6,  6,  6,  3,  6,  4,  5,  5,  4,  4,  4,  5,  5,  4,  4,  6,  5,  4,  6,  5,  6,  6,  2,  6,  4,  4,  4,  7,  2,  7,  5,  4,  4,  6,  5,  6,  5,  4,  4,  4,  4,  4,  4,  4,  3,  4,  3,  4,  5,  4,  4,  4,  4,  5,  3,  5,  5,  4,  4,  4,  4   ),
"Healthy"   = c(    4,  2,  3,  4,  7,  2,  5,  4,  2,  4,  5,  7,  3,  3,  4,  4,  4,  4,  2,  4,  4,  2,  3,  5,  3,  4,  4,  4,  2,  NA, 4,  1,  4,  4,  4,  4,  3,  3,  2,  3,  1,  3,  2,  2,  5,  6,  6,  4,  4,  NA, 6,  4,  2,  5,  3,  3,  4,  1,  4,  3,  4,  2,  6,  6,  4,  2,  4,  4,  5,  4,  4,  4,  5,  1,  2,  3,  5,  4,  5,  5,  4,  3,  2,  4,  4,  6,  4,  4,  4,  6,  3,  5,  4,  1,  6,  4,  2,  5,  6,  3,  4,  3,  4,  4,  3,  4,  4,  5,  3,  4,  4,  4,  4,  3,  6,  4,  4,  3,  4,  4,  4,  5,  5,  3,  6,  4,  1   ),
"Bitter"    = c(    1,  2,  2,  4,  3,  5,  6,  3,  3,  2,  1,  1,  1,  1,  1,  4,  3,  4,  1,  4,  3,  3,  4,  6,  3,  6,  6,  6,  6,  4,  3,  1,  4,  4,  4,  5,  4,  4,  3,  7,  4,  7,  3,  4,  5,  5,  1,  6,  2,  7,  6,  4,  2,  2,  3,  1,  6,  4,  4,  6,  3,  6,  5,  6,  4,  2,  6,  5,  7,  2,  6,  5,  3,  5,  5,  4,  2,  5,  5,  3,  4,  2,  3,  3,  5,  6,  6,  6,  3,  3,  3,  3,  3,  7,  1,  5,  3,  3,  7,  5,  3,  5,  5,  4,  3,  4,  5,  4,  6,  5,  2,  4,  3,  1,  7,  4,  4,  2,  3,  4,  4,  4,  5,  3,  4,  4,  4   ),
"Light" = c(    2,  5,  3,  3,  6,  4,  5,  2,  7,  5,  4,  3,  2,  4,  3,  4,  3,  4,  2,  4,  4,  4,  5,  6,  2,  6,  5,  6,  4,  6,  5,  3,  3,  5,  4,  5,  3,  5,  2,  5,  6,  7,  3,  3,  5,  6,  7,  7,  6,  7,  5,  6,  4,  5,  4,  7,  6,  6,  4,  6,  5,  7,  5,  5,  4,  4,  6,  6,  6,  4,  6,  5,  6,  6,  3,  3,  1,  4,  4,  5,  4,  6,  5,  4,  6,  5,  6,  6,  4,  6,  5,  4,  3,  7,  2,  7,  2,  4,  5,  4,  5,  4,  5,  4,  5,  4,  4,  4,  4,  5,  6,  3,  4,  2,  5,  4,  4,  2,  3,  3,  5,  5,  5,  3,  5,  4,  4   ),
"Crunchy"   = c(    3,  2,  5,  5,  5,  3,  6,  3,  5,  5,  1,  1,  NA, 2,  1,  4,  3,  4,  5,  5,  3,  2,  4,  3,  3,  4,  4,  4,  6,  7,  3,  4,  4,  4,  3,  5,  1,  5,  6,  4,  3,  7,  5,  5,  5,  5,  6,  4,  6,  7,  5,  4,  5,  7,  5,  5,  7,  3,  3,  4,  6,  7,  6,  5,  4,  5,  7,  4,  2,  5,  4,  3,  3,  6,  5,  6,  4,  6,  6,  6,  3,  1,  2,  4,  2,  5,  3,  4,  3,  2,  4,  3,  3,  2,  3,  7,  2,  4,  6,  6,  3,  3,  NA, 4,  3,  1,  5,  5,  5,  4,  5,  5,  3,  3,  7,  4,  4,  3,  3,  5,  3,  3,  5,  4,  5,  4,  1   ),
"Exotic"    = c(    1,  1,  1,  2,  1,  7,  5,  1,  1,  1,  1,  1,  1,  3,  2,  4,  7,  3,  1,  3,  1,  1,  7,  1,  1,  6,  6,  5,  7,  1,  1,  1,  1,  4,  1,  1,  1,  1,  6,  7,  7,  1,  7,  1,  1,  7,  7,  5,  7,  7,  7,  2,  7,  2,  2,  7,  7,  7,  5,  1,  7,  7,  NA, 7,  NA, 7,  7,  1,  7,  2,  5,  1,  6,  7,  1,  1,  7,  5,  1,  1,  1,  1,  1,  1,  7,  1,  1,  NA, 1,  NA, 1,  1,  NA, 7,  1,  1,  1,  1,  1,  7,  1,  1,  1,  NA, 1,  1,  1,  7,  1,  1,  1,  1,  1,  1,  1,  1,  3,  1,  1,  1,  5,  5,  5,  1,  1,  1,  1   ),
"Sweet" = c(    3,  6,  3,  4,  5,  7,  6,  3,  6,  4,  3,  4,  3,  4,  4,  4,  5,  4,  1,  3,  1,  3,  4,  5,  3,  5,  5,  4,  2,  5,  4,  3,  2,  4,  4,  3,  3,  3,  3,  4,  4,  6,  2,  5,  3,  5,  5,  5,  6,  1,  4,  4,  3,  4,  4,  7,  6,  4,  3,  5,  5,  7,  5,  4,  4,  2,  6,  5,  6,  4,  5,  4,  4,  3,  5,  5,  4,  4,  5,  5,  3,  2,  4,  5,  6,  6,  4,  5,  4,  4,  6,  4,  4,  7,  5,  6,  3,  4,  5,  3,  4,  3,  2,  4,  3,  3,  4,  3,  4,  4,  3,  4,  3,  3,  6,  4,  5,  2,  3,  5,  4,  4,  5,  3,  4,  4,  1   ),
"Fruity"    = c(    4,  7,  2,  4,  5,  3,  5,  3,  3,  4,  5,  5,  1,  2,  4,  4,  5,  4,  1,  3,  3,  4,  4,  4,  1,  5,  4,  4,  4,  1,  5,  3,  2,  4,  4,  5,  3,  6,  2,  4,  5,  6,  4,  5,  6,  6,  6,  5,  5,  7,  6,  4,  6,  4,  4,  7,  7,  5,  3,  5,  5,  7,  4,  6,  4,  5,  7,  5,  3,  3,  5,  4,  4,  3,  4,  4,  1,  3,  6,  3,  2,  3,  5,  4,  3,  3,  2,  5,  4,  4,  5,  3,  3,  7,  2,  6,  4,  3,  6,  3,  5,  7,  4,  4,  3,  3,  4,  3,  4,  4,  4,  1,  4,  3,  6,  4,  5,  2,  3,  4,  3,  4,  5,  4,  4,  4,  4   ),
"Respondent"    = c(    1,  3,  4,  7,  11, 12, 16, 18, 2,  4,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 1,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 2,  8,  10, 11, 13, 1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 4,  7,  8,  10, 12, 13, 14, 16, 2,  6,  7,  8,  9,  12, 13, 14, 15, 16, 17, 18, 1,  2,  3,  4,  6,  8,  10, 11, 12, 13, 14, 15, 16, 17, 1,  2,  3,  4,  5,  6,  8,  9,  11, 13, 17, 18, 4,  5,  7,  9,  12, 13, 14, 15, 16, 17, 18, 1,  2,  3,  4,  6,  8,  9,  13, 17, 18  ),
"Flavor"    = c(    1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11  ),
"Segment"   = c(    1,  1,  1,  1,  1,  1,  1,  1,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   )
)


datlogreg_127cases$Flavor <- factor(datlogreg_127cases$Flavor, 
                                   levels = c(1:11),
                                   labels = c("Milk", 
                                      "Espresso",
                                      "Buscuit",
                                      "Orange",
                                      "Strawberry",
                                      "Mango",
                                      "Cappuccino",
                                      "Mousse",
                                      "Caramel",
                                      "Nougat",
                                      "Nut"))

datlogreg_127cases$Segment <- factor(datlogreg_127cases$Segment, 
                                   levels = c(1:3),
                                   labels = c("Seg_1_Classic", 
                                              "Seg_2_Fruit",
                                              "Seg_3_Coffee"))
                                      

print(datlogreg_127cases)
##      ID Price Refreshing Delicious Healthy Bitter Light Crunchy Exotic Sweet
## 1     1     3          3         5       4      1     2       3      1     3
## 2     2     6          6         5       2      2     5       2      1     6
## 3     3     2          3         3       3      2     3       5      1     3
## 4     4     4          3         3       4      4     3       5      2     4
## 5     5     7          5         5       7      3     6       5      1     5
## 6     6     5          4         5       2      5     4       3      7     7
## 7     7     6          5         6       5      6     5       6      5     6
## 8     8     3          3         3       4      3     2       3      1     3
## 9     9     7          6         6       2      3     7       5      1     6
## 10   10     3          4         4       4      2     5       5      1     4
## 11   11     7          1         4       5      1     4       1      1     3
## 12   12     7          7         3       7      1     3       1      1     4
## 13   13     6          5         4       3      1     2      NA      1     3
## 14   14     3          3         4       3      1     4       2      3     4
## 15   15     4          6         2       4      1     3       1      2     4
## 16   16     4          3         4       4      4     4       4      4     4
## 17   17     3          4         4       4      3     3       3      7     5
## 18   18     6          3         5       4      4     4       4      3     4
## 19   19     7          7         3       2      1     2       5      1     1
## 20   20     5          2         3       4      4     4       5      3     3
## 21   21     3          4         4       4      3     4       3      1     1
## 22   22     6          2         5       2      3     4       2      1     3
## 23   23     4          3         4       3      4     5       4      7     4
## 24   24     6          2         4       5      6     6       3      1     5
## 25   25     6          5         7       3      3     2       3      1     3
## 26   26     6          2         6       4      6     6       4      6     5
## 27   27     5          2         4       4      6     5       4      6     5
## 28   28     6          5         6       4      6     6       4      5     4
## 29   29     3          4         6       2      6     4       6      7     2
## 30   30     7          7         4      NA      4     6       7      1     5
## 31   31     2          2         5       4      3     5       3      1     4
## 32   32     6          5         4       1      1     3       4      1     3
## 33   33     5          3         4       4      4     3       4      1     2
## 34   34     5          4         4       4      4     5       4      4     4
## 35   35     4          6         4       4      4     4       3      1     4
## 36   36     7          4         6       4      5     5       5      1     3
## 37   37     5          5         4       3      4     3       1      1     3
## 38   38     4          5         4       3      4     5       5      1     3
## 39   39     2          2         2       2      3     2       6      6     3
## 40   40     3          6         3       3      7     5       4      7     4
## 41   41     3          7         3       1      4     6       3      7     4
## 42   42     7          7         7       3      7     7       7      1     6
## 43   43     3          5         3       2      3     3       5      7     2
## 44   44     6          2         3       2      4     3       5      1     5
## 45   45     4          5         4       5      5     5       5      1     3
## 46   46     2          7         5       6      5     6       5      7     5
## 47   47     3          7         5       6      1     7       6      7     5
## 48   48     4          6         6       4      6     7       4      5     5
## 49   49     6          7         5       4      2     6       6      7     6
## 50   50     1          7         1      NA      7     7       7      7     1
## 51   51     2          2         2       6      6     5       5      7     4
## 52   52     2          4         4       4      4     6       4      2     4
## 53   53     3          6         2       2      2     4       5      7     3
## 54   54     2          4         3       5      2     5       7      2     4
## 55   55     5          4         5       3      3     4       5      2     4
## 56   56     1          3         3       3      1     7       5      7     7
## 57   57     3          6         4       4      6     6       7      7     6
## 58   58     3          7         3       1      4     6       3      7     4
## 59   59     5          4         4       4      4     4       3      5     3
## 60   60     7          5         6       3      6     6       4      1     5
## 61   61     3          5         5       4      3     5       6      7     5
## 62   62     2          7         3       2      6     7       7      7     7
## 63   63     3          1         3       6      5     5       6     NA     5
## 64   64     2          2         2       6      6     5       5      7     4
## 65   65     6          4         4       4      4     4       4     NA     4
## 66   66     2          1         2       2      2     4       5      7     2
## 67   67     3          4         6       4      6     6       7      7     6
## 68   68     7          4         6       4      5     6       4      1     5
## 69   69     5          3         6       5      7     6       2      7     6
## 70   70     3          4         3       4      2     4       5      2     4
## 71   71     6          2         6       4      6     6       4      5     5
## 72   72     5          3         4       4      5     5       3      1     4
## 73   73     6          3         5       5      3     6       3      6     4
## 74   74     6          4         5       1      5     6       6      7     3
## 75   75     4          2         4       2      5     3       5      1     5
## 76   76     5          3         4       3      4     3       6      1     5
## 77   77     5          3         4       5      2     1       4      7     4
## 78   78     5          5         5       4      5     4       6      5     4
## 79   79     6          4         5       5      5     4       6      1     5
## 80   80     7          5         4       5      3     5       6      1     5
## 81   81     5          4         4       4      4     4       3      1     3
## 82   82     7          6         6       3      2     6       1      1     2
## 83   83     5          2         5       2      3     5       2      1     4
## 84   84     7          5         4       4      3     4       4      1     5
## 85   85     6          2         6       4      5     6       2      7     6
## 86   86     6          4         5       6      6     5       5      1     6
## 87   87     6          6         6       4      6     6       3      1     4
## 88   88     6          2         6       4      6     6       4     NA     5
## 89   89     7          6         2       4      3     4       3      1     4
## 90   90     6          6         6       6      3     6       2     NA     4
## 91   91     5          4         4       3      3     5       4      1     6
## 92   92     5          4         4       5      3     4       3      1     4
## 93   93     4          5         4       4      3     3       3     NA     4
## 94   94     7          6         7       1      7     7       2      7     7
## 95   95     7          4         2       6      1     2       3      1     5
## 96   96     7          7         7       4      5     7       7      1     6
## 97   97     5          2         5       2      3     2       2      1     3
## 98   98     5          4         4       5      3     4       4      1     4
## 99   99     6          4         4       6      7     5       6      1     5
## 100 100     5          2         6       3      5     4       6      7     3
## 101 101     2          2         5       4      3     5       3      1     4
## 102 102     6          4         6       3      5     4       3      1     3
## 103 103     5          6         5       4      5     5      NA      1     2
## 104 104     5          4         4       4      4     4       4     NA     4
## 105 105     4          3         4       3      3     5       3      1     3
## 106 106     4          7         4       4      4     4       1      1     3
## 107 107     6          5         4       4      5     4       5      1     4
## 108 108     5          5         4       5      4     4       5      7     3
## 109 109     5          1         4       3      6     4       5      1     4
## 110 110     5          4         4       4      5     5       4      1     4
## 111 111     6         NA         3       4      2     6       5      1     3
## 112 112     6          5         4       4      4     3       5      1     4
## 113 113     5          3         3       4      3     4       3      1     3
## 114 114     4          1         4       3      1     2       3      1     3
## 115 115     5          3         5       6      7     5       7      1     6
## 116 116     4          4         4       4      4     4       4      1     4
## 117 117     7          5         4       4      4     4       4      3     5
## 118 118     4          4         4       3      2     2       3      1     2
## 119 119     5          3         4       4      3     3       3      1     3
## 120 120     5          3         5       4      4     3       5      1     5
## 121 121     3          3         3       4      4     5       3      5     4
## 122 122     5          5         5       5      4     5       3      5     4
## 123 123     6          7         5       5      5     5       5      5     5
## 124 124     4          3         4       3      3     3       4      1     3
## 125 125     5          4         4       6      4     5       5      1     4
## 126 126     3          4         4       4      4     4       4      1     4
## 127 127     5          4         4       1      4     4       1      1     1
##     Fruity Respondent     Flavor       Segment
## 1        4          1       Milk Seg_1_Classic
## 2        7          3       Milk Seg_1_Classic
## 3        2          4       Milk Seg_1_Classic
## 4        4          7       Milk Seg_1_Classic
## 5        5         11       Milk Seg_1_Classic
## 6        3         12       Milk Seg_1_Classic
## 7        5         16       Milk Seg_1_Classic
## 8        3         18       Milk Seg_1_Classic
## 9        3          2   Espresso  Seg_3_Coffee
## 10       4          4   Espresso  Seg_3_Coffee
## 11       5          7   Espresso  Seg_3_Coffee
## 12       5          8   Espresso  Seg_3_Coffee
## 13       1          9   Espresso  Seg_3_Coffee
## 14       2         10   Espresso  Seg_3_Coffee
## 15       4         11   Espresso  Seg_3_Coffee
## 16       4         12   Espresso  Seg_3_Coffee
## 17       5         13   Espresso  Seg_3_Coffee
## 18       4         14   Espresso  Seg_3_Coffee
## 19       1         15   Espresso  Seg_3_Coffee
## 20       3         16   Espresso  Seg_3_Coffee
## 21       3          1    Buscuit Seg_1_Classic
## 22       4          3    Buscuit Seg_1_Classic
## 23       4          4    Buscuit Seg_1_Classic
## 24       4          5    Buscuit Seg_1_Classic
## 25       1          6    Buscuit Seg_1_Classic
## 26       5          7    Buscuit Seg_1_Classic
## 27       4          8    Buscuit Seg_1_Classic
## 28       4          9    Buscuit Seg_1_Classic
## 29       4         10    Buscuit Seg_1_Classic
## 30       1         11    Buscuit Seg_1_Classic
## 31       5         12    Buscuit Seg_1_Classic
## 32       3         13    Buscuit Seg_1_Classic
## 33       2         14    Buscuit Seg_1_Classic
## 34       4         15    Buscuit Seg_1_Classic
## 35       4         16    Buscuit Seg_1_Classic
## 36       5         17    Buscuit Seg_1_Classic
## 37       3         18    Buscuit Seg_1_Classic
## 38       6          2     Orange   Seg_2_Fruit
## 39       2          8     Orange   Seg_2_Fruit
## 40       4         10     Orange   Seg_2_Fruit
## 41       5         11     Orange   Seg_2_Fruit
## 42       6         13     Orange   Seg_2_Fruit
## 43       4          1 Strawberry   Seg_2_Fruit
## 44       5          2 Strawberry   Seg_2_Fruit
## 45       6          3 Strawberry   Seg_2_Fruit
## 46       6          4 Strawberry   Seg_2_Fruit
## 47       6          5 Strawberry   Seg_2_Fruit
## 48       5          6 Strawberry   Seg_2_Fruit
## 49       5          7 Strawberry   Seg_2_Fruit
## 50       7          8 Strawberry   Seg_2_Fruit
## 51       6          9 Strawberry   Seg_2_Fruit
## 52       4         10 Strawberry   Seg_2_Fruit
## 53       6         11 Strawberry   Seg_2_Fruit
## 54       4         12 Strawberry   Seg_2_Fruit
## 55       4         13 Strawberry   Seg_2_Fruit
## 56       7         14 Strawberry   Seg_2_Fruit
## 57       7         15 Strawberry   Seg_2_Fruit
## 58       5         16 Strawberry   Seg_2_Fruit
## 59       3         17 Strawberry   Seg_2_Fruit
## 60       5         18 Strawberry   Seg_2_Fruit
## 61       5          4      Mango   Seg_2_Fruit
## 62       7          7      Mango   Seg_2_Fruit
## 63       4          8      Mango   Seg_2_Fruit
## 64       6         10      Mango   Seg_2_Fruit
## 65       4         12      Mango   Seg_2_Fruit
## 66       5         13      Mango   Seg_2_Fruit
## 67       7         14      Mango   Seg_2_Fruit
## 68       5         16      Mango   Seg_2_Fruit
## 69       3          2 Cappuccino  Seg_3_Coffee
## 70       3          6 Cappuccino  Seg_3_Coffee
## 71       5          7 Cappuccino  Seg_3_Coffee
## 72       4          8 Cappuccino  Seg_3_Coffee
## 73       4          9 Cappuccino  Seg_3_Coffee
## 74       3         12 Cappuccino  Seg_3_Coffee
## 75       4         13 Cappuccino  Seg_3_Coffee
## 76       4         14 Cappuccino  Seg_3_Coffee
## 77       1         15 Cappuccino  Seg_3_Coffee
## 78       3         16 Cappuccino  Seg_3_Coffee
## 79       6         17 Cappuccino  Seg_3_Coffee
## 80       3         18 Cappuccino  Seg_3_Coffee
## 81       2          1     Mousse Seg_1_Classic
## 82       3          2     Mousse Seg_1_Classic
## 83       5          3     Mousse Seg_1_Classic
## 84       4          4     Mousse Seg_1_Classic
## 85       3          6     Mousse Seg_1_Classic
## 86       3          8     Mousse Seg_1_Classic
## 87       2         10     Mousse Seg_1_Classic
## 88       5         11     Mousse Seg_1_Classic
## 89       4         12     Mousse Seg_1_Classic
## 90       4         13     Mousse Seg_1_Classic
## 91       5         14     Mousse Seg_1_Classic
## 92       3         15     Mousse Seg_1_Classic
## 93       3         16     Mousse Seg_1_Classic
## 94       7         17     Mousse Seg_1_Classic
## 95       2          1    Caramel Seg_1_Classic
## 96       6          2    Caramel Seg_1_Classic
## 97       4          3    Caramel Seg_1_Classic
## 98       3          4    Caramel Seg_1_Classic
## 99       6          5    Caramel Seg_1_Classic
## 100      3          6    Caramel Seg_1_Classic
## 101      5          8    Caramel Seg_1_Classic
## 102      7          9    Caramel Seg_1_Classic
## 103      4         11    Caramel Seg_1_Classic
## 104      4         13    Caramel Seg_1_Classic
## 105      3         17    Caramel Seg_1_Classic
## 106      3         18    Caramel Seg_1_Classic
## 107      4          4     Nougat Seg_1_Classic
## 108      3          5     Nougat Seg_1_Classic
## 109      4          7     Nougat Seg_1_Classic
## 110      4          9     Nougat Seg_1_Classic
## 111      4         12     Nougat Seg_1_Classic
## 112      1         13     Nougat Seg_1_Classic
## 113      4         14     Nougat Seg_1_Classic
## 114      3         15     Nougat Seg_1_Classic
## 115      6         16     Nougat Seg_1_Classic
## 116      4         17     Nougat Seg_1_Classic
## 117      5         18     Nougat Seg_1_Classic
## 118      2          1        Nut Seg_1_Classic
## 119      3          2        Nut Seg_1_Classic
## 120      4          3        Nut Seg_1_Classic
## 121      3          4        Nut Seg_1_Classic
## 122      4          6        Nut Seg_1_Classic
## 123      5          8        Nut Seg_1_Classic
## 124      4          9        Nut Seg_1_Classic
## 125      4         13        Nut Seg_1_Classic
## 126      4         17        Nut Seg_1_Classic
## 127      4         18        Nut Seg_1_Classic

(-) 5.4.3.1 Blockwise Logistic Regression

# Determine reference
datlogreg_127cases$Segment <- relevel(datlogreg_127cases$Segment , ref = "Seg_1_Classic")

# Model
multinom_test <- multinom(Segment ~ Price + 
                                  Refreshing + 
                                  Delicious + 
                                  Healthy + 
                                  Bitter + 
                                  Light + 
                                  Crunchy + 
                                  Exotic + 
                                  Sweet +
                                  Fruity, 
                                  data = datlogreg_127cases,
                                  model = TRUE,
                                  na.action = na.omit)
## # weights:  36 (22 variable)
## initial  value 127.439025 
## iter  10 value 80.359932
## iter  20 value 71.266966
## iter  30 value 71.008194
## final  value 71.008110 
## converged

(-) Figure 5.32 - Estimated parameters of the regression functions for segments 2 and 3

# Figure 5.32 - Estimated parameters of the regression functions for segments 2 and 3
summary(multinom_test);
## Call:
## multinom(formula = Segment ~ Price + Refreshing + Delicious + 
##     Healthy + Bitter + Light + Crunchy + Exotic + Sweet + Fruity, 
##     data = datlogreg_127cases, na.action = na.omit, model = TRUE)
## 
## Coefficients:
##              (Intercept)      Price Refreshing  Delicious      Healthy
## Seg_2_Fruit    -4.646136 -0.4187194  0.3266390 -1.2517849 -0.656861553
## Seg_3_Coffee   -1.589777  0.2652758 -0.2400111 -0.3588016  0.001248646
##                  Bitter     Light   Crunchy    Exotic      Sweet     Fruity
## Seg_2_Fruit  -0.1878724 1.0141355 0.9009985 0.2262160 -0.1992250  0.9646140
## Seg_3_Coffee -0.6407686 0.3028585 0.3523278 0.2880976  0.2462088 -0.0999244
## 
## Std. Errors:
##              (Intercept)     Price Refreshing Delicious   Healthy    Bitter
## Seg_2_Fruit     2.231297 0.3086019  0.3175597 0.4953603 0.3347354 0.3155805
## Seg_3_Coffee    1.771040 0.2236863  0.2035352 0.3361439 0.2276683 0.2494309
##                  Light   Crunchy    Exotic     Sweet    Fruity
## Seg_2_Fruit  0.4708186 0.2904776 0.1676785 0.4264263 0.4284701
## Seg_3_Coffee 0.2972507 0.2158908 0.1313590 0.2811230 0.2706426
## 
## Residual Deviance: 142.0162 
## AIC: 186.0162
multinom_test$AIC;
## [1] 186.0162
multinom_test$deviance
## [1] 142.0162

(-) Figure 5.31 - Overall Model Statistics

# Pseudo-R²: McFadden, CoxSnell, Nagelkerke
DescTools::PseudoR2(multinom_test, which = "McFadden");
##  McFadden 
## 0.3807245
DescTools::PseudoR2(multinom_test, which = "CoxSnell");
##  CoxSnell 
## 0.5288948
DescTools::PseudoR2(multinom_test, which = "Nagelkerke");
## Nagelkerke 
##  0.6139166
# Gültige komplette Fälle
sum(complete.cases(datlogreg_127cases)) # 116
## [1] 116

(-) Figure 5.32 - Estimated parameters of the regression functions for segments 2 and 3: Significances and coefficients

# Calculation of significances
z <- summary(multinom_test)$coefficients/summary(multinom_test)$standard.errors

# 2-tailed z test zu get p-Values (significances)
p <- (1 - pnorm(abs(z), 0, 1)) * 2

# Coefficients; p-values; exp(B)
coef(multinom_test);print(p);exp(coef(multinom_test))
##              (Intercept)      Price Refreshing  Delicious      Healthy
## Seg_2_Fruit    -4.646136 -0.4187194  0.3266390 -1.2517849 -0.656861553
## Seg_3_Coffee   -1.589777  0.2652758 -0.2400111 -0.3588016  0.001248646
##                  Bitter     Light   Crunchy    Exotic      Sweet     Fruity
## Seg_2_Fruit  -0.1878724 1.0141355 0.9009985 0.2262160 -0.1992250  0.9646140
## Seg_3_Coffee -0.6407686 0.3028585 0.3523278 0.2880976  0.2462088 -0.0999244
##              (Intercept)     Price Refreshing  Delicious    Healthy     Bitter
## Seg_2_Fruit    0.0373189 0.1748362  0.3036720 0.01150353 0.04972399 0.55162754
## Seg_3_Coffee   0.3693712 0.2356508  0.2383138 0.28578919 0.99562403 0.01020152
##                   Light     Crunchy     Exotic     Sweet     Fruity
## Seg_2_Fruit  0.03124146 0.001923592 0.17730284 0.6403590 0.02436665
## Seg_3_Coffee 0.30826675 0.102685236 0.02829243 0.3811363 0.71196999
##              (Intercept)     Price Refreshing Delicious  Healthy    Bitter
## Seg_2_Fruit  0.009598615 0.6578887  1.3863009 0.2859939 0.518476 0.8287205
## Seg_3_Coffee 0.203971057 1.3037904  0.7866191 0.6985129 1.001249 0.5268873
##                 Light  Crunchy   Exotic     Sweet    Fruity
## Seg_2_Fruit  2.756979 2.462060 1.253847 0.8193655 2.6237747
## Seg_3_Coffee 1.353723 1.422375 1.333887 1.2791666 0.9049058

(-) Figure 5.33 and Figure 5.34 - Estimated coefficients for the segments ‘Fruit’ versus ‘Classic’ & Estimated coefficients for the segments ‘Coffee’ versus ‘Classic’

str(coef(multinom_test))
##  num [1:2, 1:11] -4.646 -1.59 -0.419 0.265 0.327 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : chr [1:2] "Seg_2_Fruit" "Seg_3_Coffee"
##   ..$ : chr [1:11] "(Intercept)" "Price" "Refreshing" "Delicious" ...
df_multinom_test <- as.data.frame(unlist(coef(multinom_test))) %>% 
  rownames_to_column(., var = "Segment")

df_multinom_test.2 <- df_multinom_test %>% 
  gather(., c(2:12), key = "Perceived_attributes", value = "Coefficient")

print(df_multinom_test); print(df_multinom_test.2)
##        Segment (Intercept)      Price Refreshing  Delicious      Healthy
## 1  Seg_2_Fruit   -4.646136 -0.4187194  0.3266390 -1.2517849 -0.656861553
## 2 Seg_3_Coffee   -1.589777  0.2652758 -0.2400111 -0.3588016  0.001248646
##       Bitter     Light   Crunchy    Exotic      Sweet     Fruity
## 1 -0.1878724 1.0141355 0.9009985 0.2262160 -0.1992250  0.9646140
## 2 -0.6407686 0.3028585 0.3523278 0.2880976  0.2462088 -0.0999244
##         Segment Perceived_attributes  Coefficient
## 1   Seg_2_Fruit          (Intercept) -4.646136456
## 2  Seg_3_Coffee          (Intercept) -1.589777175
## 3   Seg_2_Fruit                Price -0.418719442
## 4  Seg_3_Coffee                Price  0.265275751
## 5   Seg_2_Fruit           Refreshing  0.326639006
## 6  Seg_3_Coffee           Refreshing -0.240011098
## 7   Seg_2_Fruit            Delicious -1.251784913
## 8  Seg_3_Coffee            Delicious -0.358801566
## 9   Seg_2_Fruit              Healthy -0.656861553
## 10 Seg_3_Coffee              Healthy  0.001248646
## 11  Seg_2_Fruit               Bitter -0.187872362
## 12 Seg_3_Coffee               Bitter -0.640768598
## 13  Seg_2_Fruit                Light  1.014135534
## 14 Seg_3_Coffee                Light  0.302858502
## 15  Seg_2_Fruit              Crunchy  0.900998463
## 16 Seg_3_Coffee              Crunchy  0.352327844
## 17  Seg_2_Fruit               Exotic  0.226216049
## 18 Seg_3_Coffee               Exotic  0.288097553
## 19  Seg_2_Fruit                Sweet -0.199225017
## 20 Seg_3_Coffee                Sweet  0.246208786
## 21  Seg_2_Fruit               Fruity  0.964614001
## 22 Seg_3_Coffee               Fruity -0.099924401
df_multinom_test.2 %>% 
  filter(Perceived_attributes != "(Intercept)") %>% 
  ggplot(., aes(x = Perceived_attributes, y = Coefficient, group = Segment)) +
  geom_col() + 
  facet_grid(~Segment) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Segments 2 and 3 compared to Segment 1") +
  theme(plot.title = element_text(hjust = 0.5))

(-) Figure 5.35 - Estimated coefficients for the segments ‘Fruit’ versus ‘Coffee’

df_multinom_test.3 <- as.data.frame(
  cbind("Perceived_attributes" = unique(df_multinom_test.2$Perceived_attributes),
  Coefficient = as.numeric(0))) %>% 
  slice(-1)

df_multinom_test.3$Coefficient <- as.numeric(df_multinom_test.3$Coefficient)
df_multinom_test.3$Perceived_attributes <- forcats::fct_relevel(df_multinom_test.3$Perceived_attributes, 
levels = c("Price", "Refreshing","Delicious","Healthy", "Bitter", "Light", "Crunchy","Exotic","Sweet","Fruity"))
## Warning: Outer names are only allowed for unnamed scalar atomic inputs
for (i in 1:10) {
  df_multinom_test.3[i,2] = exp(df_multinom_test[1,2+i]) - exp(df_multinom_test[2,2+i])
}

print(df_multinom_test.3)
##    Perceived_attributes Coefficient
## 1                 Price -0.64590170
## 2            Refreshing  0.59968181
## 3             Delicious -0.41251908
## 4               Healthy -0.48277343
## 5                Bitter  0.30183317
## 6                 Light  1.40325615
## 7               Crunchy  1.03968539
## 8                Exotic -0.08004089
## 9                 Sweet -0.45980112
## 10               Fruity  1.71886886
df_multinom_test.3 %>% 
  # filter(Perceived_attributes != "(Intercept)") %>% 
  ggplot(., aes(x = Perceived_attributes, y = Coefficient)) +
  geom_col() + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Segment Fruit vs. Coffee") +
  theme(plot.title = element_text(hjust = 0.5))

(-) Figure 5.36 - Testing the covariates with the likelihood ratio test

Anova(multinom_test)
## Analysis of Deviance Table (Type II tests)
## 
## Response: Segment
##            LR Chisq Df Pr(>Chisq)   
## Price        4.5152  2   0.104599   
## Refreshing   3.0788  2   0.214512   
## Delicious    8.0632  2   0.017746 * 
## Healthy      4.5292  2   0.103872   
## Bitter       7.2576  2   0.026548 * 
## Light        5.5515  2   0.062304 . 
## Crunchy     12.9140  2   0.001569 **
## Exotic       5.5976  2   0.060883 . 
## Sweet        1.1973  2   0.549549   
## Fruity       7.2082  2   0.027213 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(-) Figure 5.37 - Estimated probabilities (part of the working file)

# Save calculated predictions
predictions_multinom <- as.data.frame(multinom_test$fitted.values) %>% 
  rownames_to_column(., var = "ID")

predictions_multinom$ID <- as.numeric(predictions_multinom$ID)

datlogreg_127cases
##      ID Price Refreshing Delicious Healthy Bitter Light Crunchy Exotic Sweet
## 1     1     3          3         5       4      1     2       3      1     3
## 2     2     6          6         5       2      2     5       2      1     6
## 3     3     2          3         3       3      2     3       5      1     3
## 4     4     4          3         3       4      4     3       5      2     4
## 5     5     7          5         5       7      3     6       5      1     5
## 6     6     5          4         5       2      5     4       3      7     7
## 7     7     6          5         6       5      6     5       6      5     6
## 8     8     3          3         3       4      3     2       3      1     3
## 9     9     7          6         6       2      3     7       5      1     6
## 10   10     3          4         4       4      2     5       5      1     4
## 11   11     7          1         4       5      1     4       1      1     3
## 12   12     7          7         3       7      1     3       1      1     4
## 13   13     6          5         4       3      1     2      NA      1     3
## 14   14     3          3         4       3      1     4       2      3     4
## 15   15     4          6         2       4      1     3       1      2     4
## 16   16     4          3         4       4      4     4       4      4     4
## 17   17     3          4         4       4      3     3       3      7     5
## 18   18     6          3         5       4      4     4       4      3     4
## 19   19     7          7         3       2      1     2       5      1     1
## 20   20     5          2         3       4      4     4       5      3     3
## 21   21     3          4         4       4      3     4       3      1     1
## 22   22     6          2         5       2      3     4       2      1     3
## 23   23     4          3         4       3      4     5       4      7     4
## 24   24     6          2         4       5      6     6       3      1     5
## 25   25     6          5         7       3      3     2       3      1     3
## 26   26     6          2         6       4      6     6       4      6     5
## 27   27     5          2         4       4      6     5       4      6     5
## 28   28     6          5         6       4      6     6       4      5     4
## 29   29     3          4         6       2      6     4       6      7     2
## 30   30     7          7         4      NA      4     6       7      1     5
## 31   31     2          2         5       4      3     5       3      1     4
## 32   32     6          5         4       1      1     3       4      1     3
## 33   33     5          3         4       4      4     3       4      1     2
## 34   34     5          4         4       4      4     5       4      4     4
## 35   35     4          6         4       4      4     4       3      1     4
## 36   36     7          4         6       4      5     5       5      1     3
## 37   37     5          5         4       3      4     3       1      1     3
## 38   38     4          5         4       3      4     5       5      1     3
## 39   39     2          2         2       2      3     2       6      6     3
## 40   40     3          6         3       3      7     5       4      7     4
## 41   41     3          7         3       1      4     6       3      7     4
## 42   42     7          7         7       3      7     7       7      1     6
## 43   43     3          5         3       2      3     3       5      7     2
## 44   44     6          2         3       2      4     3       5      1     5
## 45   45     4          5         4       5      5     5       5      1     3
## 46   46     2          7         5       6      5     6       5      7     5
## 47   47     3          7         5       6      1     7       6      7     5
## 48   48     4          6         6       4      6     7       4      5     5
## 49   49     6          7         5       4      2     6       6      7     6
## 50   50     1          7         1      NA      7     7       7      7     1
## 51   51     2          2         2       6      6     5       5      7     4
## 52   52     2          4         4       4      4     6       4      2     4
## 53   53     3          6         2       2      2     4       5      7     3
## 54   54     2          4         3       5      2     5       7      2     4
## 55   55     5          4         5       3      3     4       5      2     4
## 56   56     1          3         3       3      1     7       5      7     7
## 57   57     3          6         4       4      6     6       7      7     6
## 58   58     3          7         3       1      4     6       3      7     4
## 59   59     5          4         4       4      4     4       3      5     3
## 60   60     7          5         6       3      6     6       4      1     5
## 61   61     3          5         5       4      3     5       6      7     5
## 62   62     2          7         3       2      6     7       7      7     7
## 63   63     3          1         3       6      5     5       6     NA     5
## 64   64     2          2         2       6      6     5       5      7     4
## 65   65     6          4         4       4      4     4       4     NA     4
## 66   66     2          1         2       2      2     4       5      7     2
## 67   67     3          4         6       4      6     6       7      7     6
## 68   68     7          4         6       4      5     6       4      1     5
## 69   69     5          3         6       5      7     6       2      7     6
## 70   70     3          4         3       4      2     4       5      2     4
## 71   71     6          2         6       4      6     6       4      5     5
## 72   72     5          3         4       4      5     5       3      1     4
## 73   73     6          3         5       5      3     6       3      6     4
## 74   74     6          4         5       1      5     6       6      7     3
## 75   75     4          2         4       2      5     3       5      1     5
## 76   76     5          3         4       3      4     3       6      1     5
## 77   77     5          3         4       5      2     1       4      7     4
## 78   78     5          5         5       4      5     4       6      5     4
## 79   79     6          4         5       5      5     4       6      1     5
## 80   80     7          5         4       5      3     5       6      1     5
## 81   81     5          4         4       4      4     4       3      1     3
## 82   82     7          6         6       3      2     6       1      1     2
## 83   83     5          2         5       2      3     5       2      1     4
## 84   84     7          5         4       4      3     4       4      1     5
## 85   85     6          2         6       4      5     6       2      7     6
## 86   86     6          4         5       6      6     5       5      1     6
## 87   87     6          6         6       4      6     6       3      1     4
## 88   88     6          2         6       4      6     6       4     NA     5
## 89   89     7          6         2       4      3     4       3      1     4
## 90   90     6          6         6       6      3     6       2     NA     4
## 91   91     5          4         4       3      3     5       4      1     6
## 92   92     5          4         4       5      3     4       3      1     4
## 93   93     4          5         4       4      3     3       3     NA     4
## 94   94     7          6         7       1      7     7       2      7     7
## 95   95     7          4         2       6      1     2       3      1     5
## 96   96     7          7         7       4      5     7       7      1     6
## 97   97     5          2         5       2      3     2       2      1     3
## 98   98     5          4         4       5      3     4       4      1     4
## 99   99     6          4         4       6      7     5       6      1     5
## 100 100     5          2         6       3      5     4       6      7     3
## 101 101     2          2         5       4      3     5       3      1     4
## 102 102     6          4         6       3      5     4       3      1     3
## 103 103     5          6         5       4      5     5      NA      1     2
## 104 104     5          4         4       4      4     4       4     NA     4
## 105 105     4          3         4       3      3     5       3      1     3
## 106 106     4          7         4       4      4     4       1      1     3
## 107 107     6          5         4       4      5     4       5      1     4
## 108 108     5          5         4       5      4     4       5      7     3
## 109 109     5          1         4       3      6     4       5      1     4
## 110 110     5          4         4       4      5     5       4      1     4
## 111 111     6         NA         3       4      2     6       5      1     3
## 112 112     6          5         4       4      4     3       5      1     4
## 113 113     5          3         3       4      3     4       3      1     3
## 114 114     4          1         4       3      1     2       3      1     3
## 115 115     5          3         5       6      7     5       7      1     6
## 116 116     4          4         4       4      4     4       4      1     4
## 117 117     7          5         4       4      4     4       4      3     5
## 118 118     4          4         4       3      2     2       3      1     2
## 119 119     5          3         4       4      3     3       3      1     3
## 120 120     5          3         5       4      4     3       5      1     5
## 121 121     3          3         3       4      4     5       3      5     4
## 122 122     5          5         5       5      4     5       3      5     4
## 123 123     6          7         5       5      5     5       5      5     5
## 124 124     4          3         4       3      3     3       4      1     3
## 125 125     5          4         4       6      4     5       5      1     4
## 126 126     3          4         4       4      4     4       4      1     4
## 127 127     5          4         4       1      4     4       1      1     1
##     Fruity Respondent     Flavor       Segment
## 1        4          1       Milk Seg_1_Classic
## 2        7          3       Milk Seg_1_Classic
## 3        2          4       Milk Seg_1_Classic
## 4        4          7       Milk Seg_1_Classic
## 5        5         11       Milk Seg_1_Classic
## 6        3         12       Milk Seg_1_Classic
## 7        5         16       Milk Seg_1_Classic
## 8        3         18       Milk Seg_1_Classic
## 9        3          2   Espresso  Seg_3_Coffee
## 10       4          4   Espresso  Seg_3_Coffee
## 11       5          7   Espresso  Seg_3_Coffee
## 12       5          8   Espresso  Seg_3_Coffee
## 13       1          9   Espresso  Seg_3_Coffee
## 14       2         10   Espresso  Seg_3_Coffee
## 15       4         11   Espresso  Seg_3_Coffee
## 16       4         12   Espresso  Seg_3_Coffee
## 17       5         13   Espresso  Seg_3_Coffee
## 18       4         14   Espresso  Seg_3_Coffee
## 19       1         15   Espresso  Seg_3_Coffee
## 20       3         16   Espresso  Seg_3_Coffee
## 21       3          1    Buscuit Seg_1_Classic
## 22       4          3    Buscuit Seg_1_Classic
## 23       4          4    Buscuit Seg_1_Classic
## 24       4          5    Buscuit Seg_1_Classic
## 25       1          6    Buscuit Seg_1_Classic
## 26       5          7    Buscuit Seg_1_Classic
## 27       4          8    Buscuit Seg_1_Classic
## 28       4          9    Buscuit Seg_1_Classic
## 29       4         10    Buscuit Seg_1_Classic
## 30       1         11    Buscuit Seg_1_Classic
## 31       5         12    Buscuit Seg_1_Classic
## 32       3         13    Buscuit Seg_1_Classic
## 33       2         14    Buscuit Seg_1_Classic
## 34       4         15    Buscuit Seg_1_Classic
## 35       4         16    Buscuit Seg_1_Classic
## 36       5         17    Buscuit Seg_1_Classic
## 37       3         18    Buscuit Seg_1_Classic
## 38       6          2     Orange   Seg_2_Fruit
## 39       2          8     Orange   Seg_2_Fruit
## 40       4         10     Orange   Seg_2_Fruit
## 41       5         11     Orange   Seg_2_Fruit
## 42       6         13     Orange   Seg_2_Fruit
## 43       4          1 Strawberry   Seg_2_Fruit
## 44       5          2 Strawberry   Seg_2_Fruit
## 45       6          3 Strawberry   Seg_2_Fruit
## 46       6          4 Strawberry   Seg_2_Fruit
## 47       6          5 Strawberry   Seg_2_Fruit
## 48       5          6 Strawberry   Seg_2_Fruit
## 49       5          7 Strawberry   Seg_2_Fruit
## 50       7          8 Strawberry   Seg_2_Fruit
## 51       6          9 Strawberry   Seg_2_Fruit
## 52       4         10 Strawberry   Seg_2_Fruit
## 53       6         11 Strawberry   Seg_2_Fruit
## 54       4         12 Strawberry   Seg_2_Fruit
## 55       4         13 Strawberry   Seg_2_Fruit
## 56       7         14 Strawberry   Seg_2_Fruit
## 57       7         15 Strawberry   Seg_2_Fruit
## 58       5         16 Strawberry   Seg_2_Fruit
## 59       3         17 Strawberry   Seg_2_Fruit
## 60       5         18 Strawberry   Seg_2_Fruit
## 61       5          4      Mango   Seg_2_Fruit
## 62       7          7      Mango   Seg_2_Fruit
## 63       4          8      Mango   Seg_2_Fruit
## 64       6         10      Mango   Seg_2_Fruit
## 65       4         12      Mango   Seg_2_Fruit
## 66       5         13      Mango   Seg_2_Fruit
## 67       7         14      Mango   Seg_2_Fruit
## 68       5         16      Mango   Seg_2_Fruit
## 69       3          2 Cappuccino  Seg_3_Coffee
## 70       3          6 Cappuccino  Seg_3_Coffee
## 71       5          7 Cappuccino  Seg_3_Coffee
## 72       4          8 Cappuccino  Seg_3_Coffee
## 73       4          9 Cappuccino  Seg_3_Coffee
## 74       3         12 Cappuccino  Seg_3_Coffee
## 75       4         13 Cappuccino  Seg_3_Coffee
## 76       4         14 Cappuccino  Seg_3_Coffee
## 77       1         15 Cappuccino  Seg_3_Coffee
## 78       3         16 Cappuccino  Seg_3_Coffee
## 79       6         17 Cappuccino  Seg_3_Coffee
## 80       3         18 Cappuccino  Seg_3_Coffee
## 81       2          1     Mousse Seg_1_Classic
## 82       3          2     Mousse Seg_1_Classic
## 83       5          3     Mousse Seg_1_Classic
## 84       4          4     Mousse Seg_1_Classic
## 85       3          6     Mousse Seg_1_Classic
## 86       3          8     Mousse Seg_1_Classic
## 87       2         10     Mousse Seg_1_Classic
## 88       5         11     Mousse Seg_1_Classic
## 89       4         12     Mousse Seg_1_Classic
## 90       4         13     Mousse Seg_1_Classic
## 91       5         14     Mousse Seg_1_Classic
## 92       3         15     Mousse Seg_1_Classic
## 93       3         16     Mousse Seg_1_Classic
## 94       7         17     Mousse Seg_1_Classic
## 95       2          1    Caramel Seg_1_Classic
## 96       6          2    Caramel Seg_1_Classic
## 97       4          3    Caramel Seg_1_Classic
## 98       3          4    Caramel Seg_1_Classic
## 99       6          5    Caramel Seg_1_Classic
## 100      3          6    Caramel Seg_1_Classic
## 101      5          8    Caramel Seg_1_Classic
## 102      7          9    Caramel Seg_1_Classic
## 103      4         11    Caramel Seg_1_Classic
## 104      4         13    Caramel Seg_1_Classic
## 105      3         17    Caramel Seg_1_Classic
## 106      3         18    Caramel Seg_1_Classic
## 107      4          4     Nougat Seg_1_Classic
## 108      3          5     Nougat Seg_1_Classic
## 109      4          7     Nougat Seg_1_Classic
## 110      4          9     Nougat Seg_1_Classic
## 111      4         12     Nougat Seg_1_Classic
## 112      1         13     Nougat Seg_1_Classic
## 113      4         14     Nougat Seg_1_Classic
## 114      3         15     Nougat Seg_1_Classic
## 115      6         16     Nougat Seg_1_Classic
## 116      4         17     Nougat Seg_1_Classic
## 117      5         18     Nougat Seg_1_Classic
## 118      2          1        Nut Seg_1_Classic
## 119      3          2        Nut Seg_1_Classic
## 120      4          3        Nut Seg_1_Classic
## 121      3          4        Nut Seg_1_Classic
## 122      4          6        Nut Seg_1_Classic
## 123      5          8        Nut Seg_1_Classic
## 124      4          9        Nut Seg_1_Classic
## 125      4         13        Nut Seg_1_Classic
## 126      4         17        Nut Seg_1_Classic
## 127      4         18        Nut Seg_1_Classic
# Data combined with predictions for all 3 segments
datlogreg_127cases.2 <- full_join(datlogreg_127cases, 
                                  predictions_multinom, 
                                  by = "ID")

print(datlogreg_127cases.2)
##      ID Price Refreshing Delicious Healthy Bitter Light Crunchy Exotic Sweet
## 1     1     3          3         5       4      1     2       3      1     3
## 2     2     6          6         5       2      2     5       2      1     6
## 3     3     2          3         3       3      2     3       5      1     3
## 4     4     4          3         3       4      4     3       5      2     4
## 5     5     7          5         5       7      3     6       5      1     5
## 6     6     5          4         5       2      5     4       3      7     7
## 7     7     6          5         6       5      6     5       6      5     6
## 8     8     3          3         3       4      3     2       3      1     3
## 9     9     7          6         6       2      3     7       5      1     6
## 10   10     3          4         4       4      2     5       5      1     4
## 11   11     7          1         4       5      1     4       1      1     3
## 12   12     7          7         3       7      1     3       1      1     4
## 13   13     6          5         4       3      1     2      NA      1     3
## 14   14     3          3         4       3      1     4       2      3     4
## 15   15     4          6         2       4      1     3       1      2     4
## 16   16     4          3         4       4      4     4       4      4     4
## 17   17     3          4         4       4      3     3       3      7     5
## 18   18     6          3         5       4      4     4       4      3     4
## 19   19     7          7         3       2      1     2       5      1     1
## 20   20     5          2         3       4      4     4       5      3     3
## 21   21     3          4         4       4      3     4       3      1     1
## 22   22     6          2         5       2      3     4       2      1     3
## 23   23     4          3         4       3      4     5       4      7     4
## 24   24     6          2         4       5      6     6       3      1     5
## 25   25     6          5         7       3      3     2       3      1     3
## 26   26     6          2         6       4      6     6       4      6     5
## 27   27     5          2         4       4      6     5       4      6     5
## 28   28     6          5         6       4      6     6       4      5     4
## 29   29     3          4         6       2      6     4       6      7     2
## 30   30     7          7         4      NA      4     6       7      1     5
## 31   31     2          2         5       4      3     5       3      1     4
## 32   32     6          5         4       1      1     3       4      1     3
## 33   33     5          3         4       4      4     3       4      1     2
## 34   34     5          4         4       4      4     5       4      4     4
## 35   35     4          6         4       4      4     4       3      1     4
## 36   36     7          4         6       4      5     5       5      1     3
## 37   37     5          5         4       3      4     3       1      1     3
## 38   38     4          5         4       3      4     5       5      1     3
## 39   39     2          2         2       2      3     2       6      6     3
## 40   40     3          6         3       3      7     5       4      7     4
## 41   41     3          7         3       1      4     6       3      7     4
## 42   42     7          7         7       3      7     7       7      1     6
## 43   43     3          5         3       2      3     3       5      7     2
## 44   44     6          2         3       2      4     3       5      1     5
## 45   45     4          5         4       5      5     5       5      1     3
## 46   46     2          7         5       6      5     6       5      7     5
## 47   47     3          7         5       6      1     7       6      7     5
## 48   48     4          6         6       4      6     7       4      5     5
## 49   49     6          7         5       4      2     6       6      7     6
## 50   50     1          7         1      NA      7     7       7      7     1
## 51   51     2          2         2       6      6     5       5      7     4
## 52   52     2          4         4       4      4     6       4      2     4
## 53   53     3          6         2       2      2     4       5      7     3
## 54   54     2          4         3       5      2     5       7      2     4
## 55   55     5          4         5       3      3     4       5      2     4
## 56   56     1          3         3       3      1     7       5      7     7
## 57   57     3          6         4       4      6     6       7      7     6
## 58   58     3          7         3       1      4     6       3      7     4
## 59   59     5          4         4       4      4     4       3      5     3
## 60   60     7          5         6       3      6     6       4      1     5
## 61   61     3          5         5       4      3     5       6      7     5
## 62   62     2          7         3       2      6     7       7      7     7
## 63   63     3          1         3       6      5     5       6     NA     5
## 64   64     2          2         2       6      6     5       5      7     4
## 65   65     6          4         4       4      4     4       4     NA     4
## 66   66     2          1         2       2      2     4       5      7     2
## 67   67     3          4         6       4      6     6       7      7     6
## 68   68     7          4         6       4      5     6       4      1     5
## 69   69     5          3         6       5      7     6       2      7     6
## 70   70     3          4         3       4      2     4       5      2     4
## 71   71     6          2         6       4      6     6       4      5     5
## 72   72     5          3         4       4      5     5       3      1     4
## 73   73     6          3         5       5      3     6       3      6     4
## 74   74     6          4         5       1      5     6       6      7     3
## 75   75     4          2         4       2      5     3       5      1     5
## 76   76     5          3         4       3      4     3       6      1     5
## 77   77     5          3         4       5      2     1       4      7     4
## 78   78     5          5         5       4      5     4       6      5     4
## 79   79     6          4         5       5      5     4       6      1     5
## 80   80     7          5         4       5      3     5       6      1     5
## 81   81     5          4         4       4      4     4       3      1     3
## 82   82     7          6         6       3      2     6       1      1     2
## 83   83     5          2         5       2      3     5       2      1     4
## 84   84     7          5         4       4      3     4       4      1     5
## 85   85     6          2         6       4      5     6       2      7     6
## 86   86     6          4         5       6      6     5       5      1     6
## 87   87     6          6         6       4      6     6       3      1     4
## 88   88     6          2         6       4      6     6       4     NA     5
## 89   89     7          6         2       4      3     4       3      1     4
## 90   90     6          6         6       6      3     6       2     NA     4
## 91   91     5          4         4       3      3     5       4      1     6
## 92   92     5          4         4       5      3     4       3      1     4
## 93   93     4          5         4       4      3     3       3     NA     4
## 94   94     7          6         7       1      7     7       2      7     7
## 95   95     7          4         2       6      1     2       3      1     5
## 96   96     7          7         7       4      5     7       7      1     6
## 97   97     5          2         5       2      3     2       2      1     3
## 98   98     5          4         4       5      3     4       4      1     4
## 99   99     6          4         4       6      7     5       6      1     5
## 100 100     5          2         6       3      5     4       6      7     3
## 101 101     2          2         5       4      3     5       3      1     4
## 102 102     6          4         6       3      5     4       3      1     3
## 103 103     5          6         5       4      5     5      NA      1     2
## 104 104     5          4         4       4      4     4       4     NA     4
## 105 105     4          3         4       3      3     5       3      1     3
## 106 106     4          7         4       4      4     4       1      1     3
## 107 107     6          5         4       4      5     4       5      1     4
## 108 108     5          5         4       5      4     4       5      7     3
## 109 109     5          1         4       3      6     4       5      1     4
## 110 110     5          4         4       4      5     5       4      1     4
## 111 111     6         NA         3       4      2     6       5      1     3
## 112 112     6          5         4       4      4     3       5      1     4
## 113 113     5          3         3       4      3     4       3      1     3
## 114 114     4          1         4       3      1     2       3      1     3
## 115 115     5          3         5       6      7     5       7      1     6
## 116 116     4          4         4       4      4     4       4      1     4
## 117 117     7          5         4       4      4     4       4      3     5
## 118 118     4          4         4       3      2     2       3      1     2
## 119 119     5          3         4       4      3     3       3      1     3
## 120 120     5          3         5       4      4     3       5      1     5
## 121 121     3          3         3       4      4     5       3      5     4
## 122 122     5          5         5       5      4     5       3      5     4
## 123 123     6          7         5       5      5     5       5      5     5
## 124 124     4          3         4       3      3     3       4      1     3
## 125 125     5          4         4       6      4     5       5      1     4
## 126 126     3          4         4       4      4     4       4      1     4
## 127 127     5          4         4       1      4     4       1      1     1
##     Fruity Respondent     Flavor       Segment Seg_1_Classic  Seg_2_Fruit
## 1        4          1       Milk Seg_1_Classic  8.372617e-01 2.590314e-03
## 2        7          3       Milk Seg_1_Classic  5.248649e-01 3.211692e-01
## 3        2          4       Milk Seg_1_Classic  5.706773e-01 1.273131e-01
## 4        4          7       Milk Seg_1_Classic  6.279312e-01 1.526931e-01
## 5        5         11       Milk Seg_1_Classic  4.939537e-01 3.248759e-02
## 6        3         12       Milk Seg_1_Classic  6.184230e-01 1.021955e-02
## 7        5         16       Milk Seg_1_Classic  7.001109e-01 7.664604e-02
## 8        3         18       Milk Seg_1_Classic  8.848251e-01 8.760418e-03
## 9        3          2   Espresso  Seg_3_Coffee  4.281874e-01 9.778993e-02
## 10       4          4   Espresso  Seg_3_Coffee  3.308885e-01 4.280132e-01
## 11       5          7   Espresso  Seg_3_Coffee  4.875060e-01 8.768677e-04
## 12       5          8   Espresso  Seg_3_Coffee  7.458541e-01 2.660100e-03
## 13       1          9   Espresso  Seg_3_Coffee            NA           NA
## 14       2         10   Espresso  Seg_3_Coffee  5.021530e-01 6.052343e-03
## 15       4         11   Espresso  Seg_3_Coffee  6.600936e-01 7.150063e-02
## 16       4         12   Espresso  Seg_3_Coffee  6.511805e-01 7.972398e-02
## 17       5         13   Espresso  Seg_3_Coffee  5.349070e-01 1.039604e-01
## 18       4         14   Espresso  Seg_3_Coffee  7.246686e-01 8.758794e-03
## 19       1         15   Espresso  Seg_3_Coffee  5.647898e-01 2.748588e-02
## 20       3         16   Espresso  Seg_3_Coffee  4.787279e-01 8.883101e-02
## 21       3          1    Buscuit Seg_1_Classic  8.940933e-01 3.973526e-02
## 22       4          3    Buscuit Seg_1_Classic  8.352238e-01 4.186211e-03
## 23       4          4    Buscuit Seg_1_Classic  2.770611e-01 3.555503e-01
## 24       4          5    Buscuit Seg_1_Classic  8.404555e-01 1.467937e-02
## 25       1          6    Buscuit Seg_1_Classic  9.542894e-01 9.690921e-06
## 26       5          7    Buscuit Seg_1_Classic  6.615114e-01 3.648899e-02
## 27       4          8    Buscuit Seg_1_Classic  5.788546e-01 8.202913e-02
## 28       4          9    Buscuit Seg_1_Classic  8.344206e-01 4.549184e-02
## 29       4         10    Buscuit Seg_1_Classic  4.858277e-01 4.661464e-01
## 30       1         11    Buscuit Seg_1_Classic            NA           NA
## 31       5         12    Buscuit Seg_1_Classic  7.976825e-01 8.372056e-02
## 32       3         13    Buscuit Seg_1_Classic  5.246719e-01 5.765200e-02
## 33       2         14    Buscuit Seg_1_Classic  8.862369e-01 2.841940e-03
## 34       4         15    Buscuit Seg_1_Classic  5.314700e-01 1.636100e-01
## 35       4         16    Buscuit Seg_1_Classic  8.874746e-01 5.964641e-02
## 36       5         17    Buscuit Seg_1_Classic  8.753354e-01 3.161887e-02
## 37       3         18    Buscuit Seg_1_Classic  9.682182e-01 1.657803e-03
## 38       6          2     Orange   Seg_2_Fruit  7.011570e-02 9.205845e-01
## 39       2          8     Orange   Seg_2_Fruit  1.742817e-01 4.337971e-01
## 40       4         10     Orange   Seg_2_Fruit  8.736779e-02 9.035756e-01
## 41       5         11     Orange   Seg_2_Fruit  3.612625e-03 9.946572e-01
## 42       6         13     Orange   Seg_2_Fruit  2.861386e-01 6.937273e-01
## 43       4          1 Strawberry   Seg_2_Fruit  6.050027e-02 8.904886e-01
## 44       5          2 Strawberry   Seg_2_Fruit  4.677817e-01 2.265168e-01
## 45       6          3 Strawberry   Seg_2_Fruit  2.503143e-01 7.321490e-01
## 46       6          4 Strawberry   Seg_2_Fruit  6.634381e-02 9.188927e-01
## 47       6          5 Strawberry   Seg_2_Fruit  7.174462e-03 9.408188e-01
## 48       5          6 Strawberry   Seg_2_Fruit  4.674310e-01 4.837893e-01
## 49       5          7 Strawberry   Seg_2_Fruit  4.375231e-02 5.704839e-01
## 50       7          8 Strawberry   Seg_2_Fruit            NA           NA
## 51       6          9 Strawberry   Seg_2_Fruit  2.268456e-02 9.623519e-01
## 52       4         10 Strawberry   Seg_2_Fruit  3.233241e-01 6.129944e-01
## 53       6         11 Strawberry   Seg_2_Fruit  7.449938e-04 9.974260e-01
## 54       4         12 Strawberry   Seg_2_Fruit  3.305397e-02 8.954892e-01
## 55       4         13 Strawberry   Seg_2_Fruit  6.389769e-01 7.437255e-02
## 56       7         14 Strawberry   Seg_2_Fruit  1.933117e-04 9.952303e-01
## 57       7         15 Strawberry   Seg_2_Fruit  1.081110e-03 9.982163e-01
## 58       5         16 Strawberry   Seg_2_Fruit  3.612625e-03 9.946572e-01
## 59       3         17 Strawberry   Seg_2_Fruit  7.300268e-01 1.930981e-02
## 60       5         18 Strawberry   Seg_2_Fruit  8.859790e-01 5.331168e-02
## 61       5          4      Mango   Seg_2_Fruit  8.548917e-02 7.472709e-01
## 62       7          7      Mango   Seg_2_Fruit  1.749154e-05 9.999655e-01
## 63       4          8      Mango   Seg_2_Fruit            NA           NA
## 64       6         10      Mango   Seg_2_Fruit  2.268456e-02 9.623519e-01
## 65       4         12      Mango   Seg_2_Fruit            NA           NA
## 66       5         13      Mango   Seg_2_Fruit  5.227970e-03 9.665333e-01
## 67       7         14      Mango   Seg_2_Fruit  2.450445e-02 9.629377e-01
## 68       5         16      Mango   Seg_2_Fruit  8.384397e-01 2.276847e-02
## 69       3          2 Cappuccino  Seg_3_Coffee  8.688954e-01 1.068330e-03
## 70       3          6 Cappuccino  Seg_3_Coffee  3.424851e-01 2.685003e-01
## 71       5          7 Cappuccino  Seg_3_Coffee  7.213718e-01 3.173506e-02
## 72       4          8 Cappuccino  Seg_3_Coffee  8.682389e-01 3.292221e-02
## 73       4          9 Cappuccino  Seg_3_Coffee  3.141192e-01 1.445511e-02
## 74       3         12 Cappuccino  Seg_3_Coffee  1.279168e-01 6.750712e-01
## 75       4         13 Cappuccino  Seg_3_Coffee  7.952771e-01 8.037279e-02
## 76       4         14 Cappuccino  Seg_3_Coffee  6.347485e-01 9.012006e-02
## 77       1         15 Cappuccino  Seg_3_Coffee  2.849665e-01 9.024009e-05
## 78       3         16 Cappuccino  Seg_3_Coffee  6.792606e-01 7.218907e-02
## 79       6         17 Cappuccino  Seg_3_Coffee  7.471645e-01 1.169916e-01
## 80       3         18 Cappuccino  Seg_3_Coffee  3.487102e-01 3.869849e-02
## 81       2          1     Mousse Seg_1_Classic  8.897286e-01 3.629047e-03
## 82       3          2     Mousse Seg_1_Classic  8.734116e-01 2.733135e-03
## 83       5          3     Mousse Seg_1_Classic  7.835530e-01 3.538114e-02
## 84       4          4     Mousse Seg_1_Classic  6.198427e-01 2.082946e-02
## 85       3          6     Mousse Seg_1_Classic  5.279705e-01 8.651626e-04
## 86       3          8     Mousse Seg_1_Classic  8.613241e-01 2.943571e-03
## 87       2         10     Mousse Seg_1_Classic  9.685163e-01 1.747365e-03
## 88       5         11     Mousse Seg_1_Classic            NA           NA
## 89       4         12     Mousse Seg_1_Classic  5.567916e-01 1.572016e-01
## 90       4         13     Mousse Seg_1_Classic            NA           NA
## 91       5         14     Mousse Seg_1_Classic  4.312694e-01 2.761161e-01
## 92       3         15     Mousse Seg_1_Classic  7.879379e-01 4.322667e-03
## 93       3         16     Mousse Seg_1_Classic            NA           NA
## 94       7         17     Mousse Seg_1_Classic  5.880103e-01 3.532317e-01
## 95       2          1    Caramel Seg_1_Classic  2.811884e-01 2.531893e-04
## 96       6          2    Caramel Seg_1_Classic  3.242443e-01 5.934680e-01
## 97       4          3    Caramel Seg_1_Classic  9.246631e-01 9.267922e-04
## 98       3          4    Caramel Seg_1_Classic  7.201937e-01 9.727646e-03
## 99       6          5    Caramel Seg_1_Classic  6.114651e-01 3.286485e-01
## 100      3          6    Caramel Seg_1_Classic  5.644224e-01 2.382900e-02
## 101      5          8    Caramel Seg_1_Classic  7.976825e-01 8.372056e-02
## 102      7          9    Caramel Seg_1_Classic  9.363573e-01 4.084648e-02
## 103      4         11    Caramel Seg_1_Classic            NA           NA
## 104      4         13    Caramel Seg_1_Classic            NA           NA
## 105      3         17    Caramel Seg_1_Classic  7.425731e-01 5.590975e-02
## 106      3         18    Caramel Seg_1_Classic  9.735547e-01 6.960569e-03
## 107      4          4     Nougat Seg_1_Classic  8.047231e-01 8.482573e-02
## 108      3          5     Nougat Seg_1_Classic  4.641111e-01 8.408786e-02
## 109      4          7     Nougat Seg_1_Classic  8.237046e-01 5.711491e-02
## 110      4          9     Nougat Seg_1_Classic  7.956770e-01 1.029776e-01
## 111      4         12     Nougat Seg_1_Classic            NA           NA
## 112      1         13     Nougat Seg_1_Classic  7.922356e-01 2.023552e-03
## 113      4         14     Nougat Seg_1_Classic  7.020115e-01 5.999431e-02
## 114      3         15     Nougat Seg_1_Classic  6.099251e-01 1.660326e-03
## 115      6         16     Nougat Seg_1_Classic  6.842893e-01 2.326606e-01
## 116      4         17     Nougat Seg_1_Classic  8.176163e-01 7.039820e-02
## 117      5         18     Nougat Seg_1_Classic  6.224126e-01 7.149872e-02
## 118      2          1        Nut Seg_1_Classic  8.742123e-01 2.444050e-03
## 119      3          2        Nut Seg_1_Classic  8.356363e-01 2.823448e-03
## 120      4          3        Nut Seg_1_Classic  8.185455e-01 6.999215e-03
## 121      3          4        Nut Seg_1_Classic  5.038332e-01 1.754357e-01
## 122      4          6        Nut Seg_1_Classic  7.528826e-01 2.426314e-02
## 123      5          8        Nut Seg_1_Classic  5.764703e-01 2.536727e-01
## 124      4          9        Nut Seg_1_Classic  7.970715e-01 5.100396e-02
## 125      4         13        Nut Seg_1_Classic  6.905763e-01 7.137819e-02
## 126      4         17        Nut Seg_1_Classic  8.091087e-01 1.058928e-01
## 127      4         18        Nut Seg_1_Classic  9.267478e-01 4.587869e-02
##     Seg_3_Coffee
## 1   1.601480e-01
## 2   1.539660e-01
## 3   3.020096e-01
## 4   2.193757e-01
## 5   4.735587e-01
## 6   3.713574e-01
## 7   2.232430e-01
## 8   1.064145e-01
## 9   4.740227e-01
## 10  2.410984e-01
## 11  5.116172e-01
## 12  2.514858e-01
## 13            NA
## 14  4.917947e-01
## 15  2.684057e-01
## 16  2.690955e-01
## 17  3.611325e-01
## 18  2.665726e-01
## 19  4.077243e-01
## 20  4.324411e-01
## 21  6.617144e-02
## 22  1.605900e-01
## 23  3.673886e-01
## 24  1.448651e-01
## 25  4.570090e-02
## 26  3.019996e-01
## 27  3.391163e-01
## 28  1.200875e-01
## 29  4.802588e-02
## 30            NA
## 31  1.185969e-01
## 32  4.176761e-01
## 33  1.109212e-01
## 34  3.049200e-01
## 35  5.287897e-02
## 36  9.304578e-02
## 37  3.012402e-02
## 38  9.299788e-03
## 39  3.919211e-01
## 40  9.056616e-03
## 41  1.730149e-03
## 42  2.013410e-02
## 43  4.901110e-02
## 44  3.057015e-01
## 45  1.753662e-02
## 46  1.476351e-02
## 47  5.200670e-02
## 48  4.877974e-02
## 49  3.857638e-01
## 50            NA
## 51  1.496355e-02
## 52  6.368151e-02
## 53  1.829051e-03
## 54  7.145680e-02
## 55  2.866505e-01
## 56  4.576382e-03
## 57  7.026186e-04
## 58  1.730149e-03
## 59  2.506634e-01
## 60  6.070935e-02
## 61  1.672399e-01
## 62  1.696026e-05
## 63            NA
## 64  1.496355e-02
## 65            NA
## 66  2.823874e-02
## 67  1.255783e-02
## 68  1.387919e-01
## 69  1.300363e-01
## 70  3.890146e-01
## 71  2.468931e-01
## 72  9.883894e-02
## 73  6.714257e-01
## 74  1.970120e-01
## 75  1.243501e-01
## 76  2.751314e-01
## 77  7.149433e-01
## 78  2.485504e-01
## 79  1.358440e-01
## 80  6.125913e-01
## 81  1.066423e-01
## 82  1.238553e-01
## 83  1.810658e-01
## 84  3.593278e-01
## 85  4.711643e-01
## 86  1.357324e-01
## 87  2.973629e-02
## 88            NA
## 89  2.860069e-01
## 90            NA
## 91  2.926145e-01
## 92  2.077395e-01
## 93            NA
## 94  5.875799e-02
## 95  7.185584e-01
## 96  8.228770e-02
## 97  7.441009e-02
## 98  2.700787e-01
## 99  5.988648e-02
## 100 4.117486e-01
## 101 1.185969e-01
## 102 2.279621e-02
## 103           NA
## 104           NA
## 105 2.015171e-01
## 106 1.948468e-02
## 107 1.104512e-01
## 108 4.518010e-01
## 109 1.191805e-01
## 110 1.013454e-01
## 111           NA
## 112 2.057409e-01
## 113 2.379941e-01
## 114 3.884146e-01
## 115 8.305012e-02
## 116 1.119855e-01
## 117 3.060886e-01
## 118 1.233436e-01
## 119 1.615402e-01
## 120 1.744553e-01
## 121 3.207312e-01
## 122 2.228542e-01
## 123 1.698571e-01
## 124 1.519245e-01
## 125 2.380455e-01
## 126 8.499848e-02
## 127 2.737355e-02

(-) Added estimates of classifications

# Columns from which we want to take the maximum
cols <- c("Seg_1_Classic","Seg_2_Fruit","Seg_3_Coffee")

datlogreg_127cases.2$Predictions <- names(datlogreg_127cases.2)[names(datlogreg_127cases.2) %in% cols][max.col(datlogreg_127cases.2[,cols],ties.method = "first")]

datlogreg_127cases.2 %>% 
  group_by(Predictions) %>% 
  tally()
## # A tibble: 4 x 2
##   Predictions       n
##   <chr>         <int>
## 1 Seg_1_Classic    82
## 2 Seg_2_Fruit      26
## 3 Seg_3_Coffee      8
## 4 <NA>             11

(-) Figure 5.38 - Classification table for the case example

# Create classification table
confusion_matrix <- table("Segment" = datlogreg_127cases.2$Segment, 
      "Predictions" = datlogreg_127cases.2$Predictions)

print(confusion_matrix)
##                Predictions
## Segment         Seg_1_Classic Seg_2_Fruit Seg_3_Coffee
##   Seg_1_Classic            62           1            2
##   Seg_2_Fruit               5          23            0
##   Seg_3_Coffee             15           2            6
datlogreg_127cases.2$Predictions
##   [1] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##   [5] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##   [9] "Seg_3_Coffee"  "Seg_2_Fruit"   "Seg_3_Coffee"  "Seg_1_Classic"
##  [13] NA              "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##  [17] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##  [21] "Seg_1_Classic" "Seg_1_Classic" "Seg_3_Coffee"  "Seg_1_Classic"
##  [25] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##  [29] "Seg_1_Classic" NA              "Seg_1_Classic" "Seg_1_Classic"
##  [33] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##  [37] "Seg_1_Classic" "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_2_Fruit"  
##  [41] "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_1_Classic"
##  [45] "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_2_Fruit"  
##  [49] "Seg_2_Fruit"   NA              "Seg_2_Fruit"   "Seg_2_Fruit"  
##  [53] "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_1_Classic" "Seg_2_Fruit"  
##  [57] "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_1_Classic" "Seg_1_Classic"
##  [61] "Seg_2_Fruit"   "Seg_2_Fruit"   NA              "Seg_2_Fruit"  
##  [65] NA              "Seg_2_Fruit"   "Seg_2_Fruit"   "Seg_1_Classic"
##  [69] "Seg_1_Classic" "Seg_3_Coffee"  "Seg_1_Classic" "Seg_1_Classic"
##  [73] "Seg_3_Coffee"  "Seg_2_Fruit"   "Seg_1_Classic" "Seg_1_Classic"
##  [77] "Seg_3_Coffee"  "Seg_1_Classic" "Seg_1_Classic" "Seg_3_Coffee" 
##  [81] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
##  [85] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" NA             
##  [89] "Seg_1_Classic" NA              "Seg_1_Classic" "Seg_1_Classic"
##  [93] NA              "Seg_1_Classic" "Seg_3_Coffee"  "Seg_2_Fruit"  
##  [97] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
## [101] "Seg_1_Classic" "Seg_1_Classic" NA              NA             
## [105] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
## [109] "Seg_1_Classic" "Seg_1_Classic" NA              "Seg_1_Classic"
## [113] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
## [117] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
## [121] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
## [125] "Seg_1_Classic" "Seg_1_Classic" "Seg_1_Classic"
confusion_results <- caret::confusionMatrix(as.factor(datlogreg_127cases.2$Predictions),
                       as.factor(datlogreg_127cases.2$Segment))

print(confusion_results)
## Confusion Matrix and Statistics
## 
##                Reference
## Prediction      Seg_1_Classic Seg_2_Fruit Seg_3_Coffee
##   Seg_1_Classic            62           5           15
##   Seg_2_Fruit               1          23            2
##   Seg_3_Coffee              2           0            6
## 
## Overall Statistics
##                                           
##                Accuracy : 0.7845          
##                  95% CI : (0.6985, 0.8554)
##     No Information Rate : 0.5603          
##     P-Value [Acc > NIR] : 3.761e-07       
##                                           
##                   Kappa : 0.598           
##                                           
##  Mcnemar's Test P-Value : 0.002184        
## 
## Statistics by Class:
## 
##                      Class: Seg_1_Classic Class: Seg_2_Fruit
## Sensitivity                        0.9538             0.8214
## Specificity                        0.6078             0.9659
## Pos Pred Value                     0.7561             0.8846
## Neg Pred Value                     0.9118             0.9444
## Prevalence                         0.5603             0.2414
## Detection Rate                     0.5345             0.1983
## Detection Prevalence               0.7069             0.2241
## Balanced Accuracy                  0.7808             0.8937
##                      Class: Seg_3_Coffee
## Sensitivity                      0.26087
## Specificity                      0.97849
## Pos Pred Value                   0.75000
## Neg Pred Value                   0.84259
## Prevalence                       0.19828
## Detection Rate                   0.05172
## Detection Prevalence             0.06897
## Balanced Accuracy                0.61968

(-) Results for Figure 5.39 - ROC curve for segment 1 (Classic), AUC = 0.824

print(confusion_results$overall);
##       Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull 
##   7.844828e-01   5.980039e-01   6.985078e-01   8.554091e-01   5.603448e-01 
## AccuracyPValue  McnemarPValue 
##   3.760535e-07   2.184376e-03
print(confusion_results$byClass)
##                      Sensitivity Specificity Pos Pred Value Neg Pred Value
## Class: Seg_1_Classic   0.9538462   0.6078431      0.7560976      0.9117647
## Class: Seg_2_Fruit     0.8214286   0.9659091      0.8846154      0.9444444
## Class: Seg_3_Coffee    0.2608696   0.9784946      0.7500000      0.8425926
##                      Precision    Recall        F1 Prevalence Detection Rate
## Class: Seg_1_Classic 0.7560976 0.9538462 0.8435374  0.5603448     0.53448276
## Class: Seg_2_Fruit   0.8846154 0.8214286 0.8518519  0.2413793     0.19827586
## Class: Seg_3_Coffee  0.7500000 0.2608696 0.3870968  0.1982759     0.05172414
##                      Detection Prevalence Balanced Accuracy
## Class: Seg_1_Classic           0.70689655         0.7808446
## Class: Seg_2_Fruit             0.22413793         0.8936688
## Class: Seg_3_Coffee            0.06896552         0.6196821

(-) Stepwise regression.

datlogreg_127cases_woNA <- datlogreg_127cases %>% filter(complete.cases(.))

# Stepweise regression
full.model_mnlog <- nnet::multinom(Segment ~ Price + 
                                  Refreshing + 
                                  Delicious + 
                                  Healthy + 
                                  Bitter + 
                                  Light + 
                                  Crunchy + 
                                  Exotic + 
                                  Sweet +
                                  Fruity, 
                                  data = datlogreg_127cases_woNA,
                                  na.action = na.omit) 
## # weights:  36 (22 variable)
## initial  value 127.439025 
## iter  10 value 80.359932
## iter  20 value 71.266966
## iter  30 value 71.008194
## final  value 71.008110 
## converged
full.model_mnlog_sw <- MASS::stepAIC(full.model_mnlog, direction = "both", trace = TRUE)
## Start:  AIC=186.02
## Segment ~ Price + Refreshing + Delicious + Healthy + Bitter + 
##     Light + Crunchy + Exotic + Sweet + Fruity
## 
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 81.514364
## iter  20 value 73.554724
## iter  30 value 73.265728
## final  value 73.265727 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 83.469402
## iter  20 value 72.812424
## iter  30 value 72.547501
## final  value 72.547500 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 81.784189
## iter  20 value 75.190265
## iter  30 value 75.039732
## iter  30 value 75.039731
## iter  30 value 75.039731
## final  value 75.039731 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 82.420150
## iter  20 value 73.440870
## iter  30 value 73.272709
## iter  30 value 73.272709
## iter  30 value 73.272709
## final  value 73.272709 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 83.918044
## iter  20 value 74.804347
## iter  30 value 74.636924
## final  value 74.636921 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 81.765136
## iter  20 value 73.978854
## iter  30 value 73.783842
## final  value 73.783841 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 84.362494
## iter  20 value 77.508820
## final  value 77.465121 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 78.932869
## iter  20 value 73.864227
## final  value 73.806907 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 80.102631
## iter  20 value 71.820745
## iter  30 value 71.606773
## final  value 71.606768 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 85.358098
## iter  20 value 75.305362
## iter  30 value 74.612193
## final  value 74.612188 
## converged
##              Df    AIC
## - Sweet       2 183.21
## - Refreshing  2 185.09
## <none>          186.02
## - Price       2 186.53
## - Healthy     2 186.54
## - Light       2 187.57
## - Exotic      2 187.61
## - Fruity      2 189.22
## - Bitter      2 189.27
## - Delicious   2 190.08
## - Crunchy     2 194.93
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 80.102631
## iter  20 value 71.820745
## iter  30 value 71.606773
## final  value 71.606768 
## converged
## 
## Step:  AIC=183.21
## Segment ~ Price + Refreshing + Delicious + Healthy + Bitter + 
##     Light + Crunchy + Exotic + Fruity
## 
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 82.890126
## iter  20 value 75.145108
## final  value 74.730258 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 83.319373
## iter  20 value 73.470835
## final  value 73.169343 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 82.812292
## iter  20 value 76.057318
## final  value 75.766984 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 81.932353
## iter  20 value 74.375824
## final  value 74.256864 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 84.378195
## iter  20 value 75.203538
## iter  30 value 75.031264
## iter  30 value 75.031263
## iter  30 value 75.031263
## final  value 75.031263 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 82.865334
## iter  20 value 74.612959
## iter  30 value 74.426012
## iter  30 value 74.426011
## iter  30 value 74.426011
## final  value 74.426011 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 85.799089
## iter  20 value 78.208701
## final  value 78.170635 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 79.528030
## iter  20 value 74.819538
## final  value 74.751398 
## converged
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 86.781415
## iter  20 value 75.044676
## final  value 74.979851 
## converged
## # weights:  36 (22 variable)
## initial  value 127.439025 
## iter  10 value 80.359932
## iter  20 value 71.266966
## iter  30 value 71.008194
## final  value 71.008110 
## converged
##              Df    AIC
## - Refreshing  2 182.34
## <none>          183.21
## - Healthy     2 184.51
## - Light       2 184.85
## - Price       2 185.46
## - Exotic      2 185.50
## - Fruity      2 185.96
## + Sweet       2 186.02
## - Bitter      2 186.06
## - Delicious   2 187.53
## - Crunchy     2 192.34
## # weights:  30 (18 variable)
## initial  value 127.439025 
## iter  10 value 83.319373
## iter  20 value 73.470835
## final  value 73.169343 
## converged
## 
## Step:  AIC=182.34
## Segment ~ Price + Delicious + Healthy + Bitter + Light + Crunchy + 
##     Exotic + Fruity
## 
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 83.218357
## iter  20 value 75.353632
## final  value 75.346652 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 82.437631
## iter  20 value 77.128240
## final  value 77.120020 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 85.846063
## iter  20 value 75.713548
## final  value 75.677068 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 86.985450
## iter  20 value 76.145385
## final  value 76.069615 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 85.400735
## iter  20 value 77.510592
## final  value 77.465160 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 88.779811
## iter  20 value 80.174631
## final  value 80.169006 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 80.167588
## iter  20 value 76.799976
## final  value 76.788945 
## converged
## # weights:  27 (16 variable)
## initial  value 127.439025 
## iter  10 value 87.188979
## iter  20 value 77.663105
## final  value 77.605876 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 80.102631
## iter  20 value 71.820745
## iter  30 value 71.606773
## final  value 71.606768 
## converged
## # weights:  33 (20 variable)
## initial  value 127.439025 
## iter  10 value 83.469402
## iter  20 value 72.812424
## iter  30 value 72.547501
## final  value 72.547500 
## converged
##              Df    AIC
## <none>          182.34
## - Price       2 182.69
## + Refreshing  2 183.21
## - Healthy     2 183.35
## - Bitter      2 184.14
## + Sweet       2 185.09
## - Exotic      2 185.58
## - Delicious   2 186.24
## - Light       2 186.93
## - Fruity      2 187.21
## - Crunchy     2 192.34
summary(full.model_mnlog_sw); full.model_mnlog_sw$anova
## Call:
## nnet::multinom(formula = Segment ~ Price + Delicious + Healthy + 
##     Bitter + Light + Crunchy + Exotic + Fruity, data = datlogreg_127cases_woNA, 
##     na.action = na.omit)
## 
## Coefficients:
##              (Intercept)      Price  Delicious     Healthy     Bitter     Light
## Seg_2_Fruit    -5.232899 -0.4014725 -1.2064761 -0.64143533 -0.2888273 1.1398985
## Seg_3_Coffee   -1.758628  0.2026901 -0.3332057  0.01328112 -0.5481298 0.2912457
##                Crunchy    Exotic      Fruity
## Seg_2_Fruit  0.9526701 0.2868887  1.00443564
## Seg_3_Coffee 0.3187489 0.3042279 -0.03984982
## 
## Std. Errors:
##              (Intercept)     Price Delicious   Healthy    Bitter     Light
## Seg_2_Fruit     2.248506 0.2737644 0.4795317 0.3168585 0.2781677 0.4286672
## Seg_3_Coffee    1.686695 0.2035914 0.3255033 0.2233337 0.2372438 0.2848597
##                Crunchy    Exotic    Fruity
## Seg_2_Fruit  0.2902964 0.1592675 0.3783999
## Seg_3_Coffee 0.2039375 0.1280890 0.2541415
## 
## Residual Deviance: 146.3387 
## AIC: 182.3387
## Stepwise Model Path 
## Analysis of Deviance Table
## 
## Initial Model:
## Segment ~ Price + Refreshing + Delicious + Healthy + Bitter + 
##     Light + Crunchy + Exotic + Sweet + Fruity
## 
## Final Model:
## Segment ~ Price + Delicious + Healthy + Bitter + Light + Crunchy + 
##     Exotic + Fruity
## 
## 
##           Step Df Deviance Resid. Df Resid. Dev      AIC
## 1                                 94   142.0162 186.0162
## 2      - Sweet  2 1.197316        96   143.2135 183.2135
## 3 - Refreshing  2 3.125150        98   146.3387 182.3387