{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "eb1c8b12", "metadata": { "ExecuteTime": { "end_time": "2023-03-21T02:24:44.231568Z", "start_time": "2023-03-21T02:23:26.764221Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ageblackclericalconstruceducearns74gdhlthinlfsmsalhrwage...spwrk75totwrkunionworknrmworkscndexperyngkidyrsmarrhrwageagesq
13200.000000.000001200101.95586...03438034380140137.070001024
23100.000000.000001495001100.35767...0502005020011001.43000961
34400.000000.0000017425001113.02189...12815028150210020.530001936
\n", "

3 rows × 30 columns

\n", "
" ], "text/plain": [ " age black clerical construc educ earns74 gdhlth inlf smsa lhrwage \\\n", "1 32 0 0.00000 0.00000 12 0 0 1 0 1.95586 \n", "2 31 0 0.00000 0.00000 14 9500 1 1 0 0.35767 \n", "3 44 0 0.00000 0.00000 17 42500 1 1 1 3.02189 \n", "\n", " ... spwrk75 totwrk union worknrm workscnd exper yngkid yrsmarr \\\n", "1 ... 0 3438 0 3438 0 14 0 13 \n", "2 ... 0 5020 0 5020 0 11 0 0 \n", "3 ... 1 2815 0 2815 0 21 0 0 \n", "\n", " hrwage agesq \n", "1 7.07000 1024 \n", "2 1.43000 961 \n", "3 20.53000 1936 \n", "\n", "[3 rows x 30 columns]" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "pd.set_option(\"display.precision\", 3)\n", "pd.set_option('display.float_format', lambda x: '%.5f' % x)\n", "\n", "import warnings\n", "\n", "import janitor\n", "import numpy as np\n", "import pingouin as pg\n", "\n", "warnings.filterwarnings('ignore')\n", "\n", "_url = \"https://vincentarelbundock.github.io/Rdatasets/csv/wooldridge/sleep75.csv\"\n", "drop_var = ['case', 'leis1', 'leis2', 'leis3']\n", "df = (pd.read_csv(_url, index_col=0)\n", " .drop(drop_var, axis=1)\n", "# .assign(lspsepay=lambda df: np.log1p(df.spsepay))\n", " )\n", "df.head(3)" ] }, { "cell_type": "code", "execution_count": 2, "id": "fde0505a", "metadata": { "ExecuteTime": { "end_time": "2023-03-21T02:24:44.263338Z", "start_time": "2023-03-21T02:24:44.233567Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vargrouplabel
0ageagein years
1blackother factors=1 if black
2clericaloccupation=1 if clerical worker
\n", "
" ], "text/plain": [ " var group label\n", "0 age age in years\n", "1 black other factors =1 if black\n", "2 clerical occupation =1 if clerical worker" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Prep variable lablels (fold cell)\n", "# varlabels: http://fmwww.bc.edu/ec-p/data/wooldridge/sleep75.des\n", "df_label = (pd.read_csv('data/sleep75-des.csv', encoding=\"ISO-8859-1\")\n", " .assign(label=lambda df: df['des'].str.encode('ascii', 'ignore').str.decode('ascii'))\n", " .drop(['des'], axis=1)\n", " .set_index('var')\n", " .drop(drop_var)\n", " .reset_index()\n", " )\n", "\n", "df_label.head(3)" ] }, { "cell_type": "code", "execution_count": 3, "id": "e1a383bf", "metadata": { "ExecuteTime": { "end_time": "2023-03-21T02:24:46.077018Z", "start_time": "2023-03-21T02:24:44.264768Z" }, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
varcoefseTpvalr2adj_r2llhlmodelgrouplabel
0age0.994891.969250.505210.613620.127290.10366-2.873824.86360allagein years
1age1.482892.885460.513920.607720.180380.13911-4.197247.16302menagein years
2age0.953202.943210.323860.746340.109110.05342-4.846726.75312womenagein years
3age22.6340215.495321.460700.149310.17815-0.01362-8.3612453.62927young kidsagein years
4black-84.7966182.15012-1.032220.302450.127290.10366-246.1857276.59249allother factors=1 if black
5black-132.96711132.58117-1.002910.316780.180380.13911-393.95764128.02342menother factors=1 if black
6black-68.35063108.90175-0.627640.530880.109110.05342-282.95362146.25236womenother factors=1 if black
7black-119.74104296.43295-0.403940.687690.17815-0.01362-712.69523473.21315young kidsother factors=1 if black
8clerical22.5058348.963260.459650.645960.127290.10366-73.68559118.69725alloccupation=1 if clerical worker
9clerical-229.27596102.88822-2.228400.026650.180380.13911-431.81492-26.73700menoccupation=1 if clerical worker
10clerical106.5072661.127321.742380.082810.109110.05342-13.95091226.96543womenoccupation=1 if clerical worker
11clerical-239.90257211.76020-1.132900.261760.17815-0.01362-663.48604183.68089young kidsoccupation=1 if clerical worker
12construc113.92956105.045141.084580.278610.127290.10366-92.43824320.29736alloccupation=1 if construction worker
13construc65.69606107.889210.608920.543070.180380.13911-146.68751278.07963menoccupation=1 if construction worker
14construc361.75643428.264830.844700.399180.109110.05342-482.186951205.69980womenoccupation=1 if construction worker
15construc-186.41520358.22350-0.520390.604710.17815-0.01362-902.96889530.13849young kidsoccupation=1 if construction worker
16educ-7.210567.51674-0.959270.337870.127290.10366-21.977667.55654alllabor factorsyears of schooling
17educ-7.545429.72034-0.776250.438260.180380.13911-26.6802411.58940menlabor factorsyears of schooling
18educ-6.2784011.86988-0.528940.597370.109110.05342-29.6693217.11252womenlabor factorsyears of schooling
19educ-20.9721226.97403-0.777490.439920.17815-0.01362-74.9282132.98398young kidslabor factorsyears of schooling
20gdhlth-82.5804358.20472-1.418790.156560.127290.10366-196.9272731.76641allhealth factors=1 if in good or excel. health
21gdhlth-188.2845180.47654-2.339620.020010.180380.13911-346.70531-29.86371menhealth factors=1 if in good or excel. health
22gdhlth-24.4915887.71687-0.279210.780340.109110.05342-197.34740148.36424womenhealth factors=1 if in good or excel. health
23gdhlth-141.81498203.21302-0.697860.487960.17815-0.01362-548.30154264.67159young kidshealth factors=1 if in good or excel. health
24lhrwage21.6057031.989300.675400.499720.127290.10366-41.2393084.45070alllabor factorslog hourly wage
25lhrwage3.5447547.045920.075350.939990.180380.13911-89.0667596.15625menlabor factorslog hourly wage
26lhrwage-22.5804853.78232-0.419850.675000.109110.05342-128.5645183.40355womenlabor factorslog hourly wage
27lhrwage35.60932122.323740.291110.771970.17815-0.01362-209.07459280.29322young kidslabor factorslog hourly wage
28prot-9.2494339.77146-0.232560.816190.127290.10366-87.3829868.88412allother factors=1 if Protestant
29prot-20.9673352.20106-0.401660.688240.180380.13911-123.7268981.79223menother factors=1 if Protestant
30prot1.0666461.898050.017230.986270.109110.05342-120.91033123.04361womenother factors=1 if Protestant
31prot-24.17312127.56650-0.189490.850350.17815-0.01362-279.34411230.99786young kidsother factors=1 if Protestant
32selfe-21.2741863.30392-0.336060.736960.127290.10366-145.63872103.09036alllabor factors=1 if self employed
33selfe3.4840977.585710.044910.964210.180380.13911-149.24600156.21419menlabor factors=1 if self employed
34selfe-90.68594112.55650-0.805690.421270.109110.05342-312.49100131.11913womenlabor factors=1 if self employed
35selfe-370.95651241.15347-1.538260.129240.17815-0.01362-853.33528111.42226young kidslabor factors=1 if self employed
36smsa-40.6535639.50772-1.029000.303960.127290.10366-118.2689736.96186allarea of residence=1 if live in smsa
37smsa-27.6314352.41859-0.527130.598520.180380.13911-130.8192175.55635menarea of residence=1 if live in smsa
38smsa-57.1464061.52103-0.928890.353940.109110.05342-178.3804264.08762womenarea of residence=1 if live in smsa
39smsa43.42957138.683090.313160.755250.17815-0.01362-233.97791320.83705young kidsarea of residence=1 if live in smsa
40south82.4869846.377571.778600.075890.127290.10366-8.62469173.59864allarea of residence=1 if live in south
41south79.4016964.439831.232180.218920.180380.13911-47.45031206.25369menarea of residence=1 if live in south
42south114.6229369.300491.654000.099530.109110.05342-21.94138251.18725womenarea of residence=1 if live in south
43south71.85138136.010110.528280.599250.17815-0.01362-200.20935343.91211young kidsarea of residence=1 if live in south
44spsepay-0.001010.00265-0.379740.704300.127290.10366-0.006210.00420allother factorsspousal wage income
45spsepay0.003070.004920.623340.533570.180380.13911-0.006620.01276menother factorsspousal wage income
46spsepay-0.000510.00362-0.140320.888530.109110.05342-0.007640.00663womenother factorsspousal wage income
47spsepay-0.004700.01144-0.410850.682650.17815-0.01362-0.027590.01819young kidsother factorsspousal wage income
48totwrk-0.151920.02037-7.459430.000000.127290.10366-0.19193-0.11191alllabor factorsmins worked per week
49totwrk-0.191010.02977-6.417150.000000.180380.13911-0.24960-0.13241menlabor factorsmins worked per week
50totwrk-0.125510.03271-3.836780.000160.109110.05342-0.18998-0.06105womenlabor factorsmins worked per week
51totwrk-0.112990.07636-1.479710.144180.17815-0.01362-0.265740.03975young kidslabor factorsmins worked per week
52yrsmarr-0.075962.00936-0.037800.969860.127290.10366-4.023463.87155allfamily factorsyears married
53yrsmarr0.224122.934790.076370.939180.180380.13911-5.553126.00135menfamily factorsyears married
54yrsmarr-1.414142.93198-0.482310.630050.109110.05342-7.191944.36366womenfamily factorsyears married
55yrsmarr-31.2111416.91401-1.845280.069930.17815-0.01362-65.044202.62192young kidsfamily factorsyears married
\n", "
" ], "text/plain": [ " var coef se T pval r2 adj_r2 \\\n", "0 age 0.99489 1.96925 0.50521 0.61362 0.12729 0.10366 \n", "1 age 1.48289 2.88546 0.51392 0.60772 0.18038 0.13911 \n", "2 age 0.95320 2.94321 0.32386 0.74634 0.10911 0.05342 \n", "3 age 22.63402 15.49532 1.46070 0.14931 0.17815 -0.01362 \n", "4 black -84.79661 82.15012 -1.03222 0.30245 0.12729 0.10366 \n", "5 black -132.96711 132.58117 -1.00291 0.31678 0.18038 0.13911 \n", "6 black -68.35063 108.90175 -0.62764 0.53088 0.10911 0.05342 \n", "7 black -119.74104 296.43295 -0.40394 0.68769 0.17815 -0.01362 \n", "8 clerical 22.50583 48.96326 0.45965 0.64596 0.12729 0.10366 \n", "9 clerical -229.27596 102.88822 -2.22840 0.02665 0.18038 0.13911 \n", "10 clerical 106.50726 61.12732 1.74238 0.08281 0.10911 0.05342 \n", "11 clerical -239.90257 211.76020 -1.13290 0.26176 0.17815 -0.01362 \n", "12 construc 113.92956 105.04514 1.08458 0.27861 0.12729 0.10366 \n", "13 construc 65.69606 107.88921 0.60892 0.54307 0.18038 0.13911 \n", "14 construc 361.75643 428.26483 0.84470 0.39918 0.10911 0.05342 \n", "15 construc -186.41520 358.22350 -0.52039 0.60471 0.17815 -0.01362 \n", "16 educ -7.21056 7.51674 -0.95927 0.33787 0.12729 0.10366 \n", "17 educ -7.54542 9.72034 -0.77625 0.43826 0.18038 0.13911 \n", "18 educ -6.27840 11.86988 -0.52894 0.59737 0.10911 0.05342 \n", "19 educ -20.97212 26.97403 -0.77749 0.43992 0.17815 -0.01362 \n", "20 gdhlth -82.58043 58.20472 -1.41879 0.15656 0.12729 0.10366 \n", "21 gdhlth -188.28451 80.47654 -2.33962 0.02001 0.18038 0.13911 \n", "22 gdhlth -24.49158 87.71687 -0.27921 0.78034 0.10911 0.05342 \n", "23 gdhlth -141.81498 203.21302 -0.69786 0.48796 0.17815 -0.01362 \n", "24 lhrwage 21.60570 31.98930 0.67540 0.49972 0.12729 0.10366 \n", "25 lhrwage 3.54475 47.04592 0.07535 0.93999 0.18038 0.13911 \n", "26 lhrwage -22.58048 53.78232 -0.41985 0.67500 0.10911 0.05342 \n", "27 lhrwage 35.60932 122.32374 0.29111 0.77197 0.17815 -0.01362 \n", "28 prot -9.24943 39.77146 -0.23256 0.81619 0.12729 0.10366 \n", "29 prot -20.96733 52.20106 -0.40166 0.68824 0.18038 0.13911 \n", "30 prot 1.06664 61.89805 0.01723 0.98627 0.10911 0.05342 \n", "31 prot -24.17312 127.56650 -0.18949 0.85035 0.17815 -0.01362 \n", "32 selfe -21.27418 63.30392 -0.33606 0.73696 0.12729 0.10366 \n", "33 selfe 3.48409 77.58571 0.04491 0.96421 0.18038 0.13911 \n", "34 selfe -90.68594 112.55650 -0.80569 0.42127 0.10911 0.05342 \n", "35 selfe -370.95651 241.15347 -1.53826 0.12924 0.17815 -0.01362 \n", "36 smsa -40.65356 39.50772 -1.02900 0.30396 0.12729 0.10366 \n", "37 smsa -27.63143 52.41859 -0.52713 0.59852 0.18038 0.13911 \n", "38 smsa -57.14640 61.52103 -0.92889 0.35394 0.10911 0.05342 \n", "39 smsa 43.42957 138.68309 0.31316 0.75525 0.17815 -0.01362 \n", "40 south 82.48698 46.37757 1.77860 0.07589 0.12729 0.10366 \n", "41 south 79.40169 64.43983 1.23218 0.21892 0.18038 0.13911 \n", "42 south 114.62293 69.30049 1.65400 0.09953 0.10911 0.05342 \n", "43 south 71.85138 136.01011 0.52828 0.59925 0.17815 -0.01362 \n", "44 spsepay -0.00101 0.00265 -0.37974 0.70430 0.12729 0.10366 \n", "45 spsepay 0.00307 0.00492 0.62334 0.53357 0.18038 0.13911 \n", "46 spsepay -0.00051 0.00362 -0.14032 0.88853 0.10911 0.05342 \n", "47 spsepay -0.00470 0.01144 -0.41085 0.68265 0.17815 -0.01362 \n", "48 totwrk -0.15192 0.02037 -7.45943 0.00000 0.12729 0.10366 \n", "49 totwrk -0.19101 0.02977 -6.41715 0.00000 0.18038 0.13911 \n", "50 totwrk -0.12551 0.03271 -3.83678 0.00016 0.10911 0.05342 \n", "51 totwrk -0.11299 0.07636 -1.47971 0.14418 0.17815 -0.01362 \n", "52 yrsmarr -0.07596 2.00936 -0.03780 0.96986 0.12729 0.10366 \n", "53 yrsmarr 0.22412 2.93479 0.07637 0.93918 0.18038 0.13911 \n", "54 yrsmarr -1.41414 2.93198 -0.48231 0.63005 0.10911 0.05342 \n", "55 yrsmarr -31.21114 16.91401 -1.84528 0.06993 0.17815 -0.01362 \n", "\n", " ll hl model group \\\n", "0 -2.87382 4.86360 all age \n", "1 -4.19724 7.16302 men age \n", "2 -4.84672 6.75312 women age \n", "3 -8.36124 53.62927 young kids age \n", "4 -246.18572 76.59249 all other factors \n", "5 -393.95764 128.02342 men other factors \n", "6 -282.95362 146.25236 women other factors \n", "7 -712.69523 473.21315 young kids other factors \n", "8 -73.68559 118.69725 all occupation \n", "9 -431.81492 -26.73700 men occupation \n", "10 -13.95091 226.96543 women occupation \n", "11 -663.48604 183.68089 young kids occupation \n", "12 -92.43824 320.29736 all occupation \n", "13 -146.68751 278.07963 men occupation \n", "14 -482.18695 1205.69980 women occupation \n", "15 -902.96889 530.13849 young kids occupation \n", "16 -21.97766 7.55654 all labor factors \n", "17 -26.68024 11.58940 men labor factors \n", "18 -29.66932 17.11252 women labor factors \n", "19 -74.92821 32.98398 young kids labor factors \n", "20 -196.92727 31.76641 all health factors \n", "21 -346.70531 -29.86371 men health factors \n", "22 -197.34740 148.36424 women health factors \n", "23 -548.30154 264.67159 young kids health factors \n", "24 -41.23930 84.45070 all labor factors \n", "25 -89.06675 96.15625 men labor factors \n", "26 -128.56451 83.40355 women labor factors \n", "27 -209.07459 280.29322 young kids labor factors \n", "28 -87.38298 68.88412 all other factors \n", "29 -123.72689 81.79223 men other factors \n", "30 -120.91033 123.04361 women other factors \n", "31 -279.34411 230.99786 young kids other factors \n", "32 -145.63872 103.09036 all labor factors \n", "33 -149.24600 156.21419 men labor factors \n", "34 -312.49100 131.11913 women labor factors \n", "35 -853.33528 111.42226 young kids labor factors \n", "36 -118.26897 36.96186 all area of residence \n", "37 -130.81921 75.55635 men area of residence \n", "38 -178.38042 64.08762 women area of residence \n", "39 -233.97791 320.83705 young kids area of residence \n", "40 -8.62469 173.59864 all area of residence \n", "41 -47.45031 206.25369 men area of residence \n", "42 -21.94138 251.18725 women area of residence \n", "43 -200.20935 343.91211 young kids area of residence \n", "44 -0.00621 0.00420 all other factors \n", "45 -0.00662 0.01276 men other factors \n", "46 -0.00764 0.00663 women other factors \n", "47 -0.02759 0.01819 young kids other factors \n", "48 -0.19193 -0.11191 all labor factors \n", "49 -0.24960 -0.13241 men labor factors \n", "50 -0.18998 -0.06105 women labor factors \n", "51 -0.26574 0.03975 young kids labor factors \n", "52 -4.02346 3.87155 all family factors \n", "53 -5.55312 6.00135 men family factors \n", "54 -7.19194 4.36366 women family factors \n", "55 -65.04420 2.62192 young kids family factors \n", "\n", " label \n", "0 in years \n", "1 in years \n", "2 in years \n", "3 in years \n", "4 =1 if black \n", "5 =1 if black \n", "6 =1 if black \n", "7 =1 if black \n", "8 =1 if clerical worker \n", "9 =1 if clerical worker \n", "10 =1 if clerical worker \n", "11 =1 if clerical worker \n", "12 =1 if construction worker \n", "13 =1 if construction worker \n", "14 =1 if construction worker \n", "15 =1 if construction worker \n", "16 years of schooling \n", "17 years of schooling \n", "18 years of schooling \n", "19 years of schooling \n", "20 =1 if in good or excel. health \n", "21 =1 if in good or excel. health \n", "22 =1 if in good or excel. health \n", "23 =1 if in good or excel. health \n", "24 log hourly wage \n", "25 log hourly wage \n", "26 log hourly wage \n", "27 log hourly wage \n", "28 =1 if Protestant \n", "29 =1 if Protestant \n", "30 =1 if Protestant \n", "31 =1 if Protestant \n", "32 =1 if self employed \n", "33 =1 if self employed \n", "34 =1 if self employed \n", "35 =1 if self employed \n", "36 =1 if live in smsa \n", "37 =1 if live in smsa \n", "38 =1 if live in smsa \n", "39 =1 if live in smsa \n", "40 =1 if live in south \n", "41 =1 if live in south \n", "42 =1 if live in south \n", "43 =1 if live in south \n", "44 spousal wage income \n", "45 spousal wage income \n", "46 spousal wage income \n", "47 spousal wage income \n", "48 mins worked per week \n", "49 mins worked per week \n", "50 mins worked per week \n", "51 mins worked per week \n", "52 years married \n", "53 years married \n", "54 years married \n", "55 years married " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stdopts = {'relimp': False, 'remove_na': True}\n", "x = [\n", " \"age\",\n", " \"black\",\n", " \"clerical\",\n", " \"construc\",\n", " \"educ\",\n", " \"gdhlth\",\n", " \"inlf\",\n", " \"smsa\",\n", " \"lhrwage\",\n", " \"prot\",\n", " \"selfe\",\n", " \"south\",\n", " \"spsepay\",\n", " \"totwrk\",\n", " \"yrsmarr\",\n", "]\n", "lm_all = (pg.linear_regression(df[x], df['sleep'], **stdopts)\n", " .assign(model='all')\n", " )\n", "lm_male = (pg.linear_regression(df.query('male==1')[x], df.query('male==1')['sleep'], **stdopts)\n", " .assign(model='men')\n", " )\n", "lm_female = (pg.linear_regression(df.query('male==0')[x], df.query('male==0')['sleep'], **stdopts)\n", " .assign(model='women')\n", " )\n", "lm_kids = (pg.linear_regression(df.query('yngkid==1')[x], df.query('yngkid==1')['sleep'], **stdopts)\n", " .assign(model='young kids')\n", " )\n", "df_results = (pd.concat([lm_all, lm_female, lm_male, lm_kids])\n", " .query('names!=\"Intercept\"')\n", " .reset_index(drop=True)\n", " # Get labels\n", " .rename_column('names', 'var')\n", " .merge(df_label, how='left', on='var', validate='m:1')\n", " .sort_values(['var', 'model', 'group'])\n", " .reset_index(drop=True)\n", " # Tidy up columns\n", " .rename_column(\"CI[2.5%]\", \"ll\")\n", " .rename_column(\"CI[97.5%]\", \"hl\")\n", " )\n", "df_results" ] }, { "cell_type": "code", "execution_count": 4, "id": "f0cbd40e", "metadata": { "ExecuteTime": { "end_time": "2023-03-21T02:24:46.188049Z", "start_time": "2023-03-21T02:24:46.079021Z" } }, "outputs": [], "source": [ "df_results.to_csv('../examples/data/sleep-mmodel.csv', index=False)" ] }, { "cell_type": "code", "execution_count": 5, "id": "d2283891", "metadata": { "ExecuteTime": { "end_time": "2023-03-21T02:24:46.204047Z", "start_time": "2023-03-21T02:24:46.190050Z" } }, "outputs": [], "source": [ "# _cols = ['var', 'label', 'coef', 'model', 'group', 'pval', 'll', 'hl']\n", "# df_results[_cols].head(6).to_markdown()" ] }, { "cell_type": "code", "execution_count": null, "id": "ef007948", "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.9.12" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }