Hello, It's a bad idea to name a function and one of it's arguments Y, use Yfun and Y. What does summation(x(Y.t, Y.t-1, ...)) mean? Is there a multiplication sign between x and (Y.t, ...)? And is epsilon a vector of errors, one for each Y.t? If so, the following might do it.
Yfun <- function(Y, p, x, epsilon){ for (i in 2:length(Y)) { Y[i] <- Y[i-1] + (1/p)*sum(x*Y[1:(i-1)]) + epsilon[i] } Y } Hope this helps, Rui Barradas Em 22-12-2012 09:29, Simone Gogna escreveu: > Dear R users, > IĆ¢EUR^(TM)d like to create a function as: > > Y.t+1 = Y.t + (1\p)*summation(x(Y.t,Y.t-1,...)) + epsilon.t > > where x is a function of Y.t, Y.t-1 and so on, epsilon is a random error and > p is a parameter. > > Do you think something of the following form might be appropriate? > > Y<-function(Y,p,x,epsilon){ > for (i in 2:length(Y)) { > Y[i]<-Y[i-1]+(1/p)*sum(x(Y[i-1]))+epsilo.t} > Y > } > > Any indication is warmly appreciated. > > thanks and best regards > [[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. [[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.