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

create vignette and explain sector analysis #3

Open
cells2numbers opened this issue Sep 5, 2017 · 3 comments
Open

create vignette and explain sector analysis #3

cells2numbers opened this issue Sep 5, 2017 · 3 comments
Assignees

Comments

@cells2numbers
Copy link
Owner

No description provided.

@cells2numbers cells2numbers self-assigned this Sep 5, 2017
cells2numbers added a commit that referenced this issue Sep 5, 2017
@cells2numbers
Copy link
Owner Author

Sector analysis can be calculated using

tracks %>% group_by(Track_Sector) %>% 
  count %>% 
  rename(n_per_sector  = n ) %>% 
  mutate(fraction = n_per_sector / nrow(tracks)) %>%
  print 

Result:

Track_Sector n_per_sector fraction
1 166 0.3971292
2 112 0.2679426
3 68 0.1626794
4 71 0.1698565

@cells2numbers
Copy link
Owner Author

cells2numbers commented Apr 3, 2019

for multiple experiments use

df_debug %>% 
  ungroup() %>% 
  group_by(Metadata_experiment) %>% 
  count %>% 
  rename(n_per_sector  = n ) %>% 
  spread(key = Track_Sector, value = n_per_sector) %>% 
  rename('sector_1' = '1') %>% 
  rename('sector_2' = '2') %>% 
  rename('sector_3' = '3') %>% 
  rename('sector_4' = '4') %>% 
  mutate(sector_1_fraction = sector_1 / (sector_1 + sector_2 + sector_3 + sector_4)) %>% 
  mutate(sector_2_fraction = sector_2 / (sector_1 + sector_2 + sector_3 + sector_4)) %>% 
  mutate(sector_3_fraction = sector_3 / (sector_1 + sector_2 + sector_3 + sector_4)) %>% 
  mutate(sector_4_fraction = sector_4 / (sector_1 + sector_2 + sector_3 + sector_4)) %>% 
  print

Result:

Metadata_experiment Metadata_Frame_Subset Metadata_offset sector_1 sector_2 sector_3 sector_4 sector_1_fraction sector_2_fraction sector_3_fraction sector_4_fraction
10 0 6 3 18 3 2 0.1153846 0.6923077 0.1153846 0.07692308
10 0 12 6 16 5 1 0.2142857 0.5714286 0.1785714 0.03571429
10 10 6 8 7 7 5 0.2962963 0.2592593 0.2592593 0.18518519
10 10 12 4 8 5 2 0.2105263 0.4210526 0.2631579 0.10526316

@cells2numbers
Copy link
Owner Author

The sector analysis on experiment level is implemented summarize_sectors, see PR #23
Changes to sample code above

  • sectors are renamed to left, right, up down
  • after spread: columns for empty sectors are added and filled with 0
  • example is added

Still missing:

  • test
summarize_sectors <- function(tracks, strata) {
  results <- tracks %>%
    dplyr::ungroup() %>%
    dplyr::group_by_(.dots = c(strata,'Track_Sector')) %>%
    dplyr::count() %>%
    dplyr::rename(n_per_sector  = n ) %>%
    tidyr::spread(key = Track_Sector, value = n_per_sector)

  # replace na with 0
  results[is.na(results)] <- 0

  # add missing cols
  missing_cols <- setdiff(c("1","2","3","4"),setdiff(colnames(results),strata))
  results[missing_cols] <- 0

  sector_summary <- results %>%
    dplyr::rename('sector_left' = '1') %>%
    dplyr::rename('sector_right' = '2') %>%
    dplyr::rename('sector_up' = '3') %>%
    dplyr::rename('sector_down' = '4') %>%
    dplyr::mutate(sector_left_fraction =
        sector_left  / (sector_left + sector_right + sector_up + sector_down)) %>%
    dplyr::mutate(sector_right_fraction =
        sector_right / (sector_left + sector_right + sector_up + sector_down)) %>%
    dplyr::mutate(sector_up_fraction =
        sector_up    / (sector_left + sector_right + sector_up + sector_down)) %>%
    dplyr::mutate(sector_down_fraction =
        sector_down  / (sector_left + sector_right + sector_up + sector_down))
} 

cells2numbers added a commit that referenced this issue Apr 5, 2019
implemented summary of sector analysis including example code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant