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

Rui Barradas ruipbarradas at sapo.pt
Tue Oct 9 02:23:40 CEST 2012


Hello,

Also, since the values are always 0/1, this should also do it.

with( dat, table( Rash, Hypotension ) )

Hope this helps,

Rui Barradas

Em 09-10-2012 00:36, David Winsemius escreveu:
> On Oct 8, 2012, at 9:06 AM, Rerda wrote:
>
>> 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)
> Hardly seems surprising that is not working, ... the is no "Group...." column in the data. Furthermore you would not need to use sum( !Variable[Group....==1] as well as sum(Variable[Group....==1]). The `table` function will do that for you.
>
> Given my personal memory of having a hypotensive episode as I stood at the counter of a pharmacy asking for epinephrine and a syringe to treat my urticarial reaction to shellfish, I picked these two:
>
>> with( MyData, table( Rash= as.logical(Rash), Hypotension = as.logical(Hypotension) ) )
>         Hypotension
> Rash    FALSE TRUE
>    FALSE     3    7
>    TRUE      7    3
>
> Best;
> David.
>
>
>>
>> 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.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> David Winsemius, MD
> Alameda, CA, USA
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list