文档库 最新最全的文档下载
当前位置:文档库 › Bootstrap and Jackknife Calculations in R

Bootstrap and Jackknife Calculations in R

Bootstrap and Jackknife Calculations in R
Bootstrap and Jackknife Calculations in R

Bootstrap and Jackknife Calculations in R

Version 6April 2004

These notes work through a simple example to show how one can program R to do both jackknife and bootstrap sampling.We start with bootstrapping.

Bootstrap Calculations

R has a number of nice features for easy calculation of bootstrap estimates and con?dence

intervals.To see how to use these features,consider the following 25observations:8.26 6.3310.4 5.27 5.35 5.61 6.12 6.19 5.27.018.747.787.026

6.5

5.8

5.12

7.41

6.52

6.21

12.28 5.6

5.38

6.6

8.74

Suppose we wish to estimate the coef?cient of variation,CV =√

Var /x .Let’s do this with

a bootstrap estimator.

First,let’s put the data into a vector,which we will call x ,

>x <-c(8.26, 6.33,10.4, 5.27, 5.35, 5.61, 6.12, 6.19, 5.2,7.01,8.74,7.78,7.02,6, 6.5, 5.8, 5.12,7.41, 6.52, 6.21,12.28, 5.6, 5.38, 6.6,8.74)

Now let’s de?ne a functon in R ,which we will call CV ,to compute the coef?cient of variation,

>CV <-function(x)sqrt(var(x))/mean(x)

So,let’s compute the CV

>CV(x)

[1]0.2524712

To generate a single bootstrap sample from this data vector,we use the command

>sample(x,replace=T)

which generates a bootstrap sample of the data vector x by sampling with replacement.Hence,to compute the CV using a single bootstrap sample,

>CV(sample(x,replace=T))[1]0.2242572

The particular value that R returns for you will be different as the sample is random.Some other useful commands:

>sum(x)returns the sum of the elements in x >mean(x)returns the mean of the elements in x

>var(x)returns the sample variance,i.e.,

i (x ?x )2/(n ?1)

>length(x)returns the number of items in x (i.e.,the sample size n )

Note that the sum command is fairly general,for example

>sum((x-mean(x))^2)computes

i (x ?x )2

So,lets now generate 1000bootstrap samples.We ?rst need to specify a vector of real values of lenght 1000,which we will call boot

>boot <-numeric(1000)

We now generate 1000samples,and assign the CV for bootstrap sample i as the i th element in the vector boot ,using a for loop

for (i in 1:1000)boot[i]<-CV(sample(x,replace=T))

The mean and variance of this collection of bootstrap samples are easily obtained using the mean and var commands (again,your values may differ),

>mean(boot)[1]0.2404653>var(boot)[1]0.00193073

A plot of the histogram of these values follows using

hist(boot)

Likewise,the value corresponding to the (say)upper 97.5

>quantile(boot,0.975)[1]0.3176385

while the value corresponding to the lower 2.5%follows from

>quantile(boot,0.025)[1]0.153469

Recall from the notes that the estimate of the bias is given by the difference between the mean of the bootstrap values and the initial estimate,

>bias<-mean(boot)-CV(x)

and an bootstrap-corrected estimate of the CV is just the original estimate minus the bias, >CV(x)-bias

[1]0.2644771

Assuming normality,the approximate95%con?dence interval is given by

CV±1.96

(or adjusting for the bias an lower and upper values of

>CV(x)-bias- 1.96*sqrt(var(boot))

[1]0.1783546

>CV(x)-bias+ 1.96*sqrt(var(boot))

[1]0.3505997

Efron’s con?dent limit(Equation11on resampling notes)has an upper and lower value of

>quantile(boot,0.975)

[1]0.3176385

and

>quantile(boot,0.025)

[1]0.153469

While Hall’s con?dence limits(Equation12)has an upper and lower value of >2*CV(x)-quantile(boot,0.025)

[1]0.3514734

and

>2*CV(x)-quantile(boot,0.975)

[1]0.1873039

Jackknife Calculations

We now turn to jackkni?ng the sample.Recall from the randomization notes that this involves two steps.First,we generate a jackknife sample which has value x i removed and then compute the i th partial estimate of the test statistic using this sample,

θ

(x1···x i?1,x i,···x n)

i

We then turn this i th partial estimate into the i th pseudovalue θ?i using(Equation5c in random notes)

θ?

=n θ?(n?1) θi

i

where θis the estimate using the full data.

Let’s see how to code this in R using the previous vector x of data with our test statistic again being the coef?cient of variation(and hence our function CV previously de?ned). We?rst focus on generating the i th partial estimate and i th pseudovalue.We need to take the original data vector x and turn it into a vector(which we denote jack)of lenght n?1 as follows.First,we need to specify to R that we are creating the jackknife sample vector of the n?1sampled points

jack<-numeric(length(x)-1)

As before,we will use the command lenght(x)in place of n.We also need to specify to R that we will be generating a vector pseudo of the n pseudovalues

pseudo<-numeric(length(x))

Next,we need to?ll in the elements of the jack sample vector as follows.For ji,the j?1th element of jack is the j th element of x.We can state all this using a logical if..else statement within a for loop,

for(j in1:length(x))if(j

else if(j>i)jack[j-1]<-x[j]

We can then compute the i th pseudovalue(for the CV)as follows:

pseudo[i]<-lenght(x)*CV(x)-(lenght(x)-1)*CV(jack)

Finally,we top this all off by looping through the n possible i values,giving the?nal code as

jack<-numeric(length(x)-1)

pseudo<-numeric(length(x))

for(i in1:length(x))

{for(j in1:length(x))

{if(ji)jack[j-1]<-x[j]}

pseudo[i]<-length(x)*CV(x)-(length(x)-1)*CV(jack)}

Note the use of the parenthesis({,})to delimit the appropriate elements in each loop.The mean and variance of the pseudovalues are easily found using

>mean(pseudo)

[1]0.2617376

>var(pseudo)

[1]0.07262871

Likewise,a histogram of the pseudovalues is generated using

hist(pseudo)

Recall that the mean of the pseudovalues is the bootstrap estimator,while var(pseudo)/n is the variance of this estimator,

>var(pseudo)/length(x)

[1]0.002905148

An approximate 95%con?dence interval is given by

mean(pseudo)±t 0.975,n ?1 var(pseudo)/n Using R ,the upper and lower limits become

>mean(pseudo)+qt(0.975,length(x)-1)*sqrt(var(pseudo)/length(x))[1]0.3729806

>mean(pseudo)-qt(0.975,length(x)-1)*sqrt(var(pseudo)/length(x))[1]0.1504947

Giving the approximate 95%jackknife con?dence interval as 0.150to 0.372.

Here’s a summary of the various estimated values,variances,and con?dence intervals

Method

Estimated CV Variance 95%interval Original Estimate 0.252Jackknife 0.2620.00290.150-0.373Bootstrap

0.264

0.0019

Bootstrap (normality)0.178-0.351Bootstrap (Efron)0.153-0.318Bootstrap (Hall)

0.187-0.351

Bootstrap教程第一课:简单的Bootstrap主页

Bootstrap教程第一课:简单的Bootstrap主页(1) 写在前面: Bootstrap是目前最流行的前端框架,我从简单的实例开始,写一份文字版的Bootstrap教程,希望能对大家有所帮助。 准备工作: 1、下载Bootstrap框架核心文件。 2、下载jQuery文件。 3、下载HTML5兼容IE的JS插件。 (各位可以从网上找到Bootstrap和jQuery以及HTML5 JS的官方下载地址,也可以直接点击下面的下载链接下载,我已经将jQuery文件放在了js目录里了。)点击下载Bootstrap核心文件 HTML结构: 1、Bootstrap框架的文档必须声明为HTML5文件类型,所以你的每一个页面都必须按照下面的格式进行设置: ...... 2、添加HTML文档meta标记,需要两条标记: 3、引入所需要的核心文件,包括Bootstrap的CSS文件,jQuery插件,Bootstrap的JS核心文件,以及HTML5.JS文件。

那么现在,你的HTML文档,应该是这个样子的: Bootstrap 第一课:简单的Bootstrap主页 正式开始: 现在就可以在body之间写上你的网页结构代码了,添加上Bootstrap相应的CSS 类样式,就可以完成一个最简单的Bootstrap主页了。 首先,写好HTML结构代码:

这是一个简单的Bootstrap主页

这是一个简单的Bootstrap主页,制作这个主页,可 以分为三个步骤:

基于Bootstrap的网页开发

J I A N G S U U N I V E R S I T Y 本科毕业论文 基于bootstrap的网页设计 Bootstrap-based web design 学院名称:计算机科学与通信工程学院 专业班级:软件(嵌入式)1102班 学生姓名:缪江超 指导教师姓名:马汉达 指导教师职称:高级工程师 2015年6月

基于bootstrap的网页设计 计算机科学与通信工程学院软件工程(嵌入式)缪江超 摘要::当今社会,网络是人们生活中不可或缺的一部分,网页则是传递信息的重要媒介。随着时代的进步,网页设计也随着网络技术的发展而不断发展。计算机学院实验中心信息管理系统,是2004年开发的,因设计开发时间较早,其界面已不适应当前的技术发展,不能满足师生对于网站美观要求。 Bootstrap是当下最受人们欢迎的前端框架,是基于HTML、CSS、JAVASCRIPT 的,它简洁灵活的特性使得 Web 开发更加快捷,Bootstrap提供了优雅的HTML和CSS规范,它由动态CSS语言Less写成。本文针对实验中心网站得主要问题,介绍了网页设计的相关理论,使用Bootstrap框架,对实验中心网站进行了重新布局设计,使得网站界面更为美观,用户体验更好。 关键字:前端开发 Bootstrap 布局架构实验室网站

Bootstrap-based web design Miao Jiangchao, Computer Science and Communication Engineering, Software Engineering (embedded) Professional Abstract: Nowadays, networks are an indispensable part of people's lives, the page is an important medium to transmit information. With the progress of the times,with the development of network technology,web design continue to develop. School of Computer Science Experiment Center Information Management System, developed in 2004, due to the design and development time earlier, the interface has not adapted to current technological developments, and can not meet the aesthetic requirements for teachers or students. Now Bootstrap is the most popular front frame,which is based on HTML, CSS, JAVASCRIPT, which is a clean and flexible features that make Web development faster. Bootstrap offers elegantly HTML and CSS specification, which is written by the dynamic CSS language Less. In this paper, the main problem is the Experimental Center site, introduces the theory of web design, use Bootstrap framework, the experimental center site re-layout design, making the site more attractive interface, better user experience. Key Words:Front-end development Bootstrap Layout Architecture Laboratory site

《经济学基础》各讲习题及参考答案(简)

《西方经济学》习题及参考答案 《经济学基础》第一讲绪论习题及参考答案 一、单选题 1、资源的稀缺性是指()。 A、资源的绝对有限性; B、资源的充足性; C、资源的稀少性; D、资源的相对有限性; 2、追求效用最大化的主体是()。 A、居民户; B、厂商; C、劳动者; D、政府; 3、微观经济学的中心理论是()。 A、均衡价格理论; B、消费者行为理论; C、生产者行为理论; D、分配理论; 4、宏观经济学的中心理论是()。 A、国民收入决定理论; B、失业与通货膨胀理论; C、经济周期与经济增长理论; D、宏观经济政策; 5、解决“应该是什么”问题的经济学是()。 A、理论经济学; B、应用经济学; C、实证经济学; D、规范经济学; 6、解决“是什么”问题的经济学是()。 A、理论经济学; B、应用经济学; C、实证经济学; D、规范经济学; 7、以个别居民与厂商为研究对象的经济学理论是()。 A、微观经济学; B、宏观经济学; C、实证经济学; D、规范经济学; 8、以整个国民经济为研究对象的经济学理论是()。 A、微观经济学; B、宏观经济学; C、实证经济学; D、规范经济学; 9、()奠定了经济学作为一个独立学科的基础。 A、亚当·斯密; B、马歇尔; C、凯恩斯; D、萨缪尔森; 10、()为首的经济济学家把个量分析为主的微观经济学和以总量分析为主的宏观经济学拼和在一起形成了主流经济学派。 A、亚当·斯密; B、马歇尔; C、凯恩斯; D、萨缪尔森; 二、判断题 1、自由取用物品是零点价格时供给小于需求的物品。() 2、经济物品是零点价格时供给小于需求的物品。() 3、微观经济学是宏观经济学的基础。()

黑马程序员UI教程:Bootstrap弹出框

黑马程序员UI教程:Bootstrap弹出框 使用过JQuery UI的园友们应该知道,它里面有一个dialog的弹出框组件,功能也很丰富。与jQuery UI的dialog类似,Bootstrap里面也内置了弹出框组件。打开bootstrap 文档https://www.wendangku.net/doc/216908451.html,/components/可以看到它的dialog是直接嵌入到bootstrap.js和bootstrap.css里面的,也就是说,只要我们引入了bootstrap的文件,就可以直接使用它的dialog组件,是不是很方便。本篇我们就结合新增编辑的功能来介绍下bootstrap dialog的使用。废话不多说,直接看来它如何使用吧。 1、c shtml界面代码