Re: [R] LM with summation function

From: Robbie Edwards <robbie.edwards_at_gmail.com>
Date: Tue, 22 May 2012 11:40:06 -0400

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,
1200, 1825, 2569, 3416, 4344, 5325, 6325, 7304, 8216))

In this data frame, y results from y = x * b1 + x^2 * b2 + x^3 * b3 and s is sum of the current y and all previous y (s3 = y1 + y2 + y3).

I know I can find b1, b2 and b3 using:
lm(y ~ 0 + x + I(x^2) + I(x^3), data=df)

yielding...
Coefficients:

     x  I(x^2)  I(x^3)
   100      10      -1

However, I need to find b1, b2 and b3 using the s column. The reason being, I don't actually know the values of y in the actual data set. And in the actual data, I only have a few of the values. Imagine this data is being used a reward schedule for like a loyalty points program. y represents the number of points needed for each level while s is the total number of points to reach that level. In the real problem, my data looks more like this:

d <- data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216))

Where I need to use a few sample points to help define the parameters of the curve.

thanks again and hopefully this makes the problem a bit clearer.

robbie

On Fri, May 18, 2012 at 7:40 PM, David Winsemius <dwinsemius_at_comcast.net>wrote:

>
> 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 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, since each value of x is related to the previous values of x, I
>> don't know how to do this. Any help is greatly appreciated.
>>
>>
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

        [[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. Received on Tue 22 May 2012 - 15:46:12 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 May 2012 - 16:00:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive