I am in a bind.
I am trying to create an interaction plot between some variables to determine their impact on the response.
The data is at http://faculty.chicagobooth.edu/nicholas.polson/teaching/41000/election2012.txt
I could not figure out how to do interaction plots in R, but I found a site that demonstrated a user defined function executing interaction plots:
– http://alumni.media.mit.edu/~tpminka/courses/36-350.2001/lectures/day30/
The user defined functions are located here
Using this user defined function, I am trying to create an interaction plot with
Response: VP
Predictors: G and P (I would also like to include Z, but I am having enough trouble with 2 variables so I have put that on the back burner)
(VP,G,& P are columns in the initial data set above.)
Every time I try to plug in my values, R throws me errors, claiming objects G and P are not found etc. I also tried to use the interaction.plot function, but it would draw me a blank chart, and when I changed parameters, I would get an error claiming that a variable was an atomic vector, but when I plugged the same variable into the predict.plot function (the user defined one from the MIT site) R threw an error because the same variable supposedly wasn’t atomic.
How can I make a 2 variable interaction plot like the one on the MIT site with my data (and if anyone is so inclined, how can I make it with 3 variables)?
Solved:
The problem was that I was attempting to pass column names from a data frame into the predict.plot and interaction.plot functions.
I had to convert the columns to matrices and then pass those matrices into the functions. Now everything works.
To convert data frames to matrices, use
MatrixVari = as.matrix(listColumni)
where each listColumni is a column from your data frame that you then read into its own matrixVari.