
Generate Report for Daily Cosinor and Generate Summary Plot
Source:R/write.cosinor.R
write.cosinor.RdA multi-wrapper function which generate data trend using
geom_smooth and model plot using
CosinorM or CosinorM.KDE. All daily results
could be found in the exported report. A summary file in .csv format is
also generated to update the original `Bdf` with cosinor model coefficients
for each day.
Usage
write.cosinor(
Dir,
ID,
DailyAct,
Bdf,
VAct = NULL,
VTm = NULL,
method = "OLS",
tau = 24,
ph = FALSE,
overwrite = FALSE
)Arguments
- Dir
The directory where the recordings to be exported <e.g. "C:/Users/___YOUR USERNAME___/UPSTREAM FOLDER/.../FOLDER NAME/">
- ID
The subject's ID which would be used to create a folder.
- DailyAct
A data.frame list generated by `Act2Daily()`
- Bdf
A
BriefSumobject. Note, if jet lag occurred during the recording, please, update the metadata usingTAdjustbefore passing to this function.- VAct
Optional character. Name of the activity column in each data.frame object (`df`) in `DailyAct`. If NULL, defaults to the second column of `df`.
- VTm
Optional character. Name of the activity column in each data.frame object (`df`) in `DailyAct`. If NULL, defaults to the first column of `df`.
- method
Character string specifying estimation method
"OLS": Ordinary least square cosinor model via
CosinorM. (default)"FGLS": Feasible generalized least squares cosinor model via
CosinorM."KDE": Gaussian kernel density estimate (KDE) on circular time (hours of day) via
CosinorM.KDE.
- tau
Numeric scalar or vector for the assumed circadian period, passed to
CosinorM. Default is 24 for single-phase; multiple phases can be supplied via [c()].- ph
Optional logical scaler; if only a single period is assigned to tau, TRUE will force the function to append the post-hoc circadian estimates instead of the model estimates. (default: FALSE)
- overwrite
Logical; if TRUE, existing files with the same name will be overwritten. Default = FALSE.
Value
Creates a multi-page `.pdf` visual document and a text-based `.csv` summary.
PDF A multi-page PDF written to `pdfDir` (one file per `ID`). Each page corresponds to a recording day and contains two panels: the top panel shows the raw activity (points) and a smoothed trend; the bottom panel shows the model fit for the same day
`Summary.csv` An updated `Bdf` documentation with one row per recording day. Model-based circadian parameters are appened at the end of the file for each day.
Examples
if (FALSE) { # \dontrun{
# Import data
data (FlyEast)
# Create quick summary of the recording with adjustment for daylight saving.
BdfList <-
BriefSum (
df = FlyEast,
SR = 1 / 60,
Start = "2017-10-24 13:45:00"
)
# Let's extract the quick summary of the recording
Bdf <- BdfList$Bdf
df <- BdfList$df
### Note that since the original data was affected by travel-induced time
### shift, the recordings would not be properly segmented from 2017-11-02.
## To avoid time shift due to travelling, we will keep only the first 8 days.
Bdf <- Bdf [1:8, ]
## Segment Data by Day
dfList <-
Act2Daily (
df = df,
Bdf = Bdf,
VAct = "Activity",
VTm = "Time",
Incomplete = TRUE,
Travel = TRUE
)
## Generate graphic summary of daily recordings in pdf with an addition
## `Summary` file just like write.act
write.cosinor (
Dir = getwd (), ## Export to the current working directory
ID = "JD",
DailyAct = dfList$Daily_df,
Bdf = Bdf,
VAct = "Activity",
VTm = "Time"
)
## To see what was exported copy the path generated by the code below and
## paste it as an url in a web browser or the file explorer.
getwd ()
} # }