forked from zonbeka/ucn
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
710 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Randomized Complete Block Design\n", | ||
"## Example 13-5: Fabric Strength" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import statsmodels.formula.api as smf\n", | ||
"from statsmodels.stats.anova import anova_lm\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import scipy.stats as st\n", | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style>\n", | ||
" .dataframe thead tr:only-child th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: left;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>Chemical</th>\n", | ||
" <th>Fabric</th>\n", | ||
" <th>Strength</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>1</td>\n", | ||
" <td>1</td>\n", | ||
" <td>1.3</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>1</td>\n", | ||
" <td>2</td>\n", | ||
" <td>1.6</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>1</td>\n", | ||
" <td>3</td>\n", | ||
" <td>0.5</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>1</td>\n", | ||
" <td>4</td>\n", | ||
" <td>1.2</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>1</td>\n", | ||
" <td>5</td>\n", | ||
" <td>1.1</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" Chemical Fabric Strength\n", | ||
"0 1 1 1.3\n", | ||
"1 1 2 1.6\n", | ||
"2 1 3 0.5\n", | ||
"3 1 4 1.2\n", | ||
"4 1 5 1.1" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df = pd.read_excel('table 13-12.xlsx')\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py:879: RuntimeWarning: invalid value encountered in greater\n", | ||
" return (self.a < x) & (x < self.b)\n", | ||
"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py:879: RuntimeWarning: invalid value encountered in less\n", | ||
" return (self.a < x) & (x < self.b)\n", | ||
"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py:1818: RuntimeWarning: invalid value encountered in less_equal\n", | ||
" cond2 = cond0 & (x <= self.a)\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style>\n", | ||
" .dataframe thead tr:only-child th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: left;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>df</th>\n", | ||
" <th>sum_sq</th>\n", | ||
" <th>mean_sq</th>\n", | ||
" <th>F</th>\n", | ||
" <th>PR(>F)</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>C(Chemical)</th>\n", | ||
" <td>3.0</td>\n", | ||
" <td>18.044</td>\n", | ||
" <td>6.014667</td>\n", | ||
" <td>75.894848</td>\n", | ||
" <td>4.518310e-08</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>C(Fabric)</th>\n", | ||
" <td>4.0</td>\n", | ||
" <td>6.693</td>\n", | ||
" <td>1.673250</td>\n", | ||
" <td>21.113565</td>\n", | ||
" <td>2.318913e-05</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Residual</th>\n", | ||
" <td>12.0</td>\n", | ||
" <td>0.951</td>\n", | ||
" <td>0.079250</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" df sum_sq mean_sq F PR(>F)\n", | ||
"C(Chemical) 3.0 18.044 6.014667 75.894848 4.518310e-08\n", | ||
"C(Fabric) 4.0 6.693 1.673250 21.113565 2.318913e-05\n", | ||
"Residual 12.0 0.951 0.079250 NaN NaN" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"res = smf.ols('Strength ~ C(Chemical) + C(Fabric)', data=df).fit()\n", | ||
"anova_lm(res)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.