Bootstrap R Standard Error
Contents |
The R package boot allows a user to easily generate bootstrap samples of virtually any statistic that they can calculate in R. From these samples, you can generate estimates of bias, bootstrap bootstrap to estimate standard error in r confidence intervals, or plots of your bootstrap replicates. We will demonstrate a few of these
Bootstrap Standard Error Stata
techniques in this page and you can read more details at its CRAN package page. Before using commands in the boot package, bootstrap standard error estimates for linear regression you must first download the package and load it in your workspace. We will be using the hsb2 dataset for all of the examples on this page. install.packages("boot") library(boot) hsb2<-read.table("http://www.ats.ucla.edu/stat/data/hsb2.csv", sep=",", header=T) Using the boot commandThe bootstrap standard error matlab boot command executes the resampling of your dataset and calculation of your statistic(s) of interest on these samples. Before calling boot, you need to define a function that will return the statistic(s) that you would like to bootstrap. The first argument passed to the function should be your dataset. The second argument can be an index vector of the observations in your dataset to use or a frequency or weight vector that informs the
Bootstrap Standard Error Formula
sampling probabilities. The example below uses the default index vector and assumes we wish to use all of our observations. The statistic of interest here is the correlation coefficient of write and math. f <- function(d, i){ d2 <- d[i,] return(cor(d2$write, d2$math)) }With the function fc defined, we can use the boot command, providing our dataset name, our function, and the number of bootstrap samples to be drawn.bootcorr ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = hsb2, statistic = c, R = 500) Bootstrap Statistics : original bias std. error t1* 0.6174493 -0.004455323 0.04169738While the printed output for bootcorr is brief, R saves additional information that can be listed:summary(bootcorr) Length Class Mode t0 1 -none- numeric t 500 -none- numeric R 1 -none- numeric data 11 data.frame list seed 626 -none- numeric statistic 1 -none- function sim 1 -none- character call 4 -none- call stype 1 -none- character strata 200 -none- numeric weights 200 -none- numericKnowing the seed value would allow us to replicate this analysis, if needed, and from the t vector and t0, we could calculate the bias and standard error:mean(bootcorr$t) - bootcorr$t0 [1] -0.004455323 sd(bootcorr$t) [1] 0.04169738 For using other commands in the boot package, you will often need to provide a "boot" object:class(bootcorr) [1] "boot"Bootstrap confidence intervals and plotsTo look at a histogram a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business bootstrap standard error heteroskedasticity Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation bootstrap standard error in sas Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just
Standard Error Of Bootstrap Sample
like you, helping each other. Join them; it only takes a minute: Sign up R calculate the standard error using bootstrap up vote 7 down vote favorite 1 I have this array of values: > df [1] http://www.ats.ucla.edu/stat/r/faq/boot.htm 2 0 0 2 2 0 0 1 0 1 2 1 0 1 3 0 0 1 1 0 0 0 2 1 2 1 3 1 0 0 0 1 1 2 0 1 3 [38] 1 0 2 1 1 2 2 1 2 2 2 1 1 1 2 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 http://stackoverflow.com/questions/18341569/r-calculate-the-standard-error-using-bootstrap [75] 0 0 0 0 0 1 1 0 1 1 1 1 3 1 3 0 1 2 2 1 2 3 1 0 0 1 I want to use package boot to calculate the standard error of the data. http://www.ats.ucla.edu/stat/r/faq/boot.htm So, I used this command to pursue: library(boot) boot(df, mean, R=10) and I got this error: Error in mean.default(data, original, ...) : 'trim' must be numeric of length one Can someone help me figure out the problem? Thanks r standard-error statistics-bootstrap share|improve this question edited Jul 23 '15 at 11:57 Siguza 9,21542144 asked Aug 20 '13 at 17:38 Vahid Mir 1,40152139 1 What is your function definition for c? The base c function is not suitable for bootstrapping. –Frank Aug 20 '13 at 17:43 add a comment| 3 Answers 3 active oldest votes up vote 9 down vote accepted If you are bootstrapping the mean you can do as follows: set.seed(1) library(boot) x<-rnorm(100) meanFunc <- function(x,i){mean(x[i])} bootMean <- boot(x,meanFunc,100) >bootMean ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = x, statistic = meanFunc, R = 100) Bootstrap Statistics : original bias std. error t1* 0.1088874 0.002614105 0.07902184 If you just input the mean as an argument you will get the error like the one you got: bootMean <- boot(x,mean,100) Error in mean.default(data, original, ...) : 'trim' must be numeric of length one share|improve
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and http://stats.stackexchange.com/questions/22472/use-of-standard-error-of-bootstrap-distribution policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Cross Validated Questions Tags Users Badges Unanswered Ask Question _ Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute: standard error Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Use of standard error of bootstrap distribution up vote 18 down vote favorite 7 (ignore the R code if needed, as my main question is language-independent) If I want to look at the variability of a simple bootstrap standard error statistic (ex: mean), I know I can do it via theory like: x = rnorm(50) # Estimate standard error from theory summary(lm(x~1)) # same as... sd(x) / sqrt(length(x)) or with the bootstrap like: library(boot) # Estimate standard error from bootstrap (x.bs = boot(x, function(x, inds) mean(x[inds]), 1000)) # which is simply the standard *deviation* of the bootstrap distribution... sd(x.bs$t) However, what I'm wondering is, can it be useful/valid(?) to look to the standard error of a bootstrap distribution in certain situations? The situation I'm dealing with is a relatively noisy nonlinear function, such as: # Simulate dataset set.seed(12345) n = 100 x = runif(n, 0, 20) y = SSasymp(x, 5, 1, -1) + rnorm(n, sd=2) dat = data.frame(x, y) Here the model doesn't even converge using the original data set, > (fit = nls(y ~ SSasymp(x, Asym, R0, lrc), dat)) Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model so the statistics I'm interested in instead are more stabilized estimates of these nls parameters - perhaps their means across a number of bootstrap replications. # Obtain mean bootstrap
be down. Please try the request again. Your cache administrator is webmaster. Generated Thu, 06 Oct 2016 19:41:34 GMT by s_hv978 (squid/3.5.20)