0

I am running a Rayleigh Test of Uniformity in R. I have my data frame subsetted to 3 columns with slightly differing degrees. When it then run tests selecting one of the columns, my results vary depending on how I have selected the column to use in the test: [c"Direction"] or df$Direction.

My df:

Direction Dir180 CorrDirection    Sex Location
1       146    146           128 Female      Low
2       129    129           111   Male      Low
3       337    157           319 Female      Low
4       130    130           112 Female      Low
5       216     36           198 Female      Low
6       351    171           333   Male      Low

Test:

r.test(x=df2[c("Direction")],degree=T)
r.test(x=df2$Direction,degree=T)

Test results:

> r.test(x=df2[c("Direction")],degree=T)
$r.bar
[1] 3.265616

$p.value
[1] 0.002646553

> r.test(x=df2$Direction,degree=T)
$r.bar
[1] 0.03887638

$p.value
[1] 0.880773

I would like to know why I am getting different results when to me it looks like I am selecting the same column for the tests. What is the difference between using the two different methods and how does the test or program respond to each? Thanks

Kyle Finn
  • 29
  • 5

1 Answers1

0

The issue is that first is a data.frame with single column and second is a vector. If we extract the column as a vector either by including the , for the column index (if it is tibble, use [[). According to the ?r.test

r.test(x, degree=FALSE)

x - vector of angular measurements in radians.

So it expects a vector and not a data.frame

library(CircStats)
r.test(x=df2[,c("Direction")],degree=TRUE)
#$r.bar
#[1] 0.2321319

#$p.value
#[1] 0.740345

result would be the same with $ extraction as we are dealing with vector

r.test(x=df2$Direction,degree=T)
#$r.bar
#[1] 0.2321319

#$p.value
#[1] 0.740345

data

df2 <- structure(list(Direction = c(146L, 129L, 337L, 130L, 216L, 351L
), Dir180 = c(146L, 129L, 157L, 130L, 36L, 171L), CorrDirection = c(128L, 
111L, 319L, 112L, 198L, 333L), Sex = c("Female", "Male", "Female", 
"Female", "Female", "Male"), Location = c("Low", "Low", "Low", 
"Low", "Low", "Low")), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6"))
akrun
  • 874,273
  • 37
  • 540
  • 662