Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

** R CODE ** The $Uniformleft(a,b ight)$ distribution is defined on x $in [a,b]$ and represents a random variable that takes on any value of

** R CODE **

The $Uniform\left(a,b ight)$ distribution is defined on x $\in [a,b]$ and represents a random variable that takes on any value of between `a` and `b` with equal probability. Technically since there are an infinite number of values between `a` and `b`, each value has a probability of 0 of being selected and I should say each interval of width $d$ has equal probability. It has the density function $$f\left(x ight)=\begin{cases} \frac{1}{b-a} & \;\;\;\;a\le x\le b\\ 0 & \;\;\;\;\textrm{otherwise} \end{cases}$$

The R function `dunif()` evaluates this density function for the above defined values of x, a, and b. Somewhere in that function, there is a chunk of code that evaluates the density for arbitrary values of $x$. Run this code a few times and notice sometimes the result is $0$ and sometimes it is $1/(10-4)=0.16666667$. ```{r} a <- 4 # The min and max values we will use for this example b <- 10 # Could be anything, but we need to pick something x <- runif(n=1, 0,10) # one random value between 0 and 10 # what is value of f(x) at the randomly selected x value? dunif(x, a, b) ``` We will write a sequence of statements that utilizes if statements to appropriately calculate the density of `x`, assuming that `a`, `b` , and `x` are given to you, but your code won't know if `x` is between `a` and `b`. That is, your code needs to figure out if it is and give either `1/(b-a)` or `0`. a. We could write a set of `if else` statements. ```{r, eval=FALSE} a <- 4 b <- 10 x <- runif(n=1, 0,10) # one random value between 0 and 10 if( x < a ){ result <- ???? # Replace ???? with something appropriate! }else if( x <= b ){ result <- ???? }else{ result <- ???? } print(paste('x=',round(x,digits=3), ' result=', round(result,digits=3))) ``` Replace the `????` with the appropriate value, either 0 or $1/\left(b-a ight)$. Run the code repeatedly until you are certain that it is calculating the correct density value. b. We could perform the logical comparison all in one comparison. Recall that we can use `&` to mean and and `|` to mean or. In the following two code chunks, replace the `???` with either `&` or `|` to make the appropriate result. i. ```{r, eval=FALSE} x <- runif(n=1, 0,10) # one random value between 0 and 10 if( (a<=x) ??? (x<=b) ){ result <- 1/(b-a) }else{ result <- 0 } print(paste('x=',round(x,digits=3), ' result=', round(result,digits=3))) ``` ii. ```{r, eval=FALSE} x <- runif(n=1, 0,10) # one random value between 0 and 10 if( (x

Answered: 1 week ago

Question

Explain the causes of indiscipline.

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago