From 72cc839ab39a2ef6cc596388992ba884cc820d63 Mon Sep 17 00:00:00 2001
From: Walmes Zeviani <walmes@ufpr.br>
Date: Thu, 1 Oct 2015 14:29:29 -0300
Subject: [PATCH] Script R to prepare ahs.RData.

---
 data-raw/ahs.R | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 data-raw/ahs.R

diff --git a/data-raw/ahs.R b/data-raw/ahs.R
new file mode 100644
index 0000000..0d45243
--- /dev/null
+++ b/data-raw/ahs.R
@@ -0,0 +1,66 @@
+##----------------------------------------------------------------------
+## Prepare de the data set.
+
+setwd("/home/walmes/GitLab/mcglm/data-raw")
+
+ahs <- read.table("ahs.txt", header=TRUE, sep="\t")
+str(ahs)
+
+ahs$sex <- factor(ahs$sex, labels=c("male", "female"))
+str(ahs)
+
+xtabs(~chcond1+chcond2, data=ahs)
+
+ahs$chcond <- factor(with(ahs, chcond1+2*chcond2),
+                     labels=c("otherwise", "not limited", "limited"))
+xtabs(~chcond, data=ahs)
+ahs$chcond1 <- NULL
+ahs$chcond2 <- NULL
+ahs$id <- NULL
+
+names(ahs)[c(1:9, 15, 10:14)]
+ahs <- ahs[, c(1:9, 15, 10:14)]
+str(ahs)
+
+save(ahs, file="../data/ahs.RData")
+
+##----------------------------------------------------------------------
+## Include in the @examples
+
+library(lattice)
+library(latticeExtra)
+
+data(ahs, package="mcglm")
+str(ahs)
+
+xt <- xtabs(~age+sex, data=ahs)
+mosaicplot(xt)
+
+xt <- xtabs(~age+chcond, data=ahs)
+mosaicplot(xt)
+
+useOuterStrips(
+    combineLimits(
+        xyplot(Ndoc+Nndoc+Nadm+Nhosp+Nmed~age|sex,
+               outer=TRUE, data=ahs,
+               jitter.x=TRUE, amount=0.01,
+               type=c("p", "a"),
+               scales=list(y=list(relation="free")),
+               ylab="Number or occurences",
+               xlab="Age (years/100)")
+    )
+)
+
+useOuterStrips(
+    combineLimits(
+        xyplot(Ndoc+Nndoc+Nadm+Nhosp+Nmed~income|sex,
+               outer=TRUE, data=ahs,
+               jitter.x=TRUE, amount=0.01,
+               type=c("p", "a"),
+               scales=list(y=list(relation="free")),
+               ylab="Number or occurences",
+               xlab="Age (years/100)")
+    )
+)
+
+##----------------------------------------------------------------------
-- 
GitLab