r - 计算离散时间马尔可夫链的标准误差和标准差
问题描述
我有一个从一种状态到另一种状态的转换计数矩阵,我想计算最大似然估计、标准误差和标准偏差。“markovchain”包有一个例子,但数据是一个序列。我的数据来自 155 家公司的平衡面板数据集,因此他们提供的示例代码对我不起作用。
这是我遵循的示例:
data(rain)
rain$rain[1:10]
[1] "6+" "1-5" "1-5" "1-5" "1-5" "1-5" "1-5" "6+" "6+" "6+"
#obtaining the empirical transition matrix
createSequenceMatrix(stringchar = rain$rain)
0 1-5 6+
0 362 126 60
1-5 136 90 68
6+ 50 79 124
#fitting the DTMC by MLE
alofiMcFitMle <- markovchainFit(data = rain$rain, method = "mle", name = "Alofi")
alofiMcFitMle
$estimate
Alofi
A 3 - dimensional discrete Markov Chain defined by the following states:
0, 1-5, 6+
The transition matrix (by rows) is defined as follows:
0 1-5 6+
0 0.6605839 0.2299270 0.1094891
1-5 0.4625850 0.3061224 0.2312925
6+ 0.1976285 0.3122530 0.4901186
$standardError
0 1-5 6+
0 0.03471952 0.02048353 0.01413498
1-5 0.03966634 0.03226814 0.02804834
6+ 0.02794888 0.03513120 0.04401395
$confidenceInterval
$confidenceInterval$confidenceLevel
[1] 0.95
$confidenceInterval$lowerEndpointMatrix
0 1-5 6+
0 0.6034754 0.1962346 0.08623909
1-5 0.3973397 0.2530461 0.18515711
6+ 0.1516566 0.2544673 0.41772208
$confidenceInterval$upperEndpointMatrix
0 1-5 6+
0 0.7176925 0.2636194 0.1327390
1-5 0.5278304 0.3591988 0.2774279
6+ 0.2436003 0.3700387 0.5625151
$logLikelihood
[1] -1040.419
因为我已经有一个计数数据矩阵,所以我不能使用上面的代码。我只想获取我的 6x6 转换计数矩阵并确定最大似然估计量、标准误差(置信区间)和标准偏差。有人有我可以效仿的例子吗?
解决方案
推荐阅读
- bash - 两个 JSON 文件上的 Bash 双循环命令
- java - OpenImaj - 识别形状
- ios - 为什么 Cmake 没有适用于 iOS 的官方工具链
- django - 使用 django 和 django rest 框架在 Rest API 中引发自定义 400 错误请求
- netlogo - Netlogo: Is there a way to compare strings insensitive to capitalization?
- visual-studio-2017 - 如何克服“您是否要允许来自未知发布者的此应用程序对您的设备进行更改”?
- excel - 在文件夹中循环并删除 .xlsm 文件
- android - 应用程序完成 Android Studio 安装后生成 UUID
- jquery - 如何加快猫头鹰旋转木马的滑动速度?
- c# - 你调用的对象是空的。实体与参数