The following is the funciton defined for bernoulli distribution. I am a new R user. I am not quite well-understand the following codes.
dbernoulli <- function(x, prob=0.5) {
dbinom(x, size=1, prob=prob)
}
dbernoulli(y, prob=0.7)
I thought in the defined function, we have pre-determined the argument prob
as 0.5
, so why can we change it to 0.7
when we use the defined function? Is these codes resonable? Can I correct it as follows?
dbernoulli <- function(x, prob) {
dbinom(x, size=1, prob=prob)
}
dbernoulli(y, prob=0.7)