Greetings, I have two files which contain responses to a series of multiple choice questions. One file contains responses before an "intervention" and the other contains the responses afterward. There were three possible responses to each question: D, F, T (for Don't Know, False, and True). I would like to try McNemar's test to determine if there was any significant difference between before and after. I read the files. I create tables using: firstQuestion <- table( PreSurveyData$q1, PostSurveyData$q2) for example. The problem is that for several of the questions not all of the possible responses appear. So I get a table like this: T D 6 F 2 T 12 Which cannot be used in mcnemar.test because it is not a square table and does not have enough rows and columns. Is there some way to specify that R should count the occurrences of D, F, and T even though they do not appear in the Data? Or some easy way to add the missing columns? Thank you, Jeffrey Edgington
Try this: table(factor(pre, levels = c("D", "F", "T")), factor(post, levels = c("D", "F", "T"))) On Mon, Jun 22, 2009 at 8:56 PM, Jeffrey Edgington <jedgingt@du.edu> wrote:> Greetings, > > I have two files which contain responses to a series of multiple choice > questions. One > file contains responses before an "intervention" and the other contains the > responses afterward. > > There were three possible responses to each question: D, F, T (for Don't > Know, False, and True). > > I would like to try McNemar's test to determine if there was any > significant difference between before > and after. > > I read the files. I create tables using: > > firstQuestion <- table( PreSurveyData$q1, PostSurveyData$q2) > > for example. > > The problem is that for several of the questions not all of the possible > responses appear. So I get > a table like this: > > T > D 6 > F 2 > T 12 > > Which cannot be used in mcnemar.test because it is not a square table and > does not have enough rows and columns. > > Is there some way to specify that R should count the occurrences of D, F, > and T even though they do not appear > in the Data? Or some easy way to add the missing columns? > > Thank you, > > Jeffrey Edgington > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
On Jun 22, 2009, at 7:56 PM, Jeffrey Edgington wrote:> Greetings, > > I have two files which contain responses to a series of multiple > choice questions. One > file contains responses before an "intervention" and the other > contains the responses afterward. > > There were three possible responses to each question: D, F, T (for > Don't Know, False, and True). > > I would like to try McNemar's test to determine if there was any > significant difference between before > and after. > > I read the files. I create tables using: > > firstQuestion <- table( PreSurveyData$q1, PostSurveyData$q2) > > The problem is that for several of the questions not all of the > possible responses appear. So I get > a table like this: >Missing cells added: T D F D 6 0 0 F 2 0 0 T 12 0 0> > Which cannot be used in mcnemar.test because it is not a square > table and does not have enough rows and columns. > > Is there some way to specify that R should count the occurrences of > D, F, and T even though they do not appear in the Data? Or some > easy way to add the missing columns?You might want to exercise appropriate care regarding the validity concerns, since you obviously have quite a few zero entries. -- David Winsemius, MD Heritage Laboratories West Hartford, CT
Possibly Parallel Threads
- McNemar test in R & SPSS
- Problem applying McNemar's - Different values in SPSS and R
- mcnemar.test odds ratios, CI, etc.
- Can I use "mcnemar.test" for 3*3 tables (or is there a bug in the command?)
- Using McNemar's test to detect shifts in response from pre- to post-treatment