random variables functions

I have a wetland divided into 10 regions, and the probability to find another type of toad in any region is 0.3.

I calculated the density function like this:
n <- 10 #regions
p <- 0.3
X <- 0:n

densPr<- dbinom (X, n, p)

But I have some doubt in how I can calculate the (a)and (b) below using less than, and or 4-8

(a) probability to find less than 6 regions with the toad and
(b) probability to find 4 – 8 regions (inclusive) with the toad.

This looks like a homework problem so I'll give a hint. Your vector densPr has the probability that 0, 1, 2, ..., 10 regions will have the toad.

So if you wanted to find the probability that more than 5 regions had the toad, you would need to extract the values of densPr that meet that criteria. This isn't your problem but something similar

Something like sum(densPr[which(X>5)]).

1 Like

Thanks, I usually have problems with how to create the syntax even though I am looking for which functions to use, I think it is normal for a beginner.

I used < for an example of regions with less than 6. But in the case of 4 to 8, it must be something like 4: 8 ?, I'm lost.

sum(adensPr[which(X>=5)])
sum(adensPr[which(X<6)])

You can do that a few ways:

sum(adensPr[which(X %in% c(4:8))])
sum(adensPr[which(X >=4 & X <= 8)])
1 Like

Yes, what I provided I will help with that. mu and s2 are the mean and variance of the random variable

n <- 10 #regions
p <- 0.3
X <- 0:n

densPr<- dbinom (X, n, p)
mu=sum(X*densPr)
s2=sum((mu-X)^2*densPr)

mu
s2
1 Like

Thank you so much, I appreciate your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

What are you trying to find the mean and variance of? Are you trying to find expected value and variance of the mean? This is what I'm guessing

\mu=E(X)=\sum X p(X)
\sigma^2=Var(X)=\sum (x-\mu)^2 p(x)

To do this in R,

mu=sum(X*densPr)
s2=sum((mu-X)^2*densPr)
1 Like

Thank you so much.

to calculate mean and variance is ok if I use only the functions mean and variance with the adensPr ?

mean(adensPr)

var(adensPr)

I calculated and plot the density function (if is right), but then I tried to calculate the mean and variance of the random variable.

n <- 10 #regions
p <- 0.3
X <- 0:n

densPr<- dbinom (X, n, p)