Reputation: 9
I am supposed to write a function that, for the values of Pi
and P*
returns the α.
I am having trouble with the usage of sum in my function.
So far I have something like this:
sqrt((sum(x[i], i == 1, i == length(pstar)])*(p-pstar)^2)/n)/pstar)*100
Upvotes: 1
Views: 65
Reputation: 545578
A sum over a vector x
in R is just sum(x)
, not sum(x[i], i == 1, i == length(x)) * x
. (In fact, the latter doesn’t make much sense even if the syntax was correct, since there’s no multiplication involved in a sum.)
So, in your case:
sum((p - pstar) ^ 2)
Upvotes: 1