inst/doc/mxl_models.R

## ----setup, include=FALSE, message=FALSE, warning=FALSE-----------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  fig.retina = 3,
  comment = "#>"
)

library(logitr)

# Read in results from already estimated models so that the
# examples aren't actually run when building this page,
# otherwise it'll take much longer to build
mxl_pref <- readRDS(here::here('inst', 'extdata', 'mxl_pref.Rds'))
mxl_wtp  <- readRDS(here::here('inst', 'extdata', 'mxl_wtp.Rds'))
mxl_pref_cor <- readRDS(here::here('inst', 'extdata', 'mxl_pref_cor.Rds'))

## ----eval=FALSE---------------------------------------------------------------
#  library("logitr")
#  
#  set.seed(456)
#  
#  mxl_pref <- logitr(
#    data     = yogurt,
#    outcome  = 'choice',
#    obsID    = 'obsID',
#    panelID  = 'id',
#    pars     = c('price', 'feat', 'brand'),
#    randPars = c(feat = 'n', brand = 'n'),
#    numMultiStarts = 10
#  )

## -----------------------------------------------------------------------------
summary(mxl_pref)

## -----------------------------------------------------------------------------
wtp_mxl_pref <- wtp(mxl_pref, scalePar =  "price")
wtp_mxl_pref

## ----eval=FALSE---------------------------------------------------------------
#  set.seed(6789)
#  
#  mxl_wtp <- logitr(
#    data       = yogurt,
#    outcome    = 'choice',
#    obsID      = 'obsID',
#    panelID    = 'id',
#    pars       = c('feat', 'brand'),
#    scalePar   = 'price',
#    randPars   = c(feat = 'n', brand = 'n'),
#    numMultiStarts = 10,
#    startVals = wtp_mxl_pref$Estimate
#  )

## -----------------------------------------------------------------------------
summary(mxl_wtp)

## -----------------------------------------------------------------------------
wtpCompare(mxl_pref, mxl_wtp, scalePar = 'price')

## ----eval=FALSE---------------------------------------------------------------
#  library("logitr")
#  
#  set.seed(456)
#  
#  mxl_pref_cor <- logitr(
#    data     = yogurt,
#    outcome  = 'choice',
#    obsID    = 'obsID',
#    panelID  = 'id',
#    pars     = c('price', 'feat', 'brand'),
#    randPars = c(feat = 'n', brand = 'n'),
#    numMultiStarts = 10,
#    correlation = TRUE
#  )

## -----------------------------------------------------------------------------
summary(mxl_pref_cor)

Try the logitr package in your browser

Any scripts or data that you put into this service are public.

logitr documentation built on Sept. 29, 2023, 5:06 p.m.