Re: [R] LM with summation function

2012-05-23 Thread Robbie Edwards
Thank you Peter, works perfectly. Funny how simple things are once someone tells you the answer =) robbie On Tue, May 22, 2012 at 9:37 PM, Peter Ehlers wrote: > Robbie, > > Here's what I *think* you are trying to do: > > 1. > y is a cubic function of x: > > y = b1*x + b2*x^2 + b3*x^3 > > 2.

Re: [R] LM with summation function

2012-05-22 Thread Peter Ehlers
Robbie, Here's what I *think* you are trying to do: 1. y is a cubic function of x: y = b1*x + b2*x^2 + b3*x^3 2. s is the cumsum of y: s_i = y_1 + ... + y_i 3. Given a subset of x = 1:n and the corresponding values of s, estimate the coefficients of the cubic. If that is the correct und

Re: [R] LM with summation function

2012-05-22 Thread R. Michael Weylandt
Ahh sorry -- I didn't understand that x was supposed to be an index so I was using the row number an index for the summation -- yes, my proposal probably won't work without further assumptions[I.e., you could assume linear growth between observations, but that will bias something some direc

Re: [R] LM with summation function

2012-05-22 Thread Robbie Edwards
I don't think I can. For the sample data d <- data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) when x = 4, s = 1200. However, that s4 is sum of y1 + y2 + y3 + y4. Wouldn't I have to know the y for x = 2 and x = 3 to get the value of y for x = 4? In the previous message, I created two

Re: [R] LM with summation function

2012-05-22 Thread R. Michael Weylandt
But if I understand your problem correctly, you can get the y values from the s values. I'm relying on your statement that "s is sum of the current y and all previous y (s3 = y1 + y2 + y3)." E.g., y <- c(1, 4, 6, 9, 3, 7) s1 = 1 s2 = 4 + s1 = 5 s3 = 6 + s2 = 11 more generally s <- cumsum(y) Th

Re: [R] LM with summation function

2012-05-22 Thread Robbie Edwards
Hi all, Thanks for the replies, but I realize I've done a bad job explaining my problem. To help, I've created some sample data to explain the problem. df <- data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), y=c(109, 232, 363, 496, 625, 744, 847, 928, 981, 1000, 979, 912), s=c(109, 341, 704

Re: [R] LM with summation function

2012-05-18 Thread David Winsemius
On May 18, 2012, at 1:44 PM, Robbie Edwards wrote: Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. cumsum( rowSums( cbind(B1 * x, B2 * x^2, B3 * x^3))) Anyway, if it wasn't for

Re: [R] LM with summation function

2012-05-18 Thread Bert Gunter
Following up on Rolf's post: 1) cumulative summation (cumsum) maybe? 2) In fact, you should probably **not** fit the non-summation version as you have stated. See ?poly. I would guess that context is important here. Based on (my interpretation) of the rather strange nature of your request, I sus

Re: [R] LM with summation function

2012-05-18 Thread Rolf Turner
On 19/05/12 05:44, Robbie Edwards wrote: Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. Anyway, if it wasn't for the summation, I know I would do it like this lm(y ~ x + x2 + x3) Whe

[R] LM with summation function

2012-05-18 Thread Robbie Edwards
Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. Anyway, if it wasn't for the summation, I know I would do it like this lm(y ~ x + x2 + x3) Where x2 and x3 are x^2 and x^3. However, sin