CoCalc Public Filesr-conjoint.ipynbOpen with one click!
Author: Harald Schilly
Views : 97
Compute Environment: Ubuntu 18.04 (Deprecated)

R "conjoint" on CoCalc

Kernel: R (R-Project)

https://cran.r-project.org/web/packages/conjoint/index.html

In [1]:
packageVersion("conjoint")
[1] ‘1.41’
In [6]:
library(conjoint) require(ggfortify) data(tea) segments<-caSegmentation(tpref,tprof,3) print(segments$seg) util<-as.data.frame(segments$util) set.seed(123) ggplot2::autoplot(kmeans(util,3),data=util,label=TRUE,label.size=4,frame=TRUE)
K-means clustering with 3 clusters of sizes 28, 32, 40 Cluster means: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] 1 3.608429 5.280036 5.180036 4.372714 4.272893 5.084571 5.227429 5.870571 2 4.426031 5.382906 3.026656 6.713531 6.201656 2.544812 3.751062 1.426625 3 5.480275 2.938100 1.368100 4.540275 1.973100 3.782900 1.382900 0.965750 [,9] [,10] [,11] [,12] [,13] 1 3.856286 5.2851429 4.720571 5.991714 5.106000 2 1.757875 0.9967187 6.401625 6.038562 6.644812 3 2.820750 0.1112250 3.450750 0.442900 0.692900 Clustering vector: [1] 2 1 2 1 1 3 2 1 2 2 2 2 3 3 3 3 1 3 1 3 3 2 3 1 2 2 1 2 1 1 3 2 1 2 2 2 2 [38] 3 3 3 3 1 3 1 3 2 2 3 3 3 2 3 3 3 1 2 3 1 3 1 3 3 2 1 1 2 3 3 3 1 2 3 2 1 [75] 2 1 1 3 2 2 1 2 1 2 3 3 3 3 1 3 1 3 1 3 3 2 3 1 2 2 Within cluster sum of squares by cluster: [1] 1949.076 1903.595 1605.654 (between_SS / total_SS = 41.1 %) Available components: [1] "cluster" "centers" "totss" "withinss" "tot.withinss" [6] "betweenss" "size" "iter" "ifault"
In [3]:
library(conjoint) require(fpc) data(tea) segments<-caSegmentation(tpref,tprof,3) print(segments$seg) plotcluster(segments$util,segments$sclu)
Loading required package: fpc
K-means clustering with 3 clusters of sizes 28, 32, 40 Cluster means: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] 1 3.608429 5.280036 5.180036 4.372714 4.272893 5.084571 5.227429 5.870571 2 4.426031 5.382906 3.026656 6.713531 6.201656 2.544812 3.751062 1.426625 3 5.480275 2.938100 1.368100 4.540275 1.973100 3.782900 1.382900 0.965750 [,9] [,10] [,11] [,12] [,13] 1 3.856286 5.2851429 4.720571 5.991714 5.106000 2 1.757875 0.9967187 6.401625 6.038562 6.644812 3 2.820750 0.1112250 3.450750 0.442900 0.692900 Clustering vector: [1] 2 1 2 1 1 3 2 1 2 2 2 2 3 3 3 3 1 3 1 3 3 2 3 1 2 2 1 2 1 1 3 2 1 2 2 2 2 [38] 3 3 3 3 1 3 1 3 2 2 3 3 3 2 3 3 3 1 2 3 1 3 1 3 3 2 1 1 2 3 3 3 1 2 3 2 1 [75] 2 1 1 3 2 2 1 2 1 2 3 3 3 3 1 3 1 3 1 3 3 2 3 1 2 2 Within cluster sum of squares by cluster: [1] 1949.076 1903.595 1605.654 (between_SS / total_SS = 41.1 %) Available components: [1] "cluster" "centers" "totss" "withinss" "tot.withinss" [6] "betweenss" "size" "iter" "ifault"
In [4]:
library(conjoint) data(ice) print("Preferences of all respondents (preferences as ranking data):") Conjoint(ipref,iprof,ilevn,y.type="rank")
[1] "Preferences of all respondents (preferences as ranking data):" Call: lm(formula = frml) Residuals: Min 1Q Median 3Q Max -3,9444 -1,6944 0,0833 1,3333 5,6944 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5,3472 0,3747 14,269 <2e-16 *** factor(x$flavour)1 -0,2222 0,4740 -0,469 0,6414 factor(x$flavour)2 0,7222 0,4740 1,524 0,1343 factor(x$price)1 0,8333 0,4740 1,758 0,0853 . factor(x$price)2 -0,3333 0,4740 -0,703 0,4854 factor(x$container)1 0,9167 0,3555 2,578 0,0131 * factor(x$topping)1 -0,1250 0,3555 -0,352 0,7267 --- Signif. codes: 0 ‘***’ 0,001 ‘**’ 0,01 ‘*’ 0,05 ‘.’ 0,1 ‘ ’ 1 Residual standard error: 2,463 on 47 degrees of freedom Multiple R-squared: 0,2079, Adjusted R-squared: 0,1068 F-statistic: 2,057 on 6 and 47 DF, p-value: 0,07656 [1] "Part worths (utilities) of levels (model parameters for whole sample):" levnms utls 1 intercept 5,3472 2 chocolate -0,2222 3 vanilla 0,7222 4 strawberry -0,5 5 $1.50 0,8333 6 $2.00 -0,3333 7 $2.50 -0,5 8 cone 0,9167 9 cup -0,9167 10 yes -0,125 11 no 0,125 [1] "Average importance of factors (attributes):" [1] 35,13 31,39 20,43 13,05 [1] Sum of average importance: 100 [1] "Chart of average factors importance"
In [5]:
library(conjoint) data(tea) print("Preferences of all respondents (preferences as rating data):") Conjoint(tprefm,tprof,tlevn,y.type="score")
[1] "Preferences of all respondents (preferences as rating data):" Call: lm(formula = frml) Residuals: Min 1Q Median 3Q Max -5,1888 -2,3761 -0,7512 2,2128 7,5134 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3,55336 0,09068 39,184 < 2e-16 *** factor(x$price)1 0,24023 0,13245 1,814 0,070 . factor(x$price)2 -0,14311 0,11485 -1,246 0,213 factor(x$variety)1 0,61489 0,11485 5,354 1,02e-07 *** factor(x$variety)2 0,03489 0,11485 0,304 0,761 factor(x$kind)1 0,13689 0,11485 1,192 0,234 factor(x$kind)2 -0,88977 0,13245 -6,718 2,76e-11 *** factor(x$aroma)1 0,41078 0,08492 4,837 1,48e-06 *** --- Signif. codes: 0 ‘***’ 0,001 ‘**’ 0,01 ‘*’ 0,05 ‘.’ 0,1 ‘ ’ 1 Residual standard error: 2,967 on 1292 degrees of freedom Multiple R-squared: 0,09003, Adjusted R-squared: 0,0851 F-statistic: 18,26 on 7 and 1292 DF, p-value: < 2,2e-16 [1] "Part worths (utilities) of levels (model parameters for whole sample):" levnms utls 1 intercept 3,5534 2 low 0,2402 3 medium -0,1431 4 high -0,0971 5 black 0,6149 6 green 0,0349 7 red -0,6498 8 bags 0,1369 9 granulated -0,8898 10 leafy 0,7529 11 yes 0,4108 12 no -0,4108 [1] "Average importance of factors (attributes):" [1] 24,76 32,22 27,15 15,88 [1] Sum of average importance: 100,01 [1] "Chart of average factors importance"
In [ ]: