Write a code in R markdown
Given sample data 1,2,3,2,2,2,6,0,2,3
(1) Estimate the percent bias of the sample median as a fraction of the standard error.
(2) Find an appropriate 90% confidence interval for the true median and interpret.
(3) Estimate the probability that the sample median exceeds two, i.e., P(sample median > 2)
(4) Does the data provide sufficient/significant evidence that the mean exceeds 2?
The R code for this problem is
getwd()
# the data is
#part 1
data=c(1,2,3,2,2,2,6,0,2,3)
#loading library boot
library(boot)
#settinga function that gives median
mymedian=function(x,d)
{median(x[d])}
#observed median
obs.median=median(data)
#calculation of SE of median
median.boot=boot(data,mymedian,R=10000)
#part 2
median.boot
# confidence interval of median
boot.ci(median.boot,conf = .9)
#part 3
s=sample(data,100000,replace = T)
length(s[s>2])/100000
#get answer as 0.29967
# part 4
ttest=function(x,d)
{sam=x[d]
t=(mean(sam)-2)*sqrt(length(sam)/var(sam))}
ttest=boot(data,ttest,R=10000)
#here t-statistic value is 0.60541
#hence we can say that the true mean is 2
Get Answers For Free
Most questions answered within 1 hours.