MLstuff/ISLR/notebooks/ch2-9R.ipynb

594 lines
230 KiB
Plaintext
Raw Normal View History

2020-03-27 11:07:26 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"library(ISLR)\n",
"library(repr)\n",
"options(repr.plot.width=16, repr.plot.height=16)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 9</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>mpg</th><th scope=col>cylinders</th><th scope=col>displacement</th><th scope=col>horsepower</th><th scope=col>weight</th><th scope=col>acceleration</th><th scope=col>year</th><th scope=col>origin</th><th scope=col>name</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>18</td><td>8</td><td>307</td><td>130</td><td>3504</td><td>12.0</td><td>70</td><td>1</td><td>chevrolet chevelle malibu</td></tr>\n",
"\t<tr><th scope=row>2</th><td>15</td><td>8</td><td>350</td><td>165</td><td>3693</td><td>11.5</td><td>70</td><td>1</td><td>buick skylark 320 </td></tr>\n",
"\t<tr><th scope=row>3</th><td>18</td><td>8</td><td>318</td><td>150</td><td>3436</td><td>11.0</td><td>70</td><td>1</td><td>plymouth satellite </td></tr>\n",
"\t<tr><th scope=row>4</th><td>16</td><td>8</td><td>304</td><td>150</td><td>3433</td><td>12.0</td><td>70</td><td>1</td><td>amc rebel sst </td></tr>\n",
"\t<tr><th scope=row>5</th><td>17</td><td>8</td><td>302</td><td>140</td><td>3449</td><td>10.5</td><td>70</td><td>1</td><td>ford torino </td></tr>\n",
"\t<tr><th scope=row>6</th><td>15</td><td>8</td><td>429</td><td>198</td><td>4341</td><td>10.0</td><td>70</td><td>1</td><td>ford galaxie 500 </td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 9\n",
"\\begin{tabular}{r|lllllllll}\n",
" & mpg & cylinders & displacement & horsepower & weight & acceleration & year & origin & name\\\\\n",
" & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <fct>\\\\\n",
"\\hline\n",
"\t1 & 18 & 8 & 307 & 130 & 3504 & 12.0 & 70 & 1 & chevrolet chevelle malibu\\\\\n",
"\t2 & 15 & 8 & 350 & 165 & 3693 & 11.5 & 70 & 1 & buick skylark 320 \\\\\n",
"\t3 & 18 & 8 & 318 & 150 & 3436 & 11.0 & 70 & 1 & plymouth satellite \\\\\n",
"\t4 & 16 & 8 & 304 & 150 & 3433 & 12.0 & 70 & 1 & amc rebel sst \\\\\n",
"\t5 & 17 & 8 & 302 & 140 & 3449 & 10.5 & 70 & 1 & ford torino \\\\\n",
"\t6 & 15 & 8 & 429 & 198 & 4341 & 10.0 & 70 & 1 & ford galaxie 500 \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 9\n",
"\n",
"| <!--/--> | mpg &lt;dbl&gt; | cylinders &lt;dbl&gt; | displacement &lt;dbl&gt; | horsepower &lt;dbl&gt; | weight &lt;dbl&gt; | acceleration &lt;dbl&gt; | year &lt;dbl&gt; | origin &lt;dbl&gt; | name &lt;fct&gt; |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 1 | 18 | 8 | 307 | 130 | 3504 | 12.0 | 70 | 1 | chevrolet chevelle malibu |\n",
"| 2 | 15 | 8 | 350 | 165 | 3693 | 11.5 | 70 | 1 | buick skylark 320 |\n",
"| 3 | 18 | 8 | 318 | 150 | 3436 | 11.0 | 70 | 1 | plymouth satellite |\n",
"| 4 | 16 | 8 | 304 | 150 | 3433 | 12.0 | 70 | 1 | amc rebel sst |\n",
"| 5 | 17 | 8 | 302 | 140 | 3449 | 10.5 | 70 | 1 | ford torino |\n",
"| 6 | 15 | 8 | 429 | 198 | 4341 | 10.0 | 70 | 1 | ford galaxie 500 |\n",
"\n"
],
"text/plain": [
" mpg cylinders displacement horsepower weight acceleration year origin\n",
"1 18 8 307 130 3504 12.0 70 1 \n",
"2 15 8 350 165 3693 11.5 70 1 \n",
"3 18 8 318 150 3436 11.0 70 1 \n",
"4 16 8 304 150 3433 12.0 70 1 \n",
"5 17 8 302 140 3449 10.5 70 1 \n",
"6 15 8 429 198 4341 10.0 70 1 \n",
" name \n",
"1 chevrolet chevelle malibu\n",
"2 buick skylark 320 \n",
"3 plymouth satellite \n",
"4 amc rebel sst \n",
"5 ford torino \n",
"6 ford galaxie 500 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# rownames(Auto) = Auto[ ,9]\n",
"\n",
"head(Auto)\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<table width=\"100%\" summary=\"page for Auto {ISLR}\"><tr><td>Auto {ISLR}</td><td style=\"text-align: right;\">R Documentation</td></tr></table>\n",
"\n",
"<h2>\n",
"Auto Data Set\n",
"</h2>\n",
"\n",
"<h3>Description</h3>\n",
"\n",
"<p>Gas mileage, horsepower, and other information for 392 vehicles.</p>\n",
"\n",
"\n",
"<h3>Usage</h3>\n",
"\n",
"<pre>Auto</pre>\n",
"\n",
"\n",
"<h3>Format</h3>\n",
"\n",
"<p>A data frame with 392 observations on the following 9 variables.\n",
"</p>\n",
"\n",
"<dl>\n",
"<dt><code>mpg</code></dt><dd><p>miles per gallon</p>\n",
"</dd>\n",
"<dt><code>cylinders</code></dt><dd><p>Number of cylinders between 4 and 8</p>\n",
"</dd>\n",
"<dt><code>displacement</code></dt><dd><p>Engine displacement (cu. inches)</p>\n",
"</dd>\n",
"<dt><code>horsepower</code></dt><dd><p>Engine horsepower</p>\n",
"</dd>\n",
"<dt><code>weight</code></dt><dd><p>Vehicle weight (lbs.)</p>\n",
"</dd>\n",
"<dt><code>acceleration</code></dt><dd><p>Time to accelerate from 0 to 60 mph (sec.)</p>\n",
"</dd>\n",
"<dt><code>year</code></dt><dd><p>Model year (modulo 100)</p>\n",
"</dd>\n",
"<dt><code>origin</code></dt><dd><p>Origin of car (1. American, 2. European, 3. Japanese)</p>\n",
"</dd>\n",
"<dt><code>name</code></dt><dd><p>Vehicle name</p>\n",
"</dd></dl>\n",
"\n",
"<p>The orginal data contained 408 observations but 16 observations with\n",
"missing values were removed.</p>\n",
"\n",
"\n",
"<h3>Source</h3>\n",
"\n",
"<p>This dataset was taken from the StatLib library which is maintained at Carnegie Mellon University. The dataset was used in the 1983 American Statistical Association Exposition.\n",
"</p>\n",
"\n",
"\n",
"<h3>References</h3>\n",
"\n",
"<p>James, G., Witten, D., Hastie, T., and Tibshirani, R. (2013)\n",
"<em>An Introduction to Statistical Learning with applications in R</em>,\n",
"<a href=\"www.StatLearning.com\">www.StatLearning.com</a>,\n",
"Springer-Verlag, New York\n",
"</p>\n",
"\n",
"\n",
"<h3>Examples</h3>\n",
"\n",
"<pre>\n",
"pairs(Auto)\n",
"attach(Auto)\n",
"hist(mpg)\n",
"</pre>\n",
"\n",
"<hr /><div style=\"text-align: center;\">[Package <em>ISLR</em> version 1.2 ]</div>"
],
"text/latex": [
"\\inputencoding{utf8}\n",
"\\HeaderA{Auto}{Auto Data Set}{Auto}\n",
"\\keyword{datasets}{Auto}\n",
"%\n",
"\\begin{Description}\\relax\n",
"Gas mileage, horsepower, and other information for 392 vehicles.\n",
"\\end{Description}\n",
"%\n",
"\\begin{Usage}\n",
"\\begin{verbatim}\n",
"Auto\n",
"\\end{verbatim}\n",
"\\end{Usage}\n",
"%\n",
"\\begin{Format}\n",
"A data frame with 392 observations on the following 9 variables.\n",
"\\begin{description}\n",
"\n",
"\\item[\\code{mpg}] miles per gallon\n",
"\\item[\\code{cylinders}] Number of cylinders between 4 and 8\n",
"\\item[\\code{displacement}] Engine displacement (cu. inches)\n",
"\\item[\\code{horsepower}] Engine horsepower\n",
"\\item[\\code{weight}] Vehicle weight (lbs.)\n",
"\\item[\\code{acceleration}] Time to accelerate from 0 to 60 mph (sec.)\n",
"\\item[\\code{year}] Model year (modulo 100)\n",
"\\item[\\code{origin}] Origin of car (1. American, 2. European, 3. Japanese)\n",
"\\item[\\code{name}] Vehicle name\n",
"\\end{description}\n",
"\n",
"\n",
"The orginal data contained 408 observations but 16 observations with\n",
"missing values were removed.\n",
"\\end{Format}\n",
"%\n",
"\\begin{Source}\\relax\n",
"This dataset was taken from the StatLib library which is maintained at Carnegie Mellon University. The dataset was used in the 1983 American Statistical Association Exposition.\n",
"\\end{Source}\n",
"%\n",
"\\begin{References}\\relax\n",
"James, G., Witten, D., Hastie, T., and Tibshirani, R. (2013)\n",
"\\emph{An Introduction to Statistical Learning with applications in R},\n",
"\\url{www.StatLearning.com},\n",
"Springer-Verlag, New York\n",
"\\end{References}\n",
"%\n",
"\\begin{Examples}\n",
"\\begin{ExampleCode}\n",
"pairs(Auto)\n",
"attach(Auto)\n",
"hist(mpg)\n",
"\\end{ExampleCode}\n",
"\\end{Examples}"
],
"text/plain": [
"Auto package:ISLR R Documentation\n",
"\n",
"_\bA_\bu_\bt_\bo _\bD_\ba_\bt_\ba _\bS_\be_\bt\n",
"\n",
"_\bD_\be_\bs_\bc_\br_\bi_\bp_\bt_\bi_\bo_\bn:\n",
"\n",
" Gas mileage, horsepower, and other information for 392 vehicles.\n",
"\n",
"_\bU_\bs_\ba_\bg_\be:\n",
"\n",
" Auto\n",
" \n",
"_\bF_\bo_\br_\bm_\ba_\bt:\n",
"\n",
" A data frame with 392 observations on the following 9 variables.\n",
"\n",
" mpg miles per gallon\n",
"\n",
" cylinders Number of cylinders between 4 and 8\n",
"\n",
" displacement Engine displacement (cu. inches)\n",
"\n",
" horsepower Engine horsepower\n",
"\n",
" weight Vehicle weight (lbs.)\n",
"\n",
" acceleration Time to accelerate from 0 to 60 mph (sec.)\n",
"\n",
" year Model year (modulo 100)\n",
"\n",
" origin Origin of car (1. American, 2. European, 3. Japanese)\n",
"\n",
" name Vehicle name\n",
"\n",
" The orginal data contained 408 observations but 16 observations\n",
" with missing values were removed.\n",
"\n",
"_\bS_\bo_\bu_\br_\bc_\be:\n",
"\n",
" This dataset was taken from the StatLib library which is\n",
" maintained at Carnegie Mellon University. The dataset was used in\n",
" the 1983 American Statistical Association Exposition.\n",
"\n",
"_\bR_\be_\bf_\be_\br_\be_\bn_\bc_\be_\bs:\n",
"\n",
" James, G., Witten, D., Hastie, T., and Tibshirani, R. (2013) _An\n",
" Introduction to Statistical Learning with applications in R_,\n",
" <URL: www.StatLearning.com>, Springer-Verlag, New York\n",
"\n",
"_\bE_\bx_\ba_\bm_\bp_\bl_\be_\bs:\n",
"\n",
" pairs(Auto)\n",
" attach(Auto)\n",
" hist(mpg)\n",
" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"?Auto"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" mpg cylinders displacement horsepower weight \n",
" Min. : 9.00 Min. :3.000 Min. : 68.0 Min. : 46.0 Min. :1613 \n",
" 1st Qu.:17.00 1st Qu.:4.000 1st Qu.:105.0 1st Qu.: 75.0 1st Qu.:2225 \n",
" Median :22.75 Median :4.000 Median :151.0 Median : 93.5 Median :2804 \n",
" Mean :23.45 Mean :5.472 Mean :194.4 Mean :104.5 Mean :2978 \n",
" 3rd Qu.:29.00 3rd Qu.:8.000 3rd Qu.:275.8 3rd Qu.:126.0 3rd Qu.:3615 \n",
" Max. :46.60 Max. :8.000 Max. :455.0 Max. :230.0 Max. :5140 \n",
" \n",
" acceleration year origin name \n",
" Min. : 8.00 Min. :70.00 Min. :1.000 amc matador : 5 \n",
" 1st Qu.:13.78 1st Qu.:73.00 1st Qu.:1.000 ford pinto : 5 \n",
" Median :15.50 Median :76.00 Median :1.000 toyota corolla : 5 \n",
" Mean :15.54 Mean :75.98 Mean :1.577 amc gremlin : 4 \n",
" 3rd Qu.:17.02 3rd Qu.:79.00 3rd Qu.:2.000 amc hornet : 4 \n",
" Max. :24.80 Max. :82.00 Max. :3.000 chevrolet chevette: 4 \n",
" (Other) :365 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"summary(Auto)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB4AAAAeACAMAAAAYfLr0AAADAFBMVEUAAAABAQECAgIDAwME\nBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUW\nFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJyco\nKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6\nOjo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tM\nTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1e\nXl5fX19gYGBhYWFiYmJjY2NkZGRlZWVmZmZnZ2doaGhpaWlqampra2tsbGxtbW1ubm5vb29w\ncHBxcXFycnJzc3N0dHR1dXV2dnZ3d3d4eHh5eXl6enp7e3t8fHx9fX1+fn5/f3+AgICBgYGC\ngoKDg4OEhISFhYWGhoaHh4eIiIiJiYmKioqLi4uMjIyNjY2Ojo6Pj4+QkJCRkZGSkpKTk5OU\nlJSVlZWWlpaXl5eYmJiZmZmampqbm5ucnJydnZ2enp6fn5+goKChoaGioqKjo6OkpKSlpaWm\npqanp6eoqKipqamqqqqrq6usrKytra2urq6vr6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CbOQhgwAUEsHmDADZvEMBmDgIYcAEBbN4ggM0bBLCZgwAGXEAAmzcIYPMGAWzmIIABFyIH\n8Ouj1
"text/plain": [
"plot without title"
]
},
"metadata": {
"image/png": {
"height": 960,
"width": 960
},
"text/plain": {
"height": 960,
"width": 960
}
},
"output_type": "display_data"
}
],
"source": [
"pairs(Auto[,1:4])"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" mpg cylinders displacement horsepower weight \n",
" Min. :11.00 Min. :3.000 Min. : 68.0 Min. : 46.0 Min. :1649 \n",
" 1st Qu.:17.68 1st Qu.:4.000 1st Qu.:100.2 1st Qu.: 75.0 1st Qu.:2220 \n",
" Median :23.10 Median :4.000 Median :145.5 Median : 92.0 Median :2804 \n",
" Mean :24.05 Mean :5.408 Mean :189.4 Mean :102.1 Mean :2959 \n",
" 3rd Qu.:30.00 3rd Qu.:6.000 3rd Qu.:258.5 3rd Qu.:120.0 3rd Qu.:3571 \n",
" Max. :46.60 Max. :8.000 Max. :455.0 Max. :230.0 Max. :4997 \n",
" \n",
" acceleration year origin \n",
" Min. : 8.50 Min. :70.00 Min. :1.000 \n",
" 1st Qu.:14.00 1st Qu.:74.00 1st Qu.:1.000 \n",
" Median :15.50 Median :77.00 Median :1.000 \n",
" Mean :15.67 Mean :76.84 Mean :1.601 \n",
" 3rd Qu.:17.20 3rd Qu.:80.00 3rd Qu.:2.000 \n",
" Max. :24.80 Max. :82.00 Max. :3.000 \n",
" \n",
" name \n",
" ford pinto : 5 \n",
" toyota corolla : 5 \n",
" amc matador : 4 \n",
" chevrolet chevette : 4 \n",
" amc hornet : 3 \n",
" chevrolet caprice classic: 3 \n",
" (Other) :312 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"auto2 = Auto[-c(10:65),] \n",
"summary(auto2)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A matrix: 8 × 8 of type dbl</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>mpg</th><th scope=col>cylinders</th><th scope=col>displacement</th><th scope=col>horsepower</th><th scope=col>weight</th><th scope=col>acceleration</th><th scope=col>year</th><th scope=col>origin</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>mpg</th><td> 1.0000000</td><td>-0.7776175</td><td>-0.8051269</td><td>-0.7784268</td><td>-0.8322442</td><td> 0.4233285</td><td> 0.5805410</td><td> 0.5652088</td></tr>\n",
"\t<tr><th scope=row>cylinders</th><td>-0.7776175</td><td> 1.0000000</td><td> 0.9508233</td><td> 0.8429834</td><td> 0.8975273</td><td>-0.5046834</td><td>-0.3456474</td><td>-0.5689316</td></tr>\n",
"\t<tr><th scope=row>displacement</th><td>-0.8051269</td><td> 0.9508233</td><td> 1.0000000</td><td> 0.8972570</td><td> 0.9329944</td><td>-0.5438005</td><td>-0.3698552</td><td>-0.6145351</td></tr>\n",
"\t<tr><th scope=row>horsepower</th><td>-0.7784268</td><td> 0.8429834</td><td> 0.8972570</td><td> 1.0000000</td><td> 0.8645377</td><td>-0.6891955</td><td>-0.4163615</td><td>-0.4551715</td></tr>\n",
"\t<tr><th scope=row>weight</th><td>-0.8322442</td><td> 0.8975273</td><td> 0.9329944</td><td> 0.8645377</td><td> 1.0000000</td><td>-0.4168392</td><td>-0.3091199</td><td>-0.5850054</td></tr>\n",
"\t<tr><th scope=row>acceleration</th><td> 0.4233285</td><td>-0.5046834</td><td>-0.5438005</td><td>-0.6891955</td><td>-0.4168392</td><td> 1.0000000</td><td> 0.2903161</td><td> 0.2127458</td></tr>\n",
"\t<tr><th scope=row>year</th><td> 0.5805410</td><td>-0.3456474</td><td>-0.3698552</td><td>-0.4163615</td><td>-0.3091199</td><td> 0.2903161</td><td> 1.0000000</td><td> 0.1815277</td></tr>\n",
"\t<tr><th scope=row>origin</th><td> 0.5652088</td><td>-0.5689316</td><td>-0.6145351</td><td>-0.4551715</td><td>-0.5850054</td><td> 0.2127458</td><td> 0.1815277</td><td> 1.0000000</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A matrix: 8 × 8 of type dbl\n",
"\\begin{tabular}{r|llllllll}\n",
" & mpg & cylinders & displacement & horsepower & weight & acceleration & year & origin\\\\\n",
"\\hline\n",
"\tmpg & 1.0000000 & -0.7776175 & -0.8051269 & -0.7784268 & -0.8322442 & 0.4233285 & 0.5805410 & 0.5652088\\\\\n",
"\tcylinders & -0.7776175 & 1.0000000 & 0.9508233 & 0.8429834 & 0.8975273 & -0.5046834 & -0.3456474 & -0.5689316\\\\\n",
"\tdisplacement & -0.8051269 & 0.9508233 & 1.0000000 & 0.8972570 & 0.9329944 & -0.5438005 & -0.3698552 & -0.6145351\\\\\n",
"\thorsepower & -0.7784268 & 0.8429834 & 0.8972570 & 1.0000000 & 0.8645377 & -0.6891955 & -0.4163615 & -0.4551715\\\\\n",
"\tweight & -0.8322442 & 0.8975273 & 0.9329944 & 0.8645377 & 1.0000000 & -0.4168392 & -0.3091199 & -0.5850054\\\\\n",
"\tacceleration & 0.4233285 & -0.5046834 & -0.5438005 & -0.6891955 & -0.4168392 & 1.0000000 & 0.2903161 & 0.2127458\\\\\n",
"\tyear & 0.5805410 & -0.3456474 & -0.3698552 & -0.4163615 & -0.3091199 & 0.2903161 & 1.0000000 & 0.1815277\\\\\n",
"\torigin & 0.5652088 & -0.5689316 & -0.6145351 & -0.4551715 & -0.5850054 & 0.2127458 & 0.1815277 & 1.0000000\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A matrix: 8 × 8 of type dbl\n",
"\n",
"| <!--/--> | mpg | cylinders | displacement | horsepower | weight | acceleration | year | origin |\n",
"|---|---|---|---|---|---|---|---|---|\n",
"| mpg | 1.0000000 | -0.7776175 | -0.8051269 | -0.7784268 | -0.8322442 | 0.4233285 | 0.5805410 | 0.5652088 |\n",
"| cylinders | -0.7776175 | 1.0000000 | 0.9508233 | 0.8429834 | 0.8975273 | -0.5046834 | -0.3456474 | -0.5689316 |\n",
"| displacement | -0.8051269 | 0.9508233 | 1.0000000 | 0.8972570 | 0.9329944 | -0.5438005 | -0.3698552 | -0.6145351 |\n",
"| horsepower | -0.7784268 | 0.8429834 | 0.8972570 | 1.0000000 | 0.8645377 | -0.6891955 | -0.4163615 | -0.4551715 |\n",
"| weight | -0.8322442 | 0.8975273 | 0.9329944 | 0.8645377 | 1.0000000 | -0.4168392 | -0.3091199 | -0.5850054 |\n",
"| acceleration | 0.4233285 | -0.5046834 | -0.5438005 | -0.6891955 | -0.4168392 | 1.0000000 | 0.2903161 | 0.2127458 |\n",
"| year | 0.5805410 | -0.3456474 | -0.3698552 | -0.4163615 | -0.3091199 | 0.2903161 | 1.0000000 | 0.1815277 |\n",
"| origin | 0.5652088 | -0.5689316 | -0.6145351 | -0.4551715 | -0.5850054 | 0.2127458 | 0.1815277 | 1.0000000 |\n",
"\n"
],
"text/plain": [
" mpg cylinders displacement horsepower weight \n",
"mpg 1.0000000 -0.7776175 -0.8051269 -0.7784268 -0.8322442\n",
"cylinders -0.7776175 1.0000000 0.9508233 0.8429834 0.8975273\n",
"displacement -0.8051269 0.9508233 1.0000000 0.8972570 0.9329944\n",
"horsepower -0.7784268 0.8429834 0.8972570 1.0000000 0.8645377\n",
"weight -0.8322442 0.8975273 0.9329944 0.8645377 1.0000000\n",
"acceleration 0.4233285 -0.5046834 -0.5438005 -0.6891955 -0.4168392\n",
"year 0.5805410 -0.3456474 -0.3698552 -0.4163615 -0.3091199\n",
"origin 0.5652088 -0.5689316 -0.6145351 -0.4551715 -0.5850054\n",
" acceleration year origin \n",
"mpg 0.4233285 0.5805410 0.5652088\n",
"cylinders -0.5046834 -0.3456474 -0.5689316\n",
"displacement -0.5438005 -0.3698552 -0.6145351\n",
"horsepower -0.6891955 -0.4163615 -0.4551715\n",
"weight -0.4168392 -0.3091199 -0.5850054\n",
"acceleration 1.0000000 0.2903161 0.2127458\n",
"year 0.2903161 1.0000000 0.1815277\n",
"origin 0.2127458 0.1815277 1.0000000"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cor(Auto[-c(9)])"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A matrix: 8 × 8 of type dbl</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>mpg</th><th scope=col>cylinders</th><th scope=col>displacement</th><th scope=col>horsepower</th><th scope=col>weight</th><th scope=col>acceleration</th><th scope=col>year</th><th scope=col>origin</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>mpg</th><td> 60.918142</td><td> -10.3529281</td><td> -657.58521</td><td> -233.85793</td><td> -5517.4407</td><td> 9.1155144</td><td> 16.6914766</td><td> 3.5535101</td></tr>\n",
"\t<tr><th scope=row>cylinders</th><td> -10.352928</td><td> 2.9096965</td><td> 169.72195</td><td> 55.34824</td><td> 1300.4244</td><td> -2.3750522</td><td> -2.1719296</td><td> -0.7817344</td></tr>\n",
"\t<tr><th scope=row>displacement</th><td> -657.585207</td><td> 169.7219486</td><td>10950.36755</td><td> 3614.03374</td><td> 82929.1001</td><td>-156.9944354</td><td>-142.5721332</td><td> -51.8007921</td></tr>\n",
"\t<tr><th scope=row>horsepower</th><td> -233.857926</td><td> 55.3482436</td><td> 3614.03374</td><td> 1481.56939</td><td> 28265.6202</td><td> -73.1869670</td><td> -59.0364320</td><td> -14.1127407</td></tr>\n",
"\t<tr><th scope=row>weight</th><td>-5517.440704</td><td>1300.4243632</td><td>82929.10014</td><td>28265.62023</td><td>721484.7090</td><td>-976.8152526</td><td>-967.2284566</td><td>-400.2660499</td></tr>\n",
"\t<tr><th scope=row>acceleration</th><td> 9.115514</td><td> -2.3750522</td><td> -156.99444</td><td> -73.18697</td><td> -976.8153</td><td> 7.6113312</td><td> 2.9504619</td><td> 0.4727882</td></tr>\n",
"\t<tr><th scope=row>year</th><td> 16.691477</td><td> -2.1719296</td><td> -142.57213</td><td> -59.03643</td><td> -967.2285</td><td> 2.9504619</td><td> 13.5699149</td><td> 0.5386502</td></tr>\n",
"\t<tr><th scope=row>origin</th><td> 3.553510</td><td> -0.7817344</td><td> -51.80079</td><td> -14.11274</td><td> -400.2660</td><td> 0.4727882</td><td> 0.5386502</td><td> 0.6488595</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A matrix: 8 × 8 of type dbl\n",
"\\begin{tabular}{r|llllllll}\n",
" & mpg & cylinders & displacement & horsepower & weight & acceleration & year & origin\\\\\n",
"\\hline\n",
"\tmpg & 60.918142 & -10.3529281 & -657.58521 & -233.85793 & -5517.4407 & 9.1155144 & 16.6914766 & 3.5535101\\\\\n",
"\tcylinders & -10.352928 & 2.9096965 & 169.72195 & 55.34824 & 1300.4244 & -2.3750522 & -2.1719296 & -0.7817344\\\\\n",
"\tdisplacement & -657.585207 & 169.7219486 & 10950.36755 & 3614.03374 & 82929.1001 & -156.9944354 & -142.5721332 & -51.8007921\\\\\n",
"\thorsepower & -233.857926 & 55.3482436 & 3614.03374 & 1481.56939 & 28265.6202 & -73.1869670 & -59.0364320 & -14.1127407\\\\\n",
"\tweight & -5517.440704 & 1300.4243632 & 82929.10014 & 28265.62023 & 721484.7090 & -976.8152526 & -967.2284566 & -400.2660499\\\\\n",
"\tacceleration & 9.115514 & -2.3750522 & -156.99444 & -73.18697 & -976.8153 & 7.6113312 & 2.9504619 & 0.4727882\\\\\n",
"\tyear & 16.691477 & -2.1719296 & -142.57213 & -59.03643 & -967.2285 & 2.9504619 & 13.5699149 & 0.5386502\\\\\n",
"\torigin & 3.553510 & -0.7817344 & -51.80079 & -14.11274 & -400.2660 & 0.4727882 & 0.5386502 & 0.6488595\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A matrix: 8 × 8 of type dbl\n",
"\n",
"| <!--/--> | mpg | cylinders | displacement | horsepower | weight | acceleration | year | origin |\n",
"|---|---|---|---|---|---|---|---|---|\n",
"| mpg | 60.918142 | -10.3529281 | -657.58521 | -233.85793 | -5517.4407 | 9.1155144 | 16.6914766 | 3.5535101 |\n",
"| cylinders | -10.352928 | 2.9096965 | 169.72195 | 55.34824 | 1300.4244 | -2.3750522 | -2.1719296 | -0.7817344 |\n",
"| displacement | -657.585207 | 169.7219486 | 10950.36755 | 3614.03374 | 82929.1001 | -156.9944354 | -142.5721332 | -51.8007921 |\n",
"| horsepower | -233.857926 | 55.3482436 | 3614.03374 | 1481.56939 | 28265.6202 | -73.1869670 | -59.0364320 | -14.1127407 |\n",
"| weight | -5517.440704 | 1300.4243632 | 82929.10014 | 28265.62023 | 721484.7090 | -976.8152526 | -967.2284566 | -400.2660499 |\n",
"| acceleration | 9.115514 | -2.3750522 | -156.99444 | -73.18697 | -976.8153 | 7.6113312 | 2.9504619 | 0.4727882 |\n",
"| year | 16.691477 | -2.1719296 | -142.57213 | -59.03643 | -967.2285 | 2.9504619 | 13.5699149 | 0.5386502 |\n",
"| origin | 3.553510 | -0.7817344 | -51.80079 | -14.11274 | -400.2660 | 0.4727882 | 0.5386502 | 0.6488595 |\n",
"\n"
],
"text/plain": [
" mpg cylinders displacement horsepower weight \n",
"mpg 60.918142 -10.3529281 -657.58521 -233.85793 -5517.4407\n",
"cylinders -10.352928 2.9096965 169.72195 55.34824 1300.4244\n",
"displacement -657.585207 169.7219486 10950.36755 3614.03374 82929.1001\n",
"horsepower -233.857926 55.3482436 3614.03374 1481.56939 28265.6202\n",
"weight -5517.440704 1300.4243632 82929.10014 28265.62023 721484.7090\n",
"acceleration 9.115514 -2.3750522 -156.99444 -73.18697 -976.8153\n",
"year 16.691477 -2.1719296 -142.57213 -59.03643 -967.2285\n",
"origin 3.553510 -0.7817344 -51.80079 -14.11274 -400.2660\n",
" acceleration year origin \n",
"mpg 9.1155144 16.6914766 3.5535101\n",
"cylinders -2.3750522 -2.1719296 -0.7817344\n",
"displacement -156.9944354 -142.5721332 -51.8007921\n",
"horsepower -73.1869670 -59.0364320 -14.1127407\n",
"weight -976.8152526 -967.2284566 -400.2660499\n",
"acceleration 7.6113312 2.9504619 0.4727882\n",
"year 2.9504619 13.5699149 0.5386502\n",
"origin 0.4727882 0.5386502 0.6488595"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cov(Auto[-c(9)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}