vojta9
vojta9

Reputation: 9

Coding a mathematical expression

I am supposed to write a function that, for the values of Pi and P* returns the α.

enter image description here

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

Answers (1)

Konrad Rudolph
Konrad Rudolph

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

Related Questions