【发布时间】:2017-02-18 00:58:37
【问题描述】:
y <- cumsum(rnorm(100,0,1)) # random normal, with small (1.0) drift.
y.ts <- ts(y)
x <- cumsum(rnorm(100,0,1))
x
x.ts <- ts(x)
ts.plot(y.ts,ty= "l", x.ts) # plot the two random walks
Regression.Q1 = lm(y~x) ; summary(lm2)
summary(Regression.Q1)
t.test1 <- (summary(Regression.Q1)$coef[2,3]) # T-test computation
y[t] = y[t-1] + epsilon[t]
epsilon[t] ~ N(0,1)
set.seed(1)
t=1000
epsilon=sample(c(-1,1), t, replace = 1) # Generate k random walks across time {0, 1, ... , T}
N=T=1e3
y=t(apply(matrix(sample(c(-1,1),N*T,rep=TRUE),ncol=T),1,cumsum))
y[1]<-0
for (i in 2:t) {
y[i]<-y[i-1]+epsilon[i]
}
我需要:
重复该过程 1000 次(蒙特卡洛模拟),即围绕前一个程序构建一个循环,每次保存 t 统计量。您将有 1;000 个 t-tests 序列:S = (t-test1, t-test2, ... , t-test1000)。计算 1,000 t 检验的绝对值 > 1.96 的次数,即 5% 显着性水平的临界值。如果系列是 I(0),你会发现大约 5%。这里不是这种情况(虚假回归)。
我需要添加什么来保存各自的系数?
【问题讨论】:
标签: r loops simulation montecarlo