Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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])

Add a comment
Know the answer?
Add Answer to:
In R, how do you create a bootstrap distribution for the 5% trimmed mean by taking 1000 resamples...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can you sovle this problem, also I need the code for part d. thanks Problem #5 Ri Vy= Probe I R- 1502 o VOLTMETER IN...

    can you sovle this problem, also I need the code for part d. thanks Problem #5 Ri Vy= Probe I R- 1502 o VOLTMETER INPUT CIRCUIT Probe 2 Express resistance in ohms (2) and voltage in volts (V) Requirements-Part 1 (voltmeter not attached yet) a) Suppose you want to produce a voltage of 1 V across resistor R2 (i.e. Vor 1 V) Use the voltage divider equation to find the value of Ri that is needed to do this. b)...

  • One-Variable Data Table Your maximum weekly production capability is 200 gallons. You would like to create...

    One-Variable Data Table Your maximum weekly production capability is 200 gallons. You would like to create a one-variable data table to measure the impact of Production Cost, Gross Profit, and Net Profit based on selling between 10 and 200 gallons of paint within a week. a. Start in cell E3. Complete the series of substitution values ranging from 10 to 200 at increments of 10 gallons vertically down column E. b. Enter references to the Total Production Cost, Gross Profit,...

  • 1 Overview The goal of this assignment is to help you understand caches better. You are...

    1 Overview The goal of this assignment is to help you understand caches better. You are required to write a cache simulator using the C programming language. The programs have to run on iLab machines. We are providing real program memory traces as input to your cache simulator. The format and structure of the memory traces are described below. We will not give you improperly formatted files. You can assume all your input files will be in proper format as...

  • The lab for this week addresses taking a logical database design (data model) and transforming it...

    The lab for this week addresses taking a logical database design (data model) and transforming it into a physical model (tables, constraints, and relationships). As part of the lab, you will need to download the zip file titled CIS336Lab3Files from Doc Sharing. This zip file contains the ERD, Data Dictionary, and test data for the tables you create as you complete this exercise. Your job will be to use the ERD Diagram found below as a guide to define the...

  • how to make my code of python work probely my q is how to write a...

    how to make my code of python work probely my q is how to write a code to find the average actual water level, average error by using python and my program should be flexible where user can select the column no. If you can see in the main program, it asked which column to know the maximum or average, the column number is passed to the function. The function should look which column to do. #THIS PROGRAMMING IS ABLE...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • I'm having trouble getting my balance to equal for the unadjusted balance. Also how do I...

    I'm having trouble getting my balance to equal for the unadjusted balance. Also how do I create the adjusted trial balance? Adjusting Journal Entries to be recorded on 31 Jan Account Titles and Explanation Date DebitCredit $12,385 31-Jan Supplies Expenses S12,385 Supplies (To record supplies used in the month) 31-Jan nrned Servicc Revcnuc 1,100 Service Revenue (To record revenue for the service performed) (13200 12 x 1 month 1100) S1,100 31-Jan Interest expense $100 Interest payable (To record interest on...

  • Assignment 5 will be way different. It will be more like what you will receive in...

    Assignment 5 will be way different. It will be more like what you will receive in a programming shop. By that I mean that some things are built for you and others you will need to create or finish. P.S. part of your grade will include: Did you add in the required files? Did you rename your project? does your linear searches work? Did you put your code in the correct modules? did you change modules that you weren't supposed...

  • C++ For this assignment you will be building on the Original Fraction class you began last...

    C++ For this assignment you will be building on the Original Fraction class you began last week. You'll be making four major changes to the class. [15 points] Delete your set() function. Add two constructors, a default constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Since Fractions cannot have...

  • Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in...

    Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT