Skip to content

LM with summation function

5 messages · R. Michael Weylandt, Peter Ehlers, Robbie Edwards

#
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)

Then if we only see s, we can get back the y vector by doing

c(s[1], diff(s))

which is identical to y.

So for your data, the underlying y must have been c(109, 1091, 4125,
2891) right?

Or have I completely misunderstood your problem?

Michael

On Tue, May 22, 2012 at 12:25 PM, Robbie Edwards
<robbie.edwards at gmail.com> wrote:
#
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 direction...(not sure which)]

I'll ponder it some more and get back to you if I come up with anything

Michael

On Tue, May 22, 2012 at 12:43 PM, Robbie Edwards
<robbie.edwards at gmail.com> 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.
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 understanding, then you should
be able to estimate the coefficients as follows:

a) since s_i = b1 * sum of x_k for k=1, ..., i
                + b2 * sum of (x_k)^2 for k=1, ..., i
                + b3 * sum of (x_k)^3 for k=1, ..., i

we can regress s on the cumsums of x, x^2 and x^3:

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

   e <- data.frame(x = 1:12)
   e <- merge(e, d, all.x = T)
   e <- within(e,
              {z3 <- cumsum(x^3)
               z2 <- cumsum(x^2)
               z1 <- cumsum(x)})

   coef(lm(s ~ 0 + z1 + z2 + z3, data = e))

#  z1  z2  z3
# 100  10  -1


Peter Ehlers
On 2012-05-22 09:43, Robbie Edwards wrote: