是否有可能仅将博士的预测限制为正值?

时间:2017-11-14 10:12:49

标签: r time-series forecasting bayesian

我正在学习使用R中提供的各种预测包,并遇到了bsts()。我处理的数据是需求的时间序列。

public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }

    [HttpGet]
    public ActionResult Login()
    {
        return View();  // for the login form
    }

    [HttpPost]
    public void Login(string UserName, .... <other fields>)
    {
        // validate your login first here
        FormsAuthentication.SetAuthCookie(UserName, true);
    }

}

我是否可以限制data=c(27, 2, 7, 7, 9, 4, 3, 3, 3, 9, 6, 2, 6, 2, 3, 8, 6, 1, 3, 8, 4, 5, 8, 5, 4, 4, 6, 1, 6, 5, 1, 3, 0, 2, 6, 7, 1, 2, 6, 2, 8, 6, 1, 1, 3, 2, 1, 3, 1, 6, 3, 4, 3, 7, 3, 4, 1, 7, 5, 6, 3, 4, 3, 9, 2, 1, 7, 2, 2, 9, 4, 5, 3, 4, 2, 4, 4, 8, 6, 3, 9, 2, 9, 4, 1, 3, 8, 1, 7, 7, 6, 0, 1, 4, 8, 9, 2, 5) ts.main=ts(data, start=c(1910,1), frequency=12) ss <- AddLocalLinearTrend(list(), y=ts.main) ss <- AddSeasonal(ss, y=as.numeric(ts.temp), nseasons=12) model <- bsts(as.numeric(ts.temp), state.specification = ss, niter = 1000) pred <- predict(model, horizon = 12) 变为否定?

1 个答案:

答案 0 :(得分:2)

由于您的数据是计数的时间序列,因此您需要考虑到这一点而不是假设高斯误差;有关此问题的一些讨论和一些方法的详细说明,请参阅例如Brandt et al 2000Brandt and Williams 2001。幸运的是,bsts包具有内置的功能family选项(请参阅the documentation的第24至26页)。

所以,你可以这样做

model <- bsts(as.numeric(ts.main),
              state.specification = ss,
              family = 'poisson',
              niter = 1000)

以便bsts()函数正确地将数据视为计数,这将解决您的问题,因为根据定义,后验预测分布的抽取将是非负的。

相关问题