Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.")
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

=+c) What is the P-value corresponding to this t-statistic?

Answered: 1 week ago