Question

In: Statistics and Probability

In R, how do you create a bootstrap distribution for the 5% trimmed mean by taking...

In R, how do you create a bootstrap distribution for the 5% trimmed mean by taking 1000 resamples (with replacement), with a given dataset named 'data'? I am just looking for the correct R code that will allow me to plug in my data to find the 5% trimmed mean by taking 1000 resamples. The dataset is composed of salaries of a random sample, and I am not providing it because the only question I have is how to correctly format this bootstrapping code in R. This is all I need.

Solutions

Expert Solution

R code with comments (all statements starting with # are comments)

#set the random seed
set.seed(123)

# get the data,
#data<-read....

#assuming that the data is in the dataset named data

# get the sample size (That is number of observations in data)
# assuming that data has 1 column, else use data$salary everywhere, if data is a dataframe
n<-nrow(data)

#set the bootstrap resamples
B<-1000
#initialize variable to hold the trimmed mean of resamples
mustar<-numeric(B)
for (i in 1:B){
   #sample with replacement using sample(), assuming data has 1 column, else use data$salary
   s<-sample(data[,1],size=n,replace=TRUE)
   #calculate the 5% trimmed mean
   mustar[i]<-mean(s,0.05)  
}

#Do all the things that you want to do with this, for example
#plot the distribution of mean
hist(mustar,xlab="average Salary",freq=FALSE, main="Bootstrap distribution of mean Salary")
#98% confidence interval using percentile
# get the value of alpha
alpha<-1-98/100
ci<-quantile(mustar,c(alpha/2,1-alpha/2))
sprintf("98% confidence interval for the mean Salary is [%.4f,%.4f]",ci[1],ci[2])


Related Solutions

Hey anyone good with R studio? How do you create a square shape with R code...
Hey anyone good with R studio? How do you create a square shape with R code by using plot() and lines() please show your code !
13. Percentiles of a bootstrap distribution (based on 5000 samples) are provided. 0.5% 1% 2.5% 5%...
13. Percentiles of a bootstrap distribution (based on 5000 samples) are provided. 0.5% 1% 2.5% 5% 95% 97.5% 99% 99.5% -0.945 -0.940 -0.928 -0.919 -0.741 -0.723 -0.705 -0.689 Use the percentiles to provide a 99% confidence interval for the parameter. Indicate the percentiles that you use. Use the percentiles to provide a 98% confidence interval for the parameter. Indicate the percentiles that you use. Use the percentiles to provide a 95% confidence interval for the parameter. Indicate the percentiles that...
How do you calculate the mean and standard deviation of the sampling distribution for sample means?...
How do you calculate the mean and standard deviation of the sampling distribution for sample means? [2 sentences] What is the effect of increasing sample size on the sampling distribution and what does this mean in terms of the central limit theorem? [2 sentences] Why is the standard deviation of the sampling distribution smaller than the standard deviation of the population from which it came? [3 sentences]
In R, get a sample of size n=5 from the Cauchy distribution and calculate its mean....
In R, get a sample of size n=5 from the Cauchy distribution and calculate its mean. (mean(rcauchy(5)). Repeat this 1000 times and plot the histogram of the resulting 1000 means. Please show your R codes. n <- 5 listofmeans <- c() for(i in 1:1000){ }listofmeans <- c(listofmeans, mean(rcauchy(n))) hist(listofmeans) Create other histograms, changing the value of n to 10, 30, 100, and 500. Comment on what these graphs show in light of the Central Limit Theorem.
What do you mean by pro-R and pro-S?
What do you mean by pro-R and pro-S?
How do you create a frequency distribution on excel using all 7 variables? Customer Type of...
How do you create a frequency distribution on excel using all 7 variables? Customer Type of Customer Items Net Sales Method of Payment Gender Marital Status Age 1 Regular 1 39.50 Discover Male Married 32 2 Promotional 1 102.40 Proprietary Card Female Married 36 3 Regular 1 22.50 Proprietary Card Female Married 32 4 Promotional 5 100.40 Proprietary Card Female Married 28 5 Regular 2 54.00 MasterCard Female Married 34 6 Regular 1 44.50 MasterCard Female Married 44 7 Promotional...
How do you create the dot plot?
How do you create the dot plot?
In this assignment, you will learn how to describe the distribution of the sample mean (),...
In this assignment, you will learn how to describe the distribution of the sample mean (), and investigate how sample size affects variability of the sample mean (). To find out various probability values you will have to calculate the standard error of, and use the standard error to convert into Z score. MARS Chocolate claims* that the net weight of its 31 oz Party Bucket is normally distributed with a mean of 32 oz and a standard deviation of...
using access, how do you create a table with a field called discount where 1=5% and...
using access, how do you create a table with a field called discount where 1=5% and 2=6%? screenshot how to steps with microsoft access
After taking a 5 week course in Grant Writing, do you feel that you could serve...
After taking a 5 week course in Grant Writing, do you feel that you could serve as a reviewer? Why or why not?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT