如何使用 MCMCregress 命令查找均值差异?

How to find difference in mean using MCMCregress command?

我正在尝试弄清楚如何使用 MMCCregress 找出两个分类变量的均值差异并绘制密度。

我的密码是

library(MCMCpack)
data("crabs") 
out <- MCMCregress(sex~sp , data = data, family=binomial)
summary(out)

我不断收到错误消息-

Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, : NA/NaN/Inf in 'y'

我应该怎么做才能解决这个问题?

我注意到 sex 变量是 factor。您可以简单地将 factor 转换为 numeric 并且您的代码将起作用。这是代码,

library(MCMCpack)
data("crabs") 
out <- MCMCregress(as.numeric(sex)~sp , data = crabs, family=binomial)
summary(out)

Iterations = 1001:11000
Thinning interval = 1 
Number of chains = 1 
Sample size per chain = 10000 

1. Empirical mean and standard deviation for each variable,
   plus standard error of the mean:

                  Mean      SD  Naive SE Time-series SE
(Intercept)  1.5002783 0.05052 0.0005052      0.0005052
spO         -0.0003147 0.07202 0.0007202      0.0007202
sigma2       0.2551607 0.02597 0.0002597      0.0002637

2. Quantiles for each variable:

               2.5%      25%        50%     75%  97.5%
(Intercept)  1.4016  1.46639  1.5005847 1.53420 1.5996
spO         -0.1433 -0.04842 -0.0009755 0.04696 0.1420
sigma2       0.2091  0.23688  0.2534471 0.27180 0.3105