fitSinCurve: Fit Data Based on Sine Curve

View source: R/DCP_DiffR2.R

fitSinCurveR Documentation

Fit Data Based on Sine Curve

Description

Fit sin function

Usage

fitSinCurve(
  tt,
  yy,
  period = 24,
  parStart = list(amp = 3, phase = 0, offset = 0)
)

Arguments

tt

Time vector.

yy

Expression vector.

period

Period of the sine curve. Default is 24.

parStart

Initial value for optimization purpose.

Details

Fit a sine curve where tt is time, and yy is expression value.

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.

Author(s)

Caleb (copied from Caleb's github)

Examples

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)

DiffCircaPipeline/Rpackage documentation built on March 17, 2023, 7:32 a.m.