Re: [R] fitting cosine curve

2017-06-21 Thread Charles C. Berry
On Wed, 21 Jun 2017, J C Nash wrote: Using a more stable nonlinear modeling tool will also help, but key is to get the periodicity right. The model is linear up to omega after transformation as Don and I noted. Taking a guess that 2*pi/240 = 0.0262 is about right for omega: rsq <-

Re: [R] fitting cosine curve

2017-06-21 Thread J C Nash
Using a more stable nonlinear modeling tool will also help, but key is to get the periodicity right. y=c(16.82, 16.72, 16.63, 16.47, 16.84, 16.25, 16.15, 16.83, 17.41, 17.67, 17.62, 17.81, 17.91, 17.85, 17.70, 17.67, 17.45, 17.58, 16.99, 17.10) t=c(7, 37, 58, 79, 96, 110, 114, 127, 146, 156,

Re: [R] fitting cosine curve

2017-06-20 Thread Don Cohen
If you know the period and want to fit phase and amplitude, this is equivalent to fitting a * sin + b * cos > >>> > I don't know how to set the approximate starting values. I'm not sure what you meant by that, but I suspect it's related to phase and amplitude. > >>> > Besides, does the

Re: [R] fitting cosine curve

2017-06-20 Thread Charles C. Berry
On Tue, 20 Jun 2017, lily li wrote: Hi R users, I have a question about fitting a cosine curve. I don't know how to set the approximate starting values. See Y.L. Tong (1976) Biometrics 32:85-94 The method is known as `cosinor' analysis. It takes advantage of the *intrinsic*

Re: [R] fitting cosine curve

2017-06-20 Thread lily li
I'm trying the different parameters, but don't know what the error is: Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates Thanks for any suggestions. On Tue, Jun 20, 2017 at 7:37 PM, Don Cohen wrote: > > If you

Re: [R] fitting cosine curve

2017-06-20 Thread lily li
Thanks. I will do a trial first. Also, is it okay to have the datasets that have only part of the cycle, or better to have equal or more than one cycle? That is to say, I cannot have the complete datasets sometimes. On Tue, Jun 20, 2017 at 7:37 PM, Don Cohen wrote:

Re: [R] fitting cosine curve

2017-06-20 Thread Jim Lemon
What I did was to plot your initial values, then plot the smoothed values and guess the constants. That is, I got an "eyeball" fit to the smoothed values. As I have described this as "gross cheating" in the past, you should either split your data, estimate on one subset and then test on another,

Re: [R] fitting cosine curve

2017-06-20 Thread lily li
Thanks, that is cool. But would there be a way that can approximate the curve by trying more starting values automatically? On Tue, Jun 20, 2017 at 5:45 PM, Jim Lemon wrote: > Hi lily, > You can get fairly good starting values just by eyeballing the curves: > > plot(y) >

Re: [R] fitting cosine curve

2017-06-20 Thread Jim Lemon
Hi lily, You can get fairly good starting values just by eyeballing the curves: plot(y) lines(supsmu(1:20,y)) lines(0.6*cos((1:20)/3+0.6*pi)+17.2) Jim On Wed, Jun 21, 2017 at 9:17 AM, lily li wrote: > Hi R users, > > I have a question about fitting a cosine curve. I don't

[R] fitting cosine curve

2017-06-20 Thread lily li
Hi R users, I have a question about fitting a cosine curve. I don't know how to set the approximate starting values. Besides, does the method work for sine curve as well? Thanks. Part of the dataset is in the following: y=c(16.82, 16.72, 16.63, 16.47, 16.84, 16.25, 16.15, 16.83, 17.41, 17.67,