如何测试“先前状态”是否对R中的“后续状态”有影响

机器算法验证 r 时间序列 假设检验 随机过程
2022-03-14 22:36:35

想象一个情况:我们有三个矿山的历史记录(20 年)。白银的存在是否会增加明年发现黄金的可能性?如何测试这样的问题?


在此处输入图像描述

这是示例数据:

mine_A <- c("silver","rock","gold","gold","gold","gold","gold",
            "rock","rock","rock","rock","silver","rock","rock",
            "rock","rock","rock","silver","rock","rock")
mine_B <- c("rock","rock","rock","rock","silver","rock","rock",
            "silver","gold","gold","gold","gold","gold","rock",
            "silver","rock","rock","rock","rock","rock")
mine_C <- c("rock","rock","silver","rock","rock","rock","rock",
            "rock","silver","rock","rock","rock","rock","silver",
            "gold","gold","gold","gold","gold","gold")
time <- seq(from = 1, to = 20, by = 1)

1个回答

我最好的尝试: ...@AndyW 建议的转换矩阵的使用可能不是我正在寻找的解决方案(基于@Tim 的评论)。所以我尝试了不同的方法。我发现这个链接处理如何进行逻辑回归,其中响应变量 y 和预测变量 x 都是二元的

根据示例,我应该根据我的数据创建 2 × 2 表:

               gold (yes)  gold (no)
silver (yes)       2           7
silver (no)       14          34

我如何提取值: 在此处输入图像描述

并构建一个模型:

response <- cbind(yes = c(2, 14), no = c(7, 34))

mine.logistic <- glm(response ~ as.factor(c(0,1)),
                      family = binomial(link=logit))

summary(mine.logistic)
# Coefficients:
#                     Estimate Std. Error z value Pr(>|z|)
# (Intercept)          -1.2528     0.8018  -1.562    0.118
# as.factor(c(0, 1))1   0.3655     0.8624   0.424    0.672

这是一个很好的解决方案吗?p 值 (0.673) 是否意味着银的存在不会增加找到黄金的概率?