Isak Aarrestad

I am a beginner with R, so hopefully this will be an easy fix.

I am trying to use a for loop on a dataset for neuron firing direction in order to:

- Incrementally add the next value from the dataset to a vector
- Run a Rayleigh test on that vector and save it to a variable
- Test if the Rayleigh test I just ran has a larger statistic than the the Rayleigh test in the last loop just before it, as well as having a p-value of less than .05
- If the value is larger, save the statistic value, so that the next loop can compare to it
- If the value is larger, save the vector

So far I have this for the code, and after going through it for a long time I'm at a loss for why it's not working. Every time I run it, the for loop goes all the way to the end and just reports the rayleigh value and vector for the whole dataset, which I know for sure isn't correct. (I'm using the circular package for the rayleigh test function)

```
# This first line is just to create an initial rayleigh statistic to compare to in the loop that is low
best_rayleigh <- rayleigh.test(1:10)
data_vector <- c()
for (i in firing_directions) {
data_vector <- append(data_vector, i)
ray_lee_test <- rayleigh.test(data_vector)
if ((ray_lee_test$statistic>best_rayleigh$statistic)&(ray_lee_test$p.value<=.05)) {
best_rayleigh <- ray_lee_test
best_rayleigh_vector <- data_vector
} else {
NULL
}
}
```

Any help is appreciated. Thank you!

Update: I tried using && instead of single & in the if statement, however it returned the same result

Rui Barradas

The following code doesn't give warnings and selects the vector with highest test statistic and "significant" p-value.

```
library(circular)
set.seed(2020)
firing_directions <- rvonmises(n = 25, mu = circular(pi), kappa = 2)
plot(firing_directions)
best_rayleigh <- rayleigh.test(circular(1:10))
for(i in seq_along(firing_directions)){
dv <- firing_directions[seq_len(i)]
rltest <- rayleigh.test(dv)
if((rltest$statistic > best_rayleigh$statistic) && (rltest$p.value <= 0.05)){
best_rayleigh <- rltest
best_rayleigh_vector <- dv
}
}
best_rayleigh
#
# Rayleigh Test of Uniformity
# General Unimodal Alternative
#
#Test Statistic: 0.8048
#P-value: 0.0298
best_rayleigh_vector
#Circular Data:
#Type = angles
#Units = radians
#Template = none
#Modulo = asis
#Zero = 0
#Rotation = counter
#[1] 4.172219 2.510826 2.997495 4.095335 3.655613
```

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at

- Prev: How to publish Travis CI artifacts to GitHub Release from several jobs
- Next: SQL. Find the customers who bought same brands and at-least 2 products in each brand

*1*### How i extract text from a model dialog in selenium?

*2*### How to wrap column header in ag-grid using angular

*3*### Extract value between second and third underscore in R

*4*### Mockito Test Failed: Actually, there were zero interactions with this mock

*5*### react-hook-form set to dirty when only touched

*6*### How to pass response variable in path through examples table in karate

*7*### How to reset input field from useRef in React?

*8*### Spring batch Input resource must exist (reader is in 'strict' mode) error

*9*### How we can count the number of records from JSON api response in Karate Framework?

*10*### How To Prevent Window Close Event Using HostListener In Angular 2+

*11*### How can I break from an *ngFor loop in Angular 4?

*12*### Redirect to a port number depending on the URL

*13*### pump.io port in URL

*14*### Spring AOP java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

*15*### MariaDB InnoDB table: how to find statement causing "waiting for table metadata lock"

*16*### Cypress could not verify that this server is running when using Docker and Docker Compose

*17*### Mapstruct: How to default a target String to Empty String when the Source is Null (Both fields have the same name and type) Java / Spring

*18*### Connection terminated as request was larger than 10485760

*19*### Getting next value from sequence with jpa repository in postgreSQL

*20*### ImportError: cannot import name 'adam' from 'keras.optimizers'

*21*### Key Commands must all have a Title, Key and Selector

## Comments