You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于CausalImpact/bsts纳入先验概率及M参数设置的技术问询

Answer to your CausalImpact Model Size M Question

Great question! Let's unpack how this works in the CausalImpact package:

Where is the M/J prior selection logic implemented?

The core logic for covariate selection with the M/J prior lives in two key parts of the package:

  1. Internal model-building functions: When you call CausalImpact(), it uses helper functions (like buildModel()—you can inspect this in R with getAnywhere(buildModel)) to calculate the prior probability for covariate inclusion. This probability is exactly the M/J value referenced in the paper, where J is your total number of covariates.
  2. Underlying Stan model code: The actual prior distribution is defined in the package's Stan model file. You can locate this file on your system with this R command:
    system.file("stan", "causalimpact.stan", package = "CausalImpact")
    
    Inside the file, you’ll find code for the inclusion indicator variables (typically named gamma) that uses a Bernoulli prior tied to the prior_inclusion_prob parameter. This parameter is the computed M/J value.

If you don’t specify M, the package uses a default (often a 50% inclusion rate, i.e., M = J/2) when no explicit guidance is given.

Can you set a custom M?

There’s no direct M parameter exposed in the CausalImpact() function, but you can achieve this indirectly by calculating the corresponding inclusion probability and passing it via the model.args parameter:

  1. Calculate the target probability: prob = M / J (replace M with your expected model size and J with your total number of covariates)
  2. Pass this probability when initializing your CausalImpact object:
    ci <- CausalImpact(data, pre.period, post.period,
                       model.args = list(prior.inclusion.prob = prob))
    

This lets you explicitly control the expected model size M by aligning the prior inclusion probability with your desired M/J ratio.

内容的提问来源于stack exchange,提问作者Booley

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:04:39