matiasandina / homecage_quantification

Code for quantifying homecage activity
https://github.com/homecage_quantification
0 stars 0 forks source link

Experimental data analysis #16

Open matiasandina opened 4 years ago

matiasandina commented 4 years ago

write functions to aggregate movement data and plot

Baseline can be established within animal within light stage, as the mean of the 10% lowest responses. Then subtract this to the raw movement before aggregation into temporal bins.

Likely Useful plots

Individual

Grouped

matiasandina commented 3 years ago

Looks like this function can repair the lights affecting the baseline and correct everything to baseline zero. For those values below the mean of the 0.1 quantile, the movement will be negative (probably too small so it might not modify things).

repair_baseline <- function(x){
  # we take the 0.1 quantile as the lowest values
  base <- mean(x[x < quantile(x, 0.1)])
  # we return x - base
  return(x - base)
}
matiasandina commented 3 years ago

This app needs to get revisited and redone separate into a separate project, maybe with its own repo. Some thoughts here:

matiasandina commented 3 years ago

image

solved by

           mutate(movement = ifelse(movement > 2e05, NA, movement),
                   movement = zoo::na.approx(movement, na.rm=F, rule=2))