Hi, I've got 4 variables that I want to effectively 'stack' so that I have a grand R variable and a grand L variable.
This works to achieve that goal: Twin1cor<-with(twin.wide,cbind(ACDepthR.1,ACDepthL.1)) Twin2cor<-with(twin.wide,cbind(ACDepthR.2,ACDepthL.2)) Both<-rbind(Twin1cor,Twin2cor) > str(Both) num [1:1858, 1:2] 3.36 NA NA NA NA NA NA 3.92 3.5 NA ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:2] "ACDepthR.1" "ACDepthL.1" I then want to perform a pearson correlation of the two variables, but exclude any value greater than 2.5. When I do this without excluding anything, with: cor.test(Both[,1],Both[,2]) I get: Pearson's product-moment correlation data: Both[, 1] and Both[, 2] t = 35.848, df = 854, p-value < 2.2e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.7468716 0.8005199 sample estimates: cor 0.7750889 But when I try: cor.test(Both[,1]>2.5,Both[,2]>2.5) I get: Pearson's product-moment correlation data: Both[, 1] > 2.5 and Both[, 2] > 2.5 t = 13.3192, df = 854, p-value < 2.2e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.3576600 0.4687099 sample estimates: cor 0.414728 I'm not sure why. I know the correlation should improve from the plot by excluding those under 2.5, but it decreases. Have I done something wrong here? Thanks, Paul -- View this message in context: http://n4.nabble.com/use-logical-in-cor-test-tp1744701p1744701.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.