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

Check for overlap in behaviors #7

Open
matiasandina opened this issue Oct 31, 2022 · 1 comment
Open

Check for overlap in behaviors #7

matiasandina opened this issue Oct 31, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@matiasandina
Copy link
Owner

As of today, StatEtho does not check for overlaps in behavior.
Should different behaviors be allowed to happen at the same time?
It's difficult to know beforehand if overlap is the result of a bug or ggethos working properly.
If the plot is large, it's difficult to visually inspect for overlap.

@matiasandina matiasandina added the enhancement New feature or request label Oct 31, 2022
@matiasandina
Copy link
Owner Author

matiasandina commented Apr 6, 2023

This issue is somewhat difficult to solve if providing data where behavior doesn't change between continuous trials. Note that the overlap needs not be in the original data, it can be generated by our grouping of continuous runs. For example, animal was doing behavior "A" at the end of the trail and continued doing behavior "A" at the start of the next one. Our current approach will join those runs because they are continuous, unless being told not to. To give a particular example of this issue failing in daily usage:

library(tidyverse)
library(ggethos)
toy_df <- structure(list(trial_n = c(11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
                                     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
                                     12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 
                                     13, 13, 13, 13, 13, 13, 13, 13, 13), time = c(3632, 3634, 3636, 
                                                                                   3638, 3640, 3642, 3644, 3646, 3648, 3650, 3652, 3654, 3656, 3658, 
                                                                                   3660, 3662, 3664, 3666, 3668, 3670, 3672, 3674, 3676, 3678, 3680, 
                                                                                   3682, 3684, 3686, 3688, 3690, 3692, 3694, 3696, 3698, 3700, 3702, 
                                                                                   3704, 3706, 3708, 3710, 3712, 3714, 3716, 3718, 3720, 3722, 3724, 
                                                                                   3726, 3728, 3730, 3732, 3734, 3736, 3738, 3740, 3742, 3744, 3746, 
                                                                                   3748, 3750, 3752, 3754, 3756, 3758, 3760, 3762, 3764, 3766, 3768, 
                                                                                   3770, 3772, 3774, 3776, 3778, 3780, 3782, 3784, 3786, 3788, 3790, 
                                                                                   3792, 3794, 3796, 3798, 3800, 3802, 3804, 3806, 3808, 3810, 3812, 
                                                                                   3814, 3816, 3818, 3820, 3822, 3824, 3826, 3828, 3830, 3832, 3834, 
                                                                                   3836, 3838, 3840, 3842, 3844, 3846, 3848, 3850, 3852, 3854, 3856, 
                                                                                   3858, 3860, 3862, 3864, 3866, 3868, 3870, 3872, 3874, 3876, 3878, 
                                                                                   3880, 3882, 3884, 3886, 3888, 3890, 3892, 3894, 3896, 3898, 3900, 
                                                                                   3902, 3904, 3906, 3908, 3910, 3912, 3914, 3916, 3918, 3920, 3922, 
                                                                                   3924, 3926, 3928, 3930, 4486, 4488, 4490, 4492, 4494, 4496, 4498, 
                                                                                   4500, 4502, 4504, 4506, 4508, 4510, 4512, 4514, 4516, 4518, 4520, 
                                                                                   4522, 4524, 4526, 4528, 4530, 4532, 4534, 4536, 4538, 4540, 4542, 
                                                                                   4544, 4546, 4548, 4550, 4552, 4554, 4556, 4558, 4560, 4562, 4564, 
                                                                                   4566, 4568, 4570, 4572, 4574, 4576, 4578, 4580, 4582, 4584, 4586, 
                                                                                   4588, 4590, 4592, 4594, 4596, 4598, 4600, 4602, 4604, 4606, 4608, 
                                                                                   4610, 4612, 4614, 4616, 4618, 4620, 4622, 4624, 4626, 4628, 4630, 
                                                                                   4632, 4634, 4636, 4638, 4640, 4642, 4644, 4646, 4648, 4650, 4652, 
                                                                                   4654, 4656, 4658, 4660, 4662, 4664, 4666, 4668, 4670, 4672, 4674, 
                                                                                   4676, 4678, 4680, 4682, 4684, 4686, 4688, 4690, 4692, 4694, 4696, 
                                                                                   4698, 4700, 4702, 4704, 4706, 4708, 4710, 4712, 4714, 4716, 4718, 
                                                                                   4720, 4722, 4724, 4726, 4728, 4730, 4732, 4734, 4736, 4738, 4740, 
                                                                                   4742, 4744, 4746, 4748, 4750, 4752, 4754, 4756, 4758, 4760, 4762, 
                                                                                   4764, 4766, 4768, 4770, 4772, 4774, 4776, 4778, 4780, 4782, 4784, 
                                                                                   5364, 5366, 5368, 5370, 5372, 5374, 5376, 5378, 5380, 5382, 5384, 
                                                                                   5386, 5388, 5390, 5392, 5394, 5396, 5398, 5400, 5402, 5404, 5406, 
                                                                                   5408, 5410, 5412, 5414, 5416, 5418, 5420, 5422, 5424, 5426, 5428, 
                                                                                   5430, 5432, 5434, 5436, 5438, 5440, 5442, 5444, 5446, 5448, 5450, 
                                                                                   5452, 5454, 5456, 5458, 5460, 5462, 5464, 5466, 5468, 5470, 5472, 
                                                                                   5474, 5476, 5478, 5480, 5482, 5484, 5486, 5488, 5490, 5492, 5494, 
                                                                                   5496, 5498, 5500, 5502, 5504, 5506, 5508, 5510, 5512, 5514, 5516, 
                                                                                   5518, 5520, 5522, 5524, 5526, 5528, 5530, 5532, 5534, 5536, 5538, 
                                                                                   5540, 5542, 5544, 5546, 5548, 5550, 5552, 5554, 5556, 5558, 5560, 
                                                                                   5562, 5564, 5566, 5568, 5570, 5572, 5574, 5576, 5578, 5580, 5582, 
                                                                                   5584, 5586, 5588, 5590, 5592, 5594, 5596, 5598, 5600, 5602, 5604, 
                                                                                   5606, 5608, 5610, 5612, 5614, 5616, 5618, 5620, 5622, 5624, 5626, 
                                                                                   5628, 5630, 5632, 5634, 5636, 5638, 5640, 5642, 5644, 5646, 5648, 
                                                                                   5650, 5652, 5654, 5656, 5658, 5660, 5662), behavior = c("Wake", 
                                                                                                                                           "Wake", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Wake", "Wake", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Wake", 
                                                                                                                                           "Wake", "Wake", "Sleep", "Sleep", "Sleep", "Sleep", "Wake", "Wake", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", "Sleep", 
                                                                                                                                           "Sleep", "Sleep", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", "Wake", 
                                                                                                                                           "Wake", "Wake", "Wake")), row.names = c(NA, -450L), class = c("tbl_df", 
                                                                                                                                                                                                         "tbl", "data.frame"))

toy_df %>% 
  ggplot(aes(time, y=trial_n, behaviour = behavior, color=behavior)) + 
  geom_ethogram()
#> No observation interval provided, using guessed interval 2
#> Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
#> dplyr 1.1.0.
#> ℹ Please use `reframe()` instead.
#> ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
#>   always returns an ungrouped data frame and adjust accordingly.
#> ℹ The deprecated feature was likely used in the ggethos package.
#>   Please report the issue to the authors.

I'm not showing the behavior with align_trials = T, but it also gets messed up because of the overlap.

This could be fixed by using group inside the ggplot call, which is awesome, and that's why we love ggplot2 so much. In a perfect world, I guess we could check for overlap at the exit of the ethogram calculation and throw a warning, suggesting to use group by whatever y was used

toy_df %>% 
  ggplot(aes(time, y=trial_n, behaviour = behavior, color=behavior, group=trial_n)) + 
  geom_ethogram()
#> No observation interval provided, using guessed interval 2

Another option, using get_ethogram() from #15, which also produces the same as above (not shown in the reprex).

toy_df %>% 
  group_by(trial_n) %>% 
  get_ethogram(time, behaviour = behavior) %>% 
  ggplot(aes(x = x, xend=xend, y=trial_n, yend=trial_n, color = behaviour)) +
  geom_segment(linewidth = 5)
#> Error in get_ethogram(., time, behaviour = behavior): could not find function "get_ethogram"

Created on 2023-04-06 with reprex v2.0.2

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

No branches or pull requests

1 participant