Re: [R] How to do a trig regression
Thank you all very much for your help. Unfortunately I do not have the data to test out the ideas suggested but I was able to find a good approximation using another software package. I will try to get the data for this problem so I can find out how to do it in R as I am very much interested in the process. @Dennis : Indeed, its the c that causes the problem. Without the c, solving this would be a very easy thing. On Mon, Sep 13, 2010 at 12:01 PM, Greg Snow greg.s...@imail.org wrote: Without the square term you can just use the rule for addition in sines: sin(a+b) = sin(a)cos(b) + cos(a)sin(b) So a regression of y= a + b* sin(2*pi/360*x + c) can be fit as: lm( y~ sin( 2*pi/360*x) + cos( 2*pi/360/x ) ) If you need the actual values of b and c then you will need to do a little algebra. The same idea may be sufficient for your formula (or at least a close approximation), or you could switch to nonlinear fits using the nls function and fit your formula directly. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Aaditya Nanduri Sent: Sunday, September 12, 2010 8:23 PM To: r-help@r-project.org Subject: [R] How to do a trig regression Hello All, I cant seem to do a trig regression in R. The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2 a, b, c are coefs that I want. y, x are input vectors. The equation I put into R: lm(y ~ sin(2*pi*x/360)^2) This equation is missing the c and I dont get the right answer. Also, I dont know how to plot the lm over the x values instead of the indices. Any help is sincerely appreciated. Thank you all very much. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@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. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@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.
Re: [R] How to do a trig regression
Without the square term you can just use the rule for addition in sines: sin(a+b) = sin(a)cos(b) + cos(a)sin(b) So a regression of y= a + b* sin(2*pi/360*x + c) can be fit as: lm( y~ sin( 2*pi/360*x) + cos( 2*pi/360/x ) ) If you need the actual values of b and c then you will need to do a little algebra. The same idea may be sufficient for your formula (or at least a close approximation), or you could switch to nonlinear fits using the nls function and fit your formula directly. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Aaditya Nanduri Sent: Sunday, September 12, 2010 8:23 PM To: r-help@r-project.org Subject: [R] How to do a trig regression Hello All, I cant seem to do a trig regression in R. The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2 a, b, c are coefs that I want. y, x are input vectors. The equation I put into R: lm(y ~ sin(2*pi*x/360)^2) This equation is missing the c and I dont get the right answer. Also, I dont know how to plot the lm over the x values instead of the indices. Any help is sincerely appreciated. Thank you all very much. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] How to do a trig regression
Hello All, I cant seem to do a trig regression in R. The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2 a, b, c are coefs that I want. y, x are input vectors. The equation I put into R: lm(y ~ sin(2*pi*x/360)^2) This equation is missing the c and I dont get the right answer. Also, I dont know how to plot the lm over the x values instead of the indices. Any help is sincerely appreciated. Thank you all very much. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@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.
Re: [R] How to do a trig regression
On Sep 12, 2010, at 10:23 PM, Aaditya Nanduri wrote: Hello All, I cant seem to do a trig regression in R. The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2 a, b, c are coefs that I want. y, x are input vectors. The equation I put into R: lm(y ~ sin(2*pi*x/360)^2) This equation is missing the c and I dont get the right answer. Take a look at section 2.3 of: http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf Or consider using time series or nonlinear modeling. Also, I dont know how to plot the lm over the x values instead of the indices. Without an example of your data and what you tried it is difficult to intuit what problems you may be facing. -- David. Any help is sincerely appreciated. Thank you all very much. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.