Mina
Mina

Reputation: 307

crimCV different results in R

I'm learning how to work with crimCV to cluster my data. My inputs are integers and I replaced NAs with -1 for crimCV considering them as NA. But every time I run this code:

model <- crimCV(test, 2)

I get different results! Why is that? Here is the head of my data:

  `1`   `2`   `3`   `4`   `5`   `6`   `7`   `8`   `9`  `10`  `11`  `12`  `13`  `14`  `15`  `16`

1  9    -1    -1    10     3     9     4     1     7     6    -1     4     2     9    -1     3
2 18     0     7     5    -1    -1    -1    -1    -1     3     9     8    -1    -1     6     5
3 27     0    10    -1     5    11    -1     4    11    10     9    -1     8     2     5    13
4 38     5    -1    -1    -1     9     3     5    14     5     2     1    23     5     8     0
5  8     6     7     6     6     4     7     6     0     0    -1     0     6     5     1    -1
6 17     1     2    -1     1     3     4     3     1     1     2     0     1     0     9     0

Upvotes: 0

Views: 120

Answers (1)

Basti
Basti

Reputation: 1763

There is randomness in the function you are calling as @philiptomk clearly suggested in the comments.

Check : https://github.com/cran/crimCV/blob/f102e92b78483ca5fc3c121669948f65f1282300/R/dmZIP.R and https://github.com/cran/crimCV/blob/f102e92b78483ca5fc3c121669948f65f1282300/R/dmZIPt.R which rely on Fortran functions r_dmzip_init_param and r_dmzipt_init_param and listed in : https://github.com/cran/crimCV/blob/f102e92b78483ca5fc3c121669948f65f1282300/src/crimCV.f90

Both fortran functions rely on set_random_seed which inits the random number generator.

A simple solution to fix the seed generator is to call set.seed(X) before running crimCV(), with X an integer of your choice.

Upvotes: 1

Related Questions