Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pertz-lab
shiny-timecourse-inspector
Commits
afbab618
Commit
afbab618
authored
Jun 10, 2019
by
majpark21
Browse files
Auxfun: calculate average PSD through groups
parent
a8f6e87c
Changes
1
Hide whitespace changes
Inline
Side-by-side
modules/auxfunc.R
View file @
afbab618
...
...
@@ -206,6 +206,44 @@ LOCcalcTrajCI = function(in.dt, in.col.meas, in.col.by = NULL, in.type = c('norm
return
(
loc.dt
)
}
#' Calculate the power spectrum density for time-series
#'
#' @param in.dt Data table in long format
#' @param in.col.meas Name of the column with the measurement
#' @param in.col.id Name of the column with the unique series identifier
#' @param in.col.by Column names for grouping (default NULL - no grouping). PSD of individual trajectories will be averaged within a group.
#' @param in.method Name of the method for PSD estimation, must be one of c("pgram", "ar"). Default to "pgram*.
#' @param in.return.period Wheter to return densities though periods (1/frequencies) instead of frequencies.
#' @param ... Other paramters to pass to stats::spectrum()
#'
#' @return Datatable with columns: (frequency or period), spec (the density) and grouping column
#' @export
#' @import data.table
#'
#' @examples
LOCcalcPSD
<-
function
(
in.dt
,
in.col.meas
,
in.col.id
,
in.col.by
,
in.method
=
"pgram"
,
in.return.period
=
TRUE
,
...
){
require
(
data.table
)
if
(
!
in.method
%in%
c
(
"pgram"
,
"ar"
)){
stop
(
'Method should be one of: c("pgram", "ar"'
)
}
dt_spec
<-
copy
(
in.dt
)
dt_spec
[,
c
(
"frequency"
,
"spec"
)
:=
(
spectrum
(
get
(
in.col.meas
),
plot
=
FALSE
,
method
=
in.method
,
...
)[
c
(
"freq"
,
"spec"
)]),
by
=
in.col.id
]
dt_agg
<-
dt_spec
[,
.
(
spec
=
mean
(
spec
)),
by
=
c
(
in.col.by
,
"frequency"
)]
if
(
in.return.period
){
dt_agg
[,
period
:=
1
/
frequency
]
dt_agg
[,
frequency
:=
NULL
]
}
return
(
dt_agg
)
}
#' Generate synthetic CellProfiler output with single cell time series
#'
#'
...
...
@@ -644,7 +682,7 @@ LOCplotTrajRibbon = function(dt.arg, # input data table
return
(
p.tmp
)
}
# Plot average power spectrum density per facet
# Plots a scatter plot with marginal histograms
# Points are connected by a line (grouping by cellID)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment