[R] Bootstrapping

2011-12-06 Thread Bastian Offermann

Hello,

I am having some trouble setting up a bootstrapping prodecure. I create 
artificial data and would like to use these to bootstrap a t-test 
statistic from these. Especially I do not really get how boot uses the 
indices variable or i variable. Can anybody help out? Thanks!!


b0 - 1/2 # intercept as given
b1 - 1   # slope as given
n - 20   # of rand. numbers
u - rnorm(n, mean=0, sd=1)   # generate data
x - rnorm(n, mean=0, sd=1)   #
y - b0 + b1*x + u# model
mu - 1

data1 - matrix(, n, 2)# Data from original draw

tval - function(data1, i) {
  data1[i,1] - y
  data1[i,2] - x
  m - lm(data1[,1]~data1[,2])
  p - coef(m)[2]
  t - (coef(m)[2]-mu)/sqrt(vcov(m)[2,2])   # t-test
  t

}
bs - boot(data = data1, statistic = tval, R = 500, sim = ordinary)
bs
ba - boot.array(bs)[1:5,1:10]
ci - boot.ci(bs, conf=0.95, index=1, type=all)
ci.bca - ci$bca[4:5]
plot(bs, index=1)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Static random numbers

2008-12-03 Thread Bastian Offermann

Hello,

can anybody help me out saving random numbers? What I am doing is to 
generate a series of random numbers and keep it as a zoo object.


z - 1000

rn1 - as.zoo(rnorm(z))

The random numbers will be analyzed and described in a LaTeX document, 
so I have to keep them static somehow. The fact that they are kept

as a zoo object should not be of too much concern here. Thanks in advance.

Regards

Bastian Offermann


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] remove multiple elements from vector

2008-09-27 Thread Bastian Offermann

Hello all,

one brief question

I would like to remove double/triple elements from a vector, e.g.

0 1 1 1 1 2 2 2 4 5 6 6

but keep one of these multiple ones. Should look like this finally:

0 1 2 4 5 6

My function does not work somehow

for(i in 2 : length(x)) {
if(x[i]==x[i-1]) x - x[-(i-1)]
}

any suggestion? Thanks.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.