Question: Question 4 . Let x be a random variable whose density is given by f ( x ) = { e - x , x

Question 4.
Let x be a random variable whose density is given by f(x)={e-x,x>00,x0, where >0 is a fixed parameter.
Part (a)
Create R function likely thet a,x) which, for a given value of parameter theta and a given vector x(which represents a sample from the
population x), returns the corresponding value of the likelihood function of parameter of population x, based on the sample x.
Note that since f(t)=0 for t0, we can assume that all the entries of the sample are positive. So, think of R variable x as a vector
(x1,x2,dots,xn) with xi>0, for all iin{1,2,dots,n}.
In other words, you don't need to worry about how to handle situation in which xi0 for some iin{1,2,dots,n}(although in that case the likelihood
equals 0, so it's trivial).
Your function likely() should be flexible allowing vector x to be of any length.
Hint: After figuring out the mathematical formula for the likelihood function L(;vec(x)), your R function likely () should have one or two lines of code. No
loops, nor if-else statments, please! Loops are okay only when you cannot vectorize.
Make sure that your (R) code passes ALL of the test provided by the following code:
## check the output of likely() for some combinations of x and theta
theta1=1.8;x1=c(1.4,0.5,0.15,0.8,0.4,0.06,0.7)
theta2=3.5;x2=c(0.3,0.6,0.05,0.2,0.12,0.77)
if (test_that(desc="",
expect_equal( abs(likely(theta1, x1)-0.0448921045151155)1e-7, TRUE)
})!= TRUE) stop("Sorry, wrong answer.")
if (test_that(desc="", code
expect_equal( abs(likely(theta2, x2)-1.45728892808099)1e-7, TRUE)
})!= TRUE) stop("Sorry, wrong answer.")
 Question 4. Let x be a random variable whose density is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!