【发布时间】:2020-12-11 07:31:05
【问题描述】:
我使用 rucm 包在 R 中创建了一个未观察到的组件模型:
# input regression formula and extract x and y variables
regression_formula <- as.formula(paste("WebsiteVisits ~ MarketingSpend"))
target_var <- formula.tools::lhs(regression_formula)
fo <-
as.formula(paste(formula.tools::lhs.vars(regression_formula), " ~ ", paste(
formula.tools::rhs.vars(regression_formula), collapse = " + "
)))
# build unrestricted UCM
unrestricted_mod <- ucm(
fo,
data = final_data,
level = TRUE,
slope = TRUE,
season = FALSE,
)
# build restricted UCM
restricted_mod <- ucm(
fo,
data = final_data,
level = TRUE,
level.var = .1 * mean(unrestricted_mod$vs.level),
slope = TRUE,
season = FALSE,
)
restricted_mod$s.level
如何使用 Python 的 statsmodels 中的 UnobservedComponents 重新创建它(即使用相同的参数获取完全相同的 s.level 值)?
目前进展:
unrestricted_mod = UnobservedComponents(final_data['WebsiteVisits'], exog=final_data['MarketingSpend'], level=True, slope=True, seasonal=False)
unrestricted_mod.fit().summary()
# average of the unrestricted model's level (unsure if this is the same as vs.level in R)
np.mean(unrestricted_mod.fit().level['filtered'])
# now I need to input that value in a restricted model
# ...but I can't seem to input a value here for stochastic_level, only boolean
restricted_mod = UnobservedComponents(final_data['WebsiteVisits'], exog=final_data['MarketingSpend'], level = True, stochastic_level = True, slope=True, seasonal=False)
【问题讨论】:
标签: python r time-series statsmodels