{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Internet use and religion in Europe, part four\n", "-----------------------------------------\n", "\n", "This notebook presents explorations of the association between Internet use and religion in Europe, using data from the European Social Survey (http://www.europeansocialsurvey.org).\n", "\n", "Copyright 2015 Allen Downey\n", "\n", "MIT License: http://opensource.org/licenses/MIT" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function, division\n", "\n", "import string\n", "import random\n", "import cPickle as pickle\n", "\n", "import numpy as np\n", "import pandas as pd\n", "import statsmodels.formula.api as smf\n", "\n", "import thinkstats2\n", "import thinkplot\n", "import matplotlib.pyplot as plt\n", "\n", "import ess\n", "\n", "# colors by colorbrewer2.org\n", "BLUE1 = '#a6cee3'\n", "BLUE2 = '#1f78b4'\n", "GREEN1 = '#b2df8a'\n", "GREEN2 = '#33a02c'\n", "PINK = '#fb9a99'\n", "RED = '#e31a1c'\n", "ORANGE1 = '#fdbf6f'\n", "ORANGE2 = '#ff7f00'\n", "PURPLE1 = '#cab2d6'\n", "PURPLE2 = '#6a3d9a'\n", "YELLOW = '#ffff99'\n", "BROWN = '#b15928'\n", "\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Open the store containing resampled DataFrames." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [], "source": [ "store.close()\n", "store = pd.HDFStore('ess.resamples.h5')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the country objects" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Austria\n", "Belgium\n", "Bulgaria\n", "Switzerland\n", "Cyprus\n", "Czech Rep\n", "Germany\n", "Denmark\n", "Estonia\n", "Spain\n", "Finland\n", "France\n", "UK\n", "Greece\n", "Croatia\n", "Hungary\n", "Ireland\n", "Israel\n", "Iceland\n", "Italy\n", "Lithuania\n", "Luxembourg\n", "Latvia\n", "Netherlands\n", "Norway\n", "Poland\n", "Portugal\n", "Romania\n", "Russia\n", "Sweden\n", "Slovenia\n", "Slovakia\n", "Turkey\n", "Ukraine\n" ] } ], "source": [ "reload(ess)\n", "country_map = ess.make_countries(store)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For each resampled frame, run both models and store the results in the Country objects" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "204" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "keys = store.keys()\n", "len(keys)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 /AAVZWa\n", "1 /ADbUvD\n", "2 /AJEDdF\n", "3 /AOacJP\n", "4 /AsSyrK\n", "5 /BIXejR\n", "6 /Blwttj\n", "7 /BytXnJ\n", "8 /CuiQgF\n", "9 /CxkVBv\n", "10 /DOKcxz\n", "11 /DSSzPM\n", "12 /DdpHTg\n", "13 /EBHNWn\n", "14 /EHuhuk\n", "15 /EIaigX\n", "16 /EOOBpB\n", "17 /EdeAYH\n", "18 /EiftYh\n", "19 /EoHBcy\n", "20 /Evkitq\n", "21 /FJboqX\n", "22 /FWawby\n", "23 /GIKXkG\n", "24 /GPBBMj\n", "25 /GYhuaT\n", "26 /GdTLTY\n", "27 /GeUlsB\n", "28 /GeolrR\n", "29 /GkMwBV\n", "30 /GownbC\n", "31 /GrCTmE\n", "32 /HGSBFA\n", "33 /HemGKU\n", "34 /HujYDN\n", "35 /IKLjEu\n", "36 /IORbkE\n", "37 /IXYMov\n", "38 /InEXbB\n", "39 /JKBolS\n", "40 /JVSJPq\n", "41 /JofMZK\n", "42 /JomohW\n", "43 /JznRlw\n", "44 /KEthFz\n", "45 /KFwczR\n", "46 /KUVnJc\n", "47 /KnKXTR\n", "48 /KuGUhG\n", "49 /KudtCP\n", "50 /LaUmLC\n", "51 /LissvE\n", "52 /LmraEV\n", "53 /MCmopN\n", "54 /MIdmWa\n", "55 /MgSdJx\n", "56 /NJjQrX\n", "57 /NfzPAX\n", "58 /OJZEtt\n", "59 /Oaksmf\n", "60 /OdhAjf\n", "61 /PJETsk\n", "62 /PXxSpS\n", "63 /PiWfGA\n", "64 /PptHII\n", "65 /PvfGpy\n", "66 /QTTYTa\n", "67 /QbhbQt\n", "68 /QoHLXF\n", "69 /QskeUe\n", "70 /QtkeEX\n", "71 /RHVBHl\n", "72 /RRpxwc\n", "73 /RYtpJo\n", "74 /RuCVox\n", "75 /RwJMYt\n", "76 /SHnJcB\n", "77 /ScbnLb\n", "78 /TOcaLi\n", "79 /TRVSRU\n", "80 /TaHTXL\n", "81 /UKzbGY\n", "82 /UVvNeb\n", "83 /UfXGIO\n", "84 /VHIVpS\n", "85 /VcRwRL\n", "86 /VgqgVe\n", "87 /VlUfcv\n", "88 /VzZAXk\n", "89 /WczOWP\n", "90 /WkLtrX\n", "91 /WkfCQW\n", "92 /WlHtRg\n", "93 /WwTDDj\n", "94 /WxWlWp\n", "95 /XGmIIH\n", "96 /XOxJQN\n", "97 /XhgvtL\n", "98 /YMsFSK\n", "99 /YeASVz\n", "100 /YoxGxL\n" ] } ], "source": [ "reload(ess)\n", "FORMULA1 = ('hasrelig_f ~ inwyr07_f + yrbrn60_f + yrbrn60_f2 + '\n", " 'edurank_f + hincrank_f +'\n", " 'tvtot_f + rdtot_f + nwsptot_f + netuse_f')\n", "\n", "num = 101\n", "ess.process_all_frames(store, country_map, num,\n", " smf.logit, FORMULA1, model_num=1)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 /AAVZWa\n", "1 /ADbUvD\n", "2 /AJEDdF\n", "3 /AOacJP\n", "4 /AsSyrK\n", "5 /BIXejR\n", "6 /Blwttj\n", "7 /BytXnJ\n", "8 /CuiQgF\n", "9 /CxkVBv\n", "10 /DOKcxz\n", "11 /DSSzPM\n", "12 /DdpHTg\n", "13 /EBHNWn\n", "14 /EHuhuk\n", "15 /EIaigX\n", "16 /EOOBpB\n", "17 /EdeAYH\n", "18 /EiftYh\n", "19 /EoHBcy\n", "20 /Evkitq\n", "21 /FJboqX\n", "22 /FWawby\n", "23 /GIKXkG\n", "24 /GPBBMj\n", "25 /GYhuaT\n", "26 /GdTLTY\n", "27 /GeUlsB\n", "28 /GeolrR\n", "29 /GkMwBV\n", "30 /GownbC\n", "31 /GrCTmE\n", "32 /HGSBFA\n", "33 /HemGKU\n", "34 /HujYDN\n", "35 /IKLjEu\n", "36 /IORbkE\n", "37 /IXYMov\n", "38 /InEXbB\n", "39 /JKBolS\n", "40 /JVSJPq\n", "41 /JofMZK\n", "42 /JomohW\n", "43 /JznRlw\n", "44 /KEthFz\n", "45 /KFwczR\n", "46 /KUVnJc\n", "47 /KnKXTR\n", "48 /KuGUhG\n", "49 /KudtCP\n", "50 /LaUmLC\n", "51 /LissvE\n", "52 /LmraEV\n", "53 /MCmopN\n", "54 /MIdmWa\n", "55 /MgSdJx\n", "56 /NJjQrX\n", "57 /NfzPAX\n", "58 /OJZEtt\n", "59 /Oaksmf\n", "60 /OdhAjf\n", "61 /PJETsk\n", "62 /PXxSpS\n", "63 /PiWfGA\n", "64 /PptHII\n", "65 /PvfGpy\n", "66 /QTTYTa\n", "67 /QbhbQt\n", "68 /QoHLXF\n", "69 /QskeUe\n", "70 /QtkeEX\n", "71 /RHVBHl\n", "72 /RRpxwc\n", "73 /RYtpJo\n", "74 /RuCVox\n", "75 /RwJMYt\n", "76 /SHnJcB\n", "77 /ScbnLb\n", "78 /TOcaLi\n", "79 /TRVSRU\n", "80 /TaHTXL\n", "81 /UKzbGY\n", "82 /UVvNeb\n", "83 /UfXGIO\n", "84 /VHIVpS\n", "85 /VcRwRL\n", "86 /VgqgVe\n", "87 /VlUfcv\n", "88 /VzZAXk\n", "89 /WczOWP\n", "90 /WkLtrX\n", "91 /WkfCQW\n", "92 /WlHtRg\n", "93 /WwTDDj\n", "94 /WxWlWp\n", "95 /XGmIIH\n", "96 /XOxJQN\n", "97 /XhgvtL\n", "98 /YMsFSK\n", "99 /YeASVz\n", "100 /YoxGxL\n" ] } ], "source": [ "reload(ess)\n", "FORMULA2 = ('rlgdgr_f ~ inwyr07_f + yrbrn60_f + yrbrn60_f2 + '\n", " 'edurank_f + hincrank_f +'\n", " 'tvtot_f + rdtot_f + nwsptot_f + netuse_f')\n", "\n", "ess.process_all_frames(store, country_map, num,\n", " smf.ols, FORMULA2, model_num=2)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "store.close()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [], "source": [ "with open('ess4.pkl', 'wb') as fp:\n", " pickle.dump(country_map, fp)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [], "source": [ "with open('ess4.pkl', 'rb') as fp:\n", " country_map = pickle.load(fp)" ] }, { "cell_type": "code", "execution_count": 72, "metadata": { "collapsed": true }, "outputs": [], "source": [ "plot_counter = 1\n", "\n", "def save_plot(flag=True):\n", " \"\"\"Saves plots in png format.\n", " \n", " flag: boolean, whether to save or not\n", " \"\"\"\n", " global plot_counter\n", " if flag:\n", " root = 'ess4.%2.2d' % plot_counter\n", " thinkplot.Save(root=root, formats=['png'])\n", " plot_counter += 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a plot showing confidence interval for the given parameters" ] }, { "cell_type": "code", "execution_count": 73, "metadata": { "collapsed": true }, "outputs": [], "source": [ "xlabel1 = 'Difference in percentage points of hasrelig'\n", "xlabel2 = 'Difference in religiosity (0-10 scale)'" ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "collapsed": true }, "outputs": [], "source": [ "xlim = [-25, 15]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First let's check on the estimated parameters for the age variables." ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.01.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'yrbrn60_f', 'hasrelig_f') \n", "ess.plot_cis(t, GREEN2)\n", "thinkplot.Config(title='Year born',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In almost every country, year born is associated with less religiosity." ] }, { "cell_type": "code", "execution_count": 76, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.02.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'inwyr07_f', 'hasrelig_f') \n", "ess.plot_cis(t, GREEN1)\n", "thinkplot.Config(title='Interview year',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.03.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'edurank_f', 'hasrelig_f')\n", "ess.plot_cis(t, ORANGE2)\n", "thinkplot.Config(title='Education (relative rank)',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.04.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'hincrank_f', 'hasrelig_f')\n", "ess.plot_cis(t, ORANGE1)\n", "thinkplot.Config(title='Income (relative rank)',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 79, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.05.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'tvtot_f', 'hasrelig_f')\n", "ess.plot_cis(t, RED)\n", "thinkplot.Config(title='Television watching',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 80, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.06.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'rdtot_f', 'hasrelig_f')\n", "ess.plot_cis(t, BLUE1)\n", "thinkplot.Config(title='Radio listening',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 81, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.07.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'nwsptot_f', 'hasrelig_f')\n", "ess.plot_cis(t, BLUE2)\n", "thinkplot.Config(title='Newspaper reading',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.08.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'netuse_f', 'hasrelig_f')\n", "ess.plot_cis(t, PURPLE2)\n", "thinkplot.Config(title='Internet use',\n", " xlabel=xlabel1, xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-7.6100903746 -7.99861220321\n", "-3.47246804305 -3.39621681489\n", "-1.56600401422 -1.95101119651\n", "-0.948475855492 -1.04940487676\n", "0.283111223687 -0.100804047038\n", "-0.128763052394 0.188254315036\n", "0.248812913673 0.625585601944\n", "1.30795708007 0.426758433373\n", "Writing ess4.09.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "reload(ess)\n", "cdfnames = ['yrbrn60_f', 'netuse_f', 'edurank_f', 'tvtot_f', 'hincrank_f',\n", " 'rdtot_f', 'nwsptot_f',\n", " 'inwyr07_f' ]\n", "ess.plot_cdfs(country_map, ess.extract_ranges, cdfnames=cdfnames)\n", "thinkplot.Config(xlabel='Difference in percentage points',\n", " xlim=[-20, 10],\n", " ylabel='CDF',\n", " legend=True,\n", " loc='upper left')\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.30172553685\n", "Writing ess4.10.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'netuse_f', 'hasrelig_f')\n", "ess.plot_scatter(t, BLUE)\n", "thinkplot.Config(title='',\n", " xlabel=xlabel1,\n", " ylabel='Fraction affiliated',\n", " xlim=[-10, 5], ylim=[0, 1])\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 85, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.299832107839\n", "Writing ess4.11.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'netuse_f', 'rlgdgr_f')\n", "ess.plot_scatter(t, BLUE)\n", "thinkplot.Config(title='',\n", " xlabel=xlabel1,\n", " ylabel='Mean religiosity',\n", " xlim=[-10, 5], ylim=[0, 7.5])\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.377644186914\n", "Writing ess4.12.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges(country_map, 'netuse_f', 'netuse_f')\n", "ess.plot_scatter(t, BLUE)\n", "thinkplot.Config(title='',\n", " xlabel=xlabel1,\n", " ylabel='Mean Internet use',\n", " xlim=[-10, 5], ylim=[0, 7.5])\n", "save_plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make similar figures for the second model, with degree of religiosity as the dependent variable." ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": true }, "outputs": [], "source": [ "xlim = [-2.5, 1.0]" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.13.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'yrbrn60_f', 'rlgdgr_f')\n", "ess.plot_cis(t, GREEN2)\n", "thinkplot.Config(title='Year born',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.14.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'inwyr07_f', 'rlgdgr_f')\n", "ess.plot_cis(t, GREEN1)\n", "thinkplot.Config(title='Education rank',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.15.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'edurank_f', 'rlgdgr_f')\n", "ess.plot_cis(t, ORANGE2)\n", "thinkplot.Config(title='Education rank',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.16.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'hincrank_f', 'hasrelig_f')\n", "ess.plot_cis(t, ORANGE1)\n", "thinkplot.Config(title='Income rank',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.17.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'tvtot_f', 'hasrelig_f')\n", "ess.plot_cis(t, RED)\n", "thinkplot.Config(title='Television watching',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.18.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'rdtot_f', 'hasrelig_f')\n", "ess.plot_cis(t, BLUE1)\n", "thinkplot.Config(title='Radio listening',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.19.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'nwsptot_f', 'hasrelig_f')\n", "ess.plot_cis(t, BLUE2)\n", "thinkplot.Config(title='Newspaper reading',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing ess4.20.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'netuse_f', 'hasrelig_f')\n", "ess.plot_cis(t, PURPLE2)\n", "thinkplot.Config(title='Internet use',\n", " xlabel=xlabel2,\n", " xlim=xlim)\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 96, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.361527956195 -0.334836169355\n", "-0.185573584648 -0.201108610193\n", "-0.217090335159 -0.223876985972\n", "-0.113349234086 -0.125387887266\n", "-0.0348431722332 -0.0408627145833\n", "-0.0198243358803 -0.0057449815362\n", "0.0265003098879 0.0239471272503\n", "-0.529880792947 -0.598870219159\n", "Writing ess4.21.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cdfnames = ['netuse_f', 'edurank_f', 'tvtot_f', 'hincrank_f',\n", " 'rdtot_f', 'nwsptot_f',\n", " 'inwyr07_f', 'yrbrn60_f']\n", "ess.plot_cdfs(country_map, ess.extract_ranges2, cdfnames=cdfnames)\n", "thinkplot.Config(xlabel=xlabel2,\n", " xlim=[-2, 0.7],\n", " ylabel='CDF',\n", " loc='upper left')\n", "save_plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here's the scatter plot of effect size on rlgdgr versus mean value of rlgdgr\n", "\n", "rlgdgr is on a 0 to 10 scale, so it is mildly astonishing that national means vary as much as they do, from 2.5 to 7. " ] }, { "cell_type": "code", "execution_count": 97, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.224489530769\n", "Writing ess4.22.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'netuse_f', 'hasrelig_f')\n", "ess.plot_scatter(t, BLUE)\n", "thinkplot.Config(title='',\n", " xlabel=xlabel2,\n", " ylabel='Fraction affiliated',\n", " xlim=[-2.5, 0.5], ylim=[0, 1]\n", " )\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 98, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.229662125758\n", "Writing ess4.23.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'netuse_f', 'rlgdgr_f')\n", "ess.plot_scatter(t, BLUE)\n", "thinkplot.Config(title='',\n", " xlabel=xlabel2,\n", " ylabel='Mean religiosity',\n", " xlim=[-2.5, 0.5], ylim=[0, 7.5]\n", " )\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 99, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.065890035769\n", "Writing ess4.24.png\n" ] }, { "data": { "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t = ess.extract_ranges2(country_map, 'netuse_f', 'netuse_f')\n", "ess.plot_scatter(t, PURPLE2)\n", "thinkplot.Config(title='',\n", " xlabel=xlabel2,\n", " ylabel='Mean Internet use',\n", " xlim=[-2.5, 0.5], ylim=[0, 7.5])\n", "save_plot()" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "varname \tneg* \tneg \tpos \tpos*\n", "--------- \t---- \t--- \t--- \t----\n", "yrbrn60_f \t27 \t3 \t2 \t2 \t34\n", "netuse_f \t24 \t6 \t4 \t0 \t34\n", "edurank_f \t19 \t7 \t3 \t5 \t34\n", "tvtot_f \t14 \t10 \t4 \t6 \t34\n", "nwsptot_f \t10 \t4 \t11 \t9 \t34\n", "rdtot_f \t8 \t7 \t13 \t6 \t34\n", "hincrank_f \t4 \t15 \t11 \t4 \t34\n", "inwyr07_f \t2 \t9 \t11 \t12 \t34\n" ] } ], "source": [ "reload(ess)\n", "varnames = ['inwyr07_f', 'yrbrn60_f', 'netuse_f', 'edurank_f', \n", " 'tvtot_f', 'hincrank_f', 'rdtot_f', 'nwsptot_f']\n", "\n", "ts = ess.make_table(country_map, varnames, ess.extract_ranges)\n", "ess.print_table(ts)" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "varname \tneg* \tneg \tpos \tpos*\n", "--------- \t---- \t--- \t--- \t----\n", "yrbrn60_f \t29 \t3 \t1 \t1 \t34\n", "netuse_f \t24 \t7 \t3 \t0 \t34\n", "tvtot_f \t22 \t6 \t3 \t3 \t34\n", "edurank_f \t21 \t4 \t5 \t4 \t34\n", "hincrank_f \t16 \t14 \t3 \t1 \t34\n", "rdtot_f \t13 \t7 \t7 \t7 \t34\n", "nwsptot_f \t12 \t5 \t13 \t4 \t34\n", "inwyr07_f \t4 \t10 \t12 \t8 \t34\n" ] } ], "source": [ "ts = ess.make_table(country_map, varnames, ess.extract_ranges2)\n", "ess.print_table(ts)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" } }, "nbformat": 4, "nbformat_minor": 0 }