# Statistical testing of step variables

I have three variables I'd like to analyze. Two of them are step values - one set ranges from 1-6 and the other ranges from 1-5. The third variable is not a step value but can have a relatively wide range of possible values. I'm trying to determine if my third variable is related/correlated to either of the two step values.

The step values represent differing pay grades and rankings while the non-step variable represents pay. How can I test if pay is related to pay grade and/or rankings? And is there a way to graph all three variables in one chart?

-

## migrated from stackoverflow.comSep 18 '09 at 15:54

This question came from our site for professional and enthusiast programmers.

Why was this migrated from SO? – J. Polfer Sep 21 '09 at 13:07

## 3 Answers

Should be able to graph that with a 3-d surface graph or "forest graph"- the two step functions define the plane and the non-step value is the elevation.

To analyze the correlation, I'd define a combined step function over the thirty cells defined by the plane of the two existing step functions.

-

JHC - R Statistical is an open source statistics package that runs on all major platforms (http://www.r-project.org/) and does a very nice job of analysis. The following sample code would take copied data (columns of Rank, Grade and Pay) and give you the analysis you're looking for.

mydata <- read.table("clipboard",header=TRUE);

response=mydata\$Pay~mydata\$Rank+mydata\$Grade;

plot(response);

coplot(Rank ~ Grade | Pay, data = mydata);

fit=lm(response);

afit=anova(fit);

afit;

plot(fit);

cor(mydata\$Rank,mydata\$Grade)

(for more - search help using the following commands:) help(lm); help(anova); help(coplot);

-

Sorry JDB - I tried R and I'm just not understanding it. I can't get R to read in my data (heck I can't even figure out where R wants me to put the data).

From what I'm seeing in the code example though. you're suggesting using an ANOVA test? Is there any reason the cor function only looks at Rank and Grade?

-
@user11629: read.table("clipboard") will read in data from the clipboard in Windows (you have to have copied the data from another program/text editor/etc.) As far as the cor function - a simple correlation only looks at two variables. cor(mydata\$Rank,mydata\$Grade) could also be cor(mydata\$Rank,mydata\$Pay) or cor(mydata\$Pay,mydata\$Grade). Since the question was about graphing these variables and determining correlations, this would get the job done. However, the original asker does need to consider the statistics behind these analyses. – JDB Oct 20 '10 at 15:59