tidyfun / tf

S3 classes and methods for tidy functional data
https://tidyfun.github.io/tf/
GNU Affero General Public License v3.0
5 stars 2 forks source link

Strange warning in `tf_smooth()` #32

Closed jeff-goldsmith closed 3 months ago

jeff-goldsmith commented 1 year ago

Related to #2 -- we had written some code to facilitate downsampling, which used rolling means. This is a short version of that solution with the relevant code:

library(tidyverse)
library(tidyfun)

hour_data2 <- 
  chf_df %>% 
  filter(day == "Mon") |> 
  select(id, activity) |> 
  mutate(act_hour = tf_smooth(activity, method = "rollmean", k = 60, align = "right"))

If I add in some steps that change arg for the function, though, rollmean gives a warning:

library(tidyverse)
library(tidyfun)

hour_data2 <-
  chf_df %>%
  filter(day == "Mon") |>
  select(id, activity) |>
  tf_unnest(activity) |>
  mutate(activity_arg = (activity_arg / 1440) * 24) |>
  tf_nest(activity_value, .id = id, .arg = activity_arg) |>
  mutate(act_hour = tf_smooth(activity_value, method = "rollmean", k = 60, align = "right"))
#> setting fill = 'extend' for start/end values.
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `act_hour = tf_smooth(activity_value, method = "rollmean", k =
#>   60, align = "right")`.
#> Caused by warning in `tf_smooth.tfd()`:
#> ! non-equidistant arg-values in 'activity_value' ignored by rollmean.

Created on 2023-03-14 by the reprex package (v2.0.1)

This warning doesn't seem to cause any problems, but also doesn't seem correct -- the input function is a tfd_reg. Issue seems to come from the is_equidist() check in tf_smooth.tfd(), but I'm not sure why, and I'm not sure why it only comes up after changing arg.

(Sidenote: this approach to changing arg works, although some stuff in #6 still seems relevant.)

jeff-goldsmith commented 1 year ago

Actually, sorry, I guess it's because the check in is_equidist() is at the resolution of the new tfd vector -- and that gives distances between args that are often 0.17 but sometimes 0.16 in this example. Dunno if that's something that's worth digging into much more, but ... I guess now we know it happens sometimes?

fabian-s commented 3 months ago

closing this since the misleading message here was resolution-related and we got rid of that in #24