Say I have two dataframes, one with a set of explanatory variables and another with a set of response variables.
Explanatory <- as.data.frame(matrix(sample(0:15, 4*20, replace=TRUE), ncol=4))
Response <- as.data.frame(matrix(sample(0:15, 4*20, replace=TRUE), ncol=4))
How do I conduct several second-order polynomial regressions between all individual explanatory and response variables and output a matrix of p-values?
I can do this for a normal linear regression...
Linear <- lapply(Explanatory, function (x) lm(x~., data = Response))
sapply(Linear, function(f) summary(f)$coefficients[,4])
But when I do the same thing for a polynomial...
Polynomial <- lapply(Explanatory, function (x) lm(x~poly(.,2), data = Response))
...I get this error message ' Error in poly(., 2) : anyNA() applied to non-(list or vector) of type 'closure' '
Thank you in advance for any help!