fitSinCurve | R Documentation |
Fit sin function
fitSinCurve( tt, yy, period = 24, parStart = list(amp = 3, phase = 0, offset = 0) )
tt |
Time vector. |
yy |
Expression vector. |
period |
Period of the sine curve. Default is 24. |
parStart |
Initial value for optimization purpose. |
Fit a sine curve where tt is time, and yy is expression value.
A list of amp, phase, offset, peak, A, B, SST, SSE, R2. Formula 1: yy = amp * sin(2π/period * (phase + tt)) + offset Formula 2: yy = A * sin(2π/period \times tt) + B * cos(2*π/period * tt) + offset
amp |
Amplitude based on formula 1. |
phase |
Phase based on formula 1, phase is restricted within (0, period). |
offset |
Basal level (vertical shift) based on formula 1 or on formula 2. |
A |
A based on formula 2. |
B |
B based on formula 2. |
tss |
Total sum of square. |
rss |
Residual sum of square, SSE/n is the MLE of the variance sigma square. |
R2 |
Pseudo R2 defined as (tss - rss)/tss. |
Caleb (copied from Caleb's github)
set.seed(32608) n <- 50 tt <- runif(n,0,24) Amp <- 2 Phase <- 6 Offset <- 3 yy <- Amp * sin(2*pi/24 * (tt + Phase)) + Offset + rnorm(n,0,1) fitSinCurve(tt, yy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.