Seite 1 von 1

Liste in contingency table umwandeln

Verfasst: Do Feb 14, 2019 9:56 pm
von Curnen
Hallo liebe Forum-Community,

Ich möchte einen Cochran-Mantel-Haenszel Chi-Squared Test durchführen und verzweifle gerade daran, meine Daten in das dazu nötige Table-Format zu bringen. Ich hab mir den Datensatz UCBAdmissions angeschaut, wie der aussieht und versucht, das bei mir nachzubauen:

Code: Alles auswählen

mydata <- structure(list(H3K27ac_Common_I_clade_1 = structure(c(90L, 177L, 
1125L, 586L), .Dim = c(2L, 2L), .Dimnames = list(c("observed_CAGE_enhancers", 
"observed_other_enhancers"), c("in clade", "in cluster"))), H3K27ac_Common_I_clade_2 = structure(c(83L, 
290L, 1132L, 473L), .Dim = c(2L, 2L), .Dimnames = list(c("observed_CAGE_enhancers", 
"observed_other_enhancers"), c("in clade", "in cluster"))), H3K27ac_Common_I_clade_3 = structure(c(109L, 
20L, 1106L, 743L), .Dim = c(2L, 2L), .Dimnames = list(c("observed_CAGE_enhancers", 
"observed_other_enhancers"), c("in clade", "in cluster"))), H3K27ac_Common_I_clade_4 = structure(c(292L, 
52L, 923L, 711L), .Dim = c(2L, 2L), .Dimnames = list(c("observed_CAGE_enhancers", 
"observed_other_enhancers"), c("in clade", "in cluster"))), H3K27ac_Common_I_clade_5 = structure(c(151L, 
12L, 1064L, 751L), .Dim = c(2L, 2L), .Dimnames = list(c("observed_CAGE_enhancers", 
"observed_other_enhancers"), c("in clade", "in cluster"))), H3K27ac_Common_I_clade_6 = structure(c(132L, 
115L, 1083L, 648L), .Dim = c(2L, 2L), .Dimnames = list(c("observed_CAGE_enhancers", 
"observed_other_enhancers"), c("in clade", "in cluster")))), .Names = c("H3K27ac_Common_I_clade_1", 
"H3K27ac_Common_I_clade_2", "H3K27ac_Common_I_clade_3", "H3K27ac_Common_I_clade_4", 
"H3K27ac_Common_I_clade_5", "H3K27ac_Common_I_clade_6"))
Das ist noch eine Liste, aber schon mal so strukturiert, wie es wohl aussehen muss. Im Hilfetext zu ?table steht zwar one or more objects which can be interpreted as factors (including character strings), or a list (or data frame) whose components can be so interpreted. (For as.table, arguments passed to specific methods; for as.data.frame, unused.), aber

Code: Alles auswählen

as.table(mydata)
Fehler in as.table.default(mydata) : kann nicht in eine Tabelle umwandeln
Leider ist bei den Beispielen keines mit einer Liste dabei :-(

Kann man das doch irgendwie einfach konvertieren oder soll ich lieber die Liste gar nicht erst so bauen?

Viele Grüße und Danke
Matthias

Re: Liste in contingency table umwandeln

Verfasst: Sa Feb 16, 2019 10:08 pm
von Curnen
Ich hab es doch noch gelöst. Erst mal ein anderes Problem bearbeiten und mit etwas Abstand war es dann eine Sache von fünf Minuten...

Code: Alles auswählen

mytable <- as.table(array(unlist(mydata),
                 dim=c(2,2,length(mydata)),
                 dimnames = list(rownames(mydata[[1]]),colnames(mydata[[1]]),names(mydata))))
Danke allen, die sich ebenfalls Gedanken gemacht haben!

VG
Matthias