Omni test for statistical significance

In survey research, our datasets nearly always comprise variables with mixed measurement levels - in particular, nominal, ordinal and continuous, or in R-speak, unordered factors, ordered factors and numeric variables. Sometimes it is useful to be able to do blanket tests of one set of variables (possibly of mixed level) against another without having to worry about which test to use.

For this we have developed an omni function which can do binary tests of significance between pairs of variables, either of which can be any of the three aforementioned levels. We have also generalised the function to include other kinds of variables such as lat/lon for GIS applications, and to distinguish between integer and continuous variables, but the version I am posting below sticks to just those three levels. Certainly one can argue about which tests are applicable in which precise case, but at least the principle might be interesting to my dear readeRs.

I will write another post soon about using this function in order to display heatmaps of significance levels.

The function returns the p value, together with attributes for the sample size and test used. It is also convenient to test if the two variables are literally the same variable. You can do this by providing your variables with an attribute “varnames”. So if attr(x,“varnames”) is the same as attr(y,“varnames”) then the function returns 1 (instead of 0, which would be the result if you hadn’t provided those attributes).

havevarnames=!is.null(attr(v1,“varnames”)) & !is.null(attr(v2,“varnames”))notsame=T; if (havevarnames)notsame=attr(v1,“varnames”)!=attr(v2,“varnames”)if(!havevarnames) warning(paste(“If you don’t provide varnames I can’t be sure the two variables are not identical”),attr(v2,“label”),attr(v2,“label”))if(notsame | !havevarnames){

##TODO think if these are the best testselse if(level1==“con” & level2==“con”){# ;pp=cor.test(as.numeric(v1),as.numeric(v2))p=pp$p.valueattr(p,“method”)=“Pearson correlation”attr(p,“estimate”)=pp$estimate