fitSinCurve: Fit Data Based on Sine Curve

Description Usage Arguments Details Value Author(s) Examples

View source: R/fitSinCurve.R

Description

Fit sin function

Usage

1
2
3
4
5
6
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

Examples

1
2
3
4
5
6
7
8
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)

Caleb-Huo/differentialR2 documentation built on Dec. 17, 2021, 1:55 p.m.