0

我是 R 和编码的初学者,目前正在使用 R 的贝叶斯网络分析结果。我有这个代码,将收益率结果作为概率及其 95% 的凭证间隔。

这是我用来根据吸烟状况和社会阶层预测当前哮喘的代码示例。我想要的是一种将我从两个查询中得到的结果组织到一个表中的方法。我有大约 48 个查询,从所有这些查询中复制和粘贴结果既繁琐又耗时。有什么帮助吗?

## probability of current asthma among non smoker in social class 1##
> cpquery(fitted.simpler_mice_hc, event = (c_asthma == 1) , evidence = (smoking_status == 0 & sei_class==1), n=100000)

[1] 0.09212951
 
> run_1<- replicate(100, cpquery(fitted.simpler_mice_hc, event = (c_asthma == 1) , evidence = (smoking_status == 0 & sei_class==1), n=100000))
> 
> # to get the sampling quantile interval
> quantile(run_1, c(0.05,0.975))

        5%      97.5% 
0.08218354 0.09254333 

> ### non smokers in sei2, age , gender,diabtets, dust and hypertension###
> cpquery(fitted.simpler_mice_hc, event = (c_asthma == 1) , evidence = (smoking_status == 0 & sei_class==2), n=100000)
[1] 0.08623836
> 
> run_2 <- replicate(100, cpquery(fitted.simpler_mice_hc, event = (c_asthma == 1) , evidence = (smoking_status == 0 & sei_class==2), n=100000))
> 
> # to get the sampling quantile interval
> quantile(run_2, c(0.05,0.975))
        5%      97.5% 
0.08279396 0.09144179 

在第一个查询中,0.09212951 是概率,0.08218354 0.09254333 是区间的下限和上限,如何将这些查询组织到一个表中,或者用 excel 轻松处理而不是复制和粘贴每个查询?

4

0 回答 0