0
votes

I'm currently working with data from a questionnaire where answers have been added up to find before and after scores and subsequently subtracted to find differences. I am trying to run a Mann-Witney U test to test if there is a difference between the difference scores after viewing different educational interventions. The data is arranged so one column is the differences from the first educational intervention and the second column is the differences from the second educational intervention. When I run the code:

wilcox.test(formula=opinion$video~opinion$writtenpiece)

I get this error:

Error in model.frame.default(formula = opinion$video ~ opinion$writtenpiece) : invalid type (NULL) for variable 'opinion$video'

I've tried everything I can think of to make it work and continue to get the same error. Does anyone have any ideas what I'm doing wrong? It's been a long time since I've used R for data analysis and I've never done it for this type of data, so I'm sure I'm missing something.

This is what the data looks like (I'm not sure why my numbers have an L next to them...)

dput(opinion)

structure(list(Video = c(11L, 12L, 10L, 10L, 9L, 9L, 13L, 13L, 10L, 12L, 12L, 12L, 13L, 11L, 15L, 11L, 15L, 12L, 17L, 12L, 10L, 14L, 13L, 12L, 12L, 10L, 9L, 11L, 11L, 14L, 13L, 14L, 14L, 11L, 12L, 13L, 12L, 13L, 14L, 11L, 10L, 12L, 13L, 15L, 15L, 10L, 11L, 13L, 12L, 11L, 12L, 9L, 10L, 12L, 14L, 10L, 10L, 9L, 11L, 11L, 10L, 9L, 10L, 10L, 16L, 7L, 9L, 10L, 10L, 16L, 13L, 11L, 10L, 6L, 11L, 10L, 13L, 10L, 13L, 12L, 10L, 15L, 0L, 0L, 0L, 0L, 0L, 0L), Written.Piece = c(10L, 11L, 10L, 10L, 10L, 7L, 10L, 9L, 13L, 13L, 12L, 8L, 13L, 12L, 15L, 10L, 9L, 11L, 10L, 11L, 13L, 10L, 12L, 11L, 11L, 11L, 10L, 15L, 10L, 13L, 14L, 11L, 11L, 12L, 9L, 15L, 11L, 14L, 11L, 12L, 12L, 14L, 10L, 10L, 10L, 9L, 13L, 13L, 10L, 9L, 9L, 13L, 8L, 13L, 14L, 9L, 12L, 11L, 11L, 12L, 10L, 13L, 16L, 12L, 10L, 8L, 13L, 16L, 17L, 12L, 11L, 13L, 11L, 11L, 9L, 10L, 12L, 12L, 10L, 14L, 12L, 11L, 12L, 11L, 12L, 10L, 10L, 12L)), .Names = c("Video", "Written.Piece"), class = "data.frame", row.names = c(NA, -88L))

1
R is telling you that the variable doesn't exist.Roland
Roland how could one exist and one not? As it always says it's for the video one. The video has fewer scores than the written piece but I even tried putting in code to ignore NAs.Snow Dickson

1 Answers

0
votes

It looks like the command you're using to run your wilcox.test isn't correctly referencing your data. Specifically, from your dput it appears that the Video and Written.Piece variables are capitalized. Try running this code:

melt.opinion <- melt(opinion, 
                       id.vars = c(), 
                       measure.vars = c("Video", "Written.Piece"), 
                       variable.name = "intervention.type", 
                       value.name = "difference.value")
wilcox.test(formula = 
              melt.opinion$difference.value ~ melt.opinion$intervention.type)