Skip to content

About

Choice-based conjoint for broadband plans: a D-efficient design, MNL and latent-class estimation, willingness to pay with delta-method intervals, and inattentive answers screened by simulated RLH.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

levelworth

CI

levelworth

levelworth analyses a choice-based conjoint survey for broadband plans. It builds a D-efficient design under balance and dominance constraints, simulates a seeded panel of 630 households, estimates a multinomial logit (MNL) with respondent-clustered errors and a latent-class MNL by EM, screens inattentive respondents against a simulated random-responder null, converts part-worths to willingness to pay with delta-method intervals checked by bootstrap, and runs a share-of-preference simulator with a revenue price scan. All data is synthetic.

The problem

A regional fibre provider is repackaging its plans (speed tier, monthly price, contract length, router included or rented, installation fee) and has run a choice survey of 630 households. Reading it as counts ("plans with 2 Gbps were chosen 41% of the time") confounds levels that happened to appear together, ignores the option to keep the current provider, gives no willingness-to-pay figure, and says nothing about respondents who clicked through without reading. This project replaces the counts with a model: each task is a choice among three plans and "none", utility is linear in dummy-coded levels and price, and every number carries a standard error that respects that a household answers 12 tasks.

How it works

flowchart LR
    spec["Attribute spec<br/>config/broadband.yaml"] --> design["Constrained D-efficient design<br/>swap search, balance, no dominance"]
    design --> sim["Simulated choices<br/>2 classes + 30 inattentive"]
    sim --> mnl["Pooled MNL<br/>Newton, clustered SE"]
    mnl --> screen["RLH screen<br/>vs simulated random responders"]
    screen --> lc["Latent-class MNL by EM<br/>BIC / CAIC"]
    lc --> wtp["Willingness to pay<br/>delta method + bootstrap"]
    lc --> market["Share-of-preference simulator<br/>revenue price scan"]
    wtp --> report["report.md + partworths.png"]
    market --> report
Loading

Quick start

Python 3.12 or newer.

python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"

levelworth design --data data --tasks 12 --blocks 10 --alts 3 --seed 1
levelworth simulate-responses --data data --seed 2
levelworth fit --data data
levelworth screen --data data
levelworth classes --data data --max 4
levelworth wtp --data data
levelworth market --data data --plans config/market.yaml --price-scan Gigabit --grid 30:110:10
levelworth report --data data --out out

pytest

levelworth simulate-responses --classes 1 --n 800 writes a single-class panel at the value seekers' part-worths, which the recovery tests use. The full pipeline above takes a few minutes, most of it the bootstrap and the class search.

Example output

All of this comes from the commands above on the seeded survey. Elisions are marked ....

design (D-error is the MNL D-error at the prior in config/broadband.yaml):

design: 10 blocks x 12 tasks x 3 alternatives (+ none)
swap search: 541 swaps accepted, 6411 rejected by the duplicate/dominance rules
D-error, starting design : 0.0767
D-error, searched design : 0.0658
D-error, 20 random designs: best 0.0760, mean 0.0770
searched / random mean   : 0.854

attribute     level             total  per block
------------  ----------------  -----  ---------
speed         300 Mbps          120    12-12    
speed         1 Gbps            120    12-12    
...

screen (RLH is the geometric mean probability of the chosen options):

RLH of 2000 simulated random responders: mean 0.186, 80th percentile 0.220
respondents: 630, flagged: 32 (10 gave the same answer position in every task)
RLH, flagged respondents: mean 0.202; kept: mean 0.362
planted inattentive flagged: 23 of 30; genuine flagged: 9 of 600
refit on 598 respondents; screen.json written

classes (BIC and CAIC by number of classes, shares and part-worths on the screened panel):

598 respondents after removing 32 flagged respondents
classes  log-lik  params  BIC      CAIC     best
-------  -------  ------  -------  -------  ----
1        -7736.2  8       15543.5  15551.5      
2        -7432.9  17      15016.8  15033.8  *   
3        -7426.6  26      15084.0  15110.0      
4        -7420.4  35      15151.5  15186.5      

class shares: 30.3%, 69.7% (EM log-likelihood never decreased over 26 iterations)
parameter                 class 1  class 2
------------------------  -------  -------
speed[1 Gbps]             +1.120   +0.478 
speed[2 Gbps]             +2.067   +0.583 
price                     -0.335   -0.850 
contract[12 months]       -0.107   -0.338 
contract[24 months]       -0.389   -0.946 
router[rented $10/month]  -0.295   -0.794 
installation[$99]         -0.458   -0.888 
none                      -1.488   -3.380 

planted classes: speed seekers 35%, value seekers 65%

wtp (dollars per month against the base level):

model          level vs base             WTP ($/month)  SE (delta)  SE (boot)  95% CI (delta)  
-------------  ------------------------  -------------  ----------  ---------  ----------------
pooled         speed: 1 Gbps             +9.75          0.68        0.70       [+8.42, +11.09] 
pooled         speed: 2 Gbps             +16.47         0.93        0.93       [+14.66, +18.29]
pooled         contract: 12 months       -3.99          0.46        0.47       [-4.90, -3.09]  
pooled         contract: 24 months       -11.40         0.59        0.60       [-12.56, -10.24]
pooled         router: rented $10/month  -9.02          0.44        0.45       [-9.88, -8.15]  
pooled         installation: $99         -10.57         0.48        0.52       [-11.51, -9.64] 
class 1 (30%)  speed: 1 Gbps             +33.42         3.11        3.11       [+27.33, +39.51]
class 1 (30%)  speed: 2 Gbps             +61.65         4.01        3.92       [+53.79, +69.52]
class 1 (30%)  contract: 12 months       -3.21          1.64        1.58       [-6.42, +0.00]  
class 1 (30%)  contract: 24 months       -11.62         2.12        2.04       [-15.77, -7.47] 
class 1 (30%)  router: rented $10/month  -8.80          1.50        1.43       [-11.74, -5.86] 
class 1 (30%)  installation: $99         -13.66         2.01        2.07       [-17.59, -9.72] 
class 2 (70%)  speed: 1 Gbps             +5.63          0.59        0.60       [+4.47, +6.78]  
class 2 (70%)  speed: 2 Gbps             +6.86          0.64        0.64       [+5.61, +8.12]  
class 2 (70%)  contract: 12 months       -3.97          0.46        0.44       [-4.88, -3.06]  
class 2 (70%)  contract: 24 months       -11.14         0.61        0.63       [-12.33, -9.94] 
class 2 (70%)  router: rented $10/month  -9.34          0.45        0.43       [-10.23, -8.46] 
class 2 (70%)  installation: $99         -10.45         0.46        0.49       [-11.36, -9.55] 

market (three plans plus "none", class model, with a price scan of the Gigabit plan):

model: classes
option     share
---------  -----
Gigabit    22.0%
Essential  62.4%
Ultra      9.1% 
none       6.6% 

IIA check: adding a copy of 'Gigabit' moves the share ratio Essential / Ultra from 6.8673 to 7.8552 (+14.39%)

price scan for Gigabit (revenue = share x price)
price  share  revenue
-----  -----  -------
$30    84.2%  25.27  
$40    74.3%  29.71  
$50    59.6%  29.78  
$60    42.5%  25.47  
$70    27.6%  19.34  
$80    17.5%  13.99  
$90    11.3%  10.19  
$100   7.6%   7.62   
$110   5.3%   5.83   
revenue-maximising price: $50

The planted classes are speed seekers at 35% and value seekers at 65%. The screen removes 32 respondents: 23 of the 30 planted inattentive ones and 9 of the 600 genuine ones (1.5%). The estimated speed-seeker share on the kept panel is 30.3% against the planted 35%, and the price-scan optimum for the Gigabit plan is $50. True 1 Gbps willingness to pay is $34.29 and $5.56; the estimates are $33.42 and $5.63. The screen finds 23 of 30 planted inattentive respondents; detection is limited at 12 tasks per respondent (see the screening decision below).

Design decisions

  • Swap search that preserves balance. The search exchanges the levels of one attribute between two alternatives of the same block, so each level keeps exactly its per-block frequency (the level table printed by design, shown in part above, reads 12-12 per block for the speed levels and so on). Candidate swaps that create a duplicate alternative or a dominated one are rejected, so the final design is balanced and legal by construction. The cost is a smaller search space than free recoding; the searched design still reaches 0.854 of the mean D-error of 20 random designs built under the same constraints.
  • EM with Newton M-steps and staged starts. Each class is updated with a damped Newton step on its posterior-weighted likelihood, which makes the observed log-likelihood non-decreasing (tested). Ten seeded starts run 40 iterations each; the best three run to a gain below 1e-7. This is cheaper than converging all ten. The ten stage-one log-likelihoods are kept on the fit (start_log_likelihoods, not printed by the command line), and a test checks that the best two are within 0.001 of each other after those 40 iterations; only the finalists are converged, so it does not compare converged solutions.
  • Covariance from the whole mixture. A per-class sandwich with posterior weights held fixed ignores that class membership is itself estimated from the same data, so it can understate that class's error. The reported covariance is the respondent-clustered sandwich of the full mixture likelihood, with a finite-difference Jacobian of the analytic scores as bread. Delta-method and bootstrap errors then agree within 20%.
  • RLH against a simulated null, not a fixed cut-off. A cut-off such as 0.3 means different things for different designs and none rates, so the threshold is a quantile of the RLH of 2,000 random responders answering the same task sets under the fitted model. At 12 tasks the genuine RLH distribution overlaps that null: the 95th percentile flags 69 of 600 genuine respondents (11.5%) and finds 23 of 30 planted ones, and no quantile reaches 26 of 30 with at most 3% false flags. RLH is the likelihood ratio against a random answerer, so that overlap is a property of 12 tasks per respondent, not of the fit; refitting on the cleaned panel and rescoring until the flags stop changing was tried and moves the count by one. The screen therefore uses the 80th percentile (--quantile changes it), which flags 9 genuine respondents (1.5%) and 13 of the 20 planted random clickers, plus a second rule: a respondent who gives the same answer position in all 12 tasks is flagged, because a random answerer does that with probability 4^-11 and RLH cannot see it (an always-first answer sits inside the genuine RLH range). Together they find 23 of 30 planted respondents: all 10 always-first-plan respondents and 13 of the 20 random clickers. The 7 missed are random clickers whose answers happen to score above the 80th null percentile. Detection is therefore 23 of 30 planted respondents with a 1.5% false-flag rate; raising detection to 26 of 30 would flag about 10% of genuine respondents.
  • Classes ordered by price coefficient. Class labels are otherwise arbitrary between starts. Sorting by the price coefficient, least sensitive first, makes runs comparable and lets tests address "speed seekers" and "value seekers" directly.
  • IIA made visible. The simulator adds an exact copy of a plan and reports how the share ratio of two other plans moves. Under the pooled MNL it is unchanged (the ratio is independent of irrelevant alternatives); under the class model it moves, because the copy draws mostly from the class that likes that plan.

Testing

86 tests passing. The suite covers a hand-computed MNL fixture (utilities 1.0, 0.0, -0.5 give 0.62853, 0.23122, 0.14024), the analytic gradient against central differences, a negative-definite Hessian at the MLE, single-class recovery within 3 clustered standard errors, design balance and constraints, EM monotonicity, BIC selection of two classes, willingness-to-pay recovery, delta-method against bootstrap, the IIA property, determinism of the price scan and the command line.

GITHUB_ACTIONS=true CI=true COLUMNS=80 pytest -q
ruff check . && ruff format --check .

Project layout

config/broadband.yaml    attribute spec, dominance directions, design prior
config/market.yaml       competing plans for the simulator
src/levelworth/
  attributes.py          spec loading, validation, dummy/linear coding, none constant
  design.py              balanced random designs, swap search, D-error
  simulate.py            seeded respondents, planted classes and inattentive answers
  panel.py               choice panel and file loading
  mnl.py                 log-likelihood, gradient, Hessian, Newton/BFGS, clustered SE
  screen.py              RLH and the random-responder null
  latentclass.py         EM, BIC/CAIC, mixture covariance
  wtp.py                 willingness to pay, delta method, bootstrap
  market.py              share of preference, IIA check, price scan
  analysis.py            steps shared by the CLI and the report
  report.py              report.md and partworths.png
  cli.py                 typer commands
tests/                   pytest suite

License

MIT

About

Choice-based conjoint for broadband plans: a D-efficient design, MNL and latent-class estimation, willingness to pay with delta-method intervals, and inattentive answers screened by simulated RLH.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages