Question 4.
Let x be a random variable whose density is given by f(x)={( heta e^(- heta x),x>0),(0,x<=0):}, where heta >0 is a fixed parameter.
Part (a)
Create R function likely (theta, 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 heta of population x, based on the sample x.
Note that since f(t)=0 for t<=0, we can assume that all the entries of the sample are positive. So, think of R variable x as a vector (x_(1),x_(2),...,x_(n)) with x_(i)>0, for all i in {1,2,...,n}.
In other words, you don't need to worry about how to handle situations in which x_(i)<=0 for some i in {1,2,...,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( heta ;vec(x)), your R function likely() should have one or two lines of code. No loops, nor if-else statements, please! Loops are okay only when you cannot vectorize.