What is the difference between x[,1]
and x$col1
? The spcor function below works fine for the first option, but fails with the second. Both options work if I cast my matrix to a dataframe.
library(matrixcalc)
library(ppcor)
exampledf<- matrix(ceiling(runif(16,0,50)), ncol=4)
while(is.singular.matrix(exampledf)!=TRUE){
exampledf<- matrix(ceiling(runif(16,0,50)), ncol=4)
}
colnames(exampledf)<-c("col1","col2","col3","col4")
x<-exampledf
x<-x[complete.cases(x),] #semi-partial func below requires complete cases
spcor.test(x$col1,x$col2,x$col3) #doesnt work unless cast to data.frame for some reason
spcor.test(x[,1],x[,2],x[,3]) #works fine