csv <- system.file("extdata", "NHANES_11111.csv", package = "CircaCP")
df <- import_acti_file(csv, "Date", "Time", "MIMS")
head(df)
#> # A tibble: 6 × 4
#> id Date Time Activity
#> <chr> <chr> <chr> <dbl>
#> 1 NHANES_11111 9/1/13 21:30:00 6.08
#> 2 NHANES_11111 9/1/13 21:31:00 17.5
#> 3 NHANES_11111 9/1/13 21:32:00 8.12
#> 4 NHANES_11111 9/1/13 21:33:00 11.4
#> 5 NHANES_11111 9/1/13 21:34:00 12.1
#> 6 NHANES_11111 9/1/13 21:35:00 27.8stopifnot(exists("sleep_detection", mode = "function"))
clean_df = out$clean_df
newdf <- sleep_detection(clean_df, thr = 0.4, dist = "ZAG")
head(newdf)
#> id Date Time Activity label.cos label.sw cosinor
#> 1 NHANES_11111 9/1/13 21:30:00 6.075 1 1 0.4996403
#> 2 NHANES_11111 9/1/13 21:31:00 17.457 1 1 0.4974587
#> 3 NHANES_11111 9/1/13 21:32:00 8.117 1 1 0.4952771
#> 4 NHANES_11111 9/1/13 21:33:00 11.413 1 1 0.4930956
#> 5 NHANES_11111 9/1/13 21:34:00 12.149 1 1 0.4909142
#> 6 NHANES_11111 9/1/13 21:35:00 27.817 1 1 0.4887330
#> Activity_norm
#> 1 0.03745492
#> 2 0.10762970
#> 3 0.05004470
#> 4 0.07036592
#> 5 0.07490367
#> 6 0.17150344ggplot2::ggplot(newdf, ggplot2::aes(x = seq_along(Activity))) +
ggplot2::geom_line(ggplot2::aes(y = Activity_norm), alpha = 0.4) +
ggplot2::geom_line(ggplot2::aes(y = cosinor/2), alpha = 0.4, color = "magenta") +
ggplot2::geom_line(ggplot2::aes(y = label.cos), color = "blue") +
ggplot2::labs(x = "Minute", y = "Activity", title = unique(newdf$id)) +
ggplot2::scale_color_manual(
name = NULL,
values = c(
"Activity (norm)" = "grey40",
"Cosinor" = "magenta",
"Cosinor label" = "blue"))+
ggplot2::theme_bw(12)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's colour values.ggplot2::ggplot(newdf, ggplot2::aes(x = seq_along(Activity))) +
ggplot2::geom_line(ggplot2::aes(y = Activity_norm), alpha = 0.4) +
ggplot2::geom_line(ggplot2::aes(y = cosinor/2), alpha = 0.4, color = "magenta") +
ggplot2::geom_line(ggplot2::aes(y = label.sw), color = "forestgreen") +
ggplot2::labs(x = "Minute", y = "Activity", title = unique(newdf$id)) +
ggplot2::scale_color_manual(
name = NULL,
values = c(
"Activity (norm)" = "grey40",
"Cosinor / 2" = "magenta",
"Cosinor label" = "blue",
"Sleep/Wake" = "forestgreen"))+
ggplot2::theme_bw(12)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's colour values.