File:Polyreg scheffe.svg
来自testwiki
跳转到导航
跳转到搜索
此SVG文件的PNG预览的大小:540 × 360像素。 其他分辨率:320 × 213像素 | 640 × 427像素 | 1,024 × 683像素 | 1,280 × 853像素 | 2,560 × 1,707像素。
原始文件 (SVG文件,尺寸为540 × 360像素,文件大小:40 KB)
本文件来自维基共享资源并可能被其他项目使用。 其文件描述页上的描述显示在下面。
摘要
| 描述Polyreg scheffe.svg |
English: Plot of a cubic polynomial fit using multiple least squares to a simulated data set. Along with the point estimate, a 95% simultaneous confidence band (CB) constructed using Scheffe's method is shown. |
| 日期 | |
| 来源 | 自己的作品 |
| 作者 | Skbkekas |
| 其他版本 |
[编辑]
|
| SVG开发 InfoField | |
| 源代码 InfoField | Python codeimport numpy as np
import matplotlib.pyplot as plt
import scipy.special as sp
## Sample size.
n = 100
## Predictor values.
XV = np.random.uniform(low=-4, high=4, size=n)
XV.sort()
## Design matrix.
X = np.ones((n,4))
X[:,1] = XV
X[:,2] = XV**2
X[:,3] = XV**3
## True coefficients.
beta = np.array([0, 0.1, -0.25, -0.25], dtype=np.float64)
## True response values.
EY = np.dot(X, beta)
## Observed response values.
Y = EY + np.random.normal(size=n)*np.sqrt(20)
## Get the coefficient estimates.
u,s,vt = np.linalg.svd(X,0)
v = np.transpose(vt)
bhat = np.dot(v, np.dot(np.transpose(u), Y)/s)
## The fitted values.
Yhat = np.dot(X, bhat)
## The MSE and RMSE.
MSE = ((Y-EY)**2).sum()/(n-X.shape[1])
s = np.sqrt(MSE)
## These multipliers are used in constructing the Scheffe interval.
XtX = np.dot(np.transpose(X), X)
V = [np.dot(X[i,:], np.linalg.solve(XtX, X[i,:])) for i in range(n)]
V = np.array(V)
## The F quantile used in constructing the Scheffe interval.
QF = sp.fdtri(X.shape[1], n-X.shape[1], 0.95)
## The lower and upper bounds of the confidence band.
D = s*np.sqrt(X.shape[1]*QF*V)
LB,UB = Yhat-D,Yhat+D
## Make the plot.
plt.clf()
plt.plot(XV, Y, 'o', ms=3, color='grey')
plt.plot(XV, EY, '-', color='blue', label = "Truth")
plt.plot(XV, Yhat, '-', color='green', label = "Estimate")
plt.plot(XV, LB, '-', color='red', label = "CB")
plt.plot(XV, UB, '-', color='red')
plt.legend(frameon=False)
plt.ylim([-25,20])
plt.gca().set_yticks([-20,-10,0,10,20])
plt.xlim([-4,4])
plt.gca().set_xticks([-4,-2,0,2,4])
plt.xlabel("X")
plt.ylabel("Y")
plt.savefig("polyreg_scheffe.pdf")
plt.savefig("polyreg_scheffe.svg")
|
许可协议
我,本作品著作权人,特此采用以下许可协议发表本作品:
本文件采用知识共享署名 3.0 未本地化版本许可协议授权。
- 您可以自由地:
- 共享 – 复制、发行并传播本作品
- 修改 – 改编作品
- 惟须遵守下列条件:
- 署名 – 您必须对作品进行署名,提供授权条款的链接,并说明是否对原始内容进行了更改。您可以用任何合理的方式来署名,但不得以任何方式表明许可人认可您或您的使用。
说明
添加一行文字以描述该文件所表现的内容
此文件中描述的项目
描繪內容
9 4 2009
image/svg+xml
文件历史
点击某个日期/时间查看对应时刻的文件。
| 日期/时间 | 缩略图 | 大小 | 用户 | 备注 | |
|---|---|---|---|---|---|
| 当前 | 2021年3月8日 (一) 16:27 | 540 × 360(40 KB) | wikimediacommons>Olexa Riznyk | Fixed Confidence band ("CB") label |
文件用途
以下页面使用本文件: