<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Aaron Gullickson</title>
<link>https://aarongullickson.github.io/posts.html</link>
<atom:link href="https://aarongullickson.github.io/posts.xml" rel="self" type="application/rss+xml"/>
<description>Aaron Gullickson&#39;s Website</description>
<generator>quarto-1.10.18</generator>
<lastBuildDate>Mon, 09 Aug 2021 00:00:00 GMT</lastBuildDate>
<item>
  <title>Making Your First GitHub R Project</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/first_github_repo/</link>
  <description><![CDATA[ 






<p>Increasingly, academic scholars, data scientists, and quantitative researcher are turning to <a href="https://github.com/">GitHub</a> for collaboration and to share data, code, and results. GitHub allows people to host public and private “repositories” that allow for the easy communication of research procedures and results. Underlying the GitHub architecture is the version control system, <a href="https://git-scm.com/">git</a>, which provides further benefits to researchers.</p>
<section id="why-should-you-use-gitgithub" class="level2">
<h2 class="anchored" data-anchor-id="why-should-you-use-gitgithub">Why should you use git/GitHub?</h2>
<p><a href="https://www.atlassian.com/git/tutorials/what-is-version-control">Version control systems</a> like git have long been used by programmers to sanely collaborate and organize software projects and they can serve the same purpose for quantitative researchers who spend much of their time coding. If you have never used version control systems, then the process can seem arcane and the benefits unclear. Once you start using a version control system, however, it becomes difficult to see how you ever got by before. What are some of the benefits of this approach?</p>
<p>First and probably foremost, git will allow you to <strong>collaborate sanely</strong>. Users make changes to code (“commits”) and then “push” them to a centrally shared repository (located at GitHub, for example). Other users can clone this repository and then easily “push their own changes as well as”pull” in other changes, allowing everyone to easily stay in-sync. Complex coding projects can also be “branched” and then later merged back into the main code base to avoid conflicts between users.</p>
<p>Second, by using version control systems, you effortlessly create your own <strong>research log</strong>. All changes to your code base are committed to the repository with a brief description of your changes. Collectively these commits serve as a research log of your work. You no longer have to remember when exactly you added that one variable to the model. The changes are right there in your history log.</p>
<p>Third, you can <strong>stop fearing change</strong>. Have you been in the situation where you know your code kind of works, but maybe its not the best? People often do one of two things in this situation. You might just leave it alone, because why mess with a piece of code that seems to work? Are you trying to anger the coding gods? Alternatively, you might decide to fix it, but fearful that you might make it worse, you duplicate the file (with a name like “analysis_just_trying_a_thing_v2.R”). Neither of these approaches is great. If you use version control, you can make radical changes to your code without fear. Did you mess it up? No worries, just revert back to the last “commit” and try again. To draw out an <a href="https://r-pkgs.org/git.html#git-commit">analogy from Hadley Wickham</a>, the “free-climbing” approach to coding is dangerous and scary. Git is there to catch you when you fall.</p>
<p>Fourth, you can finally <strong>keep your project tidy.</strong> The tendency I note above to simply duplicate files with slightly different names (“paper-v2.1_06272017_FINAL_REALLY_THIS_TIME.docx”) is its own form of very inefficient version control. Over time, the directory containing your project becomes littered with files, and the ability to understand this chaos is locked deep somewhere in your own brain alone. If you practice this form of <em>horizontal</em> versioning, then help is on the way! Proper version control systems, like git, use “vertical” versioning. Because all of your changes are tracked on any given file, there is no need to duplicate a bewildering array of slightly different versions of the same file. Because you no longer need to fear change, you can keep your project tidy and compact. You only need one script to organize and clean your data. You only need one file to write the paper. Your project will suddenly become easier to navigate for yourself and everyone else.</p>
</section>
<section id="your-first-github-repository" class="level2">
<h2 class="anchored" data-anchor-id="your-first-github-repository">Your First GitHub Repository</h2>
<p>Have I piqued your interest? Lets talk about how to set up a git repository using RStudio and link it to an online repository on GitHub. The instructions here assume that you have some directory with R code in it that you want to turn into a repository on GitHub. You will also need to create an account on GitHub. I also will assume you are using RStudio to run R which provides a nice user interface for working with git.</p>
<p>Git itself is a command line interface. You can work with it from inside RStudio using a GUI interface but to get it set up properly, you will need to be able to work on the command line in the working directory of your project. The easiest way to use the command line in RStudio is to use the “Terminal” tab right next to the console tab in the lower left panel. You should see something like:</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/command_line.png" class="img-fluid"></p>
<p>If you are on a Windows system, you will want a UNIX style command line. When you install git (as described below), you will gain access to a UNIX style terminal with an application called <a href="https://www.atlassian.com/git/tutorials/git-bash">Git Bash</a>. You can set git bash to be your default terminal in the RStudio preferences.</p>
<p>One thing to keep in mind is that GitHub has a single file size limit of 100 mb. If you have a single file in your directory that is larger than 100 mb, then GitHub will not allow you to push that file up to your GitHub repository. This issue most frequently arises with large datasets. Sometimes this can be fixed by compressing the file, since R can read directly from compressed files. Another solution is to host the large file somewhere else (e.g.&nbsp;DropBox).</p>
<section id="step-zero-install-and-configure-git" class="level3">
<h3 class="anchored" data-anchor-id="step-zero-install-and-configure-git">Step Zero: Install and configure git</h3>
<p>To get started you will need to install git on your local system. Git is extremely lightweight and easy to install and is available on all major operating systems. You can download and install the version for your operating system <a href="https://git-scm.com/downloads">here</a>.</p>
<p>Once you install git, you will want to set up a couple of initial parameters before you get started. The easiest way to set up git is the <a href="https://usethis.r-lib.org/"><code>usethis</code></a> R package, which includes several functions for working with git. Most importantly, you need to set up a user name and email that will be shown for all commits. You can do this with the following code:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(usethis)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">use_git_config</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">user.name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Jane Doe"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">user.email =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"jane@example.com"</span>)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git_vaccinate</span>()</span></code></pre></div></div>
<p>When you perform git operations on your GitHub repository, you will need to authenticate with GitHub. As I write this, you can do this by entering your GitHub user name and password. However, this functionality <a href="https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/">will soon be going away</a> and you will be required to have a personal access token (PAT) to authenticate with GitHub. Luckily, <a href="https://usethis.r-lib.org/articles/articles/git-credentials.html">you can easily set up a PAT</a> through the <code>usethis</code> package as well. First, you can use the <code>create_github_token()</code> command in R which will direct you to a GitHub page that will generate a PAT for your use:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_github_token</span>()</span></code></pre></div></div>
<p>You can also go to <a href="https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token">this page</a> for instructions on generating a PAT.</p>
<p>Once you have a PAT, copy it and enter the following into R:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">gitcreds<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gitcreds_set</span>()</span></code></pre></div></div>
<p>This will then guide you through the process of setting your PAT. Once this PAT is set up, pushing and pulling to GitHub should work seamlessly.</p>
<p>To check that everything seems to be working you can always use the <code>git_sitrep()</code> command in the <code>usethis</code> package.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">usethis<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git_sitrep</span>()</span></code></pre></div></div>
</section>
<section id="step-one-turn-your-code-into-an-r-project-and-git-repository" class="level3">
<h3 class="anchored" data-anchor-id="step-one-turn-your-code-into-an-r-project-and-git-repository">Step One: Turn your code into an R project and git repository</h3>
<p>Now that git is set up, you can turn that directory of code into a proper git repository. To accomplish this, you will first need to turn your directory into an R project.</p>
<p>As an example, I have set up a simple directory that I want to convert into a git repository, pictured below:</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/initial_directory.png" class="img-fluid"></p>
<p>This repository just has some data in CSV format, an R script with some code and an R Markdown file that I am using as a lab notebook.</p>
<p>Although this may be a “project” in my head, it is not yet an <em>R project</em>. If I turn this directory into an R project, RStudio will add an *.Rproj file with some additional information. R projects are useful in <a href="https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects">their own right</a>, but the real advantage here is that I can use the built-in git features of RStudio on an R project.</p>
<p>To turn this into an R project, you will go to File &gt; New Project which will bring up a dialog including several options for creating the project. In this case, you want to create the project from an existing directory.</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/existing_directory.png" class="img-fluid"></p>
<p>From the next dialog, you can browse to your directory and then just click the create button to turn it into an R project. RStudio will refresh and your working directory will shift to the chosen directory where you will see a new *.Rproj file.</p>
<p>Now that your directory is an R project, you want to turn this directory into a git repository. To do this, you will use the command line as described above. Once you have a command line interface in the correct working directory of your project, simply type:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> init</span></code></pre></div></div>
<p>This will create a git repository in your working directory. Because you are using the command line, RStudio will typically not immediately recognize the change, so you should close RStudio and re-open this project. To re-open the project, you can double-click the *.Rproj file or use the dropdown menu for managing projects in the upper-right corner of RStudio itself. Once the project is re-opened, you should see an additional “Git” tab located in the upper right panel that should look something like this:</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/git_tab.png" class="img-fluid"></p>
</section>
<section id="step-two-time-to-commit" class="level3">
<h3 class="anchored" data-anchor-id="step-two-time-to-commit">Step Two: Time to commit</h3>
<p>The git tab is the main way that you will interact with git now that we have it set up. The tab will show you new files that are not yet tracked by git as well as files that have been modified or removed since the last commit. The question mark icon for the status of each file is showing me that none of the files in my directory are currently being tracked (since I just created this repository).</p>
<p>What I need to do is <strong>commit</strong> these files. That will then tell git to track them allowing me to also commit future changes. To commit, just click the “Commit” button to bring up the commit dialog. From this dialog, you need to select all the files you want to commit and add a commit message as the picture below shows:</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/first_commit.png" class="img-fluid"></p>
<p>Once you click commit, all of these files will be committed and will disappear from the git tab. Congratulations, you have just made your first commitment to the world of git! For fun, you can view the history dialog from the git tab, to see the history of all your commits (not many yet).</p>
</section>
<section id="step-three-make-a-new-repository-on-github-and-push" class="level3">
<h3 class="anchored" data-anchor-id="step-three-make-a-new-repository-on-github-and-push">Step Three: Make a new repository on GitHub and push!</h3>
<p>Committing the files ensures that they are now tracked locally, but I still do not have a remote repository on GitHub. The final step is to set up that repository and <strong>push</strong> all of the local commits to it.</p>
<p>To set up a new repository on GitHub, you simply need to use the “+” dropdown menu in the upper right of your GitHub profile page and select the “New repository” option. The new repository dialog has several options, but for now all you need to do is enter a name for this repository. You can also decide whether you want the repository to be public or private.</p>
<p>Once you create the repository, you will see a screen that gives you several options for initializing the code in your repository. We want the second option of “…or push an existing repository from the command line” which will give you code that looks something like:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> remote add origin https://github.com/AaronGullickson/example_project.git</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> branch <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-M</span> main</span>
<span id="cb6-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> push <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-u</span> origin main</span></code></pre></div></div>
<p>The first line will look different because you are not me, so you should copy that code rather than what I have above. All you need to do is copy and paste that code to the command line interface in your project directory. This will setup GitHub as the remote “origin” repository and push all of your existing local commits to it. You can then refresh your GitHub repository page and see that all of your files and code are now showing.</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/github_code.png" class="img-fluid"></p>
<p>Because you used the command line to set up your remote repository, you should restart RStudio and re-open your project to refresh it. Once you do so, you should see that the big arrows saying “Pull” and “Push” are no longer greyed out. You now have the full capability to perform the basic git workflow of pull-commit-push using the RStudio git tab.</p>
</section>
</section>
<section id="the-basic-git-workflow" class="level2">
<h2 class="anchored" data-anchor-id="the-basic-git-workflow">The basic git workflow</h2>
<p>Now that you have your R project connected to GitHub, you can use the basic git workflow to keep your project synced between the two repositories. When you sit down to work on the project, you should do the following:</p>
<ol type="1">
<li><strong>Pull</strong> changes from the main repository on GitHub to the local repository. This will ensure that your local repository has all of the latest changes made to the central repository (for example by a co-author).</li>
<li>Make changes to the project as desired. When you are satisfied with those changes, <strong>commit</strong> them to your local repository with a helpful message like “imputed missing values” or “corrected my horrible grammar.”</li>
<li>Committing only adds the changes to your local repository. If you want to make sure everyone has access to those changes, you then <strong>push</strong> the changes to the central repository on GitHub.</li>
</ol>
<p>Lets go through a simple example of this workflow on my project. I want to change the default <code>ggplot</code> colors of the graph in my R Markdown document to something more … colorful. I am going to use the wonderful <a href="https://github.com/karthik/wesanderson">Wes Anderson R color palette</a> instead. To do that I need to add the appropriate library and the following line to my <code>ggplot</code> command:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wes_palette</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Darjeeling1"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"discrete"</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span></code></pre></div></div>
<p>Once I make these changes, the git tab will show that my R Markdown file has been modified:</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/git_tab2.png" class="img-fluid"></p>
<p>Hitting the commit button will bring up the commit dialog which will show me all of the pending changes. I can select any changes I want to commit and write a helpful commit message.</p>
<p><img src="https://aarongullickson.github.io/post/first_github_repo/git_commit2.png" class="img-fluid"></p>
<p>Once I commit these changes, I can then use the handy “Push” button to push these changes up to the GitHub repository. You can <a href="https://github.com/AaronGullickson/example_project/commits/main">see for yourself</a> how well this works by exploring this example GitHub repository.</p>
<p>In many cases you may repeat step (2) multiple times before pushing. When possible it makes sense to break up your commits into logical chunks in which you complete a certain task rather than “all the stuff I did today.” This will make it easier to understand your log history later. So you may actually do 3-4 smaller commits and then when you push, all of those commits will be pushed up to the GitHub repository at the same time.</p>
</section>
<section id="you-can-do-so-much-more" class="level2">
<h2 class="anchored" data-anchor-id="you-can-do-so-much-more">You can do so much more!</h2>
<p>This tutorial is intended to get you set up with the basic git workflow connecting a local R project to a GitHub repository. This provides powerful functionality but is really only the tip of the iceberg of what git can do for you. Git offers the ability to work in multiple branches and to revert changes. GitHub offers additional features for collaboration, most notably the wonderful <a href="https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests">pull request</a> feature. But even the basic git workflow can help change the way that your organize your work and allows you to code with the confidence that you are no longer “free-climbing” your research. Happy gitting!</p>


</section>

 ]]></description>
  <category>R</category>
  <category>git</category>
  <category>GitHub</category>
  <category>open science</category>
  <guid>https://aarongullickson.github.io/post/first_github_repo/</guid>
  <pubDate>Mon, 09 Aug 2021 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Better Contrasts for Ordinal Variables in R</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/better-contrasts-for-ordinal-variables-in-r/</link>
  <description><![CDATA[ 






<p>Social scientists routinely use categorical variables in linear models. In order to do so, we must code these categorical variables into numeric quantities in some fashion. By far the most common method is the dummy/indicator variable approach. In this approach, we create 0/1 variables for each category where 1 indicates membership in the category. We leave out this coding for one category which becomes the reference category. The estimate for each parameter then gives the mean difference between the indicated category and the reference category, all else being equal. This approach is so ubiquitous that many researchers are probably unaware of the many alternatives that exist for how to code categorical variables. Here I want to highlight an alternative method in R for the case of ordinal variables that can be used to produce much more intuitive results.</p>
<p>To illustrate, I will use <a href="https://github.com/AaronGullickson/combined_stats/tree/master/example_datasets/earnings">data on hourly wages from the Current Population Survey in 2018</a> that I use for my classes. Here is an excerpt of that data.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">load</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">url</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://github.com/AaronGullickson/combined_stats/blob/master/example_datasets/earnings/earnings.RData?raw=true"</span>))</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(earnings[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>])</span></code></pre></div></div>
<pre><code>##   wages age gender  race            marstat        education
## 1 20.84  52 Female Black Divorced/Separated       HS Diploma
## 2 10.00  19 Female Black      Never Married       HS Diploma
## 3 25.00  56 Female Black Divorced/Separated Bachelors Degree
## 4  9.50  22 Female Black      Never Married       HS Diploma
## 5 17.00  48   Male White      Never Married       HS Diploma
## 6 20.00  59   Male Black      Never Married       HS Diploma</code></pre>
<p>Lets say I want to examine the relationship between hourly wages and education. I could do this by just looking at the mean wages for each educational group. I like to use <code>tapply</code> for these sorts of operations.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">wage_means <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>wages, earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>education, mean)</span>
<span id="cb3-2">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(wage_means, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean wages"</span>)</span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">mean wages</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">No HS Diploma</td>
<td style="text-align: right;">14.26</td>
</tr>
<tr class="even">
<td style="text-align: left;">HS Diploma</td>
<td style="text-align: right;">18.67</td>
</tr>
<tr class="odd">
<td style="text-align: left;">AA Degree</td>
<td style="text-align: right;">21.91</td>
</tr>
<tr class="even">
<td style="text-align: left;">Bachelors Degree</td>
<td style="text-align: right;">30.76</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Graduate Degree</td>
<td style="text-align: right;">38.17</td>
</tr>
</tbody>
</table>
<p>Alternatively, I could use a linear model structure to get the same information.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">model_dummy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(wages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>earnings)</span>
<span id="cb4-2">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model_dummy), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>)</span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">coefficients</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">14.26</td>
</tr>
<tr class="even">
<td style="text-align: left;">educationHS Diploma</td>
<td style="text-align: right;">4.41</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educationAA Degree</td>
<td style="text-align: right;">7.65</td>
</tr>
<tr class="even">
<td style="text-align: left;">educationBachelors Degree</td>
<td style="text-align: right;">16.50</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educationGraduate Degree</td>
<td style="text-align: right;">23.91</td>
</tr>
</tbody>
</table>
<p>Because education is coded as a factor variable, the <code>lm</code> command knows what to do with it. It has created four separate dummy variables, leaving out the no high school diploma group as my reference. As a result, the intercept is the mean wages for the no high school diploma group, and all of the other numbers give me the difference in mean wages of the given educational group relative to the no high school diploma group. I can see, for example, that individuals with a bachelor’s degree make $16.50/hour more on average than those with no high school diploma. I can easily confirm this by looking back to the means I just calculated:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(wage_means[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>wage_means[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<pre><code>##       HS Diploma        AA Degree Bachelors Degree  Graduate Degree 
##             4.41             7.65            16.50            23.91</code></pre>
<section id="how-did-r-know-what-to-do-with-the-factor-variable" class="level2">
<h2 class="anchored" data-anchor-id="how-did-r-know-what-to-do-with-the-factor-variable">How did R know what to do with the factor variable?</h2>
<p>Underneath the surface, every factor variable in <em>R</em> comes with a a matrix of <em>contrasts</em>. This contrast matrix defines how such a factor variable should be converted into a set of variables for a linear model. You can see this contrast matrix with the <code>contrasts</code> command:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>education)</span></code></pre></div></div>
<pre><code>##                  HS Diploma AA Degree Bachelors Degree Graduate Degree
## No HS Diploma             0         0                0               0
## HS Diploma                1         0                0               0
## AA Degree                 0         1                0               0
## Bachelors Degree          0         0                1               0
## Graduate Degree           0         0                0               1</code></pre>
<p>The rows are the categories (or “levels” in R speak) of the factor variable and the columns are the variables that actually enter into the model. The matrix gives the numeric coding of these variables for each category. As you can see, the contrasts here just define a standard dummy/indicator variable coding. The no high school diploma category is my reference and has zero on all four variables. All of the other categories have a one for the relevant variable and a zero otherwise.</p>
<p>When you create a factor variable, R will default to this dummy coding which in R is often called a <em>treatment contrast</em>. But, treatment contrasts are not the only contrasts available and you can create your own contrast as I will show below.</p>
<p>To illustrate a change in contrast, I will change my regular factor variable to an ordered factor. The <code>factor</code> command has the option to make any factor ordered and thus recognize its underlying ordinal structure. I can do this very simply:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>educ_ordered <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
<p>An ordered factor behaves very similarly to a regular factor but has one major advantage. I can now use greater than and less than operators on my factor in a logical way. For example, lets say I wanted to look at the mean difference in wages between all those with only a high school diploma or less and those with more schooling. Rather than code a whole new variable for this binary comparison, I can just:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">model_binary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(wages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(educ_ordered<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HS Diploma"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>earnings)</span>
<span id="cb10-2">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model_binary), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>)</span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">coefficients</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">18.10</td>
</tr>
<tr class="even">
<td style="text-align: left;">I(educ_ordered &gt; “HS Diploma”)TRUE</td>
<td style="text-align: right;">12.62</td>
</tr>
</tbody>
</table>
<p>Being able to use these operators can be a real time saver if you have an ordinal variable with many categories because you can easily collapse categories for a variety of purposes.</p>
<p>However, ordered factors come with one very annoying “feature” in R. Lets say I want to estimate the same linear model as before but now using my ordered factor. Lets try it out:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">model_ordinal1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(wages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>educ_ordered, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>earnings)</span>
<span id="cb11-2">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model_ordinal1), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>)</span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">coefficients</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">24.75</td>
</tr>
<tr class="even">
<td style="text-align: left;">educ_ordered.L</td>
<td style="text-align: right;">18.94</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educ_ordered.Q</td>
<td style="text-align: right;">3.10</td>
</tr>
<tr class="even">
<td style="text-align: left;">educ_ordered.C</td>
<td style="text-align: right;">-0.09</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educ_ordered^4</td>
<td style="text-align: right;">-1.65</td>
</tr>
</tbody>
</table>
<p>😮 WTF? What are all of these terms? They certainly are not what I was expecting. We can learn more by looking at the contrasts.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>educ_ordered)</span></code></pre></div></div>
<pre><code>##              .L         .Q            .C         ^4
## [1,] -0.6324555  0.5345225 -3.162278e-01  0.1195229
## [2,] -0.3162278 -0.2672612  6.324555e-01 -0.4780914
## [3,]  0.0000000 -0.5345225 -4.095972e-16  0.7171372
## [4,]  0.3162278 -0.2672612 -6.324555e-01 -0.4780914
## [5,]  0.6324555  0.5345225  3.162278e-01  0.1195229</code></pre>
<p>We are definitely not using dummy coding here! The default behavior in R for ordered factors is to treat them as equidistant scores and then estimate an orthogonal polynomial function. So the letters L, Q, and C above refer to linear, quadratic, and cubic terms. This default behavior was inherited from S and I would argue that it is … not optimal. First, It is problematic to treat ordinal variables as equidistant scores without letting the researcher make that decision explicitly. Second, the parameter estimates from this approach are completely uninterpretable.</p>
<p>Luckily, it is not difficult to re-specify the contrasts for the education variable. R even provides some handy-dandy functions for common contrasts. In this case, we could re-code back to a standard dummy/indicator variable contrasts with <code>contr.treatment</code>, like so:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>educ_ordered) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contr.treatment</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb14-2">model_ordinal2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(wages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>educ_ordered, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>earnings)</span>
<span id="cb14-3">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model_ordinal2), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>)</span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">coefficients</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">14.26</td>
</tr>
<tr class="even">
<td style="text-align: left;">educ_ordered2</td>
<td style="text-align: right;">4.41</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educ_ordered3</td>
<td style="text-align: right;">7.65</td>
</tr>
<tr class="even">
<td style="text-align: left;">educ_ordered4</td>
<td style="text-align: right;">16.50</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educ_ordered5</td>
<td style="text-align: right;">23.91</td>
</tr>
</tbody>
</table>
</section>
<section id="use-the-stairstep-contrast-tell-a-friend" class="level2">
<h2 class="anchored" data-anchor-id="use-the-stairstep-contrast-tell-a-friend">Use the stairstep contrast, tell a friend</h2>
<p>However, since we have to re-specify our contrasts, why not take the time to think about better options? The standard dummy variable coding for ordinal variables is often not very informative. For example, I can see that individuals with a graduate degree make $23.91 more per hour than those with no high school diploma. That is a large difference, but I would have expected a large number here given that we are contrasting the poles of the distribution. A far more interesting question is how much more do those with graduate degrees make than those with only a bachelor’s degree? In that case, we are comparing how much the predicted value of the dependent variable changes when you move to the next highest adjacent category.</p>
<p>We can do this for all adjacent pairs by applying a <code>diff</code> to the vector of mean wages:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span>(wage_means)</span></code></pre></div></div>
<pre><code>##       HS Diploma        AA Degree Bachelors Degree  Graduate Degree 
##         4.407462         3.242862         8.848246         7.410229</code></pre>
<p>Every number gives us the increase in mean hourly wages when you move to that education level from the immediately preceding educational level. The biggest jump is between a Bachelor’s degree and an AA degree, while the smallest jump is between a high school diploma and an AA degree.</p>
<p>I can of course calculate these differences by hand from the results of my dummy variable coding. For example, by taking <code>\(23.91-16.50\)</code>, I will be able to see that the increase in expected hourly wages from a Bachelor’s degree to a Graduate degree is 7.41. However, wouldn’t it be nice if there was a contrast coding that would do this for me? It turns out there is!</p>
<p>The contrast coding we want looks like a stairstep.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">cont <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb17-2">cont[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(cont)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row</span>(cont)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb17-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(cont) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LHS"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HS"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BA"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Grad"</span>)</span>
<span id="cb17-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(cont) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HS vs LHS"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA vs HS"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BA vs AA"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Grad vs BA"</span>)</span>
<span id="cb17-5">cont</span></code></pre></div></div>
<pre><code>##      HS vs LHS AA vs HS BA vs AA Grad vs BA
## LHS          0        0        0          0
## HS           1        0        0          0
## AA           1        1        0          0
## BA           1        1        1          0
## Grad         1        1        1          1</code></pre>
<p>In this coding, each category gets a one if it is at or higher than the critical cut point for that contrast. The idea is that every category gets the effect of making that “jump” if they are at that level or higher. The result looks like a stairstep descending to the left. For this reason, I often call this approach <em>stairstep coding</em>.</p>
<p>Lets try out this stairstep contrast on education:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>educ_ordered) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cont</span>
<span id="cb19-2">model_ordinal3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(wages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>educ_ordered, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>earnings)</span>
<span id="cb19-3">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model_ordinal3), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>) </span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">coefficients</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">14.26</td>
</tr>
<tr class="even">
<td style="text-align: left;">educ_orderedHS vs LHS</td>
<td style="text-align: right;">4.41</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educ_orderedAA vs HS</td>
<td style="text-align: right;">3.24</td>
</tr>
<tr class="even">
<td style="text-align: left;">educ_orderedBA vs AA</td>
<td style="text-align: right;">8.85</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educ_orderedGrad vs BA</td>
<td style="text-align: right;">7.41</td>
</tr>
</tbody>
</table>
<p>The contrasts behave exactly as expected. Each parameter estimate gives the mean difference between adjacent pairs of categories on the ordinal variable. We can get the mean differences between any non-adjacent pairs simply by adding up the values of all the intervening pairs. For example, to get the difference between an AA degree and a graduate degree I take the two values for BA vs.&nbsp;AA and Grad vs.&nbsp;AA and add them up for <code>\(8.85+7.41=16.26\)</code>.</p>
<p>Finally, since setting up this contrast is a hassle, why not put all of it into a function like a coding <svg viewbox="0 0 448 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M325.4 289.2L224 390.6 122.6 289.2C54 295.3 0 352.2 0 422.4V464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48v-41.6c0-70.2-54-127.1-122.6-133.2zM32 192c27.3 0 51.8-11.5 69.2-29.7 15.1 53.9 64 93.7 122.8 93.7 70.7 0 128-57.3 128-128S294.7 0 224 0c-50.4 0-93.6 29.4-114.5 71.8C92.1 47.8 64 32 32 32c0 33.4 17.1 62.8 43.1 80-26 17.2-43.1 46.6-43.1 80zm144-96h96c17.7 0 32 14.3 32 32H144c0-17.7 14.3-32 32-32z"></path></svg>?</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">ordered_factor <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(fact_var) {</span>
<span id="cb20-2">  ord_fact <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(fact_var, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb20-3">  categories <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(fact_var)</span>
<span id="cb20-4">  n_cat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(categories)</span>
<span id="cb20-5">  cont <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, n_cat, n_cat<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>)</span>
<span id="cb20-6">  cont[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">col</span>(cont)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row</span>(cont)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb20-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(cont) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> categories</span>
<span id="cb20-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(cont) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(categories[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_cat], categories[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>(n_cat<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">-1</span>)],</span>
<span id="cb20-9">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" vs. "</span>)</span>
<span id="cb20-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(ord_fact) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cont</span>
<span id="cb20-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(ord_fact)</span>
<span id="cb20-12">}</span></code></pre></div></div>
<p>This function take a factor variable as input and returns an ordered factor with stairstep contrasts defined as well as intuitive labels. Now you can just apply this function to any existing factor variables to convert them to ordered factors with stairstep contrasts. Here it is in action.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>education <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ordered_factor</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>education)</span>
<span id="cb21-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(earnings<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>education)</span></code></pre></div></div>
<pre><code>##                  HS Diploma vs. No HS Diploma AA Degree vs. HS Diploma
## No HS Diploma                               0                        0
## HS Diploma                                  1                        0
## AA Degree                                   1                        1
## Bachelors Degree                            1                        1
## Graduate Degree                             1                        1
##                  Bachelors Degree vs. AA Degree
## No HS Diploma                                 0
## HS Diploma                                    0
## AA Degree                                     0
## Bachelors Degree                              1
## Graduate Degree                               1
##                  Graduate Degree vs. Bachelors Degree
## No HS Diploma                                       0
## HS Diploma                                          0
## AA Degree                                           0
## Bachelors Degree                                    0
## Graduate Degree                                     1</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">model_final <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(wages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>earnings)</span>
<span id="cb23-2">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model_final, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>)</span></code></pre></div></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">coefficients</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">14.261219</td>
</tr>
<tr class="even">
<td style="text-align: left;">educationHS Diploma vs.&nbsp;No HS Diploma</td>
<td style="text-align: right;">4.407462</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educationAA Degree vs.&nbsp;HS Diploma</td>
<td style="text-align: right;">3.242862</td>
</tr>
<tr class="even">
<td style="text-align: left;">educationBachelors Degree vs.&nbsp;AA Degree</td>
<td style="text-align: right;">8.848246</td>
</tr>
<tr class="odd">
<td style="text-align: left;">educationGraduate Degree vs.&nbsp;Bachelors Degree</td>
<td style="text-align: right;">7.410229</td>
</tr>
</tbody>
</table>


</section>

 ]]></description>
  <category>R</category>
  <guid>https://aarongullickson.github.io/post/better-contrasts-for-ordinal-variables-in-r/</guid>
  <pubDate>Fri, 11 Sep 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Adding Odds Ratios to Logit Model Output in R</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/adding-odds-ratios-to-logit-model-output-in-r/</link>
  <description><![CDATA[ 






<p>I recently received an email from an undergraduate student who had taken my statistics course. This student was working on their undergraduate thesis project in which they were running logit models in <em>R</em>. Their thesis adviser had asked them to produce odds ratios which is not reported in the <code>summary</code> command for a generalized linear model in <em>R</em>. Apparently, the advisor was used to programs like Stata that include the argument <code>or</code> to get odds ratios from logit models in the default output.</p>
<p>It is true that <em>R</em> does not give you odds ratios by default, but it is fairly easy to derive these values. As an example, I will use the <a href="https://github.com/AaronGullickson/combined_stats/tree/master/example_datasets/titanic">individual Titanic passenger data</a> that I use for my classes.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">load</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">url</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://github.com/AaronGullickson/combined_stats/blob/master/example_datasets/titanic/titanic.RData?raw=true"</span>))</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(titanic)</span></code></pre></div></div>
<pre><code>##   survival    sex     age agegroup pclass     fare family
## 1 Survived Female 29.0000    Adult  First 211.3375      0
## 2 Survived   Male  0.9167    Child  First 151.5500      3
## 3     Died Female  2.0000    Child  First 151.5500      3
## 4     Died   Male 30.0000    Adult  First 151.5500      3
## 5     Died Female 25.0000    Adult  First 151.5500      3
## 6 Survived   Male 48.0000    Adult  First  26.5500      0</code></pre>
<p>Lets use a model that predicts survival by sex, age, and fare paid.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>((survival<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Survived"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>sex<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>age<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>fare, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>titanic, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span>binomial)</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model)</span></code></pre></div></div>
<pre><code>## 
## Call:
## glm(formula = (survival == "Survived") ~ sex + age + fare, family = binomial, 
##     data = titanic)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.2761  -0.6282  -0.5885   0.8228   2.0294  
## 
## Coefficients:
##              Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept)  0.859815   0.178120   4.827 1.38e-06 ***
## sex2        -2.325910   0.138566 -16.786  &lt; 2e-16 ***
## age         -0.009065   0.005015  -1.807   0.0707 .  
## fare         0.010026   0.001713   5.854 4.80e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1741.0  on 1308  degrees of freedom
## Residual deviance: 1323.6  on 1305  degrees of freedom
## AIC: 1331.6
## 
## Number of Fisher Scoring iterations: 4</code></pre>
<p>The resulting coefficient estimates are in the form of log odds ratios rather than odds ratios. To convert to odds ratios (and baseline odds for the intercept), we just need to exponentiate the coefficients. We can pull the coefficients out of the model with <code>coef(model)</code> and then its just a simple matter to exponentiate them:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model))</span></code></pre></div></div>
<pre><code>## (Intercept)        sex2         age        fare 
##  2.36272327  0.09769451  0.99097602  1.01007658</code></pre>
<p>Holding constant fare and age, men (sex2) had 90% lower odds of surviving the Titanic than women. Holding constant sex and fare, a one year increase in age is associated with about a 1% reduction in the odds of survival. Similarly, holding constant age and sex, a one pound increase in fare paid is associated with a bout a 1% increase in the odds of survival.</p>
<p>I was pleased that my former student had actually figured out how to extract odds ratios using the technique above. However, what they really wanted was a method that included the odds ratio directly in the <code>summary</code> of the model. Although <em>R</em> does not do this by default, the ability to create custom functions makes it easy to build our own summary command that can do it.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">summary_or <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(m) {</span>
<span id="cb7-2">  s <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m)</span>
<span id="cb7-3">  s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients)</span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Odds Ratio"</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(s)</span>
<span id="cb7-6">}</span></code></pre></div></div>
<p>This function is basically a wrapper function for the regular summary command. The coefficients object within the summary command is just a matrix of model output. I use the <code>cbind</code> command to add a new column at the front for the odds ratio and then use <code>colnames</code> to name this column. If I then call up this function instead of <code>summary</code> I get:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary_or</span>(model)</span></code></pre></div></div>
<pre><code>## 
## Call:
## glm(formula = (survival == "Survived") ~ sex + age + fare, family = binomial, 
##     data = titanic)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.2761  -0.6282  -0.5885   0.8228   2.0294  
## 
## Coefficients:
##             Odds Ratio  Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept)   2.362723  0.859815   0.178120   4.827 1.38e-06 ***
## sex2          0.097695 -2.325910   0.138566 -16.786  &lt; 2e-16 ***
## age           0.990976 -0.009065   0.005015  -1.807   0.0707 .  
## fare          1.010077  0.010026   0.001713   5.854 4.80e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1741.0  on 1308  degrees of freedom
## Residual deviance: 1323.6  on 1305  degrees of freedom
## AIC: 1331.6
## 
## Number of Fisher Scoring iterations: 4</code></pre>
<p>So the lesson here is that while <em>R</em> sometimes does not have the easy pre-packaged arguments of other programs, it also empowers users to create their own custom output as they would like to have it.</p>
<section id="why-you-shouldnt-report-odds-ratios-anyway" class="level2">
<h2 class="anchored" data-anchor-id="why-you-shouldnt-report-odds-ratios-anyway">Why you shouldn’t report odds ratios anyway</h2>
<p>I understand that my student just wants to do what their advisor asked, but personally I am not a big fan of reporting odds ratios rather than log odds ratios. Here is what I explained to the student in my response (along with the code to do it anyway):</p>
<blockquote class="blockquote">
<p>Personally, let me just say that I prefer to see the log-odds ratios for logistic regression models for a couple reasons. First, the sign on the log-odds ratio directly indicates a positive or negative relationship which is the first thing your brain is scanning for when you look at a table of regression coefficients. The extra cognitive work of remembering &lt;1 means negative for an odds ratio is not worth it. Second, when the log-odds ratios are small the effect is easy to interpret as the percentage change. So a log-odds ratio of 0.07 is a 1.0725 odds ratio, so about a 7.25% increase in the odds. The 0.07 gives you a pretty good approximation of that. This logic breaks down when you get values above 0.25 or so, but makes it easy to get a general sense of the strength from the log odds ratio. Third, the standard error from the model is for the log-odds ratio not the odds ratio and you can’t convert it in any meaningful way, so its odd to report it with an odds ratio.</p>
</blockquote>


</section>

 ]]></description>
  <category>R</category>
  <guid>https://aarongullickson.github.io/post/adding-odds-ratios-to-logit-model-output-in-r/</guid>
  <pubDate>Wed, 06 May 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Providing Anonymous Code and Data to Reviewers</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/anonymous_code/</link>
  <description><![CDATA[ 






<p>Posting the underlying code and data for the statistical analysis in an academic paper is becoming a more common practice, although hardly universal in many disciplines. However, even when code and data are posted, it is usually made available upon publication of the paper, leaving out those who would benefit the most from access: the anonymous peer reviewers of the manuscript. Shouldn’t the people who will put your work to the most scrutiny be the ones who have full access to see exactly what you did?</p>
<p>It is possible in some cases, of course, to just zip up your data code files and dump them in with your manuscript submission to a journal as “supplementary material.” However, the availability of this option may vary by journal and reviewers who are used to just downloading the manuscript PDF may miss your supplementary material altogether.</p>
<p>In this post, I want to demonstrate a more elegant solution using the project framework of the <a href="https://osf.io/">Open Science Foundation</a> combined with <a href="https://github.com">GitHub</a>. I have used this procedure for my most recent manuscript submissions with great success. If you are not a git or GitHub user, you can ignore the final step I discuss here, but really <a href="../../post/firstgithubrep/index.html">you should become a git user</a>.</p>
<section id="step-1-prepare-your-files" class="level2">
<h2 class="anchored" data-anchor-id="step-1-prepare-your-files">Step 1: Prepare your files</h2>
<p>How to properly organize your data and code files for the easy accessibility of others is beyond the scope of this post, but here I want to highlight two basic minimum requirements that should be met before you make files available to reviewers:</p>
<ol type="1">
<li><strong>Anonymize</strong>. You are submitting these files under anonymous peer review. Therefore, you should ensure that nothing in the files can identify you. Remove all names or anything else that could identify you.</li>
<li><strong>Provide a Guide</strong>. You need to provide some basic information that will allow readers to understand what is contained in your files. A simple README file will usually suffice. This README should explain what each of the scripts does, the order in which those scripts should be run to reproduce the analysis, and distinguish which data is from the original source and which has been constructed by the analyst. Ask yourself a simple question: Would other people be able to figure out how to replicate the analysis in these files without having me there to explain it to them? If the answer is no, then you need more documentation.</li>
</ol>
</section>
<section id="step-2-set-up-an-osf-project-with-view-only-links" class="level2">
<h2 class="anchored" data-anchor-id="step-2-set-up-an-osf-project-with-view-only-links">Step 2: Set up an OSF Project with View-only Links</h2>
<p>The <a href="https://osf.io">Open Science Foundation</a> provides an excellent tool for organizing research projects and disseminating information about them. You can associate manuscripts, data, and code with projects, track changes to the project, and even include a wiki. You can also link your OSF project to manuscripts on <a href="https://socopen.org/">SocArxIV</a>. <a href="https://osf.io/rcaxh/">Here is an example</a> of a project for one of my own recently published papers. If you don’t already have an account, you should create one.</p>
<p>You can create a view-only link for any OSF project. A view-only link will open up the project page, but with all name references removed. <a href="https://osf.io/rcaxh/?view_only=65b57cc4f8d64c6db1c62bf9c2176bcb">Here is an example</a> of that same example project of mine but provided through a view-only link. Notice that contributors are listed as “Anonymous” and the person responsible for all changes to the project is listed as “user.” UPDATE: As noted by Phil Cohen on Twitter, this link provides “courtesy” anonymity, not secure anonymity. A sophisticated viewer can still access the named project page by removing the “?view_only” part of the html address.</p>
<p>To set up a view-only link for a project, follow these steps:</p>
<ol type="1">
<li>Go to the project Settings tab.</li>
<li>In the View-only Links section, click the green “+Add” button. This will bring up a dialog with more options. You must click the button to “Anonymize contributor list for this link”. If your project has multiple components, you can also decide which components to add here.</li>
<li>Now you should see a description of your View-only Link with the option to copy the full link. Here is what mine looks like:</li>
</ol>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://aarongullickson.github.io/post/anonymous_code/view_only_example.png" class="img-fluid figure-img"></p>
<figcaption>View only link example</figcaption>
</figure>
</div>
<p>To make this link available to reviewers, I include the link directly in a footnote on the first page of my manuscript with instructions that reviewers can find all code and data as well as supplementary analyses at that location.</p>
<p>But how do you get code and data into the project? You can just drag and drop your code and data files into the files section on your OSF project. However, if you use git (subliminal message: you should use git) for version control, there is a better way.</p>
</section>
<section id="step-3-link-osf-to-your-github-data" class="level2">
<h2 class="anchored" data-anchor-id="step-3-link-osf-to-your-github-data">Step 3: Link OSF to your GitHub data</h2>
<p><a href="https://github.com">Github</a> (or other git platforms like <a href="https://gitlab.com">Gitlab</a>) provides an excellent tool to disseminate data and code, include documentation, and to update that code and data with a proper log of all changes. <a href="https://github.com/AaronGullickson/beautyexchange">Here is an example</a> of a GitHub repository with code for the reproduction of an analysis.</p>
<p>Thankfully, OSF provides the ability to link to your GitHub repository. Just go to the “Add-ons” tab of your OSF project and enable the GitHub (or GitLab) settings. After authenticating with GitHub, you will then have the ability to select a repository to be associated with the project. Here is an example of what this looks like in my project:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://aarongullickson.github.io/post/anonymous_code/github_osf.png" class="img-fluid figure-img"></p>
<figcaption>GitHub on OSF</figcaption>
</figure>
</div>
<p>Once you have selected a repository, that repository will show up in the files section of your OSF project. If you make any changes to that data and code, those changes will automatically be updated on OSF once you push them to your GitHub repository. You no longer have to worry about manually moving over new files if you make a change.</p>
<p>Importantly, you can link private repositories here as well. So if you want to keep your code and data private until publication, you can set your GitHub repo to private but still make it available to reviewers through OSF.</p>
<p>If you are git-averse, then its worth noting that you can also link to Dropbox and OneDrive if you want to keep your data and code there instead.</p>


</section>

 ]]></description>
  <category>open science</category>
  <category>review process</category>
  <category>github</category>
  <category>git</category>
  <guid>https://aarongullickson.github.io/post/anonymous_code/</guid>
  <pubDate>Wed, 09 May 2018 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Re-coding Categorical Variables in R</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/coding_ifelse/</link>
  <description><![CDATA[ 






<p>While I have done data analysis almost exclusively in R for most of my career, until recently I have done a lot of my data cleaning in Stata. I have even told people in the past that I though Stata was better at data cleaning than R. However, when I switched my graduate statistics class from Stata to R last year, I decided that I needed to teach my students how to clean data in R. True to the old saying, there is no better way to learn than teach. In this case, I realized that my attitude toward data cleaning in R was more about my lack of familiarity with some nice utilities in R than it was about R itself.</p>
<p>In this post, I wanted to use some code from one of my current projects to outline how to efficiently re-code categorical variables in R. I will first outline how I used to do it and then demonstrate much simpler code to achieve the same effect. I am not using any additional packages here, including the <a href="https://www.tidyverse.org/">tidyverse</a>. All code is base R.</p>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The Data</h2>
<p>The data I am using come from a <a href="https://gssdataexplorer.norc.org/projects/40124">data extract</a> of the General Social Survey (GSS). I am particularly interested in the variable <code>PRAY</code> in this dataset. Yes, the GSS capitalizes all of its variable names because REASONS. You can access the CSV data <a href="gss_relig.csv">here</a>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">gss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gss_relig.csv"</span>)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY)</span></code></pre></div></div>
<pre><code>## 
##     0     1     2     3     4     5     6     8     9 
## 28232  9065  9936  4099  2321  5469  2239    96   302</code></pre>
<p>The default data came in numeric format. The online codebook for the GSS tells me that these numeric codes correspond to the following categories.</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Numeric Code</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td>Not applicable</td>
</tr>
<tr class="even">
<td>1</td>
<td>Several times a day</td>
</tr>
<tr class="odd">
<td>2</td>
<td>Once a day</td>
</tr>
<tr class="even">
<td>3</td>
<td>Several times a week</td>
</tr>
<tr class="odd">
<td>4</td>
<td>Once a week</td>
</tr>
<tr class="even">
<td>5</td>
<td>Lt once a week</td>
</tr>
<tr class="odd">
<td>6</td>
<td>Never</td>
</tr>
<tr class="even">
<td>8</td>
<td>Don’t know</td>
</tr>
<tr class="odd">
<td>9</td>
<td>No answer</td>
</tr>
</tbody>
</table>
<p>Ultimately, I want to turn these numeric codes into a proper factor variable. There are several issues to consider before proceeding:</p>
<ol type="1">
<li>There are multiple missing value codes to enter (0,8,9)</li>
<li>The numbering is the reverse of how I want the ordinal variable coded. I want higher values to indicate higher frequency of prayer.</li>
<li>Most importantly, the category of “Never” was not given as an explicit option until 2004, so I can’t compare data across time very well with that category. Therefore, I want to collapse the “Never” and “Lt once a week” category together.</li>
</ol>
</section>
<section id="my-old-approach" class="level2">
<h2 class="anchored" data-anchor-id="my-old-approach">My Old Approach</h2>
<p>My old approach to handling this sort of re-code problem would have been to apply what I call the <strong>bracket and boolean</strong> approach. Here is what that code would look like:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb3-2">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray[gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lt once a week"</span></span>
<span id="cb3-3">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray[gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a week"</span></span>
<span id="cb3-4">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray[gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a week"</span></span>
<span id="cb3-5">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray[gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a day"</span></span>
<span id="cb3-6">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray[gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a day"</span></span>
<span id="cb3-7">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray)</span>
<span id="cb3-8">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relevel</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a day"</span>)</span>
<span id="cb3-9">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relevel</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a day"</span>)</span>
<span id="cb3-10">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relevel</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a week"</span>)</span>
<span id="cb3-11">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relevel</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a week"</span>)</span>
<span id="cb3-12">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relevel</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lt once a week"</span>)</span>
<span id="cb3-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">exclude=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
<pre><code>##                       
##                            0     1     2     3     4     5     6     8     9  &lt;NA&gt;
##   lt once a week           0     0     0     0     0  5469  2239     0     0     0
##   once a week              0     0     0     0  2321     0     0     0     0     0
##   several times a week     0     0     0  4099     0     0     0     0     0     0
##   once a day               0     0  9936     0     0     0     0     0     0     0
##   several times a day      0  9065     0     0     0     0     0     0     0     0
##   &lt;NA&gt;                 28232     0     0     0     0     0     0    96   302     0</code></pre>
<p>First, I created a new variable full of missing values. I then used indexing and boolean statements to replace those missing values with character strings of the correct categories. I then had turned those character string into a factor with the <code>factor</code> command. However, by default, that command will order my categories alphabetically, so I then ran <em>five</em> relevel commands to get the ordering correct. I then run a <code>table</code> command with the <code>exclude=NULL</code> option to include missing values to <a href="https://www.youtube.com/watch?v=bCY9L3Xidoo">check myself before I wreck myself</a>. It works, but I am not proud of that code.</p>
<p>Had I bothered to read the help file for <code>factor</code>, I would have realized that I could actually specify ordering of the categories with the <code>levels</code> argument, so I could have simplified my code a little bit by removing the <code>factor</code> and <code>relevel</code> commands and replacing them with the following:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray,</span>
<span id="cb5-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lt once a week"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a week"</span>,</span>
<span id="cb5-3">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a week"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a day"</span>,</span>
<span id="cb5-4">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a day"</span>),</span>
<span id="cb5-5">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
<p>The <code>ordered</code> option is particularly useful here for running greater than or equal to booleans on factor variables, as I will demonstrate below. Using this code will improve my initial code considerably, but I can still do much better.</p>
</section>
<section id="my-new-approach" class="level2">
<h2 class="anchored" data-anchor-id="my-new-approach">My New Approach</h2>
<p>My new approach takes advantage of two functions. First, the <code>factor</code> function itself is very flexible and can often be used to recode categorical variables without resort to the <strong>bracket and boolean</strong> approach. In this case, I can take advantage of the <code>levels</code> and <code>labels</code> argument to directly code my original numeric variable into a categorical variable in one line.</p>
<p>The second function that is essential to date cleaning in R is the <code>ifelse</code> command. This function takes a boolean statement and assigns the value in the second argument if TRUE, and the value in the third argument if FALSE. In this case, I can easily combine the 5 and 6 numeric values from the original variable into just the value of 5 with:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY)</span></code></pre></div></div>
<p>To do the entire re-coding in one line, I just need to wrap a <code>factor</code> function around that code as follows:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY), </span>
<span id="cb7-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb7-3">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lt once a week"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a week"</span>,</span>
<span id="cb7-4">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a week"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a day"</span>,</span>
<span id="cb7-5">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"several times a day"</span>), </span>
<span id="cb7-6">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb7-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PRAY, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">exclude=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
<pre><code>##                       
##                            0     1     2     3     4     5     6     8     9  &lt;NA&gt;
##   lt once a week           0     0     0     0     0  5469  2239     0     0     0
##   once a week              0     0     0     0  2321     0     0     0     0     0
##   several times a week     0     0     0  4099     0     0     0     0     0     0
##   once a day               0     0  9936     0     0     0     0     0     0     0
##   several times a day      0  9065     0     0     0     0     0     0     0     0
##   &lt;NA&gt;                 28232     0     0     0     0     0     0    96   302     0</code></pre>
<p>Just like that, twelve lines of code become one.</p>
<p>You can apply this same trick to data to re-code and collapse data that is already coded as a factor variable. You just need to use cascading <code>ifelse</code> command to collapse and use a character vector for the levels.</p>
<p>To demonstrate, I use my new <code>pray</code> variable to create a <code>pray.simple</code> variable that collapses the data as follows:</p>
<ul>
<li>“lt once a week”</li>
<li>“weekly”: “once a week” and “several times a week”</li>
<li>“daily”: “once a day” and “several times a day”</li>
</ul>
<p>I can do this again in a single line of code by using <em>cascading</em> <code>ifelse</code> statements. When the result of an <code>ifelse</code> statement is FALSE, I use another <code>ifelse</code> statement to continue looking for categories that I need.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray.simple <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray), <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb9-2">                                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a day"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"daily"</span>,</span>
<span id="cb9-3">                                        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"once a week"</span>,</span>
<span id="cb9-4">                                               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"weekly"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lt once a week"</span>))),</span>
<span id="cb9-5">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lt once a week"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"weekly"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"daily"</span>), </span>
<span id="cb9-6">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb9-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray, gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray.simple, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">exclude=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
<pre><code>##                       
##                        lt once a week weekly daily  &lt;NA&gt;
##   lt once a week                 7708      0     0     0
##   once a week                       0   2321     0     0
##   several times a week              0   4099     0     0
##   once a day                        0      0  9936     0
##   several times a day               0      0  9065     0
##   &lt;NA&gt;                              0      0     0 28630</code></pre>
<p>The first <code>ifelse</code> command filters out the missing values. Then I can use <code>&gt;=</code> booleans (because I used the <code>ordered=TRUE</code> on the factor variable) to partition my valid categories and collapse them into the three that I want. I then define the ordering of the categories by feeding a character vector into <code>levels</code>. The <code>table</code> command shows that everything is ended up where I expected it to be.</p>
<p>Now that my variable is all coded properly, I can look at the trend over time in the frequency of prayer:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prop.table</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>YEAR, gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray.simple),<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb11-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(p)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rainbow</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb11-3">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">las=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percent"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>),</span>
<span id="cb11-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trend in frequency of prayer in the US,</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">General Social Survey"</span>)</span>
<span id="cb11-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1972</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(gss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pray.simple), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rainbow</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb11-6">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<p><img src="https://aarongullickson.github.io/post/coding_ifelse/trend-1.png" class="img-fluid"></p>


</section>

 ]]></description>
  <category>R</category>
  <guid>https://aarongullickson.github.io/post/coding_ifelse/</guid>
  <pubDate>Sun, 28 Jan 2018 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Response to McClintock Response</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/mcclintock_response/</link>
  <description><![CDATA[ 






<p>In a 2014 <a href="http://journals.sagepub.com/doi/10.1177/0003122414536391">article in the <em>American Sociological Review</em></a>, Elizabeth McClintock claimed to find little evidence of exchange of beauty for status in union formation, based on data of young adults. I wrote a <a href="http://journals.sagepub.com/doi/full/10.1177/0003122417724001">critical comment</a> on this article that is now published in the ASR<sup>1</sup>, and McClintock wrote a <a href="http://journals.sagepub.com/doi/full/10.1177/0003122417725175">response</a>. In her response, McClintock falsely accused me of model mis-specification in part of the analysis, despite the fact that my model is identical to her own model. This accusation stems from McClintock’s own confusion regarding how to interpret model parameters. In this blog post, I explain this problem of interpretation.</p>
<section id="interpreting-interaction-terms" class="level2">
<h2 class="anchored" data-anchor-id="interpreting-interaction-terms">Interpreting interaction terms</h2>
<p>McClintock suggests at several points in her response that I fit alternate log-linear models that are distinct from her own and that these models are in some way mis-specified. This claim is a factually incorrect distraction. I estimate the exact same model as McClintock. The fundamental disagreement is over the correct interpretation of parameter estimates in models that allow the effect of beauty to differ for men and women.</p>
<p>McClintock’s estimates from her original article (Table 7) are shown below. The key parameters of interest are what McClintock refers to as “Gender-Symmetric Exchange” and “Gender-Stereotypical Exchange”. These numbers measure the degree to which physical beauty is exchangeable for another partner’s education.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://aarongullickson.github.io/post/mcclintock_response/mcclintock_orig_table.png" class="img-fluid figure-img"></p>
<figcaption>extract of McClintock’s original Table 7</figcaption>
</figure>
</div>
<p>McClintock and I agree on the estimation and interpretation of model 1a. As the name implies, “gender-symmetric exchange” in model 1a assumes that the effect of beauty (i.e.&nbsp;its exchangeability for higher levels of education in a partner) is the same for men and women. These results are in the form of log-odds ratios so the value of 0.524 is both substantively large and statistically significant.</p>
<p>The disagreement arises over how to interpret the numbers in model 1b. The goal of model 1b is to relax the assumption that the beauty effect is the same for men and women. How might one go about this task? You do not need special familiarity with log-linear models to answer this question. Anyone who has taken a first year graduate sequence in statistics should know how to allow effects to vary across categories.</p>
<p>Lets say that you want to know whether the effect of \(x\) on \(y\) in an OLS regression model is different for men and women. Effectively you want two different slopes that we can call \(b_m\) and \(b_w\) for men and women, respectively. You can approach this issue in three different ways:</p>
<ol type="1">
<li><p>Interact a dummy variable for women with \(x\) in the model. The main effect of \(x\) in this model will give you the effect for men, \(b_m\), and the interaction term will give you the difference, \(b_w-b_m\), in the two effects.</p></li>
<li><p>Interact a dummy variable for men with \(x\) in the model. The main effect of \(x\) in this model will give you the effect for women, \(b_w\), and the interaction term will give you the difference, \(b_m-b_w\), in the two effects.</p></li>
<li><p>Create two separate variables that give you the main effects for \(b_m\) and \(b_w\), respectively, but not the difference between the effects.</p></li>
</ol>
<p>If you have any two of these values (i.e.&nbsp;a main effect and difference or two main effects) you can derive the third, so the choice of model is primarily driven by ease of interpretation relative to the question at hand. The standard practice is to do either (1) or (2) because researchers often want to directly test whether the difference in effect (i.e.&nbsp;\(H_0:b_m=b_w\)) is statistically significant. This sort of approach can get you into a bit of a pickle, however, because its possible for only one main effect to be statistically distinguishable from zero while the difference between the two effects is statistically indistinguishable from zero. Is it more appropriate in this case to assume that the effects are the same or that one effect is zero and the other non-zero? This situation is exactly what happens in McClintock’s case.</p>
<p>In the table below, I show the parameter estimates for men’s and women’s beauty effects using all three approaches. I also label each approach where it applies to a model used in my response.</p>
<table class="caption-top table">
<colgroup>
<col style="width: 24%">
<col style="width: 14%">
<col style="width: 21%">
<col style="width: 18%">
<col style="width: 21%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Beauty effect on exchange</th>
<th style="text-align: right;">Symmetric (1a)</th>
<th style="text-align: right;">Men as reference (1b)</th>
<th style="text-align: right;">Women as reference</th>
<th style="text-align: right;">Separate Effects (1c)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Gender-Symmetric</td>
<td style="text-align: right;">0.52*</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Men</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.34</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.34</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Women</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.69*</td>
<td style="text-align: right;">0.69*</td>
</tr>
<tr class="even">
<td style="text-align: left;">Difference, Women-Men</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.35</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Difference, Men-Women</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;">-0.35</td>
<td style="text-align: right;"></td>
</tr>
</tbody>
</table>
<p>For the last three columns, you can derive the numbers for any of the other models from the numbers in a given model because these models are the same. Although each model removes one value, the numbers within each row are identical across columns 2-4, because they measure the same underlying thing. Also note that the gender-symmetric effect from the first column is in between the two separate gender effects from the fourth column, as you would expect. Everything in this table makes sense. The beauty exchange effect for women is substantively large and statistically significant. The beauty exchange effect for men is more uncertain. We cannot confidently say that it is different than zero. However, we also cannot confidently say that it is any different than the effect for women. The model fit statistics (not shown here) prefer the symmetric version of the model, so in the absence of any priors, we should probably assume that there is a real beauty effect of similar magnitude for men and women.<sup>2</sup></p>
<p>McClintock uses method (1) in her model 1b. She estimates the main beauty effect for men, and the difference in the beauty effect between men and women. Neither of these effects is statistically significant. In my response, I use method (3) in my model 1c to show that McClintock’s approach left out the most important effect which is the direct effect of beauty for women, i.e.&nbsp;stereotypical exchange. The results for women’s beauty effect are both substantively large and statistically significant. The beauty effect for men is far more equivocal. Its important to note that there is no disagreement between myself or McClintock in how to estimate these values. I am able to reproduce her models 1a and 1b in my comment, and she is able to replicate my model 1c in her response.</p>
<p>The point of this part of my comment was that McClintock used misleading language in both the table and text of her article to describe these effects in a way that made it seem like the beauty effect for women was equivocal when it was clearly unequivocal. I won’t belabor all of those points here, but I do want to address the issue of labeling in her original table because it came up again in McClintock’s response, and suggests to me that she doesn’t fully understand her own models.</p>
<p>If you look again at McClintock’s table above, you will see that she labels the 0.34 effect in model 1b as a “gender-symmetric” effect, whereas I have identified it in my table above and in my comment as the effect for men only. <strong>This is the root of our entire disagreement</strong>. While it is true that the effect for men is estimated by the same variable that estimates the gender-symmetric effect, the existence of a separate dummy variable for women’s beauty effect means that this variable can no longer be interpreted in the same way in model 1b. One does not need to be technically sophisticated to see that if the model includes a term that identifies women’s beauty effect, then a “gender-symmetric” effect cannot also exist. The entire point of model 1b is to relax the assumption of gender symmetry. Furthermore, the label of “gender stereotypical exchange” in McClintock’s table for the 0.35 number is also misleading. This number is the difference in effect for men and women, not women’s effect alone. One must add the 0.34 and 0.35 together to get the full effect of women’s beauty which is 0.69.</p>
<p>When I wrote the comment, I assumed that these misleading labels were just a result of sloppy but forgivable editing. As someone who does a lot of quantitative work, I know how many versions of a table one can go through and how errors in thinking can easily slip by you. I did not expect McClintock to defend what are clearly misleading labels and I instead figured that she would focus on other aspects of her argument, such as the robustness of the results. Instead, McClintock double downed on this mis-interpretation.</p>
<p>Here is the relevant part of McClintock’s response (Table 1):</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://aarongullickson.github.io/post/mcclintock_response/mcclintock_table.png" class="img-fluid figure-img"></p>
<figcaption>extract of McClintock’s Table 1 from response</figcaption>
</figure>
</div>
<p>She replicates my results exactly but continues to incorrectly label men’s beauty effect (“reverse stereotypical exchange”) in the second column as a “gender symmetric” effect, despite the fact that the number is identical to the “reverse stereotypical” exchange number in the third column. However, she goes even further than that and says explicitly in table note d:</p>
<blockquote class="blockquote">
<p>“In a gender-symmetric exchange, either partner may trade socioeconomic status for the other partner’s physical attractiveness. Gullickson lists this parameter twice in his Table 3, as “Gender Symmetric” in Model 1a and as “Men” in Model 1b. Presumably, Gullickson labels the same term differently in Models 1a and 1b because in Model 1b the main “effect” of the gender-symmetric exchange term is interpreted differently due to inclusion of the higher-order (gender-stereotypical) interaction—the main effect in Model 1b is the effect for men; the effect for women is the sum of this main effect and the gender-stereotypical term (described in note e). Despite Gullickson listing this parameter twice, under different names and on different lines, it is the same parameter.” (table 1, note d)</p>
</blockquote>
<p>Please read that again twice. Her presumption is correct. I do label them differently because the main effect must be interpreted differently “due to inclusion of the higher-order interaction.” She says outright that the main effect in model 1b is the “effect for men” and that the “effect for women is the sum of the this main effect and the gender-stereotypical term.” Yet, she criticizes me for applying labels that accurately describe the effects in exactly this manner. Within the space of two sentences she directly contradicts herself by saying first that the terms must be interpreted differently and then saying they are the same parameter. I have to conclude that either she is confused about parameter interpretation or she is being deliberately obscurantist.</p>
<p>To help illustrate the problem with her approach let me show the same table I presented above but this time using McClintock’s approach to labeling:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 24%">
<col style="width: 14%">
<col style="width: 21%">
<col style="width: 18%">
<col style="width: 21%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Beauty effect on exchange</th>
<th style="text-align: right;">Symmetric (1a)</th>
<th style="text-align: right;">Men as reference (1b)</th>
<th style="text-align: right;">Women as reference</th>
<th style="text-align: right;">Separate Effects (1c)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Gender-Symmetric</td>
<td style="text-align: right;">0.52*</td>
<td style="text-align: right;">0.34</td>
<td style="text-align: right;">0.69*</td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Stereotypical</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.35</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.69*</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Reverse-Stereotypical</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;">-0.35</td>
<td style="text-align: right;">0.34</td>
</tr>
</tbody>
</table>
<p>Compare this to my table:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 24%">
<col style="width: 14%">
<col style="width: 21%">
<col style="width: 18%">
<col style="width: 21%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Beauty effect on exchange</th>
<th style="text-align: right;">Symmetric (1a)</th>
<th style="text-align: right;">Men as reference (1b)</th>
<th style="text-align: right;">Women as reference</th>
<th style="text-align: right;">Separate Effects (1c)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Gender-Symmetric</td>
<td style="text-align: right;">0.52*</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Men</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.34</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.34</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Women</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.69*</td>
<td style="text-align: right;">0.69*</td>
</tr>
<tr class="even">
<td style="text-align: left;">Difference, Women-Men</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">0.35</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Difference, Men-Women</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;">-0.35</td>
<td style="text-align: right;"></td>
</tr>
</tbody>
</table>
<p>In my table, the numbers for each row stay the same because they measure the same thing. In McClintock’s table, the numbers in the same row jump around from model to model because they measure different things. The labels on the row do not correctly map onto the underlying concepts being measured. It baffles me why McClintock remains committed to this misleading approach when her own words indicate that she knows better.</p>
<section id="on-the-matter-of-mis-specification" class="level3">
<h3 class="anchored" data-anchor-id="on-the-matter-of-mis-specification">On the matter of mis-specification</h3>
<p>At various points in her response, McClintock hints that my model may be mis-specified. The clearest statement of this comes in endnote 1:</p>
<blockquote class="blockquote">
<p>“Gullickson’s model is misspecified, in that it excludes appropriate lower-order terms (Agresti 1996). Gullickson’s beauty-status exchange terms are not hierarchically nested, whereas I nest gender-stereotypical exchange within the lower- order interaction, gender-symmetric exchange. Strictly speaking, gender-stereotypical beauty- status exchange is an interaction of educational hypergamy (he is more educated) and physical attractiveness hypogamy (he is less attractive), so these lower-order terms should also be included. However, including hypergamy and hypogamy parameters does not substantively alter the results, nor does it improve model fit.” (endnote 1)</p>
</blockquote>
<p>There is quite a bit I could attempt to unpack here, but its not worth my time. The fundamental mistake comes in the first two words of this note - “Gullickson’s model.” Let me explain the issue here in programming language terms:</p>
<pre><code>Gullickson's model == McClintock's model</code></pre>
<p>I am not proposing an alternate model. As the previous section hopefully made clear, I am simply running McClintock’s own model with different sets of 1’s and 0’s in order to illuminate what she obscures. She herself recognizes this point in endnote 2:</p>
<blockquote class="blockquote">
<p>“For the purposes of model fit, my specification of gendered beauty-status exchange and Gullickson’s specification are equivalent. The models differ in their ability to detect significant gender differences, but they use the same degrees of freedom and predict identical cell counts.”</p>
</blockquote>
<p>That is correct. I run the model parameterized with two separate main effects rather than one main effect and a difference, but the underlying model is the same.<sup>3</sup> Therefore, <strong>if there is a mis-specification error in terms of missing lower-order terms, the error is McClintock’s and not mine</strong>. However, let me re-assure her that I don’t think there is a mis-specification error.<sup>4</sup></p>
<p>Once you understand that I am not adding a new model to the analysis, McClintock’s claim that my model does not improve fit (from the abstract and repeated on pg. 7, OnlineFirst) makes no sense. Given that I am estimating the exact same model with the exact same fit, as she admits in the footnote quoted above, what improvement to model fit could there be? In note 4, she claims that “Compared to the model that only includes gender- symmetric exchange (SYM), Gullickson’s pre- ferred model raises the BIC by 4.” This footnote is loaded with misrepresentations of my comment. First, she implies that I am proposing an alternate model that I prefer to her own model. However, as noted above, I am not proposing an alternate model, but rather a different coding of her own gender-specific model. Second, I expressed no preference for the the gender-specific relative to the gender-symmetric model in my comment, because such preferences were irrelevant to the point of my comment. Third, because the gender-symmetric model and gender-specific model were both specified by McClintock herself in the original article, she is only arguing with herself over model preference, yet she misrepresents this as a McClintock vs.&nbsp;Gullickson model comparison. The gender-symmetric model is preferred to the gender-specific models by four regardless of which way you code terms (as anyone can see from Table 1 of McClintock’s response). You can either believe that beauty exchange matters for men and women (gender-symmetric model) or you can believe it only matters for women (gender specific model), but in neither case does this indicate an equivocal finding with regard to the effect for women, as she implied in her original article.</p>
</section>
</section>
<section id="other-issues" class="level2">
<h2 class="anchored" data-anchor-id="other-issues">Other Issues</h2>
<p>I don’t want to test the reader’s patience by addressing in detail any of the other issues raised in McClintock’s response, but I do want to make a few brief comments about a few points.</p>
<ul>
<li>The difference model and conventional regression model are both linear equations of the same four variables. Therefore, they are not conceptually distinct models with conceptually distinct meanings, but rather different specifications of the same underlying relationships. Mcclintock wants to accept my computations but reject my conclusions on the grounds that the models tell us different things (pg. 2, OnlineFirst). However, the mechanical and conceptuals issues are inseparable in this case. The <strong>only</strong> substantive difference between the conventional regression models and the difference models as McClintock employed them is that the difference models fail to control for the variables that McClintock correctly argues must be taken into account in order to accurately measure exchange, namely ego partner’s status and the other partner’s beauty. Therefore, by McClintock’s own standards, the difference models are bad models.</li>
<li>McClintock spends a great deal of time in the response defending the idea that there really is no beauty-status exchange effect. This is somewhat odd given that my comment was specifically directed at problematic model formulation and interpretation and not a direct challenge to her conclusions. It is true that once these issues are taken into account, the evidence of beauty-status exchange is stronger and I tend to think it exists, but I have no strong commitment here, nor am I expecting other scholars to concur. I wish more time had been spent honestly addressing my concerns about methods rather than defending a conclusion that I was not directly addressing.</li>
<li>Robustness is great. I don’t think what McClintock is doing is robustness checking, however. Proper robust checking means that you address models and measures that give contradictory results in order to understand why the discrepancies occurred. Treating all models and measures as equally valid and then declaring no effect when any of these produce null results is an exercise in motivated reasoning.</li>
<li>McClintock claims in the response that, for Table 1, “BIC is <em>not</em> decisively improved by adding parameters for beauty-status exchange” (pg. 7, OnlineFirst). She claims this is true of the gender-symmetric model as well as the model that separates the effect by gender. The meaning of the term “decisively” here is quite ambiguous. BIC does prefer the gender-symmetric model to the model with no exchange parameters by a margin of six (1218 vs.&nbsp;1224). According to the benchmarks suggested by <a href="http://www.jstor.org/stable/271063?seq=1">Raftery</a>, a BIC difference of six is right at the boundary between “Positive” and “Strong” results. So why is this difference not “decisive?” I find it hard to believe that any objective researcher would look at the strong substantive size of the effect (68% in the odds ratio), its statistical significance (p-value=0.0008), and the improvement in model fit by BIC and the LRT and reach the conclusion that it should not be in the model.</li>
<li>The idea that I prioritize statistical significance is laughable. I am an unapologetic Bayesian with a strong distaste for the <a href="http://library.mpib-berlin.mpg.de/ft/gg/GG_Mindless_2004.pdf">null ritual</a>. When I see a substantively large but statistically insignificant effect that accords with my vague priors (such as a beauty exchange effect for men, or that the beauty exchange effect for men is smaller than for women), I am happy to think that its probably a real effect rather than zero. McClintock is the one treating a null effect as a zero effect, which is a standard practice among those who fetishize the p-value.</li>
</ul>
</section>
<section id="notes" class="level2">
<h2 class="anchored" data-anchor-id="notes">Notes</h2>
<hr>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>A non pay-walled pre-print is available <a href="https://osf.io/preprints/socarxiv/5ydxd/">here</a>.↩︎</p></li>
<li id="fn2"><p>Personally, I do have priors that women’s beauty effect would be stronger than men’s, so this would not be my conclusion based on the data. However, this is a whole different conversation.↩︎</p></li>
<li id="fn3"><p>Any interested party can confirm this by looking at the model fit statistics on Table 1 in McClintock’s response or by comparing the deviance and degrees of freedom in the <a href="https://github.com/AaronGullickson/beautyexchange/blob/master/logs/loglinmodels.txt">log output of my models 1b and 1c</a>.↩︎</p></li>
<li id="fn4"><p>For those who want the gory details of unpacking endnote 1, here it goes. McClintock appears to actually be making two distinct claims here. At first, she suggests (in the second sentence) that my use of two main effects rather than a main effect and interaction term is a violation of hierarchical nesting. This is simply wrong. Interaction style coding is the norm in the discipline, but one can easily and correctly code two separate main effects rather than an interaction term. McClintock obviously must know this because she was able to replicate my model exactly and observe that it had the same deviance and degrees of freedom as her model. Starting with the sentence that begins “Strictly speaking”, McClintock brings up an entirely different issue. Here she suggests that the beauty-status exchange term is itself an interaction of some lower ordered hypergamy terms for education and attractiveness that are not included in the model. Although she only mentions this in the context of gender-stereotypical exchange, the same potential issue applies to the gender-symmetric exchange. In either case, if such an error were to exist, it would be an error in her model specification from the original article. I find it objectionable to pass this off as my error. On the issue itself, there has been considerable debate between Rosenfeld and several other scholars (including myself) on this issue in measuring exchange. Interested readers should check out my <a href="https://link.springer.com/article/10.1007/s13524-014-0300-2">article with Florencia Torche</a>, and in particular the <a href="https://static-content.springer.com/esm/art%3A10.1007%2Fs13524-014-0300-2/MediaObjects/13524_2014_300_MOESM2_ESM.docx">online resource 2</a> for more information.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>status exchange</category>
  <category>modeling</category>
  <guid>https://aarongullickson.github.io/post/mcclintock_response/</guid>
  <pubDate>Thu, 24 Aug 2017 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Adventures in Markdown</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/adventures_markdown/</link>
  <description><![CDATA[ 






<p>For most of my career, I have been pretty old-school in my use of open source tools. Not <a href="http://ex-vi.sourceforge.net/">vi</a> old-school, mind you, but still old school. I primarily used the venerable <a href="https://www.gnu.org/software/emacs/">emacs</a> editor to both write <a href="https://www.r-project.org/">R</a> code and to write papers in <a href="https://www.latex-project.org/">LaTeX</a>. Although I have experimented a bit with <a href="http://www.statistik.lmu.de/~leisch/Sweave/">Sweave</a>, I generally just manually constructed my tables in LaTeX after I was satisfied with the analysis and produced my figures as EPS files for inclusion in LaTeX at runtime. Over the years, I have accumulated a substantial amount of code that goes into my LaTeX preamble that makes it come out <em>just so</em> and also allows me to adjust it to the often silly and idiosyncratic demands of journals for manuscript preparation. Then, when I get an acceptance, I often have to figure out how to manually convert my nice LaTeX pdfs into an awful Word document, because sociology journals. This is never a fun experience but the benefits of using LaTeX seemed to outweigh it.</p>
<p>Recently, I decided to make the switch to <a href="https://www.rstudio.com/">RStudio</a> for my analysis and began to explore the possibilities of using <a href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> and <a href="http://rmarkdown.rstudio.com/">R Markdown</a> to write papers. The promise was tantalizing. R Markdown offered a very simple mark-up system for writing papers that would let me lose all the baggage and complication of LaTeX and yet I could still produce documents of the same quality. I would be able to focus on content instead of complex mark-up. Furthermore, I could integrate R code directly into my document, thus automating the process of producing tables and figures. In fact, it seemed possible to fully integrate manuscript preparation with the analysis itself, which would create a much more streamlined research process. For me, the most exciting prospect of R Markdown is that I could produce word documents from it just as easily as PDF documents, and thus I could write once and then send out the formatted document to journals in the format of their choice with the click of a button. I was sold and decided to give it a try.</p>
<section id="same-old-problems-sort-of" class="level3">
<h3 class="anchored" data-anchor-id="same-old-problems-sort-of">Same Old Problems, sort of</h3>
<p>After many months of experimentation, I can report that while I am impressed by the possibilities of Markdown for writing academic papers, it also still falls somewhat short of the promise that I had for it. By definition, Markdown is designed to offer a minimal set of mark-up options, but the cost of this simplicity is that it can be difficult to get it to do what someone might expect of an academic publication. The answers to these problems typically involve a visit to some StackExchange forum and then fiddling around with latex templates, CSS files, and the like. So, in some sense, I am back in that world of LaTeX where I am trying to figure out how to get my sideways table with multicolumn support and decimal alignment right there, dammit! Nonetheless, I still see a lot of merit in the approach of R Markdown and I intend to continue using it for my manuscripts. After doing some fiddling around, I feel that I have a structure now that works pretty well. I wanted to share what I feel its current shortcomings are and how I have worked around them.</p>
<section id="integrating-tables-and-figures" class="level4">
<h4 class="anchored" data-anchor-id="integrating-tables-and-figures">Integrating tables and figures</h4>
<p>Integrating tables into R Markdown can be a frustrating experience. The syntax for tables in Markdown is very basic and so it is difficult to produce the kinds of tables that I would want in an academic publication. Packages like <code>pander</code> and <code>knitr</code> can help in making markdown tables, but can’t overcome the basic problem. For example, multicolumn support is not possible in Markdown. I was working on a paper about interracial marriage in which I wanted to show a cross-tabulation of husband’s race and wife’s race. Here is the best I was able to produce with the <code>knitr::kable</code> function:</p>
<p><img src="https://aarongullickson.github.io/post/adventures_markdown/martable1.png" class="img-fluid"></p>
<p>This is a decent looking table, but its impossible to tell at a glance which spouse is on the column and which spouse is on the row. Furthermore, I would have liked a line that separated the column and row marginal totals.</p>
<p>I can produce a table more to my liking by using the <code>xtable</code> package in R. With some custom work, I am able to produce the following table:</p>
<p><img src="https://aarongullickson.github.io/post/adventures_markdown/martable2.png" class="img-fluid"></p>
<p>In order to do this, I had to use the LaTeX <code>\multicolumn</code> tag to get “Wife’s race” to display properly over the column headers. R packages like <code>xtable</code> and <code>stargazer</code> provide excellent tools for producing nice tables in LaTeX like this one. Such tables can be integrated easily into R Markdown documents by using the <code>results='asis'</code> option, but the resulting document can then only be compiled as a tex or PDF document, which obviates one of the primary reasons for adopting Markdown in the first place.</p>
<p>Figures are less problematic, but I have run into a problem that of figures with horrible resoluation when I produce a Word document from a Markdown document. There might be a way around this from within the R Markdown options, but I have not been able to get it working yet.</p>
</section>
<section id="adjusting-for-journal-requirements" class="level4">
<h4 class="anchored" data-anchor-id="adjusting-for-journal-requirements">Adjusting for journal requirements</h4>
<p>Journals typically want manuscripts to be double-spaced. Many journals also want the notes to come at the end in a separate section rather than as footnotes. Most journals want the tables and figures to come at the end of the manuscript, <em>after</em> the references. Its not often a technical requirement, but I also usually don’t send in my manuscripts with justified text, even though it looks nicer. Markdown is not very flexible about making these kinds of adjustments. You can employ LaTeX headers to do it, but then you can only produce your document in LaTeX and if you have to put all this stuff in your document, the benefits of moving from LaTeX to Markdown diminish significantly.</p>
</section>
<section id="integrating-analysis-and-manuscript-preparation" class="level4">
<h4 class="anchored" data-anchor-id="integrating-analysis-and-manuscript-preparation">Integrating analysis and manuscript preparation</h4>
<p>In the analysis stage, many of the initial figures and tables will be exploratory and it is not worth my time to polish them up with the best labeling and captioning since I may end up moving onto something better in the end. So, in practice, I have ended up cutting and pasting code from my analysis into the R Markdown document and then polishing it up for final presentation. This is still a very useful feature but not as completely seamless as I had originally hoped.</p>
<p>Additionally, some analyses can take substantial amounts of time to run and you don’t want this added processing time every time you knit your document after editing a paragraph of text. For example, I am working on a project now that involves millions of observations, complicated models that are computationally intensive to fit, and multiple imputation. As a result, it takes about five hours to go from raw data to final models. So, in practice, I save my final model summaries as RData objects and then load those objects into my R Markdown to produce tables and figures.</p>
</section>
</section>
<section id="my-solution" class="level3">
<h3 class="anchored" data-anchor-id="my-solution">My Solution</h3>
<p>The beginning of my solution came from the LaTeX template for R Markdown articles developed by <a href="http://svmiller.com/blog/2016/02/svm-r-markdown-manuscript/">Steven V. Miller</a>. I made some additions and edits to this template for my own purposes, but the template I am using is largely based on his efforts. The latest version of my template is <a href="https://github.com/AaronGullickson/basic_template/tree/master/PAPER">available</a> on GitHub, along with some other tools for compiling the manuscript.</p>
<p>My biggest decision was to separate the main body of my article and the tables and figures into separate R Markdown documents that produce separate PDFs. These separate documents are then concatenated together using <code>pdftk</code> after they are converted to PDF documents. One important addition I made to the template is the ability in the YAML headers to provide a different starting pagination for a document. This allows all of the pagination to match when you combine the final manuscript together from its parts.</p>
<p>I made the decision to keep these documents separate for several reasons. First, many journals require that tables and figures come at the very end after references and I could not figure out how to make this happen in a single document when using a bib file to generate references. Second, this allows me when necessary to easily produce a Word document of the main text of the mansucript and then to separately fiddle around with the tables and figures to get them to work in Word. References will be correct in the Word document and it also seems to do a pretty decent job of converting LaTeX equations. Third, keeping tables and figures separate also makes sensitivity analyses easier. I can make a few changes to the coding procedures (or whatever), rerun the analysis and then save my PDF of the tables and figures under a separate name to preserve my sensitivity analysis for easy comparison.</p>
<p>There are several other options that can be specified in the YAML header. You can see examples of most of these in the starter R Markdown documents on GitHub and the <a href="https://github.com/AaronGullickson/basic_template/blob/master/PAPER/templates/aog-latex-ms.tex">template</a> itself describes them in detail. I added an endnote option that moves footnotes to the end of the paper. I also adjusted the anonymous option so that it produces double-spaced ragged right text.</p>
<p><a href="https://aarongullickson.netlify.app/other/fullmanuscript.pdf">Here</a> is an example of what a full nicely formatted manuscript would look like under the default settings. The tables were produced with the <code>stargazer</code> package. <a href="https://aarongullickson.netlify.app/other/fullmanuscript_submission.pdf">Here</a> is the same manuscript but with the anonymous option turned on.</p>
<p>This is still a work in progress and I am sure that I will probably fiddle with this a bit more as my current projects make their way through the publication process. However, I am hopeful that there won’t be too much more fiddling. Feel free to take this template and adjust it to your own purposes.</p>


</section>

 ]]></description>
  <category>markdown</category>
  <category>R</category>
  <guid>https://aarongullickson.github.io/post/adventures_markdown/</guid>
  <pubDate>Tue, 13 Dec 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Setting Up a Git Repository</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/settingupgit/</link>
  <description><![CDATA[ 






<p>I have really become an evangelist for using <a href="https://git-scm.com/">git</a> to manage research projects. I use it now for all of my research projects, whether working in collaboration of by myself. In a future post, I will outline what I think are the many advantages of using version control for research projects. This post is more of self-centered post. I want to have a reference for remembering how to set up a fresh git repository, so I don’t have to keep googling it every time to make sure I get the syntax right. I do it to infrequently to remember it, but frequently enough that its a pain that I can’t remember it. I am hoping this post may also be helpful to others wanting to get started with git.</p>
<p>My set up is that I have a laptop running OSX and a desktop running linux. I keep a “bare” repository on the desktop that serves as my “central” repository and then I keep separate clones of that repository on both my desktop and laptop from which I work.</p>
<p>Typically, I will start by just setting up a directory for the research project on my laptop. In most cases, there will already be some preliminary data/code/notes in this directory. The first step is to initialize this repository. From the command line:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> path/to/newproject/directory</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> init</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> add .</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> commit <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-m</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"initial commit"</span></span></code></pre></div></div>
<p>So, the git repository is now all set up on my laptop.</p>
<p>Next, I set up the bare repository that will serve as the “central” repo on my desktop server. I typically keep these bare repositories in a directory called “repo.” Log into the account where I want the repo to be and from the command line:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> ~/repo</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mkdir</span> newproject.git</span>
<span id="cb2-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> newproject.git</span>
<span id="cb2-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> init <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--bare</span></span></code></pre></div></div>
<p>This will initialize the empty bare git repository. The next step is to then push the actual contents from my laptop repo into that bare repository. On the laptop again, from the command line:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> remote add origin ssh://username@myserver.uoregon.edu:XXXX/home/username/repo/newproject.git</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> push origin master</span></code></pre></div></div>
<p>Obviously, username, myserver, and XXXX need to be replaced with real vaues for the user name, server name, and port number. Once this is done, my central repository is set up. The last step is to clone this central repo to a working repository on my desktop machine and make sure everything looks right. On the desktop, from the command line:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> path/to/working/repo</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> clone /home/username/repo/newproject.git</span></code></pre></div></div>
<p>If all goes well, I should get a copy of the repository here. Note that this only works if I am on the same desktop as the bare repository with the same username. Otherwise, you would have to clone over ssh like so:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> clone ssh://username@myserver.uoregon.edu:XXXX/home/username/repo/newproject.git</span></code></pre></div></div>
<p>Thats it. At this point, I have one “central” bare repository and two separate working repository on each of my computers from which I can start working, committing, pushing, and pulling changes as needed.</p>



 ]]></description>
  <category>git</category>
  <guid>https://aarongullickson.github.io/post/settingupgit/</guid>
  <pubDate>Thu, 06 Oct 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Racial Fluidity, Social Status, and Measurement Error</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/reportingerror/</link>
  <description><![CDATA[ 






<p>The most recent <a href="http://www.journals.uchicago.edu/toc/ajs/current">issue</a> of the American Journal of Sociology contains a <a href="http://www.journals.uchicago.edu/doi/full/10.1086/687374">comment</a> by Kramer, DeFina, and Hannon (KD&amp;H) on Saperstein and Penner’s (S&amp;P) <a href="http://www.socsci.uci.edu/~penner/media/2012_ajs.pdf">article</a> on racial fluidity as well as a <a href="http://www.journals.uchicago.edu/doi/full/10.1086/687806">response</a> by Saperstein and Penner (there is also <a href="http://www.journals.uchicago.edu/doi/full/10.1086/687375">another comment</a> by Richard Alba and colleagues, but the issues they raises are not the focus of this post). As a fellow co-author with Saperstein on <a href="https://sociology.stanford.edu/publications/mulatto-escape-hatch-examining-evidence-us-racial-and-social-mobility-jim-crow-era">another paper</a> looking at racial fluidity on linked Census data from the late 19th and early 20th century, I have been aware of and following the debate between these scholars for some time. Prior to the comment’s publication, Andrew Gelman <a href="http://andrewgelman.com/2016/06/07/social-problems-with-a-paper-in-social-problems/">posted</a> on the debate, and I <a href="http://andrewgelman.com/2016/06/07/social-problems-with-a-paper-in-social-problems/#comment-276828">posted</a> a comment on that post with a <a href="http://pages.uoregon.edu/aarong/reportingerror.html">link</a> to an R simulation that I had put together to show more clearly the nature of the methodological issue that forms the bulk of KD&amp;H’s criticism and how likely it might be to affect different types of models. I had largely put together the simulation for my own purposes in trying to sort out what was going on, but thought it might be useful for others to see, as well. Gelman then quoted my comment in a <a href="http://andrewgelman.com/2016/06/10/racial-classification-sociology-controversy-update/">new post</a> in which he invited Hannon to respond.</p>
<p>So that pretty much takes us to the present. Now that the comment is published (and now that I have switched over to markdown and jekyll for posting to my website), I wanted to use this post to more clearly explain what the simulation is doing and what I think we can take from it. The post here is not intended to be a general defense or attack on any of the scholars involved. In full disclosure, I happen to be good friends with both Saperstein and Penner. However, I happen to also be a scholar interested in both racial fluidity and racial inequality and so getting this right is what I care about most. My post here is also not intended to address all of the criticisms by KD&amp;H nor the responses by S&amp;P. Interested readers should read both the comments and the response for a fuller picture of the debate.</p>
<section id="the-models" class="level2">
<h2 class="anchored" data-anchor-id="the-models">The Models</h2>
<p>S&amp;P use panel data where a measurement of race is taken at multiple time points and the race response occasionally varies within individuals over time. This is the racial fluidity that S&amp;P identify. In particular, they are interested in whether this fluidity is associated with changes in social status (e.g.&nbsp;employment, occupational prestige, ever incarcerated). The fundamental insight here (and why the original article generated so much buzz) is that the causal direction of the association between race and social status may in fact run both directions, both of which serve to reinforce the racial hierarchy. S&amp;P actually have multiple papers on this topic, using different data sets and measures of social status. The AJS article uses NLSY79 data and measures social status by characteristics such as unemployment, poverty, marriage, and incarceration. However, regardless of the measure of social status, they employ two modeling approaches to look at the association. First, they run a straight regression model in which racial identification in the later period is predicted by social status in the later period <em>and</em> racial identification in the earlier period.</p>
<p><img src="https://latex.codecogs.com/png.latex?logit(P(black_%7Bi2%7D))=%5Cbeta_0+%5Cbeta_1(black_%7Bi1%7D)+%5Cbeta_2(status_%7Bi2%7D)"></p>
<p>The idea here is that we can see the effect of social status on the probability of being identified as black in time 2, even while controlling for whether the respondent was identified as black or not in time 1. Controlling for racial identification at time 1 is crucial because otherwise the association between being black in time 2 and social status in time 2 will almost certainly reflect the racial inequality (e.g.&nbsp;black people are more likely to have ever been incarcerated) rather than the racial fluidity that S&amp;P are interested in.</p>
<p>An alternative approach uses a fixed effects panel model.</p>
<p><img src="https://latex.codecogs.com/png.latex?logit(P(black_%7Bit%7D))=%5Calpha_i+%5Cbeta_1(status_%7Bit%7D)"></p>
<p>Here the \(\) fixed effects allow S&amp;P to look at within-person change. So, \(_1\) tells you how a change in social status changes the log-odds that a person will by identified (or self-identify, depending on the measure) as black. Because the fixed effects model controls for all time constant variables, the model effectively controls for phenotypical differences (e.g.&nbsp;skin tone, hair texture) between individuals that might affect both how they identify or are identified and how they are treated.</p>
<p>KD&amp;H’s primary criticism is that the results of S&amp;P’s analysis could easily be driven by measurement error. I feel that they are somewhat vague about the source of such measurement error (a point I will return to below as it forms a significant part of Hannon’s response on Gelman’s blog to my simulation). Lets assume for the moment that we are simply talking about either interviewers or respondents (depending on the data collection format) literally checking the wrong box relative to the box they meant to check or a transcription error when the raw data is compiled. I think everyone can agree that these situations truly would constitute measurement error as the intention of the person giving the response in that particular time and place is not accurately recorded.</p>
<p>KD&amp;H describe a simulation in their comment which seems to show that even in the absence of real effects, a measurement error in race reporting at time 2 of 1.6% can still produce large effects of the size that S&amp;P report. S&amp;P respond by (correctly) pointing out that the simulation should allow for a similar degree of measurement error for race reporting at time 1. When S&amp;P make this correction, the effects that KD&amp;H report are roughly cut in half and substantially below most of the effects that S&amp;P report.</p>
<p>Neither set of authors provide any real discussion of <strong>why</strong> such a large bias might be produced in the face of such a small amount of measurement error. I can be a bit thick sometimes and it was not immediately clear to me how such measurement bias was produced. So, I built the following simulation mostly to figure it out for myself. If at this point, you just want the tl;dr version, the conclusion is that measurement error could potentially create association in the basic regression model that S&amp;P run, but not the fixed-effects model, because the bias operates in the between-person comparison not the within-person comparison.</p>
</section>
<section id="the-simulation" class="level2">
<h2 class="anchored" data-anchor-id="the-simulation">The Simulation</h2>
<section id="setting-up-the-basic-dataset" class="level3">
<h3 class="anchored" data-anchor-id="setting-up-the-basic-dataset">Setting up the basic dataset</h3>
<p>In order to run the simulation, I first constructed a fake dataset with two time points and no fluidity. There are two groups, A and D, where D is the disadvantaged group (10% of the population). I refer to the social status characteristic as unemployment, but really it could be any dummy variable where 1 indicates a negative social status. I set the unemployment rate for A at 10% and for D at 20%. All of these parameters are adjustable and I have played around with different values. The conclusions seem pretty robust for realistic values.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">sampleSize <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span></span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#two groups, A and D, for advantaged and disadvantaged. What proportion are D?</span></span>
<span id="cb1-4">propD <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#base unemployment rate for A</span></span>
<span id="cb1-6">baseUnempA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ratio of unemployment rate for D</span></span>
<span id="cb1-8">ratioUnemp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-9"></span>
<span id="cb1-10">race.time1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>propD)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize)),</span>
<span id="cb1-11">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(propD<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize))))</span>
<span id="cb1-12"></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#because we start with no fluidity and no measurement error</span></span>
<span id="cb1-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#race.time2 is identical</span></span>
<span id="cb1-15"></span>
<span id="cb1-16">race.time2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> race.time1</span>
<span id="cb1-17"></span>
<span id="cb1-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#assume double the unemployment rate for Ds as As (20% and 10% respectively)</span></span>
<span id="cb1-19">unemp.time1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>((baseUnempA)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>propD)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize)),</span>
<span id="cb1-20">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>baseUnempA)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>propD)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize)),</span>
<span id="cb1-21">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>((baseUnempA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>ratioUnemp)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(propD)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize)),</span>
<span id="cb1-22">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(baseUnempA<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>ratioUnemp))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(propD)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize)))</span>
<span id="cb1-23"></span>
<span id="cb1-24">baseData <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(race.time2,race.time1,unemp.time1)</span>
<span id="cb1-25"></span>
<span id="cb1-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Create unemp.time2 by  randomly redistributing unemployment within each race group.</span></span>
<span id="cb1-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#This should give us the same distribution of unemployment by race in each time period</span></span>
<span id="cb1-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#and of course there can't be a correlation with switching because there is no switching</span></span>
<span id="cb1-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#in the real data.</span></span>
<span id="cb1-30"></span>
<span id="cb1-31">baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(baseData))</span>
<span id="cb1-32">temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time1[baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>]</span>
<span id="cb1-33">temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(temp),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(temp),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)]</span>
<span id="cb1-34">baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time2[baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp</span>
<span id="cb1-35">temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time1[baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>]</span>
<span id="cb1-36">temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(temp),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(temp),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)]</span>
<span id="cb1-37">baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time2[baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp</span></code></pre></div></div>
<p>Perform some checks to make sure everything lines up as expected.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(baseData)</span></code></pre></div></div>
<pre><code>##  race.time2 race.time1  unemp.time1    unemp.time2
##  A:9000     A:9000     Min.   :0.00   Min.   :0.00
##  D:1000     D:1000     1st Qu.:0.00   1st Qu.:0.00
##                        Median :0.00   Median :0.00
##                        Mean   :0.11   Mean   :0.11
##                        3rd Qu.:0.00   3rd Qu.:0.00
##                        Max.   :1.00   Max.   :1.00</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1, baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time2)</span></code></pre></div></div>
<pre><code>##
##        A    D
##   A 9000    0
##   D    0 1000</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time1, baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1, mean)</span></code></pre></div></div>
<pre><code>##   A   D
## 0.1 0.2</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time2, baseData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time2, mean)</span></code></pre></div></div>
<pre><code>##   A   D
## 0.1 0.2</code></pre>
</section>
<section id="introducing-measurement-error" class="level3">
<h3 class="anchored" data-anchor-id="introducing-measurement-error">Introducing measurement error</h3>
<p>Now, I set up a monte carlo simulation in which I introduce measurement error in the race measurement and run both types of models outlined above to see if the results show an association between race and social status.</p>
<p>First, I set up some parameters for the simulation. The boolean variable <code>dvError</code> can be toggled so FALSE to more closely follow the KD&amp;H simulation which only induced error in race at time 1. I have it toggled to TRUE here, but in other runs, I confirm S&amp;P’s finding that when error is only induced in race at time 1, the reported bias is about double what it should be.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#reporting error percent</span></span>
<span id="cb10-2">errorProp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span></span>
<span id="cb10-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#include errors on DV?</span></span>
<span id="cb10-4">dvError <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb10-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#number of simulations</span></span>
<span id="cb10-6">nSim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span></code></pre></div></div>
<p>Next, I induce the error in each simulation and estimate the key coefficient for each model.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(survival)</span>
<span id="cb11-2"></span>
<span id="cb11-3">coefs.basic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb11-4">coefs.fixed <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb11-5">tabAA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb11-6">tabDD <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb11-7">tabAD <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb11-8">tabDA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb11-9"></span>
<span id="cb11-10"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nSim) {</span>
<span id="cb11-11"></span>
<span id="cb11-12">  errorData <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> baseData</span>
<span id="cb11-13"></span>
<span id="cb11-14">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#race.time2</span></span>
<span id="cb11-15">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(dvError) {</span>
<span id="cb11-16">    errors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(errorData), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(errorProp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb11-17">    temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time2[errors]</span>
<span id="cb11-18">    temp2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(errors))</span>
<span id="cb11-19">    temp2[temp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span></span>
<span id="cb11-20">    temp2[temp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span></span>
<span id="cb11-21">    errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time2[errors] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp2</span>
<span id="cb11-22">  }</span>
<span id="cb11-23"></span>
<span id="cb11-24">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#race.time1</span></span>
<span id="cb11-25">  errors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(errorData), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(errorProp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sampleSize), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb11-26">  temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1[errors]</span>
<span id="cb11-27">  temp2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(errors))</span>
<span id="cb11-28">  temp2[temp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span></span>
<span id="cb11-29">  temp2[temp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span></span>
<span id="cb11-30">  errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1[errors] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp2</span>
<span id="cb11-31"></span>
<span id="cb11-32">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#get the mean unemployment by each group of switchers and stayers</span></span>
<span id="cb11-33">  tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time2, errorData[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], mean)</span>
<span id="cb11-34">  tabAA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(tabAA, tab[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb11-35">  tabDD <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(tabDD, tab[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb11-36">  tabAD <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(tabAD, tab[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb11-37">  tabDA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(tabDA, tab[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb11-38"></span>
<span id="cb11-39">  model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(race.time2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>unemp.time2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(race.time1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>errorData,</span>
<span id="cb11-40">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span>binomial)</span>
<span id="cb11-41"></span>
<span id="cb11-42">  coefs.basic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(coefs.basic, model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unemp.time2"</span>])</span>
<span id="cb11-43"></span>
<span id="cb11-44">  panelData <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">race=</span>errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time1,</span>
<span id="cb11-45">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unemp=</span>errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time1,</span>
<span id="cb11-46">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">person=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(errorData),</span>
<span id="cb11-47">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(errorData))),</span>
<span id="cb11-48">                       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">race=</span>errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>race.time2,</span>
<span id="cb11-49">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unemp=</span>errorData<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>unemp.time2,</span>
<span id="cb11-50">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">person=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(errorData),</span>
<span id="cb11-51">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(errorData))))</span>
<span id="cb11-52"></span>
<span id="cb11-53">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#clogit in the survival library will fit an FE logit</span></span>
<span id="cb11-54">  model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clogit</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(race<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>unemp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strata</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(person)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>panelData)</span>
<span id="cb11-55">  coefs.fixed <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(coefs.fixed, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(model)[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unemp"</span>])</span>
<span id="cb11-56">}</span></code></pre></div></div>
</section>
<section id="the-simulation-results" class="level3">
<h3 class="anchored" data-anchor-id="the-simulation-results">The simulation results</h3>
<p>First, lets take a look at the results for the basic regression models with a control for prior racial identification.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(coefs.basic, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>,</span>
<span id="cb12-2">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"effect of unemployment on log odds of identifying as black"</span>,</span>
<span id="cb12-3">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic regression bias"</span>)</span></code></pre></div></div>
<p><img src="https://aarongullickson.github.io/post/reportingerror/biasbasic.png" class="img-fluid"></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(coefs.basic)</span></code></pre></div></div>
<pre><code>##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
## -0.1781  0.2799  0.3959  0.3984  0.5158  1.0430</code></pre>
<p>There is evidence of substantial bias here as a result of measurement error. I will get more into why this happens below, but first lets look at the results for the fixed effects model.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(coefs.fixed, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>,</span>
<span id="cb15-2">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"effect of unemployment on log odds of identifying as black"</span>,</span>
<span id="cb15-3">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fixed effects bias"</span>)</span></code></pre></div></div>
<p><img src="https://aarongullickson.github.io/post/reportingerror/biasfixed.png" class="img-fluid"></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(coefs.fixed)</span></code></pre></div></div>
<pre><code>##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
## -1.350000 -0.223100  0.000000 -0.003183  0.211900  1.065000</code></pre>
<p>There is no systematic bias from the measurement error in the fixed effects model, although it does produce some substantial noise in the estimate. So, the fixed effects model seems to be robust to this form of measurement error, while the non-fixed effects model is not.</p>
</section>
<section id="what-is-driving-the-bias" class="level3">
<h3 class="anchored" data-anchor-id="what-is-driving-the-bias">What is driving the bias?</h3>
<p>By looking at the average unemployment among all four types of people (AA non-switchers, DD non-switchers, AD switchers, and DA switchers), we can get a clue as to the source of the bias.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(tabAA),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(tabDA)),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(tabAD),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(tabDD)))</span>
<span id="cb18-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(tab) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>)</span>
<span id="cb18-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(tab) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>)</span>
<span id="cb18-4"></span>
<span id="cb18-5">tab</span></code></pre></div></div>
<pre><code>##           A         D
## A 0.1000189 0.1087715
## D 0.1081952 0.2000196</code></pre>
<p>Because switchers are drawn randomly from the total population, their average unemployment rate will equal the population average in both cases of switching. The average unemployment rate of stayers on the other hand is very close to the group-specific averages (at least when the error rate is small). Thus when you compare AD switchers to AA stayers on the first row, AD switchers will have a higher unemployment rate. Similarly, when comparing DD stayers to DA switchers (the second row), the DA switchers will have a much lower unemployment rate. This is what produces the bias.</p>
<p>This bias disappears in the fixed-effects model because it only exists in the between-person comparisons (i.e.&nbsp;AA stayers to AD switchers and DD stayers to DA switchers). By definition, fixed-effects models only estimate within-person comparisons. Thus, the fixed-effects model is robust to this kind of bias.</p>
<p>I should also note that this table helps to illuminate why only inducing errors for race at time 1 inflates the bias significantly. Here is the output of that table when I ran this simulation with <code>dvError</code> set to FALSE.</p>
<pre><code>##            A         D
## A 0.10001088 0.1994540
## D 0.09881213 0.1999546</code></pre>
<p>Both types of switchers have unemployment rates that are the same as the race-specific unemployment rates of their group at time 2, rather than the population wide average. Therefore, the log odds ratio will just mirror the log-odds ratio in unemployment between the A and D groups, generally.</p>
</section>
<section id="what-is-measurement-error" class="level3">
<h3 class="anchored" data-anchor-id="what-is-measurement-error">What is measurement error?</h3>
<p>Given the results here, a key question is how big would we expect this measurement error to be and where does it come from? As I noted above, recording and/or transcription errors could clearly be classed as measurement error. I said in my original simulation that we should think of these errors as being produced at random in the data (I referred to this as “MCAR”“, although technically it should be ECAR, I suppose) and that is the way the errors are modeled in the simulation. In Hannon’s <a href="http://andrewgelman.com/2016/06/10/racial-classification-sociology-controversy-update/">response</a> on Gelman’s blog, he says:</p>
<blockquote class="blockquote">
<p>I don’t agree with his suggestion that accounting for measurement error in racial fluidity studies means a total focus on missing completely at random because “Anything else gets into the tricky question of what measurement error really means anyway on a variable with no real true response.” I think non-random measurement error matters too in this context.</p>
</blockquote>
<p>I was initially very confused by this response. Was Hannon suggesting that changes in the race response that were correlated with other variables (i.e.&nbsp;not completely at random) should be thought of as “non-random measurement error?” That would be odd, considering this is exactly what S&amp;P were trying to measure. It was only after I read the published KD&amp;H comment that I realized they were suggesting something else. KD&amp;H argue that the significant level of race reporting inconsistency over time is “not due to racial fluidity but rather a flawed classification scheme.” (pg. 235) Alba et. al.&nbsp;make a similar point. More specific to the issue of non-random measurement error, KD&amp;H argue in footnote 6 that:</p>
<blockquote class="blockquote">
<p>As S&amp;P note, in 1979, respondents chose from a list of 28 ethnicities/nationalities, but in 2002 they chose from only five racial groups and had a separate question about Hispanic ethnicity. This dramatic change in survey questions could obviously introduce significant error in longitudinal social science models. Such error need not be randomly distributed.</p>
</blockquote>
<p>It is absolutely true that the survey design will affect the degree of inconsistency in race reporting over time, but to think of this as measurement error is problematic. On a basic level, this kind of process does not correspond to the simulation that KD&amp;H themselves conducted. But on a more fundamental level, its a wrong-headed way to think about the process of racial identification and classification (as well as classification by gender, sexuality, social class, etc.) and reveals a superficial attachment to the notion of socially constructed identities. The disagreement here really gets to the core of the issue where I feel people involved in the debate are talking past each other. We are not measuring someone’s years of education or how many push-ups they did last week, both of which have an objectively true value. We are measuring a concept that all parties agree is socially constructed and subjective. The only measurement error that can logically exist is if when confronted with a set of categories, a person’s intent in that moment <em>relative to those categories</em> is incorrectly recorded. That a person’s response would be different with a different set of categories is not evidence of measurement error. At the risk of a lack of humility, let me quote <a href="http://abs.sagepub.com/content/60/4/498">myself</a> on this topic:</p>
<blockquote class="blockquote">
<p>Given this implicit correspondence between race and ancestry, it may be useful to make comparisons between the two responses by treating each response as a subjective assessment of a person’s essentialized identity. The goal is not to judge the accuracy of either report, which would be a quixotic task, but rather to understand the correspondence in reporting on two subjective responses in order to draw better conclusions about processes of identification, the nature of racial boundaries, and even racial inequality.</p>
</blockquote>
<p>I was referring in this quote to a comparison between race and ancestry reporting on the Census and ACS, but the basic point applies equally to this situation. What KD&amp;H see as a fundamental problem – that poor survey design induces inconsistency – is actually a virtue. Take the case of Hispanics. Both KD&amp;H and Alba et. al.&nbsp;point out that the high level of inconsistency for Hispanics is driven by the choice set of white/black/other that respondents faced for most waves of the NLSY79. Many Hispanics vacillated between white and other. Their point here is accurate, but is largely irrelevant to the findings of S&amp;P. If declining social status makes Hispanics more likely to choose “other” compared to “white”, then we have learned something. In this sense, the poor survey design can be exploited to draw interesting conclusions. Its not a bug, its a feature.</p>
</section>
</section>
<section id="what-now" class="level2">
<h2 class="anchored" data-anchor-id="what-now">What now?</h2>
<p>Given the results of the simulation, one suggestion might be that we move away from the basic regression model approach in future work toward fixed-effects models that are more robust to potential measurement error. This is a suggestion that KD&amp;H also make.</p>
<p>I think there is also potential for more advanced models here. Both KD&amp;H and Alba et. al.&nbsp;suggest that the model should really only be applied to individuals who are racially ambigious (i.e.&nbsp;that have the potential to be classified in multiple ways). Gelman in his <a href="http://andrewgelman.com/2016/06/07/social-problems-with-a-paper-in-social-problems/">blog post</a> says “For example, I’ll never be counted as “black” no matter how many times I go to jail.” Gelman suggests this might be a source of bias, but I have long thought that S&amp;P are probably underestimating the effect of social status change on racial reporting change, because they are averaging the effects across individuals who vary substantially in their probability to be differently classified. KD&amp;H and Alba et. al.&nbsp;suggest running the models on subsets that are believed to be more racially ambigious (e.g.&nbsp;latinos, multiracial individuals). I think this is an inefficient and overly simplistic approach. I think what we are after here is something like a “treatment on the treated” effect - the effect of switching on those who actually switched, except in this case the switching is the outcome, not the treatment. Some of the innovations in causal modeling on panel data may help provide more clarity in the future.</p>


</section>

 ]]></description>
  <category>racial fluidity</category>
  <category>modeling</category>
  <category>R</category>
  <guid>https://aarongullickson.github.io/post/reportingerror/</guid>
  <pubDate>Thu, 01 Sep 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>My First GitHub Repository</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/firstgithubrep/</link>
  <description><![CDATA[ 






<p>The <a href="https://en.wikipedia.org/wiki/Replication_crisis">recent crisis of replication</a> in psychology has increased <a href="http://opensciencefederation.com/">the call</a> to make our research analyses more open and reproducible. It is a movement that I fully support in principle, although there is little institutional support for it and limited incentive given the current norms of social science production and publication.</p>
<p>Over the last couple of years, I have been trying to incorporate more of the philosophy behind open-source programming into my research practices. Most notably, I have been keeping track of my research projects using the <a href="https://git-scm.com/">git</a> version control system. Version control has numerous benefits such as providing an effective back-up system, the ability to sync easily across different computers, a complete log of changes made, the ability to revert to prior versions, and the ability to collaborate without having to akwardly pass back and forth files and data with dates and version numbers ridiculously hardcoded into the file name (e.g.&nbsp;ourpaper06112015v12_agedits.docx).</p>
<p>Because I was using git already, it occurred to me that it should be straightforward to just make my repository available on <a href="https://github.com/">GitHub</a> for other scholars to clone. So, I decided to set up a GitHub repository for the the analysis from my most recent article “<a href="http://abs.sagepub.com/content/60/4/498">Essential Measures: Ancestry, Race, and Social Difference</a>” published in the American Behavioral Scientist.</p>
<p>After much trial and tribulation, that <a href="https://github.com/AaronGullickson/essentialmeasures">Github repository is now available</a>. It turned out to be a much more time-consuming process than simply cloning my existing repository. That repository was my own private fiefdom and although I always try to comment my code well and organize my scripts systematically, it was still littered with still-born and abandoned scripts, spots of poor commenting where even I couldn’t quite remember what I did, and the sloppy dumping of all output files and datasets into the same base directory. Ultimately, I had to start with a fresh repository, which I then selectively copied scripts into after cleaning up their commenting. I then had to make sure the whole thing actually still worked and replicated my analysis (spoiler: it did). In other words, it took a significant amount of “curating” to whip my code into something that would be intelligible by others.</p>
<p>I probably could have started with an easier project, in retrospect. This project involved Stata, R, and python scripts. Stata was the primary workhorse, which is a little unusual for me (normally its R). That caused all sorts of problems setting up a bash script to run the whole analysis because it appears that a command line stata executable is not linked to your path when you install Stata. The python script is also tricky because it requires the use of a special library called <a href="http://tuvalu.santafe.edu/~simon/page7/page7.html">THOTH</a> for calculating entropy via bootstrap. This library is difficult to install. I was able to install it on my linux box, but never could get it to work on my mac laptop. So, I ended up writing an alternate R script to calculate entropy for users who might not be able to get THOTH installed.</p>
<p>I learned a lot in the process of creating the repository. It really helped me think about how to organize my research practices from the beginning so that the level of curating necessary to produce this public record will be minimal. The knowledge that all of your analyses will be public in the future is a great motivator for writing clear and well-organized code. Some may <a href="http://www.nejm.org/doi/full/10.1056/NEJMe1516564">turn their nose up</a> at open science as some kind of objectionable surveillance. On the contrary, I have found that it really helps us as researchers be more clear from the beginning about what it is we are doing. It makes me feel like I am in dialogue with a larger community even as I sit in my office writing code with the lights off.</p>
<p>Here are some more practical points I have taken from the exercise:</p>
<ol type="1">
<li><p>The first thing that should go into any research project is a README file that can be updated as the project progresses. This README file should explain the relationship between the various scripts, data sources, and outputs.</p></li>
<li><p>Data restrictions! This project uses <a href="http://www.ipums.org">IPUMS</a> data. I am so used to the free and open nature of IPUMS data that it didn’t occur to me until late in the process that I might not be able to re-distribute my data. Sure enough, the data contract with IPUMS indicates that you cannot re-distribute without explicit permission, unless replicability is required by a journal. I understand the requirement, but I also feel that it needs to be amended in order to make the scientific process more open. I sent an email inquiring about the issue, but have not yet heard back. In the meantime, I decided to make the codebook for my IPUMS extract part of the repository so that users could easily reproduce my extract. However, I do feel that the lack of raw data is likely to lead most users to give up on experimenting with the analysis unless they are very interested in the topic. Even if I do get permission however, I am not sure if I will even be able to fit the data on GitHub. I have heard conflicting reports about the maximum size of data files. Even gzipped, the raw data file from the IPUMS extract is 640mb.</p></li>
<li><p>I never really thought about licensing the code I create. However, according to GitHub’s <a href="https://help.github.com/articles/open-source-licensing/">licensing FAQ</a>, without a license, default copyright laws apply which means “nobody else may reproduce, distribute, or create derivative works from your work.” This is certainly not what I want. Luckily, Github provides a <a href="http://choosealicense.com/">useful website</a> to help determine the best license. Apparently, a lot of academic work uses the <a href="http://choosealicense.com/licenses/cc-by-4.0/">Creative Commons Attribution 4.0 license</a>, but I felt that it seemed a bit intimidating at first glance, so I went with the short and sweet <a href="http://choosealicense.com/licenses/mit/">MIT license</a>.</p></li>
</ol>



 ]]></description>
  <category>github</category>
  <category>git</category>
  <category>open science</category>
  <category>ancestry</category>
  <guid>https://aarongullickson.github.io/post/firstgithubrep/</guid>
  <pubDate>Tue, 16 Aug 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Measuring Status Exchange</title>
  <dc:creator>Aaron Gullickson</dc:creator>
  <link>https://aarongullickson.github.io/post/statusexchangemodels/</link>
  <description><![CDATA[ 






<p>There has been a lot of interest in the log-linear methods used to measure exchange in <a href="http://link.springer.com/article/10.1353/dem.2006.0033#page-1">my 2006 Demography article</a> and in my <a href="http://link.springer.com/article/10.1007/s13524-014-0300-2">2014 Demography article</a> with <a href="https://sociology.stanford.edu/people/florencia-torche">Florencia Torche</a>. However, many people have expressed that the methods seem complex. In an effort to help people understand these models, I am providing here some basic code written in R that sets up the “market” and “dyadic” exchange models that we fit in Gullickson and Torche (2014).</p>
<p>I run the models on some <a href="usmardata1990.csv">1990 census data</a> that I had lying around, although I can’t verify how representative that data is, so the results here should not be used to draw conclusions. I also include some models to show that Rosenfeld’s proposed model corrections (namely conrtrolling for all two and three-way interaction terms) lead to perfect collinearity and are therefore bad models. I also show how to do the geometric mean models we discussed in the <a href="intermar_appendix.pdf">appendix</a> to the the Gullickson and Torche paper.</p>
<p>For those who prefer Stata, I also provide some commented <a href="statusexchangemodels.do">Stata code</a> that will do the same thing. The Stata code requires the installation of the desmat library to deal with all the interaction terms. Personally, I recommend the R code if you know R, but they should produce the same results.</p>
<section id="the-data" class="level1">
<h1>The Data</h1>
<p>The data used here is a 2x2x4x4 table (flattened) of husband’s race (HR) by wife’s race (WR) by husband’s education (HE) by wife’s education (WE). Race is white (1) and black (2). Education is less than high school (1), high school (2), some college (3), and college+ (4). The data come from the US Census 1990, but PLEASE NOTE that I found this data lying around in and cannot vouch for its completeness or representativeness. It is being used for demonstrative purposes and inferences and conclusions should not be drawn from it</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">mardata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"usmardata1990.csv"</span>)</span></code></pre></div></div>
</section>
<section id="dyadic-exchange-terms" class="level1">
<h1>Dyadic Exchange Terms</h1>
<p>I simply code a set of dummy variables for cases of non-homogamy among interracial couples. This is coded separately by the gender combination of the couple (BM/WF vs.&nbsp;WM/BF) and whether it implies upward or downward marriage for the black partner (not the woman).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEBMWFUp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-2">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEBMWFDown <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-3">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEWMBFUp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb2-4">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEWMBFDown <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span></code></pre></div></div>
<p>I also code symmetric terms, that assume the same upward and downward effect.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEBMWF <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb3-2">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEBMWF[mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb3-3">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEBMWF[mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb3-4">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEWMBF <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb3-5">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEWMBF[mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb3-6">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEWMBF[mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span></code></pre></div></div>
<p>Here is the most parsimonious term which assumes both directional symmetry and identical effects for BM/WF and WM/BF couples.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEBMWF<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SEWMBF</span></code></pre></div></div>
</section>
<section id="market-exchange-terms" class="level1">
<h1>Market Exchange Terms</h1>
<p>These terms are synonomous with the educational boundary terms in Gullickson (2006) which are themselves very similar to the terms used by <a href="http://link.springer.com/article/10.1353/dem.2001.0011">Fu (2001)</a>. As I will show below these terms are actually identical to fitting the three way HRxWRxHE and HRxWRxHE (and lower ordered HRxWE and WRxHE) tables, but this particular coding scheme makes the results more interpretable.I use “stairstep” coding here, such that each level of education gets the effect for that level PLUS the effect for lower levels. Using this technique means that each coefficient measures the difference between adjacent levels of education (e.g.&nbsp;college vs.&nbsp;some college) rather than between that level and a fixed reference (e.g.&nbsp;college vs.&nbsp;less than high school). I also included a commented out more traditional dummy formulation for users that prefer that style.</p>
<p>Each term here can be thought of as the increase in the likelihood of interracial marriage when education increases by one level for each race-gender type (i.e.&nbsp;black men, black women,white men, white women).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBBM1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-2">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBBM2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-3">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBBM3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-4"></span>
<span id="cb5-5">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBWF1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-6">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBWF2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-7">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBWF3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-8"></span>
<span id="cb5-9">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBWM1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb5-10">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBWM2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb5-11">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBWM3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb5-12"></span>
<span id="cb5-13">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBBF1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb5-14">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBBF2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb5-15">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>EBBF3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span></code></pre></div></div>
</section>
<section id="geometric-mean-of-hexwe" class="level1">
<h1>Geometric mean of HExWE</h1>
<p>One of Rosenfeld’s criticisms of prior research is that it did not correctly account for lower-order interaction terms when estimating the status exchange parameter. He argues that the status exchange term is a parameterized coding of the HExWExHRxWR table and thus it is necessary to fit all the three-way and two-way interactions. This includes HRxWRxHE, HRxWRxWE, HRxHExWE, WRxHExWE, HRxWE, and WRxHE. As the appendix to Gullickson and Torche (2014) makes clear, Rosenfeld is wrong about the nature of the dyadic status exchange term. It is actually a parameterized coding of the HExWExHR and HExWExWR tables. As a result, when Rosenfeld includes these terms, his models are overfit, as I will show below. The HRxWRxHE and HRxWRxWE tables are also identical to the market exchange terms coded here which can be thought of as an alternate way of measuring exchange rather than a nuisance control term. For more details, see Gullickson and Torche (2014) and the appendix, <a href="http://www.jstor.org/stable/10.1086/649049">Gullickson and Fu (2010)</a>, and <a href="http://www.jstor.org/stable/10.1086/649050?seq=1#page_scan_tab_contents">Kalmijn (2010)</a>.</p>
<p>Despite this inherent problems. Rosenfeld’s criticism does reveal one potential shortcoming of the way thesemodels are estimated. When estimating how different the educational assorative mating is for interracial couples (i.e.&nbsp;whether status exchange is occurring), interracial couples are implicitly being compared to the pooled tabled for white and black endogamous couples. But if white and black couples themselves differ in their patterns of ed assortative mating, then the results may be misleading. Probably the best way to handle this is that suggested by <a href="http://sf.oxfordjournals.org/content/72/1/119.short">Kalmijn (1993)</a> in which the baseline assumption about the educational assortative mating of black/white couples is taken as the geometric mean of the educational asortative mating (HExWE) of white and black endogamous couples. Gullickson and Torche (2014) discusses this in more detail (particularly the appendix). Ultimately we found the results to be similar using the geometric mean (and a few other specifications) as the more naive approach, but it is worth testing on a data set specific basis.</p>
<p>The way of coding this geometric mean is a bit tedious. I fit dummies for each of the nine terms in the HExWE table separately for white endogmous and black endogamous couples and then allow interracial couples to be a 0.5 on each dummy.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-2">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-3">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb6-4">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-5">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-6">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb6-7">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE7 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-8">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE8 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-9">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WWHEWE9 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb6-10"></span>
<span id="cb6-11">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-12">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-13">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb6-14">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-15">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-16">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb6-17">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE7 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-18">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE8 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb6-19">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>BBHEWE9 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (((mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mardata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
<p>Make sure R treats these as categories and not numbers:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HE)</span>
<span id="cb7-2">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WE)</span>
<span id="cb7-3">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>HR)</span>
<span id="cb7-4">mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(mardata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>WR)</span></code></pre></div></div>
</section>
<section id="the-models" class="level1">
<h1>The Models</h1>
<p>I first run a baseline model which just fits a general term for racial and educational homogamy (HRxWR and HExWE) as well as account for the differential distribution of education by race (HExHR and WExWR). This model also fits the four marginal terms themselves, of course. Then I fit separate dyadic and market exchange models, plus one that combines them both together. I also run a model with just the straight three way interactions of HRxWRxHE and HRxWRxWE (model.compare) to show that this model is identical to the market exchange model.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">model.base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Freq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span>poisson, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>mardata)</span>
<span id="cb8-2"></span>
<span id="cb8-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#dyadic - full symmetry in terms of up/down and couple type</span></span>
<span id="cb8-4">model.dyadic.symmetry <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SE)</span>
<span id="cb8-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.symmetry)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>,],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##   Estimate Std. Error    z value   Pr(&gt;|z|)
##      0.181      0.029      6.281      0.000</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#dyadic - relax symmetry on couple type but not up/down</span></span>
<span id="cb10-2">model.dyadic.partialsym <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWF<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBF)</span>
<span id="cb10-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.partialsym)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEBMWF"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEWMBF"</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##        Estimate Std. Error z value Pr(&gt;|z|)
## SEBMWF    0.206      0.034   6.130    0.000
## SEWMBF    0.111      0.056   1.967    0.049</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#dyadic - full model allowing different up/down and couple type</span></span>
<span id="cb12-2">model.dyadic.full <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFDown<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFDown)</span>
<span id="cb12-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.full)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEBMWFUpTRUE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEBMWFDownTRUE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEWMBFUpTRUE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEWMBFDownTRUE"</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##                Estimate Std. Error z value Pr(&gt;|z|)
## SEBMWFUpTRUE      0.311      0.055   5.605    0.000
## SEBMWFDownTRUE   -0.095      0.057  -1.664    0.096
## SEWMBFUpTRUE      0.035      0.092   0.382    0.703
## SEWMBFDownTRUE   -0.197      0.101  -1.948    0.051</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">model.market<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBM1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBM2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBM3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWF1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWF2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWF3</span>
<span id="cb14-2">                                     <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWM1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWM2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWM3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBF1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBF2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBF3)</span>
<span id="cb14-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBBM"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBBM1TRUE    0.065      0.092   0.706    0.480
## EBBM2TRUE    0.475      0.057   8.275    0.000
## EBBM3TRUE    0.156      0.075   2.076    0.038</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBWF"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBWF1TRUE   -0.327      0.086  -3.825    0.000
## EBWF2TRUE    0.062      0.057   1.093    0.274
## EBWF3TRUE   -0.118      0.072  -1.645    0.100</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBWM"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBWM1TRUE   -0.108      0.162  -0.668    0.504
## EBWM2TRUE    0.290      0.098   2.963    0.003
## EBWM3TRUE   -0.386      0.110  -3.511    0.000</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBBF"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBBF1TRUE   -0.039      0.182  -0.214    0.831
## EBBF2TRUE    0.283      0.100   2.834    0.005
## EBBF3TRUE    0.080      0.109   0.737    0.461</code></pre>
<p>It can be shown that the market exchange model is just a re-parameterized version of a model with the three-way tables of HWxWRxHE and HRxWRxWE:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">model.compare <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE)</span>
<span id="cb22-2"></span>
<span id="cb22-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#models are the same</span></span>
<span id="cb22-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anova</span>(model.market, model.compare)</span></code></pre></div></div>
<pre><code>## Analysis of Deviance Table
##
## Model 1: Freq ~ HR + WR + HE + WE + EBBM1 + EBBM2 + EBBM3 + EBWF1 + EBWF2 +
##     EBWF3 + EBWM1 + EBWM2 + EBWM3 + EBBF1 + EBBF2 + EBBF3 + HR:WR +
##     HR:HE + WR:WE + HE:WE
## Model 2: Freq ~ HR + WR + HE + WE + HR:WR + HR:HE + WR:WE + HE:WE + WR:HE +
##     HR:WE + HR:WR:HE + HR:WR:WE
##   Resid. Df Resid. Dev Df   Deviance
## 1        27     129.31
## 2        27     129.31  0 4.6612e-12</code></pre>
<p>I also run a model with both, I think this model is too complex and multicollinear to estimate well for the size of the US data</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1">model.both <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.market, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFDown<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFDown)</span>
<span id="cb24-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.both)</span></code></pre></div></div>
<pre><code>##
## Call:
## glm(formula = Freq ~ HR + WR + HE + WE + EBBM1 + EBBM2 + EBBM3 +
##     EBWF1 + EBWF2 + EBWF3 + EBWM1 + EBWM2 + EBWM3 + EBBF1 + EBBF2 +
##     EBBF3 + SEBMWFUp + SEBMWFDown + SEWMBFUp + SEWMBFDown + HR:WR +
##     HR:HE + WR:WE + HE:WE, family = poisson, data = mardata)
##
## Deviance Residuals:
##     Min       1Q   Median       3Q      Max
## -4.2687  -0.6727  -0.0512   0.8401   3.5696
##
## Coefficients:
##                 Estimate Std. Error  z value Pr(&gt;|z|)
## (Intercept)     9.433917   0.008771 1075.539  &lt; 2e-16 ***
## HR2            -5.248402   0.097723  -53.707  &lt; 2e-16 ***
## WR2            -6.592480   0.189743  -34.744  &lt; 2e-16 ***
## HE2             0.123694   0.011866   10.424  &lt; 2e-16 ***
## HE3            -1.107176   0.017309  -63.964  &lt; 2e-16 ***
## HE4            -3.064602   0.041522  -73.806  &lt; 2e-16 ***
## WE2             0.298178   0.011448   26.046  &lt; 2e-16 ***
## WE3            -0.757925   0.015195  -49.880  &lt; 2e-16 ***
## WE4            -2.791104   0.035573  -78.460  &lt; 2e-16 ***
## EBBM1TRUE       0.044220   0.120767    0.366  0.71424
## EBBM2TRUE       0.440828   0.100567    4.383 1.17e-05 ***
## EBBM3TRUE       0.132652   0.110613    1.199  0.23043
## EBWF1TRUE      -0.286336   0.114631   -2.498  0.01249 *
## EBWF2TRUE       0.095140   0.101745    0.935  0.34975
## EBWF3TRUE      -0.092201   0.107721   -0.856  0.39204
## EBWM1TRUE       0.037637   0.207485    0.181  0.85606
## EBWM2TRUE       0.463988   0.177990    2.607  0.00914 **
## EBWM3TRUE      -0.199226   0.188281   -1.058  0.29000
## EBBF1TRUE      -0.205636   0.225675   -0.911  0.36219
## EBBF2TRUE       0.106623   0.176812    0.603  0.54649
## EBBF3TRUE      -0.104977   0.186340   -0.563  0.57319
## SEBMWFUpTRUE    0.129040   0.113272    1.139  0.25462
## SEBMWFDownTRUE  0.054126   0.115582    0.468  0.63958
## SEWMBFUpTRUE    0.166370   0.199566    0.834  0.40447
## SEWMBFDownTRUE -0.290923   0.204039   -1.426  0.15392
## HR2:WR2         9.415216   0.214532   43.887  &lt; 2e-16 ***
## HR2:HE2        -0.009614   0.020975   -0.458  0.64671
## HR2:HE3        -0.161524   0.022436   -7.199 6.05e-13 ***
## HR2:HE4        -0.946840   0.027690  -34.194  &lt; 2e-16 ***
## WR2:WE2        -0.003369   0.023034   -0.146  0.88372
## WR2:WE3         0.215772   0.023881    9.035  &lt; 2e-16 ***
## WR2:WE4         0.052217   0.028100    1.858  0.06313 .
## HE2:WE2         1.493872   0.014242  104.892  &lt; 2e-16 ***
## HE3:WE2         1.914786   0.019376   98.825  &lt; 2e-16 ***
## HE4:WE2         2.599609   0.043212   60.159  &lt; 2e-16 ***
## HE2:WE3         1.804567   0.017698  101.967  &lt; 2e-16 ***
## HE3:WE3         3.460550   0.021548  160.597  &lt; 2e-16 ***
## HE4:WE3         4.710513   0.043668  107.871  &lt; 2e-16 ***
## HE2:WE4         2.392793   0.037683   63.499  &lt; 2e-16 ***
## HE3:WE4         4.417645   0.039069  113.073  &lt; 2e-16 ***
## HE4:WE4         7.437631   0.054080  137.529  &lt; 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
##     Null deviance: 1359384.24  on 63  degrees of freedom
## Residual deviance:     123.07  on 23  degrees of freedom
## AIC: 696.5
##
## Number of Fisher Scoring iterations: 4</code></pre>
</section>
<section id="rosenfeld-models" class="level1">
<h1>Rosenfeld Models</h1>
<p>I follow rosenfeld’s protocol of adding in all of the missing two and three way tables and show that his method leads to collinearity such that terms are dropped from the model. This happens because of collinearity between the HExWExHR and HExWExWR terms and the dyadic exchange term.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1">model.dyadic.symmetry.rosen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.dyadic.symmetry, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR)</span>
<span id="cb26-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.symmetry.rosen)</span></code></pre></div></div>
<pre><code>##
## Call:
## glm(formula = Freq ~ HR + WR + HE + WE + SE + HR:WR + HR:HE +
##     WR:WE + HE:WE + WR:HE + HR:WE + HR:WR:HE + HR:WR:WE + HR:HE:WE +
##     WR:HE:WE, family = poisson, data = mardata)
##
## Deviance Residuals:
##      Min        1Q    Median        3Q       Max
## -2.00114  -0.11134   0.00007   0.09103   0.86440
##
## Coefficients: (1 not defined because of singularities)
##              Estimate Std. Error  z value Pr(&gt;|z|)
## (Intercept)  9.442819   0.008901 1060.919  &lt; 2e-16 ***
## HR2         -5.515703   0.132445  -41.645  &lt; 2e-16 ***
## WR2         -6.459140   0.189711  -34.047  &lt; 2e-16 ***
## HE2          0.110730   0.012251    9.038  &lt; 2e-16 ***
## HE3         -1.124848   0.017972  -62.588  &lt; 2e-16 ***
## HE4         -3.105487   0.042970  -72.272  &lt; 2e-16 ***
## WE2          0.286471   0.011776   24.327  &lt; 2e-16 ***
## WE3         -0.773848   0.015838  -48.860  &lt; 2e-16 ***
## WE4         -2.831289   0.037708  -75.084  &lt; 2e-16 ***
## SE          -0.238405   0.513277   -0.464 0.642306
## HR2:WR2      9.445999   0.205511   45.963  &lt; 2e-16 ***
## HR2:HE2      0.799361   0.513035    1.558 0.119209
## HR2:HE3      1.024105   0.482226    2.124 0.033695 *
## HR2:HE4      0.728863   0.695441    1.048 0.294611
## WR2:WE2     -0.067885   0.574681   -0.118 0.905968
## WR2:WE3      0.278550   0.584551    0.477 0.633704
## WR2:WE4      0.952901   0.977790    0.975 0.329786
## HE2:WE2      1.508189   0.014876  101.383  &lt; 2e-16 ***
## HE3:WE2      1.941309   0.020216   96.028  &lt; 2e-16 ***
## HE4:WE2      2.637738   0.044730   58.971  &lt; 2e-16 ***
## HE2:WE3      1.828234   0.018611   98.234  &lt; 2e-16 ***
## HE3:WE3      3.484150   0.022600  154.163  &lt; 2e-16 ***
## HE4:WE3      4.757091   0.045287  105.044  &lt; 2e-16 ***
## HE2:WE4      2.440390   0.039969   61.057  &lt; 2e-16 ***
## HE3:WE4      4.460603   0.041393  107.762  &lt; 2e-16 ***
## HE4:WE4      7.511727   0.056616  132.678  &lt; 2e-16 ***
## WR2:HE2     -0.740162   0.517347   -1.431 0.152520
## WR2:HE3     -0.279076   0.479371   -0.582 0.560452
## WR2:HE4     -0.453587   0.710676   -0.638 0.523313
## HR2:WE2     -0.090518   0.566985   -0.160 0.873158
## HR2:WE3      0.148923   0.578828    0.257 0.796959
## HR2:WE4     -0.467346   0.976898   -0.478 0.632367
## HR2:WR2:HE2  0.075881   0.190844    0.398 0.690921
## HR2:WR2:HE3 -0.688182   0.194748   -3.534 0.000410 ***
## HR2:WR2:HE4 -0.465144   0.217321   -2.140 0.032326 *
## HR2:WR2:WE2  0.288773   0.206524    1.398 0.162037
## HR2:WR2:WE3 -0.049173   0.209064   -0.235 0.814048
## HR2:WR2:WE4 -0.018368   0.230452   -0.080 0.936474
## HR2:HE2:WE2 -0.687546   0.191297   -3.594 0.000325 ***
## HR2:HE3:WE2 -0.316237   0.625629   -0.505 0.613229
## HR2:HE4:WE2 -0.571651   0.752693   -0.759 0.447569
## HR2:HE2:WE3 -1.112013   0.534309   -2.081 0.037414 *
## HR2:HE3:WE3 -0.740565   0.252233   -2.936 0.003324 **
## HR2:HE4:WE3 -0.797097   0.751690   -1.060 0.288960
## HR2:HE2:WE4 -0.439894   0.267458   -1.645 0.100027
## HR2:HE3:WE4 -0.451155   0.128731   -3.505 0.000457 ***
## HR2:HE4:WE4 -0.602608   0.680483   -0.886 0.375855
## WR2:HE2:WE2  0.529706   0.194919    2.718 0.006576 **
## WR2:HE3:WE2 -0.019024   0.632898   -0.030 0.976020
## WR2:HE4:WE2 -0.062874   0.765853   -0.082 0.934570
## WR2:HE2:WE3  0.873657   0.534613    1.634 0.102220
## WR2:HE3:WE3  0.473865   0.258185    1.835 0.066451 .
## WR2:HE4:WE3  0.012654   0.764538    0.017 0.986794
## WR2:HE2:WE4 -0.060050   0.244462   -0.246 0.805960
## WR2:HE3:WE4        NA         NA       NA       NA
## WR2:HE4:WE4 -0.521754   0.692958   -0.753 0.451488
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
##     Null deviance: 1.3594e+06  on 63  degrees of freedom
## Residual deviance: 1.5464e+01  on  9  degrees of freedom
## AIC: 616.89
##
## Number of Fisher Scoring iterations: 4</code></pre>
<p>The same holds for the other dyadic models but I don’t show them for brevity</p>
<p>I show that dropping out HExWExHR and HExWExWR resolves the problem.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1">model.dyadic.symmetry2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.dyadic.symmetry.rosen, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WE)</span>
<span id="cb28-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.symmetry2)</span></code></pre></div></div>
<pre><code>##
## Call:
## glm(formula = Freq ~ SE + HE + WE + HR + WR + HR:WR + HE:WE +
##     HR:HE + WR:WE + HR:WR:HE + HR:WR:WE, family = poisson, data = mardata)
##
## Deviance Residuals:
##     Min       1Q   Median       3Q      Max
## -4.2768  -0.6448  -0.0025   0.9059   3.5663
##
## Coefficients:
##               Estimate Std. Error  z value Pr(&gt;|z|)
## (Intercept)  9.4336620  0.0087707 1075.582   &lt;2e-16 ***
## SE           0.0896727  0.0921363    0.973   0.3304
## HE2          0.1240076  0.0118625   10.454   &lt;2e-16 ***
## HE3         -1.1064333  0.0173026  -63.946   &lt;2e-16 ***
## HE4         -3.0637522  0.0415174  -73.794   &lt;2e-16 ***
## WE2          0.2986655  0.0114452   26.095   &lt;2e-16 ***
## WE3         -0.7577437  0.0151914  -49.880   &lt;2e-16 ***
## WE4         -2.7912246  0.0355690  -78.473   &lt;2e-16 ***
## HR2         -5.1859816  0.0913501  -56.770   &lt;2e-16 ***
## WR2         -6.6378141  0.1833072  -36.211   &lt;2e-16 ***
## HR2:WR2      9.3981456  0.2059242   45.639   &lt;2e-16 ***
## HE2:WE2      1.4931995  0.0142350  104.896   &lt;2e-16 ***
## HE3:WE2      1.9139129  0.0193652   98.832   &lt;2e-16 ***
## HE4:WE2      2.5988140  0.0432090   60.145   &lt;2e-16 ***
## HE2:WE3      1.8045918  0.0176897  102.014   &lt;2e-16 ***
## HE3:WE3      3.4596951  0.0215402  160.616   &lt;2e-16 ***
## HE4:WE3      4.7097796  0.0436655  107.861   &lt;2e-16 ***
## HE2:WE4      2.3927802  0.0376795   63.503   &lt;2e-16 ***
## HE3:WE4      4.4175471  0.0390664  113.078   &lt;2e-16 ***
## HE4:WE4      7.4370806  0.0540787  137.523   &lt;2e-16 ***
## HE2:HR2     -0.0116255  0.1134661   -0.102   0.9184
## HE3:HR2      0.2408140  0.1694825    1.421   0.1554
## HE4:HR2     -0.4581314  0.2400019   -1.909   0.0563 .
## WE2:WR2     -0.1067811  0.1921746   -0.556   0.5785
## WE3:WR2      0.3248699  0.2278745    1.426   0.1540
## WE4:WR2      0.1699295  0.2906272    0.585   0.5587
## HE2:HR1:WR2 -0.0480788  0.1739408   -0.276   0.7822
## HE3:HR1:WR2  0.3128585  0.2135509    1.465   0.1429
## HE4:HR1:WR2  0.0006849  0.2793518    0.002   0.9980
## HE2:HR2:WR2  0.0020019  0.1150646    0.017   0.9861
## HE3:HR2:WR2 -0.4022965  0.1707187   -2.356   0.0184 *
## HE4:HR2:WR2 -0.4886577  0.2413877   -2.024   0.0429 *
## WE2:HR2:WR1 -0.2614800  0.1092373   -2.394   0.0167 *
## WE3:HR2:WR1 -0.1269414  0.1681540   -0.755   0.4503
## WE4:HR2:WR1 -0.1754218  0.2377134   -0.738   0.4605
## WE2:HR2:WR2  0.1034074  0.1933343    0.535   0.5927
## WE3:HR2:WR2 -0.1091439  0.2289138   -0.477   0.6335
## WE4:HR2:WR2 -0.1178039  0.2917812   -0.404   0.6864
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
##     Null deviance: 1359384.24  on 63  degrees of freedom
## Residual deviance:     128.37  on 26  degrees of freedom
## AIC: 695.79
##
## Number of Fisher Scoring iterations: 4</code></pre>
<p>The resulting model is equivalent to a model with both a dyadic and market exchange term</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">model.equivalent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.market, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SE)</span>
<span id="cb30-2"></span>
<span id="cb30-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#models are the same</span></span>
<span id="cb30-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anova</span>(model.dyadic.symmetry2, model.equivalent)</span></code></pre></div></div>
<pre><code>## Analysis of Deviance Table
##
## Model 1: Freq ~ SE + HE + WE + HR + WR + HR:WR + HE:WE + HR:HE + WR:WE +
##     HR:WR:HE + HR:WR:WE
## Model 2: Freq ~ HR + WR + HE + WE + EBBM1 + EBBM2 + EBBM3 + EBWF1 + EBWF2 +
##     EBWF3 + EBWM1 + EBWM2 + EBWM3 + EBBF1 + EBBF2 + EBBF3 + SE +
##     HR:WR + HR:HE + WR:WE + HE:WE
##   Resid. Df Resid. Dev Df   Deviance
## 1        26     128.37
## 2        26     128.37  0 1.0829e-11</code></pre>
</section>
<section id="geometric-mean-models" class="level1">
<h1>Geometric Mean Models</h1>
<p>Here I just rerun the dyadic and market exchange models with the geometric mean baseline rather than the pooled HE*WE baseline. The results are fairly consistent with what we had before for BM/WF couples, but not WM/BF couples.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">model.base.geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Freq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>HE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>HR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WE<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>WR</span>
<span id="cb32-2">                      <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE5<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE6<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE7<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE8<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>WWHEWE9</span>
<span id="cb32-3">                      <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE5<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE6<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE7<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE8<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>BBHEWE9,</span>
<span id="cb32-4">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span>poisson, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>mardata)</span>
<span id="cb32-5"></span>
<span id="cb32-6">model.dyadic.symmetry.geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base.geo, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SE)</span>
<span id="cb32-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.symmetry.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>,],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##   Estimate Std. Error    z value   Pr(&gt;|z|)
##      0.094      0.032      2.909      0.004</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">model.dyadic.partialsym.geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base.geo, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWF<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBF)</span>
<span id="cb34-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.partialsym.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEBMWF"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEWMBF"</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##        Estimate Std. Error z value Pr(&gt;|z|)
## SEBMWF    0.127      0.037   3.462    0.001
## SEWMBF    0.002      0.059   0.026    0.979</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">model.dyadic.full.geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base.geo, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFDown<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFDown)</span>
<span id="cb36-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.dyadic.full.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEBMWFUpTRUE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEBMWFDownTRUE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEWMBFUpTRUE"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SEWMBFDownTRUE"</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##                Estimate Std. Error z value Pr(&gt;|z|)
## SEBMWFUpTRUE      0.228      0.058   3.955    0.000
## SEBMWFDownTRUE   -0.021      0.059  -0.349    0.727
## SEWMBFUpTRUE     -0.084      0.094  -0.889    0.374
## SEWMBFDownTRUE   -0.099      0.103  -0.966    0.334</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1">model.market.geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.base.geo, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBM1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBM2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBM3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWF1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWF2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWF3</span>
<span id="cb38-2">                                     <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWM1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWM2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBWM3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBF1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBF2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>EBBF3)</span>
<span id="cb38-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBBM"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBBM1TRUE   -0.023      0.094  -0.245    0.807
## EBBM2TRUE    0.443      0.066   6.758    0.000
## EBBM3TRUE   -0.117      0.115  -1.020    0.308</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBWF"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBWF1TRUE   -0.246      0.087  -2.820    0.005
## EBWF2TRUE    0.072      0.062   1.175    0.240
## EBWF3TRUE    0.012      0.092   0.127    0.899</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBWM"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBWM1TRUE   -0.029      0.163  -0.181    0.856
## EBWM2TRUE    0.321      0.103   3.124    0.002
## EBWM3TRUE   -0.112      0.140  -0.798    0.425</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.market.geo)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coef[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EBBF"</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),],<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<pre><code>##           Estimate Std. Error z value Pr(&gt;|z|)
## EBBF1TRUE   -0.105      0.182  -0.576    0.565
## EBBF2TRUE    0.264      0.103   2.574    0.010
## EBBF3TRUE   -0.036      0.122  -0.297    0.767</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1">model.both.geo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(model.market.geo, .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEBMWFDown<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFUp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>SEWMBFDown)</span>
<span id="cb46-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model.both.geo)</span></code></pre></div></div>
<pre><code>##
## Call:
## glm(formula = Freq ~ HR + WR + HE + WE + WWHEWE1 + WWHEWE2 +
##     WWHEWE3 + WWHEWE4 + WWHEWE5 + WWHEWE6 + WWHEWE7 + WWHEWE8 +
##     WWHEWE9 + BBHEWE1 + BBHEWE2 + BBHEWE3 + BBHEWE4 + BBHEWE5 +
##     BBHEWE6 + BBHEWE7 + BBHEWE8 + BBHEWE9 + EBBM1 + EBBM2 + EBBM3 +
##     EBWF1 + EBWF2 + EBWF3 + EBWM1 + EBWM2 + EBWM3 + EBBF1 + EBBF2 +
##     EBBF3 + SEBMWFUp + SEBMWFDown + SEWMBFUp + SEWMBFDown + HR:WR +
##     HR:HE + WR:WE, family = poisson, data = mardata)
##
## Deviance Residuals:
##      Min        1Q    Median        3Q       Max
## -2.04068  -0.15854  -0.00307   0.08040   1.29960
##
## Coefficients:
##                  Estimate Std. Error  z value Pr(&gt;|z|)
## (Intercept)     9.4424651  0.0089015 1060.771  &lt; 2e-16 ***
## HR2            -5.2992451  0.0992333  -53.402  &lt; 2e-16 ***
## WR2            -6.6419054  0.1916985  -34.648  &lt; 2e-16 ***
## HE2             0.1113715  0.0122500    9.092  &lt; 2e-16 ***
## HE3            -1.1244246  0.0179676  -62.581  &lt; 2e-16 ***
## HE4            -3.1048894  0.0429522  -72.287  &lt; 2e-16 ***
## WE2             0.2869685  0.0117756   24.370  &lt; 2e-16 ***
## WE3            -0.7731030  0.0158353  -48.821  &lt; 2e-16 ***
## WE4            -2.8312119  0.0377131  -75.072  &lt; 2e-16 ***
## WWHEWE1         1.5073958  0.0148737  101.346  &lt; 2e-16 ***
## WWHEWE2         1.8270943  0.0186076   98.191  &lt; 2e-16 ***
## WWHEWE3         2.4401371  0.0399709   61.048  &lt; 2e-16 ***
## WWHEWE4         1.9407072  0.0202114   96.021  &lt; 2e-16 ***
## WWHEWE5         3.4833896  0.0225929  154.181  &lt; 2e-16 ***
## WWHEWE6         4.4603494  0.0413926  107.757  &lt; 2e-16 ***
## WWHEWE7         2.6369640  0.0447113   58.978  &lt; 2e-16 ***
## WWHEWE8         4.7560636  0.0452671  105.067  &lt; 2e-16 ***
## WWHEWE9         7.5114299  0.0566029  132.704  &lt; 2e-16 ***
## BBHEWE1         1.3410881  0.0502215   26.703  &lt; 2e-16 ***
## BBHEWE2         1.5779047  0.0585859   26.933  &lt; 2e-16 ***
## BBHEWE3         1.9362962  0.1155999   16.750  &lt; 2e-16 ***
## BBHEWE4         1.5986861  0.0694740   23.011  &lt; 2e-16 ***
## BBHEWE5         3.2093970  0.0736196   43.594  &lt; 2e-16 ***
## BBHEWE6         4.0051074  0.1216050   32.935  &lt; 2e-16 ***
## BBHEWE7         1.9926851  0.1731084   11.511  &lt; 2e-16 ***
## BBHEWE8         3.9602726  0.1708851   23.175  &lt; 2e-16 ***
## BBHEWE9         6.3820746  0.1947376   32.773  &lt; 2e-16 ***
## EBBM1TRUE      -0.0768475  0.1208813   -0.636 0.524955
## EBBM2TRUE       0.3702178  0.1052368    3.518 0.000435 ***
## EBBM3TRUE      -0.1798681  0.1407477   -1.278 0.201268
## EBWF1TRUE      -0.1700799  0.1153182   -1.475 0.140246
## EBWF2TRUE       0.1432551  0.1023114    1.400 0.161458
## EBWF3TRUE       0.0741508  0.1208766    0.613 0.539584
## EBWM1TRUE       0.0836009  0.2055211    0.407 0.684173
## EBWM2TRUE       0.4612129  0.1771260    2.604 0.009218 **
## EBWM3TRUE       0.0421616  0.2045247    0.206 0.836678
## EBBF1TRUE      -0.2424182  0.2239950   -1.082 0.279142
## EBBF2TRUE       0.1226603  0.1755297    0.699 0.484677
## EBBF3TRUE      -0.1889397  0.1926369   -0.981 0.326688
## SEBMWFUpTRUE    0.1713216  0.1123854    1.524 0.127406
## SEBMWFDownTRUE -0.0002799  0.1147010   -0.002 0.998053
## SEWMBFUpTRUE    0.1163524  0.1968910    0.591 0.554555
## SEWMBFDownTRUE -0.2600328  0.2019226   -1.288 0.197821
## HR2:WR2         9.4082094  0.2166726   43.421  &lt; 2e-16 ***
## HR2:HE2         0.1420302  0.0436537    3.254 0.001140 **
## HR2:HE3         0.0616976  0.0644029    0.958 0.338065
## HR2:HE4        -0.1823256  0.1702354   -1.071 0.284160
## WR2:WE2         0.1358971  0.0421421    3.225 0.001261 **
## WR2:WE3         0.3853543  0.0519410    7.419 1.18e-13 ***
## WR2:WE4         0.4693778  0.1136058    4.132 3.60e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
##     Null deviance: 1.3594e+06  on 63  degrees of freedom
## Residual deviance: 2.6313e+01  on 14  degrees of freedom
## AIC: 617.74
##
## Number of Fisher Scoring iterations: 4</code></pre>


</section>

 ]]></description>
  <category>status exchange</category>
  <category>modeling</category>
  <category>intermarriage</category>
  <category>R</category>
  <guid>https://aarongullickson.github.io/post/statusexchangemodels/</guid>
  <pubDate>Fri, 05 Aug 2016 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
