SSharm: self start for a harmonic regression model

SSharm1R Documentation

self start for a harmonic regression model

Description

Self starter for a harmonic regression

Usage

harm1(x, b0, b1, cos1, sin1)

SSharm1(x, b0, b1, cos1, sin1)

Arguments

x

input vector

b0

intercept of the harmonic regression

b1

slope of the harmonic regression

cos1

coefficient associated with the cosine of the harmonic regression

sin1

coefficient associated with the sine of the harmonic regression

Details

Harmonic regression is actually a type of linear regression. Just adding it for convenience.

Value

a numeric vector of the same length as x containing parameter estimates for equation specified

harm1: vector of the same length as x using a harmonic regression

Examples


require(ggplot2)
set.seed(1234)
x <- seq(0, 3, length.out = 100)
y <- harm1(x, 0, 0, 0.05, 0) + rnorm(length(x), 0, 0.002)
dat <- data.frame(x = x, y = y)
fit <- nls(y ~ SSharm1(x, b0, b1, cos1, sin1), data = dat)
## plot
ggplot(data = dat, aes(x = x, y = y)) + 
  geom_point() + 
  geom_line(aes(y = fitted(fit)))


nlraa documentation built on May 29, 2024, 2:01 a.m.