Bayesian networks in R with the gRain package
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Bayesian networks in R with the gRain package
Søren Højsgaard
Aalborg University,Denmark
gRain version1.2-5as of2015-12-29
Contents
1Introduction1 2A worked example:chest clinic2
2.1Building a network (2)
2.2Queries to networks (3)
3A one–minute version of gRain3
3.1Specifying a network (3)
3.2Querying a network (4)
3.3Conditioning on evidence with zero probability (5)
4Hard and virtual(likelihood)evidence7
4.1An excerpt of the chest clinic network (7)
4.2Specifying hard evidence (8)
4.3What is virtual evidence(also called likelihood evidence)? (9)
4.4Specifying virtual evidence (10)
4.5A mixture of a discrete and a continuous variable (10)
5Building networks from data11
5.1Extracting information from tables (11)
5.2Using smooth (12)
5.3Extracting tables (13)
1Introduction
The gRain package implements propagation in[gra]phical[i]ndependence[n]etworks(hereafter ab-breviated grain).Such networks are also known as probabilistic networks and Bayesian networks. To cite gRain in publications,please use:
Søren Højsgaard(2012).Graphical Independence Networks with the gRain Package
for R.Journal of Statistical Software,46(10),1-26./v46/
i10/.
and possibly also
Søren Højsgaard,David Edwards and Steffen Lauritzen(2012).Graphical Models with
R.Springer
More information about the package,other graphical modelling packages and development versions is available from
http://people.math.aau.dk/~sorenh/software/gR
2A worked example:chest clinic
This section reviews the chest clinic example of Lauritzen and Spiegelhalter(1988)(illustrated in Figure1)and shows one way of specifying the model in uritzen and Spiegelhalter(1988) motivate the chest clinic example as follows:
“Shortness–of–breath(dyspnoea)may be due to tuberculosis,lung cancer or bronchitis,
or none of them,or more than one of them.A recent visit to Asia increases the chances
of tuberculosis,while smoking is known to be a risk factor for both lung cancer and
bronchitis.The results of a single chest X–ray do not discriminate between lung cancer
and tuberculosis,as neither does the presence or absence of dyspnoea.”
asia tub
smoke
lung
bronc
either
xray dysp Figure1:Chest clinic example from LS.
2.1Building a network
A Bayesian network is a special case of graphical independence networks.In this section we outline how to build a Bayesian network.The starting point is a probability distribution factorising accoring to a DAG with nodes V.Each node v∈V has a set pa(v)of parents and each node v∈V has afinite set of states.A joint distribution over the variables V can be given as
p(V)=
v∈V
p(v|pa(v))(1)
where p(v|pa(v))is a function defined on(v,pa(v)).This function satisfies that
v∗
p(v=
v∗|pa(v))=1,i.e.that for each configuration of the parents pa(v),the sum over the levels of v equals one.Hence p(v|pa(v))becomes the conditional distribution of v given pa(v).In practice p(v|pa(v))is specified as a table called a conditional probability table or a CPT for short.Thus, a Bayesian network can be regarded as a complex stochastic model built up by putting together simple components(conditional probability distributions).
Thus the DAG in Figure1dictates a factorization of the joint probability function as
p(V)=p(α)p(σ)p(τ|α)p(λ|σ)p(β|σ)p( |τ,λ)p(δ| ,β)p(ξ| ).(2)