Reputation: 117
I would like to make to plot this following function:
where
Let r in (0,1) and \mu in (0,1) but in my case \mu=0.5. My code is following and I have the problem to make a plot of this function.
n <- 10
r <- seq(from=0.0, to=1, by = 0.0001)
h.star <- r*log(r/0.5)+(1-r)*log((1-r)/(1-0.5))
F.mu <- function(r) {
if (r > 0 & r < 0.5)
F.mu <- exp(-n*h.star)
else (r > 0.5 & r < 1)
F.mu <- 1
}
plot(r, F.mu)
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
Upvotes: 0
Views: 135
Reputation: 12559
I suppose you want this:
n <- 10
r <- seq(from=0.0, to=1, by = 0.0001)
F.mu <- function(r, mu) {
H.star <- r*log(r/mu) + (1-r)*log((1-r)/(1-mu))
ifelse(r >= mu, 1, exp(-n*H.star))
}
plot(r, F.mu(r, mu=0.5))
You can reduce the needed calculations in the function:
H.star <- ifelse(r>=mu, 0, r*log(r/mu) + (1-r)*log((1-r)/(1-mu)))
Upvotes: 3