虚拟变量线回归源程序代码.doc_第1页
虚拟变量线回归源程序代码.doc_第2页
虚拟变量线回归源程序代码.doc_第3页
虚拟变量线回归源程序代码.doc_第4页
虚拟变量线回归源程序代码.doc_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

源代码显示原始数据:Private Sub Command1_Click()Open C:x.txt For Input As #1Open c:y.txt For Input As #2Dim X(1 To 22), Y(1 To 22), X1!, Y1!, a1%Do While Not EOF(1) Input #1, X1 a1 = a1 + 1 X(a1) = X1 Loop a1 = 0Do While Not EOF(2) Input #2, Y1 a1 = a1 + 1 Y(a1) = Y1 Loop Close #1Close #2PrintPrint Spc(35); 1994年1月至1999年2月社会消费品零售总额(Y:亿元)Print -Print Spc(5); X:;For i = 1 To 11Print Spc(2); X(i);Next iPrintPrint Spc(5); X:;For i = 12 To 22Print Spc(1); X(i);Next iPrintPrint -Print Spc(5); Y:;For i = 1 To 11Print Spc(1); Y(i);Next iPrintPrint Spc(5); Y:;For i = 12 To 22Print Spc(1); Y(i);Next iPrintPrint -End Sub绘制时序图程序:Private Sub Command1_Click()Open C:x.txt For Input As #1Open c:y.txt For Input As #2Dim X(1 To 22), Y(1 To 22), X1!, Y1!, a1%Do While Not EOF(1) Input #1, X1 a1 = a1 + 1 X(a1) = X1 Loop a1 = 0Do While Not EOF(2) Input #2, Y1 a1 = a1 + 1 Y(a1) = Y1 Loop Close #1Close #2Dim i%Form3.Scale (1, 9500)-(30, 3000)DrawWidth = 7Line (3, 3300)-(30, 3300): Line (3, 3000)-(3, 9200)CurrentX = 25: CurrentY = 3800: Print XCurrentX = 4: CurrentY = 9000: Print YFor i = 1 To 21Form3.Line (i + 3), Y(i)-(i + 4), Y(i + 1), vbBlueNext iEnd Sub线性回归结果程序:Private Sub Command1_Click()Open C:x.txt For Input As #1Open c:y.txt For Input As #2Dim X(1 To 22), Y(1 To 22), X1!, Y1!, a1%Do While Not EOF(1) Input #1, X1 a1 = a1 + 1 X(a1) = X1 Loop a1 = 0Do While Not EOF(2) Input #2, Y1 a1 = a1 + 1 Y(a1) = Y1 Loop Close #1Close #2Dim a, b, sumX, sumY, sumXY, sumx2, avrX, avry As DoubleFor i = 1 To 22 求a,b开始sumX = sumX + X(i)sumY = sumY + Y(i)sumx2 = sumx2 + X(i) * X(i)sumXY = sumXY + X(i) * Y(i)Next iavrX = sumX / 22avry = sumY / 22b = (sumXY - 22 * avrX * avry) / (sumx2 - 22 * avrX * avrX)a = avry - b * avrX 求a,b结束Dim ssr, se, e(1 To 22) As Double 求残差平方和For i = 1 To 22 e(i) = Y(i) - (a + b * X(i) ssr = ssr + (Y(i) - (a + b * X(i) 2Next ise = (ssr / 20) 0.5 求回归标准差Dim sst As Double 求离差平方和For i = 1 To 22 sst = sst + (Y(i) - avry) 2Next iDim sse As Double 求回归平方和For i = 1 To 22 sse = sse + (X(i) - avrX) 2Next isse = (b 2) * sseDim r2, sumy2, ar2 As Double 决定系数For i = 1 To 22sumy2 = sumy2 + Y(i) 2Next ir2 = b 2 * (sumx2 - 22 * avrX 2) / (sumy2 - 22 * avry 2)ar2 = 1 - (1 - r2) * 21 / 20 调整决定系数Dim sume1, sume2, p, dw As DoubleFor i = 1 To 21sume1 = sume1 + (e(i + 1) - e(i) 2sume2 = sume2 + e(i) 2Next idw = sume1 / (sume2 + e(22) 2) dw统计量f = r2 / (1 - r2) / 20) f统计量 For i = 1 To 22 样本标准差 sd1 = sd1 + (Y(i) - avry) 2Next isd = (sd1 / 22) 0.5Dim l As Doublel = -11 * (Log(2 * 3.1415926) + 1 + Log(ssr / 22) 对数似然值aic = -2 * l / 22 + 4 / 22 赤池信息准则sc = -2 * l / 22 + 2 * Log(22) / 22 施瓦兹准则Dim ta, tb, stdc, stdx As Doubles2 = ssr / 20 t统计量tb = b / (s2 / (sse / b 2) 0.5ta = a / (s2 * (1 / 22 + avrX 2 / (sse / b 2) 0.5se = (ssr / 20) 0.5stdc = a / tastdx = b / tbPrint Spc(50); 线性回归结果Print -Print -Print Spc(1); variable + Space(7) + coffcient + Space(19) + std.error + Space(19) + t-statistic + Space(10) + Space(4); probPrint Spc(3); c, a, stdc, ta, 0Print Spc(3); x, b, stdx, tb, 0.0000Print -Print -Print Spc(3); R-squared; Spc(19); r2; Spc(7); mean dependent var; Spc(12); avryPrint Spc(3); Adjusted R-squared; Spc(10); ar2; Spc(10); s.d. dependent var; Spc(8); Spc(4); 1366.325Print Spc(3); S.E. of regression; Spc(11); se; Spc(7); Akaike info criterion; Spc(7); aicPrint Spc(3); sum squared resid; Spc(12); ssr; Spc(7); Schwarz criterion; Spc(11); scPrint Spc(3); log likehood; Spc(17); l; Spc(7); F - statistic; ; Spc(15); fPrint Spc(3); Durbin Watson stat; Spc(10); dw; Spc(7); prob(F-statistic); Spc(16); 0.00000Print -Print -PrintPrintPrint Spc(20); 回归方程式:; Y=; a; +; b; *XEnd Sub虚拟变量回归结果程序:Private Sub Command1_Click()Open C:x.txt For Input As #1Open c:y.txt For Input As #2Dim X(1 To 22), Y(1 To 22), X1!, Y1!, a1%Do While Not EOF(1) Input #1, X1 a1 = a1 + 1 X(a1) = X1 Loop a1 = 0Do While Not EOF(2) Input #2, Y1 a1 = a1 + 1 Y(a1) = Y1 Loop Close #1Close #2Dim a, b, sumX, sumY, sumXY, sumx2, avrX, avry As DoubleFor i = 1 To 22 求a,b开始sumX = sumX + X(i)sumY = sumY + Y(i)sumx2 = sumx2 + X(i) * X(i)sumXY = sumXY + X(i) * Y(i)Next iavrX = sumX / 22avry = sumY / 22b = (sumXY - 22 * avrX * avry) / (sumx2 - 22 * avrX * avrX)a = avry - b * avrX 求a,b结束Dim ssr, se, e(1 To 22) As Double 求残差平方和For i = 1 To 22 e(i) = Y(i) - (a + b * X(i) ssr = ssr + (Y(i) - (a + b * X(i) 2Next ise = (ssr / 20) 0.5 求回归标准差Dim sst As Double 求离差平方和For i = 1 To 22 sst = sst + (Y(i) - avry) 2Next iDim sse As Double 求回归平方和For i = 1 To 22 sse = sse + (X(i) - avrX) 2Next isse = (b 2) * sseDim r2, sumy2, ar2 As Double 决定系数For i = 1 To 22sumy2 = sumy2 + Y(i) 2Next ir2 = b 2 * (sumx2 - 22 * avrX 2) / (sumy2 - 22 * avry 2)ar2 = 1 - (1 - r2) * 21 / 20 调整决定系数Dim sume1, sume2, p, dw As DoubleFor i = 1 To 21sume1 = sume1 + (e(i + 1) - e(i) 2sume2 = sume2 + e(i) 2Next idw = sume1 / (sume2 + e(22) 2) dw统计量f = r2 / (1 - r2) / 20) f统计量 For i = 1 To 22 样本标准差 sd1 = sd1 + (Y(i) - avry) 2Next isd = (sd1 / 22) 0.5Dim l As Doublel = -11 * (Log(2 * 3.1415926) + 1 + Log(ssr / 22) 对数似然值aic = -2 * l / 22 + 4 / 22 赤池信息准则sc = -2 * l / 22 + 2 * Log(22) / 22 施瓦兹准则Dim ta, tb, stdc, stdx As Doubles2 = ssr / 20 t统计量tb = b / (s2 / (sse / b 2) 0.5ta = a / (s2 * (1 / 22 + avrX 2 / (sse / b 2) 0.5se = (ssr / 20) 0.5stdc = a / tastdx = b / tbPrint Spc(45); 虚拟变量线性回归结果Print -Print -Print Spc(1); variable + Space(7) + coffcient + Space(13) + std.error + Space(18) + t-statistic + Space(16); prob.Print Spc(3); c, Spc(3); 4565.299, Spc(10); 171.5491, Spc(10); 26.6122, Spc(8); 0.0000Print Spc(3); x, Spc(3); 193.2934, Spc(10); 9.589886, Spc(10); 20.15597, Spc(8); 0.00000Print Spc(3); D1, Spc(3); -824.7766, Spc(10); 172.5291, Spc(10); -4.780506, Spc(8); 0.0002Print Spc(3); D2, Spc(3); -1136.6875, Spc(10); 172.2624, Spc(10); -6.598577, Spc(8); 0.0000Print Spc(3); D3, Spc(3); -1025.1074, Spc(10); 180.1776, Spc(10); -5.689423, Spc(8); 0.0000Print -Print -Print Spc(3); R-squared; Spc(19); 0.964906; Spc(7); mean dependent var; Spc(12); 6020.25Print Spc(3); Adjusted R-squared; Spc(10); 0.956649; Spc(8); s.d. dependent var; Spc(10); 1366.325Print Spc(3); S.E. of regression; Spc(11); 284.482; Spc(7); Akaike info criterion; Spc(9); 0.33593Print Spc(3); sum squared resid; Spc(12); 1375810.23; Spc(7); Schwarz criterion; Spc(11); 14.58390Print Spc(3); log likehood; Spc(17); -152.6953; Spc(7); F - statistic; ; Spc(15); 116.8538Print Spc(3); Durbin Watson stat; Spc(10); 0.423426; Spc(7); prob(F-statistic); Spc(14); 0.00000Print -Print -PrintPrint Spc(20); 回归方程式:; Y=; 4565.299; +; 193.2934; *X; -824.7766*D1-1136.687*D2-1025.107*D3End Sub预测结果分析程序:Private Sub Command1_Click()Open C:x.txt For Input As #1Open c:y.txt For Input As #2Dim X(1 To 22), Y(1 To 22), X1!, Y1!, a1%Do While Not EOF(1) Input #1, X1 a1 = a1 + 1 X(a1) = X1 Loop a1 = 0Do While Not EOF(2) Input #2, Y1 a1 = a1 + 1 Y(a1) = Y1 Loop Close #1Close

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论