library(conjoint)
## Warning: package 'conjoint' was built under R version 3.4.3
## 
## This is package 'modeest' written by P. PONCET.
## For a complete list of functions, use 'library(help = "modeest")' or 'help.start()'.
# Read in data into CSV file...

myconjoint <- read.csv('conjoint.csv')
str(myconjoint)
## 'data.frame':    15 obs. of  5 variables:
##  $ rating: int  4 4 8 6 3 4 9 6 1 5 ...
##  $ make  : int  0 0 0 0 0 0 0 0 1 1 ...
##  $ mpg   : int  0 0 0 0 1 1 1 1 0 0 ...
##  $ door  : int  0 0 1 1 0 0 1 1 0 0 ...
##  $ price : int  0 1 0 1 0 1 0 1 0 1 ...
summary(myconjoint)
##      rating         make             mpg              door       
##  Min.   :1.0   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
##  1st Qu.:4.0   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
##  Median :5.0   Median :0.0000   Median :0.0000   Median :0.0000  
##  Mean   :5.2   Mean   :0.4667   Mean   :0.4667   Mean   :0.4667  
##  3rd Qu.:6.5   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
##  Max.   :9.0   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
##      price       
##  Min.   :0.0000  
##  1st Qu.:0.0000  
##  Median :1.0000  
##  Mean   :0.5333  
##  3rd Qu.:1.0000  
##  Max.   :1.0000
# Run conjoint analysis with regression
conj.result <- lm(rating~make+mpg+door+price,data=myconjoint)
myz <-c()
  
  
summary(conj.result)
## 
## Call:
## lm(formula = rating ~ make + mpg + door + price, data = myconjoint)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0455 -1.3750  0.2954  1.1932  1.7046 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)   3.0682     0.9214   3.330  0.00762 **
## make         -0.3864     0.8530  -0.453  0.66027   
## mpg           0.3636     0.8530   0.426  0.67893   
## door          3.8636     0.8530   4.529  0.00109 **
## price         0.6364     0.8530   0.746  0.47284   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.633 on 10 degrees of freedom
## Multiple R-squared:  0.6912, Adjusted R-squared:  0.5677 
## F-statistic: 5.595 on 4 and 10 DF,  p-value: 0.01252
# load 'conjoint' library
#Conjoint(myconjoint[,1],myconjoint[,2:5])


# Get utilities of each attributes
kk<- caModel(myconjoint[,1],myconjoint[,2:5])
summary(kk)
##               Length Class  Mode   
## call           2     -none- call   
## terms          3     terms  call   
## residuals     15     -none- numeric
## coefficients  20     -none- numeric
## aliased        5     -none- logical
## sigma          1     -none- numeric
## df             3     -none- numeric
## r.squared      1     -none- numeric
## adj.r.squared  1     -none- numeric
## fstatistic     3     -none- numeric
## cov.unscaled  25     -none- numeric
# Total utilities based on model (maybe include)
# caTotalUtilities(conjoint1[,1],conjoint1[,2:5])

# Attribute importance
imp <-  caImportance(myconjoint[,1],myconjoint[,2:5])
print(paste("Sum: ", sum(imp)), quote=FALSE)
## [1] Sum:  100