Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in dimnames(trajectories)[[3]] : subscript out of bounds #12

Closed
gmersy opened this issue Jan 7, 2020 · 4 comments
Closed

Error in dimnames(trajectories)[[3]] : subscript out of bounds #12

gmersy opened this issue Jan 7, 2020 · 4 comments

Comments

@gmersy
Copy link

gmersy commented Jan 7, 2020

Each function called on the resulting mousetrap object from the long import is giving this same error.

@PascalKieslich
Copy link
Owner

Hi,
I am happy to look into the problem, but I would need more information to do so. Specifically, it would be great if you could provide the code that produced the error and potentially even a dataset with which I can reproduce it on my computer.
Best,
Pascal

@gmersy
Copy link
Author

gmersy commented Jan 7, 2020

Hi Pascal,
Sorry for the short message. Thank you for being willing to look into it. Here is some code that generates a test dataset and gives me the "dimnames(trajectories)[[3]] : subscript out of bounds" error. I am working on an IO Psych research paper and we are trying to use your package to analyze mouse trajectories. We are importing from a .csv file of mouse data. Although I cannot provide you with the specific dataset, hopefully this will be helpful.

Thanks so much!
Gabe

x = c(1,2,3)
y = c(4, 5, 6)
unix_time = c(120000, 124000, 200000)
event_time = c("test1", "test2", "test3")

sequence_number = c(1,2,3)

dummy = data.frame(x, y, unix_time, event_time, sequence_number)

test = mt_import_long(dummy, xpos_label = "x", ypos_label = "y",
               zpos_label = NULL, timestamps_label = "unix_time",
               add_labels = NULL, mt_id_label = "event_time", mt_seq_label = "sequence_number", reset_timestamps = FALSE, verbose = TRUE)

mt_angles(test)

@PascalKieslich
Copy link
Owner

Hi Gabe,
thanks for the code.
I think the cause of the problem is the incorrect specification / use of the mt_id variable whose label is specified via the mt_id_label argument. The idea is that the mt_id variable is used to identify which data points belong to the same trial. So all data points from the same trial should have the same label (e.g., all should be called "test1" in your example above). If you change accordingly, it works.

See the following example that modifies your code to "simulate" two trials - one with label test1, one with label test2:

library(mousetrap)

x = c(1,2,3,1,2,5)
y = c(4, 5, 6,2,6,8)
unix_time = c(120000, 124000, 200000,120000, 124000, 200000)
event_time = c("test1", "test1", "test1","test2", "test2", "test2")

sequence_number = c(1,2,3,1,2,3)

dummy = data.frame(x, y, unix_time, event_time, sequence_number)

test = mt_import_long(dummy, xpos_label = "x", ypos_label = "y",
                      zpos_label = NULL, timestamps_label = "unix_time",
                      add_labels = NULL, mt_id_label = "event_time", mt_seq_label = "sequence_number", reset_timestamps = FALSE, verbose = TRUE)

mt_angles(test)

Does this help?

Best,

Pascal

@gmersy
Copy link
Author

gmersy commented Jan 12, 2020

That is super helpful, Pascal. Thank you for looking into it for me! I appreciate it.

Gabe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants