s-news
[Top] [All Lists]

Responses to "Recurrent sum"

To: S-News <s-news@lists.biostat.wustl.edu>
Subject: Responses to "Recurrent sum"
From: Tristan Lorino <tristan.lorino@lcpc.fr>
Date: Tue, 13 Feb 2007 16:29:58 +0100
Organization: LCPC
Reply-to: Tristan Lorino <tristan.lorino@lcpc.fr>
Many thanks to Patrick Agin and Dimitris Rizopoulos.

Dimitri said...
you can try something like this:

data$out <- data$T0 * sapply(data$Age, function(i, r.) sum((1 + 
r)^(1:i)), r. = r)


Patrick said...
A geometric series a + as + as^2 + ... + as^(n-1) 
can be written as
(a-s.k)/(1-s) where k = a.s^(n-1)

For your specific problem, try:
k <- data[,"T0"]*(1+r)^data[,"Age"]
data[,4] <- -(data[,"T0"]-(1+r)*k)/r-data[,"T0"]

hope this helps,
Patrick Agin

-- 
Laboratoire Central des Ponts et Chaussées
[Division ESAR ? Section AGR]
Route de Bouaye BP 4129
44341 Bouguenais Cedex
France
Tél 33 (0)2 40 84 56 18
Fax 33 (0)2 40 84 59 92


<Prev in Thread] Current Thread [Next in Thread>
  • Responses to "Recurrent sum", Tristan Lorino <=