Again, just like last time it is wise to start with fixing the random seed.
set.seed(123)
n
numbers from a normal distribution with a user defined mean (i.e. a mean that you can choose when running the function) and standard deviation 1, and returns the p.value
for the test that the mean is 0.qqplot
to compare distribution of the \(p\)-values with a uniform \([0,1]\) variable.In a study that examined the use of acupuncture to treat migraine headaches, consenting patients on a waiting list for treatment for migraine were randomly assigned in a 2:1:1 ratio to acupuncture treatment, a “sham” acupuncture treatment in which needles were inserted at non-acupuncture points, and waiting-list patients whose only treatment was self-administered (Linde et al., 2005). The “sham” acupuncture treatment was described to trial participants as an acupuncture treatment that did not follow the principles of Chinese medicine.
Use the following data
data <- matrix(c(74, 71, 43, 38, 11, 65), nrow = 2, ncol = 3)
colnames(data) <- c("Acupuncture", "Sham", "Waiting list")
rownames(data) <- c("> 50% reduction", "< 50% reduction")
data
## Acupuncture Sham Waiting list
## > 50% reduction 74 43 11
## < 50% reduction 71 38 65
data <- matrix(c(82, 17, 30, 30, 26, 16), nrow = 3, ncol = 2)
colnames(data) <- c("Acupuncture", "Sham")
rownames(data) <- c("Chinese", "Other", "Don't know")
data
## Acupuncture Sham
## Chinese 82 30
## Other 17 26
## Don't know 30 16
In the following simulation experiment we investigate least-squares estimation of the mean.
32083
.lsfun
because we are going to identify the least squares estimate in exercise 8.lsfun()
. Let the function plot the curve and print the location where the minimum of the sum of the squares is located each time. Fix the seed to set.seed(123)
:Hint: use the sample mean \(\bar{x}\) as the center of your graph and add/subtract e.g. .5
from this value to plot a range.
End of practical.