Instruction Aside from your handwritten or typed report with

Instruction: Aside from your handwritten or typed report with R outputs and programs, please, submit your programs and all data used for testing your program to me by email. One of the objectives of experimental design is to determine whether the treatments of a factor in an experiment have the same effect on the response or output or yield y of the experiment. It is also of interest to identify the best\' (if any) treatment. Suppose that there are a treatments in a single-factor fixed effects experiment. Let Ti denote the effect of treatment i, i a and yij, j 1, n, the jth response under treatment i. The model commonly used to describe such experiments is given by yij u nit cij, i 1, 2, a; j 1,2 ni, where ni is the number of responses under treatment i, u is the overall mean and eu is a random error which is assumed to be normally distributed with mean 0 and constant variance o2. In order to determine whether the treatment effects are the same, we test 0 T1 m T2 against a suitable alternative. Define, N 1 ni, 1 yau/ni, ij/N, MS The test statistic is MS when Ho is true the distribution of Fo is the Fa-1.N-a) distribution. It is therefore recommended to reject Ho if Fo is larger than the critical value F (N-a)(a) for some (a-1) fixed value of a Recall that P(F UN-a) Fo) p value. In this project, we will like to examine the distributions of M MSE and of Fo. We will also like to estimate a, the size of the test and 1-B the power of the test under various conditions. write R statements or an R function that will implement the following steps. 617.75, and a 1.5. Let a b) Generate for all i and j and compute yas under Ho. c) Compute M MSE and Fo and store the values. d For a 0.05 determine whether to reject Ho. Introduce a counter for the number of rejections

Solution

One of the great strengths of R is the user\'s ability to add functions. In fact, many of the functions in Rare actually functions of functions. The structure of a function is given below.

myfunction <- function(arg1, arg2, ... ){
statements
return(object)
}

Objects in the function are local to the function. The object returned can be any data type. Here is an example.

# function example - get measures of central tendency
# and spread for a numeric vector x. The user has a
# choice of measures and whether the results are printed.

mysummary <- function(x,npar=TRUE,print=TRUE) {
  if (!npar) {
    center <- mean(x); spread <- sd(x)
  } else {
    center <- median(x); spread <- mad(x)
  }
  if (print & !npar) {
    cat(\"Mean=\", center, \"\ \", \"SD=\", spread, \"\ \")
  } else if (print & npar) {
    cat(\"Median=\", center, \"\ \", \"MAD=\", spread, \"\ \")
  }
  result <- list(center=center,spread=spread)
  return(result)
}

# invoking the function
set.seed(1234)
x <- rpois(500, 4)
y <- mysummary(x)
Median= 4
MAD= 1.4826
# y$center is the median (4)
# y$spread is the median absolute deviation (1.4826)

y <- mysummary(x, npar=FALSE, print=FALSE)
# no output
# y$center is the mean (4.052)
# y$spread is the standard deviation (2.01927)

It can be instructive to look at the code of a function. In R, you can view a function\'s code by typing the function name without the ( ).

These are some good programing techniques in general.

Writing Functions

Functions in R can do 3 things

The R function Statement

The basic R function statement looks like this
FUNname <- function( arglist ) { code }

Function Return Values

Functions are designed to return values. It is call returning because the value is taken from the function and is returned to the calling code.

 Instruction: Aside from your handwritten or typed report with R outputs and programs, please, submit your programs and all data used for testing your program t
 Instruction: Aside from your handwritten or typed report with R outputs and programs, please, submit your programs and all data used for testing your program t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site