aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2024-02-23 23:22:05 -0800
committerGravatar Anshul Gupta <ansg191@anshulg.com> 2024-02-23 23:22:05 -0800
commitbe61f1593fd04a9f3420fc37e9eeee848476a39e (patch)
treeea1e89287943f8a60f8e6e889c9563bb7f43555c
parentc42a013995537f27f46800d0d31a1107db59ec36 (diff)
downloadCS105MiniProject-be61f1593fd04a9f3420fc37e9eeee848476a39e.tar.gz
CS105MiniProject-be61f1593fd04a9f3420fc37e9eeee848476a39e.tar.zst
CS105MiniProject-be61f1593fd04a9f3420fc37e9eeee848476a39e.zip
Finishes hypot1
-rw-r--r--CS105MiniProject.ipynb173
1 files changed, 132 insertions, 41 deletions
diff --git a/CS105MiniProject.ipynb b/CS105MiniProject.ipynb
index ba21518..a0522d5 100644
--- a/CS105MiniProject.ipynb
+++ b/CS105MiniProject.ipynb
@@ -36,8 +36,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:54.973509Z",
- "start_time": "2024-02-24T07:00:54.931665Z"
+ "end_time": "2024-02-24T07:21:38.151425Z",
+ "start_time": "2024-02-24T07:21:38.129592Z"
}
},
"outputs": [
@@ -84,8 +84,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:54.991580Z",
- "start_time": "2024-02-24T07:00:54.974862Z"
+ "end_time": "2024-02-24T07:21:38.167750Z",
+ "start_time": "2024-02-24T07:21:38.152499Z"
}
},
"outputs": [
@@ -180,8 +180,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:55.003163Z",
- "start_time": "2024-02-24T07:00:54.994655Z"
+ "end_time": "2024-02-24T07:21:38.175951Z",
+ "start_time": "2024-02-24T07:21:38.168372Z"
}
},
"outputs": [
@@ -210,8 +210,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:55.013927Z",
- "start_time": "2024-02-24T07:00:55.004472Z"
+ "end_time": "2024-02-24T07:21:38.182948Z",
+ "start_time": "2024-02-24T07:21:38.176646Z"
}
},
"outputs": [
@@ -246,8 +246,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:55.212651Z",
- "start_time": "2024-02-24T07:00:55.015240Z"
+ "end_time": "2024-02-24T07:21:38.320548Z",
+ "start_time": "2024-02-24T07:21:38.183489Z"
}
},
"outputs": [
@@ -317,8 +317,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:55.426118Z",
- "start_time": "2024-02-24T07:00:55.214378Z"
+ "end_time": "2024-02-24T07:21:38.504579Z",
+ "start_time": "2024-02-24T07:21:38.322532Z"
}
},
"id": "c533e52f7d64a4df",
@@ -360,8 +360,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:55.582387Z",
- "start_time": "2024-02-24T07:00:55.429377Z"
+ "end_time": "2024-02-24T07:21:38.622759Z",
+ "start_time": "2024-02-24T07:21:38.508034Z"
}
},
"id": "450665f2272bb3a2",
@@ -405,8 +405,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:55.914365Z",
- "start_time": "2024-02-24T07:00:55.595859Z"
+ "end_time": "2024-02-24T07:21:38.716057Z",
+ "start_time": "2024-02-24T07:21:38.623992Z"
}
},
"id": "1a704a4702ea3f9c",
@@ -451,8 +451,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:57.258272Z",
- "start_time": "2024-02-24T07:00:55.921452Z"
+ "end_time": "2024-02-24T07:21:39.046666Z",
+ "start_time": "2024-02-24T07:21:38.717321Z"
}
},
"id": "ae23070caa8a3c88",
@@ -507,8 +507,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:57.502313Z",
- "start_time": "2024-02-24T07:00:57.263584Z"
+ "end_time": "2024-02-24T07:21:39.136880Z",
+ "start_time": "2024-02-24T07:21:39.048148Z"
}
},
"id": "464b4dec962ea0ae",
@@ -556,8 +556,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:57.811998Z",
- "start_time": "2024-02-24T07:00:57.510472Z"
+ "end_time": "2024-02-24T07:21:39.309745Z",
+ "start_time": "2024-02-24T07:21:39.138109Z"
}
},
"id": "101f55892c052d46",
@@ -595,8 +595,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:58.074567Z",
- "start_time": "2024-02-24T07:00:57.814673Z"
+ "end_time": "2024-02-24T07:21:39.512158Z",
+ "start_time": "2024-02-24T07:21:39.311676Z"
}
},
"id": "350d4fef50f55e38",
@@ -626,6 +626,97 @@
{
"cell_type": "markdown",
"source": [
+ "# Hypothesis 1: There will be a correlation between whether people live with family, friends, or neither and whether or not they work\n",
+ "\n",
+ "Null Hypothesis: There is no relationship between people who live with family, friends, or neither and whether or not they work.\n",
+ "\n",
+ "Significance value: 0.1\n",
+ "Degrees of freedom: 3"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "af9e65fe95ad565e"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": "Do you currently work? No Yes Total\nWho do you live with? \nBoth 22 5 27\nFamily 61 33 94\nFriends 57 27 84\nNeither 42 12 54\nTotal 182 77 259",
+ "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th>Do you currently work?</th>\n <th>No</th>\n <th>Yes</th>\n <th>Total</th>\n </tr>\n <tr>\n <th>Who do you live with?</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Both</th>\n <td>22</td>\n <td>5</td>\n <td>27</td>\n </tr>\n <tr>\n <th>Family</th>\n <td>61</td>\n <td>33</td>\n <td>94</td>\n </tr>\n <tr>\n <th>Friends</th>\n <td>57</td>\n <td>27</td>\n <td>84</td>\n </tr>\n <tr>\n <th>Neither</th>\n <td>42</td>\n <td>12</td>\n <td>54</td>\n </tr>\n <tr>\n <th>Total</th>\n <td>182</td>\n <td>77</td>\n <td>259</td>\n </tr>\n </tbody>\n</table>\n</div>"
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "hyp3_major_table = pd.crosstab(df.iloc[:, 3], df.iloc[:, 8], margins=True, margins_name='Total')\n",
+ "hyp3_major_table"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-02-24T07:21:39.555055Z",
+ "start_time": "2024-02-24T07:21:39.514908Z"
+ }
+ },
+ "id": "48b809cbd77a656f",
+ "execution_count": 13
+ },
+ {
+ "cell_type": "code",
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Chi-squared value: 4.616203438011947\n"
+ ]
+ }
+ ],
+ "source": [
+ "num_rows, num_cols = hyp3_major_table.shape\n",
+ "# Initialize expected frequencies\n",
+ "expected_frequencies = []\n",
+ "chi_squared = 0\n",
+ "for i in range(num_rows - 1):\n",
+ " row_totals = hyp3_major_table.iloc[i, -1]\n",
+ " for j in range(num_cols - 1):\n",
+ " col_totals = hyp3_major_table.iloc[-1, j]\n",
+ " expected_frequency = (row_totals * col_totals) / hyp3_major_table.iloc[-1, -1]\n",
+ " expected_frequencies.append(expected_frequency)\n",
+ " chi_squared += ((hyp3_major_table.iloc[i, j] - expected_frequency) ** 2) / expected_frequency\n",
+ "\n",
+ "print(\"Chi-squared value:\", chi_squared)"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "ExecuteTime": {
+ "end_time": "2024-02-24T07:21:39.564411Z",
+ "start_time": "2024-02-24T07:21:39.556730Z"
+ }
+ },
+ "id": "b82779602aa7b791",
+ "execution_count": 14
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "With a significance value of 0.1 and 3 degrees of freedom, chi-squared must be greater than 6.25.\n",
+ "Since chi-squared of `4.61 < 6.25`, we accept the null hypothesis:\n",
+ "\n",
+ "There is no relationship between people who live with family, friends, or neither and whether or not they work."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "543e4daba6344237"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
"### Hypothesis 2: Students who live on-campus are more likely to have roommates of the same major.\n",
"\n",
"Null Hypothesis: There is no relationship between students who live on-campus and students who have roommates of the same major.\n",
@@ -643,27 +734,27 @@
"outputs": [
{
"data": {
- "text/plain": "How many hours do you work per week on average? 0 1 - 5 10 - 20 20 - 40 \\\nWho do you live with? \nBoth 22 1 2 0 \nFamily 61 6 10 4 \nFriends 57 2 11 2 \nNeither 42 0 5 0 \nTotal 182 9 28 6 \n\nHow many hours do you work per week on average? 5 - 10 Total \nWho do you live with? \nBoth 2 27 \nFamily 13 94 \nFriends 12 84 \nNeither 7 54 \nTotal 34 259 ",
- "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th>How many hours do you work per week on average?</th>\n <th>0</th>\n <th>1 - 5</th>\n <th>10 - 20</th>\n <th>20 - 40</th>\n <th>5 - 10</th>\n <th>Total</th>\n </tr>\n <tr>\n <th>Who do you live with?</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Both</th>\n <td>22</td>\n <td>1</td>\n <td>2</td>\n <td>0</td>\n <td>2</td>\n <td>27</td>\n </tr>\n <tr>\n <th>Family</th>\n <td>61</td>\n <td>6</td>\n <td>10</td>\n <td>4</td>\n <td>13</td>\n <td>94</td>\n </tr>\n <tr>\n <th>Friends</th>\n <td>57</td>\n <td>2</td>\n <td>11</td>\n <td>2</td>\n <td>12</td>\n <td>84</td>\n </tr>\n <tr>\n <th>Neither</th>\n <td>42</td>\n <td>0</td>\n <td>5</td>\n <td>0</td>\n <td>7</td>\n <td>54</td>\n </tr>\n <tr>\n <th>Total</th>\n <td>182</td>\n <td>9</td>\n <td>28</td>\n <td>6</td>\n <td>34</td>\n <td>259</td>\n </tr>\n </tbody>\n</table>\n</div>"
+ "text/plain": "Do you work in a department related to your major? No Yes Total\nDo you currently live in a house, apartment, or... \nApartment 22 16 38\nDorm 4 1 5\nHouse 27 7 34\nTotal 53 24 77",
+ "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th>Do you work in a department related to your major?</th>\n <th>No</th>\n <th>Yes</th>\n <th>Total</th>\n </tr>\n <tr>\n <th>Do you currently live in a house, apartment, or dorm?</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Apartment</th>\n <td>22</td>\n <td>16</td>\n <td>38</td>\n </tr>\n <tr>\n <th>Dorm</th>\n <td>4</td>\n <td>1</td>\n <td>5</td>\n </tr>\n <tr>\n <th>House</th>\n <td>27</td>\n <td>7</td>\n <td>34</td>\n </tr>\n <tr>\n <th>Total</th>\n <td>53</td>\n <td>24</td>\n <td>77</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
- "execution_count": 13,
+ "execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "roommates_major_table = pd.crosstab(df.iloc[:, 3], df.iloc[:, 9], margins=True, margins_name='Total')\n",
+ "roommates_major_table = pd.crosstab(df.iloc[:, 4], df.iloc[:, 11], margins=True, margins_name='Total')\n",
"roommates_major_table"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:58.107622Z",
- "start_time": "2024-02-24T07:00:58.086610Z"
+ "end_time": "2024-02-24T07:21:39.599685Z",
+ "start_time": "2024-02-24T07:21:39.566651Z"
}
},
"id": "24d1f01fdd4ca1d6",
- "execution_count": 13
+ "execution_count": 15
},
{
"cell_type": "code",
@@ -672,7 +763,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Chi-squared value: 10.845786899856222\n"
+ "Chi-squared value: 4.183390044200403\n"
]
}
],
@@ -694,12 +785,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:58.112397Z",
- "start_time": "2024-02-24T07:00:58.108287Z"
+ "end_time": "2024-02-24T07:21:39.604065Z",
+ "start_time": "2024-02-24T07:21:39.600815Z"
}
},
"id": "fd3e73d9f461afd1",
- "execution_count": 14
+ "execution_count": 16
},
{
"cell_type": "markdown",
@@ -762,12 +853,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:58.135808Z",
- "start_time": "2024-02-24T07:00:58.113051Z"
+ "end_time": "2024-02-24T07:21:39.625364Z",
+ "start_time": "2024-02-24T07:21:39.604708Z"
}
},
"id": "b513f8e8241e86e5",
- "execution_count": 15
+ "execution_count": 17
},
{
"cell_type": "markdown",
@@ -789,12 +880,12 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
- "end_time": "2024-02-24T07:00:58.137929Z",
- "start_time": "2024-02-24T07:00:58.136527Z"
+ "end_time": "2024-02-24T07:21:39.628186Z",
+ "start_time": "2024-02-24T07:21:39.626237Z"
}
},
"id": "55fb116c79c479a1",
- "execution_count": 15
+ "execution_count": 17
}
],
"metadata": {