Skip to content

Instantly share code, notes, and snippets.

@ereyester
Created July 31, 2020 08:58
Show Gist options
  • Save ereyester/b42e8d36bf47f70e7092a0d0bd44e673 to your computer and use it in GitHub Desktop.
Save ereyester/b42e8d36bf47f70e7092a0d0bd44e673 to your computer and use it in GitHub Desktop.
jouhou2_3_13_R.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "jouhou2_3_13_R.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "ir",
"display_name": "R"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/ereyester/b42e8d36bf47f70e7092a0d0bd44e673/jouhou2_3_13_r.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fuY8nwn4wG7M",
"colab_type": "text"
},
"source": [
"# 高等学校情報科「情報Ⅱ」教員用研修教材\n",
"## 第3章前半 13重回帰分析とモデルの決定\n",
"### R版"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ruQBFn3Z7FvP",
"colab_type": "text"
},
"source": [
"google colab上で、Rを使う方法は以下を確認する。\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "C1HRSxCAKSFq",
"colab_type": "text"
},
"source": [
"https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/lm"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bSKtPtZpR8_l",
"colab_type": "text"
},
"source": [
"lm()はweights = nullの場合、OLS使用(ordinary least squares is used.)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "uzJCC6cUw-RM",
"colab_type": "text"
},
"source": [
"- Estimate:係数の推定値\n",
"- Residual standard error:(残差)標準誤差\n",
"- degrees of freedom(残差)自由度\n",
"- Multiple R-squared:寄与率 R2\n",
"- Adjusted R-squared:自由度修正済みR2"
]
},
{
"cell_type": "code",
"metadata": {
"id": "FbMh5ncYDUDo",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 391
},
"outputId": "62439a5b-8f59-40c5-f8bb-1c6841f7cea1"
},
"source": [
"# データの読み込み\n",
"high_male <- read.csv(\"high_male_data.csv\")\n",
"# 4 つの説明変数による重回帰分析\n",
"res <- lm(X50m走 ~ 立ち幅跳び + ハンドボール投げ + 握力得点 + 上体起こし得点, data = high_male)\n",
"summary(res)"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"\n",
"Call:\n",
"lm(formula = X50m走 ~ 立ち幅跳び + ハンドボール投げ + \n",
" 握力得点 + 上体起こし得点, data = high_male)\n",
"\n",
"Residuals:\n",
" Min 1Q Median 3Q Max \n",
"-0.66229 -0.22824 -0.03057 0.22797 0.99194 \n",
"\n",
"Coefficients:\n",
" Estimate Std. Error t value Pr(>|t|) \n",
"(Intercept) 10.819417 0.324609 33.331 < 2e-16 ***\n",
"立ち幅跳び -0.012005 0.001570 -7.648 3.89e-12 ***\n",
"ハンドボール投げ -0.014393 0.006081 -2.367 0.0194 * \n",
"握力得点 -0.040185 0.023969 -1.677 0.0960 . \n",
"上体起こし得点 -0.025489 0.020163 -1.264 0.2084 \n",
"---\n",
"Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n",
"\n",
"Residual standard error: 0.3349 on 131 degrees of freedom\n",
"Multiple R-squared: 0.5249,\tAdjusted R-squared: 0.5104 \n",
"F-statistic: 36.18 on 4 and 131 DF, p-value: < 2.2e-16\n"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "AKZdGqOj6Ome",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 476
},
"outputId": "8c262f08-3630-4767-ad1a-f9eb4912b543"
},
"source": [
"# データの読み込み\n",
"high_male <- read.csv(\"high_male_data.csv\")\n",
"# 全ての説明変数によるステップワイズ法(変数増減法)による重回帰分析\n",
"res <- lm(X50m走 ~ 立ち幅跳び + ハンドボール投げ + 握力得点 + 上体起こし得点, data = high_male)\n",
"step(res)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Start: AIC=-292.67\n",
"X50m走 ~ 立ち幅跳び + ハンドボール投げ + 握力得点 + \n",
" 上体起こし得点\n",
"\n",
" Df Sum of Sq RSS AIC\n",
"- 上体起こし得点 1 0.1792 14.868 -293.02\n",
"<none> 14.689 -292.67\n",
"- 握力得点 1 0.3152 15.004 -291.79\n",
"- ハンドボール投げ 1 0.6281 15.317 -288.98\n",
"- 立ち幅跳び 1 6.5586 21.248 -244.47\n",
"\n",
"Step: AIC=-293.02\n",
"X50m走 ~ 立ち幅跳び + ハンドボール投げ + 握力得点\n",
"\n",
" Df Sum of Sq RSS AIC\n",
"<none> 14.868 -293.02\n",
"- 握力得点 1 0.3817 15.250 -291.58\n",
"- ハンドボール投げ 1 0.9663 15.835 -286.46\n",
"- 立ち幅跳び 1 6.6831 21.552 -244.54\n"
],
"name": "stdout"
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"\n",
"Call:\n",
"lm(formula = X50m走 ~ 立ち幅跳び + ハンドボール投げ + \n",
" 握力得点, data = high_male)\n",
"\n",
"Coefficients:\n",
" (Intercept) 立ち幅跳び ハンドボール投げ 握力得点 \n",
" 10.71205 -0.01210 -0.01689 -0.04389 \n"
]
},
"metadata": {
"tags": []
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment