{"id":5049,"date":"2022-11-21T14:29:14","date_gmt":"2022-11-21T06:29:14","guid":{"rendered":"https:\/\/seitlab.com\/?p=5049"},"modified":"2022-11-21T14:30:24","modified_gmt":"2022-11-21T06:30:24","slug":"5-4-%e8%ae%a1%e9%87%8f%e5%88%86%e6%9e%904%ef%bc%9a%e5%a4%9a%e5%85%83%e7%ba%bf%e6%80%a7%e5%9b%9e%e5%bd%92","status":"publish","type":"post","link":"https:\/\/www.seitlab.com\/?p=5049","title":{"rendered":"5.4 \u8ba1\u91cf\u5206\u67904\uff1a\u591a\u5143\u7ebf\u6027\u56de\u5f52"},"content":{"rendered":"<h3>\u4f8b7.1\uff1a\u9a8c\u8bc1\u591a\u5143\u7ebf\u6027\u56de\u5f52\u7684\u504f\u56de\u5f52\u7cfb\u6570<\/h3>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/seitlab.com\/wp-content\/uploads\/2020\/05\/%E5%AE%9E%E9%AA%8C3-1.png?w=750&#038;ssl=1\" alt=\"\u4f8b7.1\" \/><\/p>\n<h3>\u4ee3\u7801\u90e8\u5206<\/h3>\n<pre><code># lec04\n# \u8ba1\u91cf\u5b9e\u9a8c3-\u4ee3\u7801\u90e8\u5206-01\n\n# \u5bfc\u5165\u5e93\u6587\u4ef6\nimport pandas as pd\n# import matplotlib.pyplot as plt\nimport statsmodels.api as sm\nimport ssl\n\n# \u7981\u7528SSL\u8bc1\u4e66\u6821\u9a8c\nssl._create_default_https_context = ssl._create_unverified_context# \u5bfc\u5165\u5728\u7ebf\u6570\u636e\n\n# \u8bfb\u53d6\u5728\u7ebf\u6570\u636e\ndf01 = pd.read_excel(r&quot;https:\/\/cdn.seitlab.com\/data\/econometrics\/exp7.1.xlsx&quot;)\n\n# \u5c55\u793a\u6570\u636e\nprint(&quot;\u539f\u59cb\u6570\u636e\u5c55\u793a\u5982\u4e0b\uff1a&quot;)\nprint(df01, &quot;\\n&quot;)\n\n# \u7b80\u8981\u7684\u63cf\u8ff0\u6027\u7edf\u8ba1\nprint(&quot;\u539f\u59cb\u6570\u636e\u7684\u4e3b\u8981\u7edf\u8ba1\u6307\u6807\uff1a&quot;)\nprint(df01.describe(), &quot;\\n&quot;)\n\n# \u591a\u5143\u7ebf\u6027\u56de\u5f52\n\n# \u4e3b\u56de\u5f52\u6a21\u578b\ny = df01[&quot;CM&quot;]\nx = df01[[&quot;PGNP&quot;, &quot;FLR&quot;]]\nX = sm.add_constant(x)                            # \u6dfb\u52a0\u5e38\u6570\u9879\nOLS_model = sm.OLS(y, X).fit()                    # OLS\u56de\u5f52\nprint(OLS_model.summary(), &quot;\\n&quot;)                  # \u663e\u793aOLS\u56de\u5f52\u7ed3\u679c\ndfc = pd.DataFrame(OLS_model.params).round(4)     # \u83b7\u53d6\u56de\u5f52\u53c2\u6570,\u4fdd\u7559\u5c0f\u6570\u70b9\u540e4\u4f4d\ndfc = dfc.astype(&quot;string&quot;)                        # \u8f6c\u6362\u683c\u5f0f\u4e3a\u5b57\u7b26\u4e32\nbeta0 = dfc.iloc[0, 0]                            # \u5b9a\u4e49beta0\nbeta1 = dfc.iloc[1, 0]                            # \u5b9a\u4e49beta1\nbeta2 = dfc.iloc[2, 0]                            # \u5b9a\u4e49beta2\nOLS_equation = &quot;CM=&quot; + beta0 + beta1 + &quot;*PGNP&quot; + beta2 + &quot;*FLR&quot;  # \u5b9a\u4e49\u56de\u5f52\u65b9\u7a0b\uff0c\u683c\u5f0f\uff1a\u5b57\u7b26\u4e32\nprint(&quot;\u4f30\u8ba1\u7684\u56de\u5f52\u65b9\u7a0b\u4e3a\uff1a&quot;)\nprint(OLS_equation)\n\n# \u8f85\u52a9\u56de\u5f52\u6a21\u578b1\ny = df01[&quot;CM&quot;]\nx = df01[&quot;FLR&quot;]\nX = sm.add_constant(x)                             # \u6dfb\u52a0\u5e38\u6570\u9879\nOLS_model = sm.OLS(y, X).fit()                     # OLS\u56de\u5f52\nprint(OLS_model.summary(), &quot;\\n&quot;)                   # \u663e\u793aOLS\u56de\u5f52\u7ed3\u679c\nresid01 = OLS_model.resid                          # \u751f\u6210\u6b8b\u5dee\ndfc = pd.DataFrame(OLS_model.params).round(4)      # \u83b7\u53d6\u56de\u5f52\u53c2\u6570,\u4fdd\u7559\u5c0f\u6570\u70b9\u540e4\u4f4d\ndfc = dfc.astype(&quot;string&quot;)                         # \u8f6c\u6362\u683c\u5f0f\u4e3a\u5b57\u7b26\u4e32\nbeta0 = dfc.iloc[0, 0]                             # \u5b9a\u4e49beta0\nbeta1 = dfc.iloc[1, 0]                             # \u5b9a\u4e49beta1\nAUX_equation01 = &quot;CM=&quot; + beta0 + beta1 + &quot;*FLR&quot;    # \u5b9a\u4e49\u56de\u5f52\u65b9\u7a0b\uff0c\u683c\u5f0f\uff1a\u5b57\u7b26\u4e32\nprint(&quot;\u4f30\u8ba1\u7684\u56de\u5f52\u65b9\u7a0b\u4e3a\uff1a&quot;)\nprint(AUX_equation01)\n\n# \u8f85\u52a9\u56de\u5f52\u6a21\u578b2\ny = df01[&quot;PGNP&quot;]\nx = df01[&quot;FLR&quot;]\nX = sm.add_constant(x)                             # \u6dfb\u52a0\u5e38\u6570\u9879\nOLS_model = sm.OLS(y, X).fit()                     # OLS\u56de\u5f52\nprint(OLS_model.summary(), &quot;\\n&quot;)                   # \u663e\u793aOLS\u56de\u5f52\u7ed3\u679c\nresid02 = OLS_model.resid                          # \u751f\u6210\u6b8b\u5dee\ndfc = pd.DataFrame(OLS_model.params).round(4)      # \u83b7\u53d6\u56de\u5f52\u53c2\u6570,\u4fdd\u7559\u5c0f\u6570\u70b9\u540e4\u4f4d\ndfc = dfc.astype(&quot;string&quot;)                         # \u8f6c\u6362\u683c\u5f0f\u4e3a\u5b57\u7b26\u4e32\nbeta0 = dfc.iloc[0, 0]                             # \u5b9a\u4e49beta0\nbeta1 = dfc.iloc[1, 0]                             # \u5b9a\u4e49beta1\nAUX_equation02 = &quot;PGNP=&quot; + beta0 + &quot;+&quot; + beta1 + &quot;*FLR&quot;  # \u5b9a\u4e49\u56de\u5f52\u65b9\u7a0b\uff0c\u683c\u5f0f\uff1a\u5b57\u7b26\u4e32\nprint(&quot;\u4f30\u8ba1\u7684\u56de\u5f52\u65b9\u7a0b\u4e3a\uff1a&quot;)\nprint(AUX_equation02)\n\n# \u8f85\u52a9\u56de\u5f52\u6a21\u578b3\ny = resid01\nx = resid02\n# X = sm.add_constant(x)                            # \u6dfb\u52a0\u5e38\u6570\u9879\nOLS_model = sm.OLS(y, x).fit()                   # OLS\u56de\u5f52\nprint(OLS_model.summary(), &quot;\\n&quot;)                   # \u663e\u793aOLS\u56de\u5f52\u7ed3\u679c\ndfc = pd.DataFrame(OLS_model.params).round(4)     # \u83b7\u53d6\u56de\u5f52\u53c2\u6570,\u4fdd\u7559\u5c0f\u6570\u70b9\u540e4\u4f4d\ndfc = dfc.astype(&quot;string&quot;)                        # \u8f6c\u6362\u683c\u5f0f\u4e3a\u5b57\u7b26\u4e32\nbeta1 = dfc.iloc[0, 0]                             # \u5b9a\u4e49beta1\nAUX_equation03 = &quot;E1=&quot; + beta1 + &quot;*E2&quot;  # \u5b9a\u4e49\u56de\u5f52\u65b9\u7a0b\uff0c\u683c\u5f0f\uff1a\u5b57\u7b26\u4e32\nprint(&quot;\u4f30\u8ba1\u7684\u56de\u5f52\u65b9\u7a0b\u4e3a\uff1a&quot;)\nprint(AUX_equation03, &quot;\\n&quot;)\n\n# \u663e\u793a\u6240\u6709\u56de\u5f52\u65b9\u7a0b\nprint(&quot;\u6240\u6709\u56de\u5f52\u7ed3\u679c\u5c55\u793a\u5982\u4e0b\uff1a&quot;)\nprint(&quot;\u4e3b\u56de\u5f52\u65b9\u7a0b\uff1a&quot; + OLS_equation)\nprint(&quot;\u8f85\u52a9\u56de\u5f52\u65b9\u7a0b1\uff1a&quot; + AUX_equation01)\nprint(&quot;\u8f85\u52a9\u56de\u5f52\u65b9\u7a0b2\uff1a&quot; + AUX_equation02)\nprint(&quot;\u8f85\u52a9\u56de\u5f52\u65b9\u7a0b3\uff1a&quot; + AUX_equation03)\nprint(&quot;\u6bd4\u8f83\u4e0a\u8ff0\u56de\u5f52\u7ed3\u679c\u53d1\u73b0\uff1a\u4e3b\u56de\u5f52\u65b9\u7a0b\u4e2dPGNP\u7cfb\u6570\u4e0e\u8f85\u52a9\u56de\u5f52\u65b9\u7a0b3\u4e2dE2\u7cfb\u6570\u76f8\u540c\u3002&quot;)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f8b7.1\uff1a\u9a8c\u8bc1\u591a\u5143\u7ebf\u6027\u56de\u5f52\u7684\u504f\u56de\u5f52\u7cfb\u6570 \u4ee3\u7801\u90e8\u5206 # lec04 # \u8ba1\u91cf\u5b9e\u9a8c3-\u4ee3\u7801\u90e8\u5206-01 # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[29,30],"tags":[],"class_list":["post-5049","post","type-post","status-publish","format-standard","hentry","category-29","category-30"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.seitlab.com\/index.php?rest_route=\/wp\/v2\/posts\/5049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seitlab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.seitlab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.seitlab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seitlab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5049"}],"version-history":[{"count":0,"href":"https:\/\/www.seitlab.com\/index.php?rest_route=\/wp\/v2\/posts\/5049\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.seitlab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.seitlab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.seitlab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}