{"id":1465,"date":"2024-12-20T18:33:33","date_gmt":"2024-12-20T18:33:33","guid":{"rendered":"https:\/\/www.allendowney.com\/blog\/?p=1465"},"modified":"2024-12-23T16:13:43","modified_gmt":"2024-12-23T16:13:43","slug":"political-alignment-and-outlook","status":"publish","type":"post","link":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/","title":{"rendered":"Political Alignment and Outlook"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>This is the fourth in a series of excerpts from <em>Elements of Data Science<\/em>, now <a href=\"https:\/\/www.lulu.com\/shop\/allen-downey\/elements-of-data-science\/paperback\/product-9dyrwn.html\">available from Lulu.com<\/a> and online booksellers. It&#8217;s from Chapter 15, which is part of the political alignment case study. You can read the complete chapter <a href=\"https:\/\/allendowney.github.io\/PoliticalAlignmentCaseStudy\/03_outlook.html\">here<\/a>, or run the Jupyter notebook on <a href=\"https:\/\/colab.research.google.com\/github\/AllenDowney\/PoliticalAlignmentCaseStudy\/blob\/v1\/03_outlook.ipynb\">Colab<\/a>.<\/p>\n<\/blockquote>\n\n\n\n<p>In the <a href=\"https:\/\/allendowney.github.io\/PoliticalAlignmentCaseStudy\/02_polviews_soln.html\">previous chapter<\/a>, we used data from the General Social Survey (GSS) to plot changes in political alignment over time. In this notebook, we\u2019ll explore the relationship between political alignment and respondents\u2019 beliefs about themselves and other people.<\/p>\n\n\n\n<p>First we\u2019ll use <code>groupby<\/code> to compare the average response between groups and plot the average as a function of time. Then we\u2019ll use the Pandas function <code>pivot table<\/code> to compute the average response within each group as a function of time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Are People Fair?<\/h2>\n\n\n\n<p>In the GSS data, the variable <code>fair<\/code> contains responses to this question:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Do you think most people would try to take advantage of you if they got a chance, or would they try to be fair?<\/p>\n<\/blockquote>\n\n\n\n<p>The possible responses are:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Code<\/th><th>Response<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Take advantage<\/td><\/tr><tr><td>2<\/td><td>Fair<\/td><\/tr><tr><td>3<\/td><td>Depends<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>As always, we start by looking at the distribution of responses, that is, how many people give each response:<\/p>\n\n\n\n<pre id=\"codecell5\" class=\"wp-block-preformatted\">values(gss[\"fair\"])\n<\/pre>\n\n\n\n<pre id=\"codecell6\" class=\"wp-block-preformatted\">1.0    16089\n2.0    23417\n3.0     2897\nName: fair, dtype: int64\n<\/pre>\n\n\n\n<p>The plurality think people try to be fair (2), but a substantial minority think people would take advantage (1). There are also a number of NaNs, mostly respondents who were not asked this question.<\/p>\n\n\n\n<pre id=\"codecell7\" class=\"wp-block-preformatted\">gss[\"fair\"].isna().sum()\n<\/pre>\n\n\n\n<pre id=\"codecell8\" class=\"wp-block-preformatted\">29987\n<\/pre>\n\n\n\n<p>To count the number of people who chose option <code>2<\/code>, \u201cpeople try to be fair\u201d, we\u2019ll use a dictionary to recode option <code>2<\/code> as <code>1<\/code> and the other options as <code>0<\/code>.<\/p>\n\n\n\n<pre id=\"codecell9\" class=\"wp-block-preformatted\">recode_fair = {1: 0, 2: 1, 3: 0}\n<\/pre>\n\n\n\n<p>As an alternative, we could include option <code>3<\/code>, \u201cdepends\u201d, by replacing it with <code>1<\/code>, or give it less weight by replacing it with an intermediate value like <code>0.5<\/code>. We can use <code>replace<\/code> to recode the values and store the result as a new column in the <code>DataFrame<\/code>.<\/p>\n\n\n\n<pre id=\"codecell10\" class=\"wp-block-preformatted\">gss[\"fair2\"] = gss[\"fair\"].replace(recode_fair)\n<\/pre>\n\n\n\n<p>And we\u2019ll use <code>values<\/code> to make sure it worked.<\/p>\n\n\n\n<pre id=\"codecell11\" class=\"wp-block-preformatted\">values(gss[\"fair2\"])\n<\/pre>\n\n\n\n<pre id=\"codecell12\" class=\"wp-block-preformatted\">0.0    18986\n1.0    23417\nName: fair2, dtype: int64\n<\/pre>\n\n\n\n<p>Now let\u2019s see how the responses have changed over time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fairness Over Time<\/h2>\n\n\n\n<p>As we saw in the previous chapter, we can use <code>groupby<\/code> to group responses by year.<\/p>\n\n\n\n<pre id=\"codecell13\" class=\"wp-block-preformatted\">gss_by_year = gss.groupby(\"year\")\n<\/pre>\n\n\n\n<p>From the result we can select <code>fair2<\/code> and compute the mean.<\/p>\n\n\n\n<pre id=\"codecell14\" class=\"wp-block-preformatted\">fair_by_year = gss_by_year[\"fair2\"].mean()\n<\/pre>\n\n\n\n<p>Here\u2019s the result, which shows the fraction of people who say people try to be fair, plotted over time. As in the previous chapter, we plot the data points themselves with circles and a local regression model as a line.<\/p>\n\n\n\n<pre id=\"codecell15\" class=\"wp-block-preformatted\">plot_series_lowess(fair_by_year, \"C1\")\n\ndecorate(\n    xlabel=\"Year\",\n    ylabel=\"Fraction saying yes\",\n    title=\"Would most people try to be fair?\",\n)\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"255\" src=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\" alt=\"_images\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\" class=\"wp-image-1468\" srcset=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png 442w, https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851-300x173.png 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/figure>\n\n\n\n<p>Sadly, it looks like faith in humanity has declined, at least by this measure. Let\u2019s see what this trend looks like if we group the respondents by political alignment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Political Views on a 3-point Scale<\/h2>\n\n\n\n<p>In the previous notebook, we looked at responses to <code>polviews<\/code>, which asks about political alignment. The valid responses are:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Code<\/th><th>Response<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Extremely liberal<\/td><\/tr><tr><td>2<\/td><td>Liberal<\/td><\/tr><tr><td>3<\/td><td>Slightly liberal<\/td><\/tr><tr><td>4<\/td><td>Moderate<\/td><\/tr><tr><td>5<\/td><td>Slightly conservative<\/td><\/tr><tr><td>6<\/td><td>Conservative<\/td><\/tr><tr><td>7<\/td><td>Extremely conservative<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>To make it easier to visualize groups, we\u2019ll lump the 7-point scale into a 3-point scale.<\/p>\n\n\n\n<pre id=\"codecell16\" class=\"wp-block-preformatted\">recode_polviews = {\n    1: \"Liberal\",\n    2: \"Liberal\",\n    3: \"Liberal\",\n    4: \"Moderate\",\n    5: \"Conservative\",\n    6: \"Conservative\",\n    7: \"Conservative\",\n}\n<\/pre>\n\n\n\n<p>We\u2019ll use <code>replace<\/code> again, and store the result as a new column in the <code>DataFrame<\/code>.<\/p>\n\n\n\n<pre id=\"codecell17\" class=\"wp-block-preformatted\">gss[\"polviews3\"] = gss[\"polviews\"].replace(recode_polviews)\n<\/pre>\n\n\n\n<p>With this scale, there are roughly the same number of people in each group.<\/p>\n\n\n\n<pre id=\"codecell18\" class=\"wp-block-preformatted\">values(gss[\"polviews3\"])\n<\/pre>\n\n\n\n<pre id=\"codecell19\" class=\"wp-block-preformatted\">Conservative    21573\nLiberal         17203\nModerate        24157\nName: polviews3, dtype: int64\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fairness by Group<\/h2>\n\n\n\n<p>Now let\u2019s see who thinks people are more fair, conservatives or liberals. We\u2019ll group the respondents by <code>polviews3<\/code>.<\/p>\n\n\n\n<pre id=\"codecell20\" class=\"wp-block-preformatted\">by_polviews = gss.groupby(\"polviews3\")\n<\/pre>\n\n\n\n<p>And compute the mean of <code>fair2<\/code> in each group.<\/p>\n\n\n\n<pre id=\"codecell21\" class=\"wp-block-preformatted\">by_polviews[\"fair2\"].mean()\n<\/pre>\n\n\n\n<pre id=\"codecell22\" class=\"wp-block-preformatted\">polviews3\nConservative    0.577879\nLiberal         0.550849\nModerate        0.537621\nName: fair2, dtype: float64\n<\/pre>\n\n\n\n<p>It looks like conservatives are a little more optimistic, in this sense, than liberals and moderates. But this result is averaged over the last 50 years. Let\u2019s see how things have changed over time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fairness over Time by Group<\/h2>\n\n\n\n<p>So far, we have grouped by <code>polviews3<\/code> and computed the mean of <code>fair2<\/code> in each group. Then we grouped by <code>year<\/code> and computed the mean of <code>fair2<\/code> for each year. Now we\u2019ll group by <code>polviews3<\/code> and <code>year<\/code>, and compute the mean of <code>fair2<\/code> in each group over time.<\/p>\n\n\n\n<p>We could do that computation \u201cby hand\u201d using the tools we already have, but it is so common and useful that it has a name. It is called a <strong>pivot table<\/strong>, and Pandas provides a function called <code>pivot_table<\/code> that computes it. It takes the following arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>values<\/code>, which is the name of the variable we want to summarize: <code>fair2<\/code> in this example.<\/li>\n\n\n\n<li><code>index<\/code>, which is the name of the variable that will provide the row labels: <code>year<\/code> in this example.<\/li>\n\n\n\n<li><code>columns<\/code>, which is the name of the variable that will provide the column labels: <code>polview3<\/code> in this example.<\/li>\n\n\n\n<li><code>aggfunc<\/code>, which is the function used to \u201caggregate\u201d, or summarize, the values: <code>mean<\/code> in this example.<\/li>\n<\/ul>\n\n\n\n<p>Here\u2019s how we run it.<\/p>\n\n\n\n<pre id=\"codecell23\" class=\"wp-block-preformatted\">table = gss.pivot_table(\n    values=\"fair2\", index=\"year\", columns=\"polviews3\", aggfunc=\"mean\"\n)\n<\/pre>\n\n\n\n<p>The result is a <code>DataFrame<\/code> that has years running down the rows and political alignment running across the columns. Each entry in the table is the mean of <code>fair2<\/code> for a given group in a given year.<\/p>\n\n\n\n<pre id=\"codecell24\" class=\"wp-block-preformatted\">table.head()\n<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>polviews3<\/th><th>Conservative<\/th><th>Liberal<\/th><th>Moderate<\/th><\/tr><tr><th>year<\/th><th><\/th><th><\/th><th><\/th><\/tr><\/thead><tbody><tr><th>1975<\/th><td>0.625616<\/td><td>0.617117<\/td><td>0.647280<\/td><\/tr><tr><th>1976<\/th><td>0.631696<\/td><td>0.571782<\/td><td>0.612100<\/td><\/tr><tr><th>1978<\/th><td>0.694915<\/td><td>0.659420<\/td><td>0.665455<\/td><\/tr><tr><th>1980<\/th><td>0.600000<\/td><td>0.554945<\/td><td>0.640264<\/td><\/tr><tr><th>1983<\/th><td>0.572438<\/td><td>0.585366<\/td><td>0.463492<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Reading across the first row, we can see that in 1975, moderates were slightly more optimistic than the other groups. Reading down the first column, we can see that the estimated mean of <code>fair2<\/code> among conservatives varies from year to year. It is hard to tell looking at these numbers whether it is trending up or down \u2013 we can get a better view by plotting the results.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Plotting the Results<\/h2>\n\n\n\n<p>Before we plot the results, I\u2019ll make a dictionary that maps from each group to a color. Seaborn provide a palette called <code>muted<\/code> that contains the colors we\u2019ll use.<\/p>\n\n\n\n<pre id=\"codecell25\" class=\"wp-block-preformatted\">muted = sns.color_palette(\"muted\", 5)\nsns.palplot(muted)\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"305\" height=\"76\" src=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/b9bf5d3cbb6f6a04d01b52567e56405de67e9bf8bcb03a1e273d04a32110617d.png\" alt=\"_images\/b9bf5d3cbb6f6a04d01b52567e56405de67e9bf8bcb03a1e273d04a32110617d.png\" class=\"wp-image-1467\" srcset=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/b9bf5d3cbb6f6a04d01b52567e56405de67e9bf8bcb03a1e273d04a32110617d.png 305w, https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/b9bf5d3cbb6f6a04d01b52567e56405de67e9bf8bcb03a1e273d04a32110617d-300x75.png 300w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/figure>\n\n\n\n<p>And here\u2019s the dictionary.<\/p>\n\n\n\n<pre id=\"codecell26\" class=\"wp-block-preformatted\">color_map = {\"Conservative\": muted[3], \"Moderate\": muted[4], \"Liberal\": muted[0]}\n<\/pre>\n\n\n\n<p>Now we can plot the results.<\/p>\n\n\n\n<pre id=\"codecell27\" class=\"wp-block-preformatted\">groups = [\"Conservative\", \"Liberal\", \"Moderate\"]\nfor group in groups:\n    series = table[group]\n    plot_series_lowess(series, color_map[group])\n\ndecorate(\n    xlabel=\"Year\",\n    ylabel=\"Fraction saying yes\",\n    title=\"Would most people try to be fair?\",\n)\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"255\" src=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/d2722be4b358d5c87b76d18010edb6d4725fe64d9bbb4ec4c55b2fde9d3cf5df.png\" alt=\"_images\/d2722be4b358d5c87b76d18010edb6d4725fe64d9bbb4ec4c55b2fde9d3cf5df.png\" class=\"wp-image-1469\" srcset=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/d2722be4b358d5c87b76d18010edb6d4725fe64d9bbb4ec4c55b2fde9d3cf5df.png 442w, https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/d2722be4b358d5c87b76d18010edb6d4725fe64d9bbb4ec4c55b2fde9d3cf5df-300x173.png 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/figure>\n\n\n\n<p>The fraction of respondents who think people try to be fair has dropped in all three groups, although liberals and moderates might have leveled off. In 1975, liberals were the least optimistic group. In 2022, they might be the most optimistic. But the responses are quite noisy, so we should not be too confident about these conclusions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Discussion<\/h2>\n\n\n\n<p>I heard from a reader that they appreciated this explanation of pivot tables because it provides a concrete example of something that can be pretty abstract. I occurred to me that it is hard to define what a pivot table it because the table itself can be almost anything. What the term really refers to is the computation pattern rather than the result. One way to express the computational pattern is &#8220;Group by this on one axis, group by that on the other axis, select a variable, and summarize&#8221;.<\/p>\n\n\n\n<p>In Pandas, another way to compute a pivot table is like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">table = gss.groupby(['year', 'polviews3'])['fair2'].mean().unstack()<\/pre>\n\n\n\n<p>This way of writing it makes the grouping part of the computation more explicit. And the <code>groupby<\/code> function is more versatile, so if you only want to learn one thing, you might prefer this version. The <code>unstack<\/code> at the end is only needed if you want a wide table (with time down the rows and alignment across the columns) &#8212; without it, you get the long table (with one row for each pair of time and alignment, and only one column).<\/p>\n\n\n\n<p>So, should we forget about <code>pivot_table<\/code> (and <code>crosstab<\/code> while we&#8217;re at it) and use <code>groupby<\/code> for everything? I&#8217;m not sure. For people who are already know the terms, it can be helpful to use functions with familiar names. But if you understand the group-by computational pattern, it might not be useful to use different functions for particular instances of the pattern.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the fourth in a series of excerpts from Elements of Data Science, now available from Lulu.com and online booksellers. It&#8217;s from Chapter 15, which is part of the political alignment case study. You can read the complete chapter here, or run the Jupyter notebook on Colab. In the previous chapter, we used data from the General Social Survey (GSS) to plot changes in political alignment over time. In this notebook, we\u2019ll explore the relationship between political alignment and&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-1465","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Political Alignment and Outlook - Probably Overthinking It<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Political Alignment and Outlook - Probably Overthinking It\" \/>\n<meta property=\"og:description\" content=\"This is the fourth in a series of excerpts from Elements of Data Science, now available from Lulu.com and online booksellers. It&#8217;s from Chapter 15, which is part of the political alignment case study. You can read the complete chapter here, or run the Jupyter notebook on Colab. In the previous chapter, we used data from the General Social Survey (GSS) to plot changes in political alignment over time. In this notebook, we\u2019ll explore the relationship between political alignment and... Read More Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\" \/>\n<meta property=\"og:site_name\" content=\"Probably Overthinking It\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-20T18:33:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-23T16:13:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\" \/>\n<meta name=\"author\" content=\"AllenDowney\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@AllenDowney\" \/>\n<meta name=\"twitter:site\" content=\"@AllenDowney\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"AllenDowney\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\"},\"author\":{\"name\":\"AllenDowney\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/#\/schema\/person\/4e5bfb2e9af6c3446cb0031a7bf83207\"},\"headline\":\"Political Alignment and Outlook\",\"datePublished\":\"2024-12-20T18:33:33+00:00\",\"dateModified\":\"2024-12-23T16:13:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\"},\"wordCount\":1170,\"publisher\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\",\"url\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\",\"name\":\"Political Alignment and Outlook - Probably Overthinking It\",\"isPartOf\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\",\"datePublished\":\"2024-12-20T18:33:33+00:00\",\"dateModified\":\"2024-12-23T16:13:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage\",\"url\":\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\",\"contentUrl\":\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png\",\"width\":442,\"height\":255},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.allendowney.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Political Alignment and Outlook\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/#website\",\"url\":\"https:\/\/www.allendowney.com\/blog\/\",\"name\":\"Probably Overthinking It\",\"description\":\"Data science, Bayesian Statistics, and other ideas\",\"publisher\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.allendowney.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/#organization\",\"name\":\"Probably Overthinking It\",\"url\":\"https:\/\/www.allendowney.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2025\/03\/probably_logo.png\",\"contentUrl\":\"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2025\/03\/probably_logo.png\",\"width\":714,\"height\":784,\"caption\":\"Probably Overthinking It\"},\"image\":{\"@id\":\"https:\/\/www.allendowney.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/AllenDowney\",\"https:\/\/www.linkedin.com\/in\/allendowney\/\",\"https:\/\/bsky.app\/profile\/allendowney.bsky.social\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/#\/schema\/person\/4e5bfb2e9af6c3446cb0031a7bf83207\",\"name\":\"AllenDowney\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.allendowney.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fb01b3a7f7190bea1bbf7f0852e686c2f8c03b099222df2ce4bc7926f15bcb43?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fb01b3a7f7190bea1bbf7f0852e686c2f8c03b099222df2ce4bc7926f15bcb43?s=96&d=mm&r=g\",\"caption\":\"AllenDowney\"},\"url\":\"https:\/\/www.allendowney.com\/blog\/author\/allendowney_6dbrc4\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Political Alignment and Outlook - Probably Overthinking It","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/","og_locale":"en_US","og_type":"article","og_title":"Political Alignment and Outlook - Probably Overthinking It","og_description":"This is the fourth in a series of excerpts from Elements of Data Science, now available from Lulu.com and online booksellers. It&#8217;s from Chapter 15, which is part of the political alignment case study. You can read the complete chapter here, or run the Jupyter notebook on Colab. In the previous chapter, we used data from the General Social Survey (GSS) to plot changes in political alignment over time. In this notebook, we\u2019ll explore the relationship between political alignment and... Read More Read More","og_url":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/","og_site_name":"Probably Overthinking It","article_published_time":"2024-12-20T18:33:33+00:00","article_modified_time":"2024-12-23T16:13:43+00:00","og_image":[{"url":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png","type":"","width":"","height":""}],"author":"AllenDowney","twitter_card":"summary_large_image","twitter_creator":"@AllenDowney","twitter_site":"@AllenDowney","twitter_misc":{"Written by":"AllenDowney","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#article","isPartOf":{"@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/"},"author":{"name":"AllenDowney","@id":"https:\/\/www.allendowney.com\/blog\/#\/schema\/person\/4e5bfb2e9af6c3446cb0031a7bf83207"},"headline":"Political Alignment and Outlook","datePublished":"2024-12-20T18:33:33+00:00","dateModified":"2024-12-23T16:13:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/"},"wordCount":1170,"publisher":{"@id":"https:\/\/www.allendowney.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage"},"thumbnailUrl":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/","url":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/","name":"Political Alignment and Outlook - Probably Overthinking It","isPartOf":{"@id":"https:\/\/www.allendowney.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage"},"image":{"@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage"},"thumbnailUrl":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png","datePublished":"2024-12-20T18:33:33+00:00","dateModified":"2024-12-23T16:13:43+00:00","breadcrumb":{"@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#primaryimage","url":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png","contentUrl":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/12\/c66dd4e209513c6b52923f0279d558dc7cf98d7002a9608170da7c0372146851.png","width":442,"height":255},{"@type":"BreadcrumbList","@id":"https:\/\/www.allendowney.com\/blog\/2024\/12\/20\/political-alignment-and-outlook\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.allendowney.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Political Alignment and Outlook"}]},{"@type":"WebSite","@id":"https:\/\/www.allendowney.com\/blog\/#website","url":"https:\/\/www.allendowney.com\/blog\/","name":"Probably Overthinking It","description":"Data science, Bayesian Statistics, and other ideas","publisher":{"@id":"https:\/\/www.allendowney.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.allendowney.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.allendowney.com\/blog\/#organization","name":"Probably Overthinking It","url":"https:\/\/www.allendowney.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.allendowney.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2025\/03\/probably_logo.png","contentUrl":"https:\/\/www.allendowney.com\/blog\/wp-content\/uploads\/2025\/03\/probably_logo.png","width":714,"height":784,"caption":"Probably Overthinking It"},"image":{"@id":"https:\/\/www.allendowney.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/AllenDowney","https:\/\/www.linkedin.com\/in\/allendowney\/","https:\/\/bsky.app\/profile\/allendowney.bsky.social"]},{"@type":"Person","@id":"https:\/\/www.allendowney.com\/blog\/#\/schema\/person\/4e5bfb2e9af6c3446cb0031a7bf83207","name":"AllenDowney","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.allendowney.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fb01b3a7f7190bea1bbf7f0852e686c2f8c03b099222df2ce4bc7926f15bcb43?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fb01b3a7f7190bea1bbf7f0852e686c2f8c03b099222df2ce4bc7926f15bcb43?s=96&d=mm&r=g","caption":"AllenDowney"},"url":"https:\/\/www.allendowney.com\/blog\/author\/allendowney_6dbrc4\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1213,"url":"https:\/\/www.allendowney.com\/blog\/2024\/02\/04\/political-alignment-affiliation-and-attitudes\/","url_meta":{"origin":1465,"position":0},"title":"Political Alignment, Affiliation, and Attitudes","author":"AllenDowney","date":"February 4, 2024","format":false,"excerpt":"Is there a growing gender gap in the U.S? Alignment A recent article in the Financial Times suggests that among young people there is a growing gender gap in political alignment on a spectrum from liberal to conservative. In last week's post, I tried to replicate this result using data\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ideology_gap5.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ideology_gap5.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ideology_gap5.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ideology_gap5.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ideology_gap5.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ideology_gap5.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":344,"url":"https:\/\/www.allendowney.com\/blog\/2019\/12\/03\/political-alignment-and-beliefs-about-homosexuality\/","url_meta":{"origin":1465,"position":1},"title":"Political alignment and beliefs about homosexuality","author":"AllenDowney","date":"December 3, 2019","format":false,"excerpt":"In the United States, beliefs and attitudes about homosexuality have changed drastically over the last 50 years. In 1972, 74% of U.S. residents thought sexual relations between two adults of the same sex were \"always wrong\", according to results from the General Social Survey (GSS). In 2018, that fraction was\u2026","rel":"","context":"In \"general social survey\"","block_context":{"text":"general social survey","link":"https:\/\/www.allendowney.com\/blog\/tag\/general-social-survey\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2019\/12\/image-3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2019\/12\/image-3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2019\/12\/image-3.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1477,"url":"https:\/\/www.allendowney.com\/blog\/2025\/01\/04\/confidence-in-the-press\/","url_meta":{"origin":1465,"position":2},"title":"Confidence In the Press","author":"AllenDowney","date":"January 4, 2025","format":false,"excerpt":"This is the fifth in a series of excerpts from Elements of Data Science, now available from Lulu.com and online booksellers. It\u2019s based on Chapter 16, which is part of the political alignment case study. You can read the complete example here, or run the Jupyter notebook on Colab. Because\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2025\/01\/f652e115b3186a827e67d0882df2218fecf3f5466985f3da007a09e983e93aa6.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":243,"url":"https:\/\/www.allendowney.com\/blog\/2019\/07\/26\/right-left-apart-together\/","url_meta":{"origin":1465,"position":3},"title":"Right, left, apart, together?","author":"AllenDowney","date":"July 26, 2019","format":false,"excerpt":"Is the United States getting more conservative? With the rise of the alt-right, Republican control of Congress, and the election of Donald Trump, it might seem so. Or is the country getting more liberal? With the 2015 Supreme Court decision supporting same-sex marriage, the incremental legalization of marijuana, and recent\u2026","rel":"","context":"In \"general social survey\"","block_context":{"text":"general social survey","link":"https:\/\/www.allendowney.com\/blog\/tag\/general-social-survey\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2019\/07\/image-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1221,"url":"https:\/\/www.allendowney.com\/blog\/2024\/02\/11\/the-political-gender-gap-is-not-growing\/","url_meta":{"origin":1465,"position":4},"title":"The Political Gender Gap is Not Growing","author":"AllenDowney","date":"February 11, 2024","format":false,"excerpt":"In a previous article, I used data from the General Social Survey (GSS) to see if there is a growing gender gap among young people in political alignment, party affiliation, or political attitudes. So far, the answer is no. Young women are more likely than men to say they are\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/ft_ideology_gap_us.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1233,"url":"https:\/\/www.allendowney.com\/blog\/2024\/02\/18\/the-gender-gap-in-political-beliefs-is-small\/","url_meta":{"origin":1465,"position":5},"title":"The Gender Gap in Political Beliefs Is Small","author":"AllenDowney","date":"February 18, 2024","format":false,"excerpt":"In previous articles (here, here, and here) I've looked at evidence of a gender gap in political alignment (liberal or conservative), party affiliation (Democrat or Republican), and policy preferences. Using data from the GSS, I found that women are more likely to say they are liberal, and more likely to\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/belief_gap3-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/belief_gap3-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/belief_gap3-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/belief_gap3-1.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/belief_gap3-1.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.allendowney.com\/blog\/wp-content\/uploads\/2024\/02\/belief_gap3-1.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/posts\/1465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/comments?post=1465"}],"version-history":[{"count":3,"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/posts\/1465\/revisions"}],"predecessor-version":[{"id":1472,"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/posts\/1465\/revisions\/1472"}],"wp:attachment":[{"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/media?parent=1465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/categories?post=1465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.allendowney.com\/blog\/wp-json\/wp\/v2\/tags?post=1465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}