[R] summation equation whose numerator has subscript
David Winsemius
dwinsemius at comcast.net
Mon Nov 30 23:27:46 CET 2015
> On Nov 30, 2015, at 1:20 PM, Sherouk Moawad via R-help <r-help at r-project.org> wrote:
>
> Dear R experts
> Please do you have any idea about how this summation can be written in R(the equation can be viewed in the following link):
> http://s16.postimg.org/or2km30ph/equation.jpg
Can you explain in natural language the goals of this expression. It makes little sense to me to start with an index of j_sub_l = 0 and to then iterate to up to j_sub_(l-1) -1 . How can there be a value for j_sub(l-1) with a starting point of zero. The notation saying to do something for l = 2:n is not helpful since values of “l” doesn’t really appear in the looped expression (noting that j_sub_l starts at 0, so it's not being determined by “l".
I believe the confused notation was the cause of this question being closed after it appeared last week on SO:
http://stackoverflow.com/questions/33882285/summation-equation-whose-numerator-has-subscript
And what intent is meant for the indices of the outer summation? The expression j_sub_1 = 0 seems to have no corresponding reference point inside the looped expression. So you would simply be summing the same value N times, but since N is not defined we cannot write any code.
>
> I've tried out out this code but it gave me error for writing brackets in function of summation:
You should _always_, _always_, _always_ post the entire results of an error. We have no way of seeing your console. Error messages are usually informative.
>
>>>>
> x=matrix(c(6,2,1),3,1)
>
> for (l in 1:3){
> sum(sapply(1:3, function(j[l]){if(l>1){sum(sapply(1:j[l-1], function(j[l]){x[j[l]]*(j[l]<j[l-1])}))}}))}
You have three nested loops in the code above, but at least it appears you do understand that R is a 1-based language. But since the image-expression goes from 0 to some cryptic value (minus one) then the R version ought to go from one to "one more” than that expression.
> >>>Thank you
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list