1
$\begingroup$

I have three variables:

  • GENDER {“Male”, “Female”}
  • AGE {“0-18”, “19-30”, “30-60”, “60+”}
  • REGION {“Europe”, “Asia”, “Africa”, “America”}

From the literature I “know” that:

Males who live in Asia and who fall into 19-30 age group have 5% probability of having certain disease. Males in general have 3% probability of having the same disease Asian .. teenagers have average of 2% Americans 4% etc.

The point is that I have some knowledge and I want to record it in a network “format” and I would like to use that network in future.

I’m no R expert but I was reading lately about “bnlearn” package. It looks like it is exactly what I need but I can’t get my head around it! Am I on the right track? How do I specify my probabilities?

library(bnlearn);
net <- model2network("
[Gender.Male]
[Gender.Female]

[Region.Asia]
[Region.Europe]
[Region.America]

[Age.18.24]
[Age.24.30]
[Age.30.35]
[Age.45.50]
[Age.50.plus]
");
plot(net);

I actually have ~30 variables with up to 10 levels each.

$\endgroup$
  • $\begingroup$ @william, please stop spamming the site w/ tag edits. This shouldn't be done this way. You should raise the issue on meta.CV & we can make it a synonym. $\endgroup$ – gung - Reinstate Monica May 1 '16 at 19:32
1
$\begingroup$

I believe that a package like gRain may be more what you're looking for. This package has an article explaining it that should give you a flavor of how it works.

EDIT: I think you would do something like:

library (gRain)
region <- cptable (~region, values=c(0, 0, 0, 0), levels=c("Europe", "Asia", "Africa", "America"))
gender <- cptable (~gender + region, values=c(0, 0, 0, 0, 0, 0, 0, 0), levels=c("Male", "Female"))
age    <- cptable (~age + region, values=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), levels=c("0-18", "19-30", "30-60", "60+"))
disease <- cptable (~disease + region + gender + age, values=rep (0, 2*4*2*4), levels=c("Y", "N"))

plist <- compileCPT (list (region, gender, age, disease))
grn1 <- grain (plist)

summary (grn1)
plot (grn1)

Where the 0 values should actually be your percentages.

$\endgroup$
  • $\begingroup$ Still no good. I spent hours trying to get it to work. Any other ideas? $\endgroup$ – user13467 Jul 12 '13 at 14:19
  • $\begingroup$ Do I need a state for each attribute of the variable or is it could be achieved in some other way... $\endgroup$ – user13467 Jul 12 '13 at 14:20
  • $\begingroup$ gRain seems to be dependent on graph package which is not available anymore. I hope bnlearn or similar packages can do the same $\endgroup$ – user13467 Jul 22 '13 at 10:12
  • $\begingroup$ You get graph from the Bioconductor package. In the R Package Installer (Mac version, at least) choose BioConductor(binaries). $\endgroup$ – Wayne Jul 22 '13 at 12:37
  • $\begingroup$ Hi Wayne. Thanks for that. I searched in the list of packages (from R installer) and there is no package called Bioconductor... do you have a direct link maybe? $\endgroup$ – user13467 Jul 22 '13 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.