I assume that you are trying to fit the sinusoidal model, with an error
term, to data:
y = a * sin(b*x) + error
Here you can use the `nls' function for non-linear least-squares.
?nls
Here is an example:
a <- 0.5
b <- 0.2
x <- seq(0, 10, length=100)
eps <- rnorm(length(x), sd=0.1)
y <- a*sin(b*x) + eps
plot(x, y, type="p")
nls(y ~ a * sin(b*x), start=list(a=0.1, b=0.1))
Note that `nls' will fail to converge without the "error" term.
Best,
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: rvaradhan at jhmi.edu
Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml
----------------------------------------------------------------------------
--------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of HAKAN DEMIRTAS
Sent: Wednesday, October 07, 2009 11:28 AM
To: r-help at r-project.org
Subject: [R] sinusoidal relationship
Hi,
Suppose x and y are vectors whose elements are known. I know that there is a
sinusoidal relation between them. In other words,
y=a*sin(bx) where b is probably a function of pi.
How do I find a and b in R?
Hakan
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.