Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using R, Exercise 3 (Writing More Functions) In this exercise we will write our own functions related to performing a one-sample t test. That is

Using R,

image text in transcribed

Exercise 3 (Writing More Functions) In this exercise we will write our own functions related to performing a one-sample t test. That is Ho : versus H1 : , where ,40 is the hypothesized value of Throughout this exercise you may not use the t.test) function inside your functions. You may use it to check your work separately, but no such double-checks should appear in your final report Some built in R functions that may be useful to you when writing your functions include: cO, ifelse), mean O, sd abs, length), sqrtO, and pt ) (a) Write a function called do_t_test which takes two inputs: . x: A vector which stores observations. mu: The hypothesized value of which defaults to 0 The function should output The value of the test statistic, t .The p-value of the test. The function only needs to be able to handle a two-sided alternative. In order to output both, consider using c(t, pval) as the last line of your function, and store those two values elsewhere in the body of your function. (b) Write a function called make_decision which takes two inputs: pval: The p-value of a test . alpha: The significance level of a test. Set a default value of 0.05 The function should output "Reject!" or "Fail to Reject." based on the comparison of pval to alpha. (c) Now we will test the quality of your functions from parts (a) and (b). Run the following code: set.seed (114) y rnorm(25, 1.4, 1) pval do_t test(y, mu- 2) [2] pval make_decision(pval, alpha 0.10) If your do_t_testO and make_decision) functions are correct, you should obtain a decision of "Reject." You will also be evaluated on whether the numeric p-value you obtain is correct Exercise 3 (Writing More Functions) In this exercise we will write our own functions related to performing a one-sample t test. That is Ho : versus H1 : , where ,40 is the hypothesized value of Throughout this exercise you may not use the t.test) function inside your functions. You may use it to check your work separately, but no such double-checks should appear in your final report Some built in R functions that may be useful to you when writing your functions include: cO, ifelse), mean O, sd abs, length), sqrtO, and pt ) (a) Write a function called do_t_test which takes two inputs: . x: A vector which stores observations. mu: The hypothesized value of which defaults to 0 The function should output The value of the test statistic, t .The p-value of the test. The function only needs to be able to handle a two-sided alternative. In order to output both, consider using c(t, pval) as the last line of your function, and store those two values elsewhere in the body of your function. (b) Write a function called make_decision which takes two inputs: pval: The p-value of a test . alpha: The significance level of a test. Set a default value of 0.05 The function should output "Reject!" or "Fail to Reject." based on the comparison of pval to alpha. (c) Now we will test the quality of your functions from parts (a) and (b). Run the following code: set.seed (114) y rnorm(25, 1.4, 1) pval do_t test(y, mu- 2) [2] pval make_decision(pval, alpha 0.10) If your do_t_testO and make_decision) functions are correct, you should obtain a decision of "Reject." You will also be evaluated on whether the numeric p-value you obtain is correct

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions