{"id":5162,"date":"2022-11-28T15:06:11","date_gmt":"2022-11-28T07:06:11","guid":{"rendered":"https:\/\/seit2019.xyz\/?p=5162"},"modified":"2022-11-28T15:06:11","modified_gmt":"2022-11-28T07:06:11","slug":"5-8-%e8%ae%a1%e9%87%8f%e5%88%86%e6%9e%908%ef%bc%9a%e8%99%9a%e6%8b%9f%e5%8f%98%e9%87%8f%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/seit2019.xyz\/?p=5162","title":{"rendered":"5.8 \u8ba1\u91cf\u5206\u67908\uff1a\u865a\u62df\u53d8\u91cf\u6a21\u578b"},"content":{"rendered":"<h3>\u4f8b\u5b50<\/h3>\n<p>\u4ee5\u8bfe\u672c\u88689.1\u7684\u6570\u636e\u4e3a\u6837\u672c\uff0c\u5efa\u7acb\u865a\u62df\u53d8\u91cf\u6a21\u578b\uff1a<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/seit2019.xyz\/wp-content\/uploads\/2020\/06\/6-1.png?w=750&#038;ssl=1\" alt=\"IMG\" \/><\/p>\n<h3>\u4ee3\u7801\u90e8\u5206<\/h3>\n<pre><code># lec08\n# \u8ba1\u91cf\u5b9e\u9a8c6\uff1a\u865a\u62df\u53d8\u91cf-\u4ee3\u7801\u90e8\u5206\n\n# \u5bfc\u5165\u7a0b\u5e8f\u5305\nimport pandas as pd\nimport statsmodels.api as sm\nimport ssl\n\n# \u7981\u7528SSL\u8bc1\u4e66\u6821\u9a8c\nssl._create_default_https_context = ssl._create_unverified_context\n\n# \u5bfc\u5165\uff08\u5728\u7ebf\uff09\u6570\u636e\ndf = pd.read_excel(r&quot;https:\/\/cdn.seit2019.xyz\/data\/econometrics\/table9.1.xlsx&quot;)\n\n# \u5c55\u793a\u6570\u636e\nprint(&quot;\u6570\u636e\u5c55\u793a\u5982\u4e0b\uff1a&quot;)\nprint(df, &quot;\\n&quot;)\n\n# \u7b80\u8981\u7edf\u8ba1\u63cf\u8ff0\nprint(&quot;\u7b80\u8981\u7edf\u8ba1\u63cf\u8ff0\uff1a&quot;)\nprint(df.describe(), &quot;\\n&quot;)\n\n# \u751f\u6210Dummy\ndf = pd.get_dummies(df, prefix=&quot;D&quot;, prefix_sep=&quot;_&quot;, columns=[&quot;District&quot;])\n# \u547d\u540dD1,D2,D3: D1=1,\u897f\u90e8\uff1bD2=1,\u4e2d\u4e1c\u5317\u90e8\uff1bD3=\u5357\u90e8\ndf = df.rename(columns={&quot;D_West&quot;: &quot;D1&quot;, &quot;D_North&amp;East&quot;: &quot;D2&quot;, &quot;D_South&quot;: &quot;D3&quot;})\nprint(&quot;\u6240\u6709\u6570\u636e\uff1a&quot;)\nprint(df, &quot;\\n&quot;)\n\n# ANOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52191\n# \u5b9a\u4e49\u53d8\u91cf\nSalary = df[&quot;Salary&quot;]\nx = df[[&quot;D2&quot;, &quot;D3&quot;]]\nX = sm.add_constant(x)\n# OLS\u56de\u5f52\nOLS_ANOVA_01 = sm.OLS(Salary, X).fit()\nprint(&quot;ANOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52191&quot;)\nprint(OLS_ANOVA_01.summary(), &quot;\\n&quot;)\n\n# ANOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52192\n# Eviews\u4e2d\uff0c\u5f15\u5165\u5e38\u6570\u9879\uff0c\u62a5\u9519\uff1bpython\u4e2d\uff0c\u4ecd\u53ef\u56de\u5f52\uff0c\u56de\u5f52\u7ed3\u679cNotes[2]\u63d0\u793a\u6709\u4e25\u91cd\u7684\u591a\u91cd\u5171\u7ebf\u6027\u3002\n# \u5b9a\u4e49\u53d8\u91cf\nSalary = df[&quot;Salary&quot;]\nx = df[[&quot;D1&quot;, &quot;D2&quot;, &quot;D3&quot;]]\n# X = sm.add_constant(x)\n# OLS\u56de\u5f52\nOLS_ANOVA_02 = sm.OLS(Salary, x).fit()\nprint(&quot;ANOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52192&quot;)\nprint(OLS_ANOVA_02.summary(), &quot;\\n&quot;)\n\n# ANCOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52191\n# \u5b9a\u4e49\u53d8\u91cf\nSalary = df[&quot;Salary&quot;]\nx = df[[&quot;D2&quot;, &quot;D3&quot;, &quot;Spending&quot;]]\nX = sm.add_constant(x)\n# OLS\u56de\u5f52\nOLS_ANCOVA_01 = sm.OLS(Salary, X).fit()\nprint(&quot;ANCOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52191&quot;)\nprint(OLS_ANCOVA_01.summary(), &quot;\\n&quot;)\n\n# ANCOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52192\n# \u5b9a\u4e49\u53d8\u91cf\nSalary = df[&quot;Salary&quot;]\nx = df[[&quot;D1&quot;, &quot;D2&quot;, &quot;D3&quot;, &quot;Spending&quot;]]\n# X = sm.add_constant(x)\n# OLS\u56de\u5f52\nOLS_ANCOVA_02 = sm.OLS(Salary, x).fit()\nprint(&quot;ANCOVA\u6a21\u578b\uff1a\u865a\u62df\u53d8\u91cf\u5f15\u5165\u89c4\u52192&quot;)\nprint(OLS_ANCOVA_02.summary(), &quot;\\n&quot;)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f8b\u5b50 \u4ee5\u8bfe\u672c\u88689.1\u7684\u6570\u636e\u4e3a\u6837\u672c\uff0c\u5efa\u7acb\u865a\u62df\u53d8\u91cf\u6a21\u578b\uff1a \u4ee3\u7801\u90e8\u5206 # lec08 # \u8ba1\u91cf\u5b9e\u9a8c6\uff1a\u865a\u62df [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,30],"tags":[],"class_list":["post-5162","post","type-post","status-publish","format-standard","hentry","category-29","category-30"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/posts\/5162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5162"}],"version-history":[{"count":0,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/posts\/5162\/revisions"}],"wp:attachment":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}