R 序贯蒙特卡罗

R 序贯蒙特卡罗,r,statistics,distribution,normal-distribution,montecarlo,R,Statistics,Distribution,Normal Distribution,Montecarlo,我得到了这个模型,为了得到模拟数据的概率 x_1 ∼N(0, 102) x_t =0.5 ∗ (x_t−1) + 25 · (x_t−1)/(1 + (x_t-1)^2) + 8 · cos(1.2 ∗ (t − 1)) + εt , t = 2, 3, .. y_t =(x_t)^2/25 + ηt, t = 1, 2, 3, ... 其中εT和ηT服从正态分布 我试图反转函数,但我不能这样做,因为我不知道我的X是正的还是负的。我知道我应该使用顺序蒙特卡罗,但我不知道如何找到算法的函数。

我得到了这个模型,为了得到模拟数据的概率

x_1 ∼N(0, 102)

x_t =0.5 ∗ (x_t−1) + 25 · (x_t−1)/(1 + (x_t-1)^2) + 8 · cos(1.2 ∗ (t − 1)) + εt
, t = 2, 3, ..

y_t =(x_t)^2/25 + ηt, t = 1, 2, 3, ...
其中εT和ηT服从正态分布

我试图反转函数,但我不能这样做,因为我不知道我的X是正的还是负的。我知道我应该使用顺序蒙特卡罗,但我不知道如何找到算法的函数。什么是f和g,我们怎样才能确定x(t-1),因为x的平方,它是正的还是负的

算法:

1 Sample X1 ∼ g1(·). Let w1 = u1 = f1(x1)/g1(x1). Set t = 2

2 Sample Xt|xt−1 ∼ gt(xt|xt−1).

3 Append xt to x1:t−1, obtaining xt

4 Let ut = ft(xt|xt−1)/gt(xt|xt−1)

5 Let wt = wt−1ut , the importance weight for x1:t

6 Increment t and return to step 2

对于像您这样的时间序列模型,计算x或y的概率分布的唯一方法基本上是对该模型进行多次模拟,随机抽取x_0、eps_t、eta_t的值,然后通过聚合所有运行的样本来构建直方图。在非常特殊的情况下(例如阻尼布朗运动),可以用代数方法计算得到的概率分布,但我认为你的模型不可能这样

在Python中(恐怕我对R不够流利),您可以通过以下方式模拟时间序列:

import math, random    

def simSequence(steps, eps=0.1, eta=0.1):
    x = random.normalvariate(0, 102)

    ySamples = []

    for t in range(steps):
        y = (x ** 2) / 25 + random.normalvariate(0, eta)
        ySamples.append(y)

        x = (0.5 * x + 25 * x / (1 + x ** 2)
                + 8 * math.cos(1.2 * t) + random.normalvariate(0, eps))

    return ySamples
(这将t=1..n替换为t=0..n(n-1)。)

然后,您可以生成一些y时间序列示例的绘图:

import matplotlib.pyplot as plt

nSteps = 100
for run in range(5):
    history = simSequence(nSteps)
    plt.plot(range(nSteps), history)
plt.show()
要获得类似于:

然后,如果您想计算y在不同时间的概率分布,您可以生成一个矩阵,其列表示y_t在公共时间值的实现,并计算选定t值的直方图:

import numpy

runs = numpy.array([ simSequence(nSteps) for run in range(10000) ])
plt.hist(runs[:,5], bins=25, label='t=5', alpha=0.5, normed=True)
plt.hist(runs[:,10], bins=25, label='t=10', alpha=0.5, normed=True)
plt.legend(loc='best')
plt.show()
其中: