R Show P-value results of lm as matrix -
i have data frame containing multiple socio-economic factors correspondent obersvations. want run lm-analysis on of them , form new matrix(or data frame) contains pvalues each combination of variables.
my original data in matrix sfi.matrix , contains 7 rows each 12 entries.
i tried following: 1.) build result matrix 2.) run lm of different combinations 3.) combine results in result matrix.
my code looks follows:
levene.tests.results <- matrix(1, nr=7, nc=7) rownames(levene.tests) <- colnames(levene.tests) <- colnames(sfi.matrix) for(i in 1:7) { for(j in 1:7) { levene.tests <- lm(sfi.matrix[,i] ~ sfi.matrix[,j])$p.value }}
my problem result matrix [n=7,m=7] nas.
i appreciate advise :-)
also, not sure whether works because data entries rates... can me this?
thanks advice of @benbolker able solve problem. indeed, lm wrong function. correct function test.cor brings useful results:
correlations<- matrix( nrow=7, ncol=7) for(i in 1:7) { for(j in 1:7) { correlations[i,j] <- cor.test( sfi.matrix[,i], sfi.matrix[,j] )$p.value } }
thank once more, stackoverflow!
Comments
Post a Comment