# [R] Missing data (Na) and chi-square tests

Rerda gerda.lindsted at gmail.com
Mon Oct 8 18:06:44 CEST 2012

```Dear Rui and David
Thank you very much for taking your time to look at my problem.
However, I still cannot seem to figure it out.

I think that you David are corect in your assumption of how my data is
structured. The data in the two columns that I need to cross-table is either
1 or 0.
I made a mistanke in the formula that I sent to you. The one I use is:
data <- matrix(c(sum(!Variable[Group....==1]), sum(Variable[Group....==1]),
sum(!Variable[Group....==0]), sum(Variable[Group....==0])),2,2)

This is the output of >dput( head(MyData, 20) ):

structure(list(Patient.nr = c(1L, 3L, 4L, 5L, 6L, 7L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 19L, 20L, 21L, 22L, 23L, 24L),
DAAC.... = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), TAA = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), Sex = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L), Alder = c(1L, 6L,
3L, 3L, 6L, 6L, 2L, 6L, 5L, 2L, 6L, 4L, 6L, 2L, 2L, 5L, 3L,
6L, 6L, 6L), Reak.1 = structure(c(2L, 1L, 2L, 2L, 1L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L), .Label = c("0",
"1", "na"), class = "factor"), Reak.2 = structure(c(1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 1L), .Label = c("0", "2", "na"), class = "factor"),
Reak.3 = structure(c(1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L), .Label = c("0",
"3", "na"), class = "factor"), Reak.4 = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("0", "4", "na"), class = "factor"),
Tryptase = structure(c(1L, 1L, 1L, 3L, 1L, 3L, 1L, 2L, 2L,
1L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 2L, 1L), .Label = c("0",
"1", "na"), class = "factor"), Hypotension = c(0L, 1L, 0L,
0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
1L, 0L), Tachycardia = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L), Br.spasm. = c(0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), Angioedema = c(0L, 0L, 0L, 1L, 0L, 1L, 0L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L), Urticaria = c(0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), Flush. = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Rash = c(1L,
0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L,
1L, 1L, 0L, 1L), Pruritus = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L), Transf. = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L)), .Names = c("Patient.nr", "DAAC....", "TAA",
"Sex", "Alder", "Reak.1", "Reak.2", "Reak.3", "Reak.4", "Tryptase",
"Hypotension", "Tachycardia", "Br.spasm.", "Angioedema", "Urticaria",
"Flush.", "Rash", "Pruritus", "Transf."), row.names = c(NA, 20L
), class = "data.frame")

And I still can get it to work.
Is it possible to put is.na(Variable) or something into my formula?

I understand if it is to difficult to figure it put.
Thank you very much

Kind Regards Gerda

--
View this message in context: http://r.789695.n4.nabble.com/Missing-data-Na-and-chi-square-tests-tp4645167p4645464.html
Sent from the R help mailing list archive at Nabble.com.

```