R/tipa.R
tipaCosinor.Rd
Calculate the phase shift based on fitting sine curves to waveform data
before and after the stimulus, accounting for possible period changes and for
the point in the circadian cycle at which the stimulus occurred. This
function will work best for measurements whose rhythms are approximately
sinusoidal, or at least smoothly increasing and decreasing. If your data are
not sinusoidal, you can first define the phase reference points and then use
tipaPhaseRef()
.
tipaCosinor( time, y, stimOnset, stimDuration = 0, periodGuess = 24, trend = TRUE, shortcut = TRUE )
time  Vector of time values for the full timecourse. 

y  Vector of measurements (e.g., bioluminescence) for the full timecourse. 
stimOnset  Time at which the stimulus started. 
stimDuration  Duration of the stimulus and any transients. Data between

periodGuess  Approximate period of the oscillations (in the same units
used in 
trend  Model a longterm trend in the cosinor fit for each epoch. Uses
a natural cubic spline with 4 degrees of freedom. It is strongly
recommended to keep as 
shortcut  Calculate phase shift using the standard TIPA procedure or using a shortcut based on the phases of the sine curve fits. The two methods give exactly the same result. 
A list.
Estimated phase shift in circadian hours. Negative values correspond to a delay, positive values an advance.
Dataframe containing information about the sine curve fits
for each epoch: period (in the same units used in time
), phase (in
radians), and root mean square error (in the same units as y
). If the RMS
errors prestimulus and poststimulus are substantially different, then the
stimulus may have induced a change in the waveform and thus phase shift
estimates may be invalid.
# Timecourse data from multiple (simulated) experiments getTimecourseFile = function() { system.file('extdata', 'timecourses.csv', package = 'tipa')} df = read.csv(getTimecourseFile(), stringsAsFactors = FALSE) resultList = lapply(sort(unique(df$expId)), function(ii) { time = df$time[df$expId == ii] y = df$intensity[df$expId == ii] tipaCosinor(time, y, stimOnset = 0)}) phaseShifts = sapply(resultList, function(r) r$phaseShift) write.csv(data.frame(expId = sort(unique(df$expId)), phaseShift = phaseShifts), 'tipa_cosinor.csv', quote = FALSE, row.names = FALSE)