################
### EXERCISE 4.1 Computer Simulation
################
### Assume, you want to compare the vitamin C content of
### two food products, A and B.
### Simulate that you repeated this study K times.
### Change parameters values for K, for sample sizes n1 and n2,
### and for means and standard deviations in the population.
### Choose also scenarios with unequal standard deviations
### and unequal sample sizes in the two groups.
### In scenarios with mu1=mu2, i.e. under H0, determine the simulated rate
### (in percentages) of false positives.
### In scenarios with mu1!=mu2, i.e. under H1, determine the simulated rate
### (in percentages) of false negatives.
### Summarize all results in a table in a structured WORD-document.
K = 1000
n1 = 10
n2 = 10
mu1 = 20
mu2 = 20
sd1 = 1
sd2 = 1
P = rep(NA, K)
for (k in 1:K) {
S1 = rnorm(n1, mu1, sd1)
S2 = rnorm(n2, mu2, sd2)
T = t.test(S1, S2, paired=FALSE, var.equal=TRUE)
P[k] = T$p.value
}
### Under H0: rate of false positives
100 * sum(P<0.05)/K
### Under H1: rate of false negatives
100 * sum(P>=0.05)/K
### Based on your summary table in WORD, visualize false positive and
### false negative rate for selected parameters graphically as line plots.
### (One varried parameters should be on the X-axis, the rate on the Y-axis.)
### Consider also the difference D=mu1-mu2 to be displayed on the X-axis.
################
### EXERCISE 4.2
################
### Repeated EXERCISE 4.1 but draw data from a non-normal
### distribution, e.g. from the exponential distribution.
### Study again false positive and false negative rate, when
### the normality assumption for the t-test is not fulfilled,
### and summarize your results in a structured WORD-table.
################
### EXERCISE 4.3
################
### Import the unpdated data from EXERCISE 2.1 --> Apples_V02.xlsx
### Check the normality assumption for the weight of apples
### in plantation A, B, and C. Use quantile-quantile-plots.
### Check the normality assumption also using the
### Kolmogorow-Smirnov-test:
x1 = X$Weight[X$Plantation=="A"]
ks.test(x, "pnorm", mean(x1), sd(x1))
### Check also the assumption of equal variances of the apple
### weights between the three plantations, using graphical methods
### and F-tests:
x1 = X$Weight[X$Plantation=="A"]
x2 = X$Weight[X$Plantation=="B"]
x3 = X$Weight[X$Plantation=="C"]
var.test(x1, x2)
### Compare the apple weight between the three plantation
### using t-tests between each pair of plantation.
### Do the same analysis for the VitaminC content of the apples.