Question

Write an R function that will simulate 2 data sets from gamma distributions (``rgamma'' function, this...

Write an R function that will simulate 2 data sets from gamma distributions (``rgamma'' function, this gives us skewed samples) then does a standard t-test comparing the 2 means (``t.test'' function) and returns the p-value. The function should have 2 sample sizes and 2 sets of parameters as input.

Now use the function to simulate a case with small sample sizes and the null hypothesis being true (equal means) and see how the type I error rate is affected by the skewness.

Run some simulations to find a combination of sample sizes and parameter values that will give you between 80% and 95% power.

Homework Answers

Answer #1

Run the code below in R:


set.seed(1001)
test <- function(m,n,par1,par2){
sample1 <- rgamma(m,par1)
sample2 <- rt(n,par2)
test <- t.test(sample1,sample2)
return(test$p.value)
}

thres <- 0.05
test.result <- function(pvalue){
ifelse(pvalue<thres,1,0)
}

nnMC <- 2500
power <- function(m,n,par1,par2){
res <- numeric(nnMC)
for(i in 1:nnMC){
t <- test(m,n,par1,par2)
res[i] <- test.result(t)
}
return(mean(res))
}


power(25,35,2,2)


par2.range <- seq(0.5,10,by = 0.05)
power.test <- numeric(length(par2.range))
for(k in 1:length(par2.range)){
power.test[k] <- power(25,35,par2.range[k],2)
}

par2.range[which.max(power.test>0.8)]
par2.range[which.max(power.test>0.95)]
plot(par2.range,power.test)
#Thus in the range(1.3,2.2) the given conditions hold where power is in (0.80,0.95)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
R Simulation: For n = 10, simulate a random sample of size n from N(µ,σ2), where...
R Simulation: For n = 10, simulate a random sample of size n from N(µ,σ2), where µ = 1 and σ2 = 2; compute the sample mean. Repeat the above simulation 500 times, plot the histogram of the 500 sample means (does it mean that I can just use hist() method instead of plot() method). Now repeat the 500 simulations for n = 1,000. Compare these two sets of results with different sample sizes, and discuss it in the context...
Instructions Estimation of the parameters for the Exponential and Weibull distributions. DATA SET A: 2, 14,...
Instructions Estimation of the parameters for the Exponential and Weibull distributions. DATA SET A: 2, 14, 23, 45, 67, 75, 89, 99, 101, 123, 138, 159, 188, 201, 203 DATA SET B: 13, 24, 35+, 65, 86, 99, 109, 118+, 131, 159, 189, 207 DATA SET C: 5, 13, 34+, 46+, 55, 74, 89, 93, 104, 112+, 126, 134, 145, 159, 167+, 173, 198, 203, 226, 241 DATA SET D: 9, 14, 85, 99, 126, 155, 169+, 199, 201+, 224+,...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT