代码拉取完成,页面将自动刷新
同步操作将从 连享会/Greene_Econometrics 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# p. 502e; p. 460
# Gamma distribution
# Table FC1
import numpy as np
import pandas as pd
from scipy import optimize
from scipy.special import gamma, gammaln, digamma
from scipy import stats
df = pd.read_csv('http://www.stern.nyu.edu/~wgreene/'
'Text/Edition7/TableFC-1.csv',
index_col='I')
def mom_cond(theta, x=df.Y.values):
P, lambda_ = theta
m1 = x - P / lambda_
m2 = x ** 2 - (P * (P + 1) / lambda_**2)
m3 = np.log(x) - (digamma(P) - np.log(lambda_))
m4 = (1 / x) - lambda_ / (P - 1)
return np.vstack([m1, m2, m3, m4]).T.sum(0) # k x 1
sample_moms = (np.array([df.Y, df.Y ** 2, np.log(df.Y), 1 / df.Y]).sum(1) /
len(df.Y))
def pick_moms(theta, x, l=[0, 1]):
"""
List of pairs used to estimate.
"""
return sum(mom_cond(theta, x)[l] ** 2)
"""
I've got the estimation somewhat.
optimize.fmin(pick_moms, x0=[2, 2], args=[df.Y.values, [3, 3]])
"""
for pair in [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]:
print('{}\n'.format(pair))
print(optimize.fmin(pick_moms, x0=[2, 2], args=[df.Y.values, pair]))
print('\n\n')
# all of them
optimize.fmin(pick_moms, x0=[2, 2], args=[df.Y.values, [0, 1, 2, 3]])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。