# Data-generating process shared by sim.jl, mc.jl and coverage.jl const a, c = 0.8, 0.6 # TV -> branded searches, searches -> social budget const b1, b2 = 1.0, 0.5 # direct effects on sales of TV and paid social const v = 1.5 # sales per click on your result, paid or organic const cpc = 0.5 # price of a paid click # Where branded searches end up, with and without a brand keyword bid const share_paid = (on = 0.60, off = 0.00) const share_org = (on = 0.38, off = 0.95) # the rest are lost to competitors function simulate(n; sd_social = 1.0, holdout = 8) bid = trues(n); bid[randperm(n)[1:holdout]] .= false # a few weeks with bidding switched off tv = 10 .+ 2 .* randn(n) # TV spend search = 5 .+ a .* tv .+ randn(n) # branded search volume social = 2 .+ c .* search .+ sd_social .* randn(n) # paid social budget, set from search trends sp = ifelse.(bid, share_paid.on, share_paid.off) so = ifelse.(bid, share_org.on, share_org.off) paid = sp .* search .+ 0.05 .* randn(n) .* bid # paid clicks org = so .* search .+ 0.05 .* randn(n) # organic clicks brand = cpc .* (1 .+ 0.05 .* randn(n)) .* paid # branded search spend: the bill for paid clicks sales = 20 .+ b1 .* tv .+ b2 .* social .+ v .* (paid .+ org) .+ 2 .* randn(n) (; bid, tv, search, social, paid, org, brand, sales) end