<?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>Blue Cognition</title>
<link>https://www.bluecognition.net/</link>
<atom:link href="https://www.bluecognition.net/index.xml" rel="self" type="application/rss+xml"/>
<description>People analytics, decoded — data-driven essays on HR strategy, workforce metrics, and organizational behavior.</description>
<generator>quarto-1.8.25</generator>
<lastBuildDate>Thu, 09 Apr 2026 04:00:00 GMT</lastBuildDate>
<item>
  <title>Welcome to Blue Cognition People Analytics Blog</title>
  <dc:creator>Felix Betancourt</dc:creator>
  <link>https://www.bluecognition.net/posts/welcome/</link>
  <description><![CDATA[ 




<section id="data-has-always-been-about-people" class="level2">
<h2 class="anchored" data-anchor-id="data-has-always-been-about-people">Data Has Always Been About People</h2>
<p>For over two decades I’ve worked in HR — hiring, developing, and retaining talent across industries and countries. And throughout that journey, one thing has become clear: <strong>the best HR decisions aren’t made by gut feeling alone</strong>.</p>
<p>Data changes how we see people — not as numbers, but as patterns. Patterns of engagement, of attrition risk, of what makes a team thrive or fall apart. When used thoughtfully, analytics doesn’t dehumanize HR. It makes it more precise, more fair, and more impactful.</p>
</section>
<section id="what-this-blog-is-about" class="level2">
<h2 class="anchored" data-anchor-id="what-this-blog-is-about">What This Blog Is About</h2>
<p><strong>Blue Cognition</strong> is my consulting practice. This blog is where I think out loud — combining my years of HR experience with the data science skills I’ve been building.</p>
<p>You’ll find:</p>
<ul>
<li>📊 <strong>Analyses</strong> — real datasets, R code, and insights on workforce topics</li>
<li>🧠 <strong>Deep dives</strong> — organizational behavior, talent strategy, culture</li>
<li>🤖 <strong>AI &amp; HR</strong> — practical applications of machine learning in people management</li>
<li>🛠️ <strong>Tutorials</strong> — how to do people analytics in R, step by step</li>
</ul>
</section>
<section id="why-r" class="level2">
<h2 class="anchored" data-anchor-id="why-r">Why R?</h2>
<p>R is my tool of choice. It’s the language of data science in academia and increasingly in business analytics. Combined with Quarto, I can write posts that are fully reproducible — you can run the code yourself and see exactly how I got there.</p>
</section>
<section id="lets-connect" class="level2">
<h2 class="anchored" data-anchor-id="lets-connect">Let’s Connect</h2>
<p>If you’re an HR professional curious about data, a data scientist interested in organizational topics, or a business leader trying to make sense of your workforce — this blog is for you.</p>
<p>Feel free to reach out on <a href="https://www.linkedin.com/in/felixbetancourt/">LinkedIn</a>.</p>
<p>— Felix</p>


<!-- -->

</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{betancourt2026,
  author = {Betancourt, Felix},
  title = {Welcome to {Blue} {Cognition} {People} {Analytics} {Blog}},
  date = {2026-04-09},
  url = {https://www.bluecognition.net/posts/welcome/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-betancourt2026" class="csl-entry quarto-appendix-citeas">
Betancourt, Felix. 2026. <span>“Welcome to Blue Cognition People
Analytics Blog.”</span> April 9, 2026. <a href="https://www.bluecognition.net/posts/welcome/">https://www.bluecognition.net/posts/welcome/</a>.
</div></div></section></div> ]]></description>
  <category>welcome</category>
  <category>people analytics</category>
  <category>HR strategy</category>
  <guid>https://www.bluecognition.net/posts/welcome/</guid>
  <pubDate>Thu, 09 Apr 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.bluecognition.net/posts/welcome/thumbnail.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>HR Metrics Every People Analytics Team Should Track</title>
  <dc:creator>Felix Betancourt</dc:creator>
  <link>https://www.bluecognition.net/posts/post-with-code/</link>
  <description><![CDATA[ 




<section id="why-hr-metrics-matter" class="level2">
<h2 class="anchored" data-anchor-id="why-hr-metrics-matter">Why HR Metrics Matter</h2>
<p>Most HR departments collect data. Far fewer actually use it. The gap between having a spreadsheet and having insight is where People Analytics lives.</p>
<p>In this post I’ll walk through the <strong>five foundational HR metrics</strong> every analytics-capable team should have on their dashboard — and show how to calculate them in R.</p>
</section>
<section id="setup" class="level2">
<h2 class="anchored" data-anchor-id="setup">Setup</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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>(tidyverse)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulated employee dataset</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)</span>
<span id="cb1-5">n <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;">500</span></span>
<span id="cb1-6"></span>
<span id="cb1-7">employees <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;">tibble</span>(</span>
<span id="cb1-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">employee_id   =</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>n,</span>
<span id="cb1-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hire_date     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2018-01-01"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-01-01"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"day"</span>), n, <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;">TRUE</span>),</span>
<span id="cb1-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">term_date =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</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;">as.Date</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;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2020-01-01"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-12-31"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"day"</span>), n, <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;">TRUE</span>)), n, <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;">TRUE</span>),</span>
<span id="cb1-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">department    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</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;">"Sales"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Engineering"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HR"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Finance"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Operations"</span>), n, <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;">TRUE</span>),</span>
<span id="cb1-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">salary        =</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;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20000</span>)),</span>
<span id="cb1-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">performance   =</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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, n, <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;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.40</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>)),</span>
<span id="cb1-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">active        =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(term_date)</span>
<span id="cb1-15">)</span></code></pre></div></div>
</details>
</div>
</section>
<section id="headcount" class="level2">
<h2 class="anchored" data-anchor-id="headcount">1. Headcount</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">headcount <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> employees <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(active) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(department, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"headcount"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(headcount))</span>
<span id="cb2-5"></span>
<span id="cb2-6">headcount</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 2
  department headcount
  &lt;chr&gt;          &lt;int&gt;
1 Finance            1
2 HR                 1</code></pre>
</div>
</div>
</section>
<section id="turnover-rate" class="level2">
<h2 class="anchored" data-anchor-id="turnover-rate">2. Turnover Rate</h2>
<p>Annualized voluntary turnover is one of the most watched metrics in HR:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BTurnover%20Rate%7D%20=%20%5Cfrac%7B%5Ctext%7BSeparations%20in%20Period%7D%7D%7B%5Ctext%7BAverage%20Headcount%7D%7D%20%5Ctimes%20100"></p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">separations_2024 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> employees <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</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;">is.na</span>(term_date), </span>
<span id="cb4-3">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">between</span>(term_date, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-01-01"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-12-31"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>()</span>
<span id="cb4-5"></span>
<span id="cb4-6">avg_headcount <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> employees <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(hire_date <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;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024-12-31"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>()</span>
<span id="cb4-9"></span>
<span id="cb4-10">turnover_rate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (separations_2024 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> avg_headcount) <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;">100</span></span>
<span id="cb4-11"></span>
<span id="cb4-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual Turnover Rate (2024):"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(turnover_rate, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Annual Turnover Rate (2024): 17.6 %</code></pre>
</div>
</div>
</section>
<section id="average-tenure" class="level2">
<h2 class="anchored" data-anchor-id="average-tenure">3. Average Tenure</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">employees <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_date  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(active, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.Date</span>(), term_date),</span>
<span id="cb6-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tenure_yrs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(end_date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> hire_date) <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;">365.25</span></span>
<span id="cb6-5">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(department) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_tenure_years =</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;">mean</span>(tenure_yrs), <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;">|&gt;</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(avg_tenure_years))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 5 × 2
  department  avg_tenure_years
  &lt;chr&gt;                  &lt;dbl&gt;
1 Finance                  1.5
2 Engineering              1.4
3 HR                       1.4
4 Sales                    1.4
5 Operations               1.1</code></pre>
</div>
</div>
</section>
<section id="salary-distribution-by-department" class="level2">
<h2 class="anchored" data-anchor-id="salary-distribution-by-department">4. Salary Distribution by Department</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">employees <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(active) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(department, salary, median), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> salary, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> department)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> scales<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;">dollar_format</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-6">  <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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#29abe2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1a7db5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#74c8ec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#0d5c8a"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#a8d8ea"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb8-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Salary Distribution by Department"</span>,</span>
<span id="cb8-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Active employees only"</span>,</span>
<span id="cb8-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x        =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb8-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y        =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Annual Salary"</span></span>
<span id="cb8-13">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1a1a2e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/post-with-code/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="864"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="performance-distribution" class="level2">
<h2 class="anchored" data-anchor-id="performance-distribution">5. Performance Distribution</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">perf_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> employees <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(active) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(performance) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct =</span> n <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;">sum</span>(n) <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;">100</span>,</span>
<span id="cb9-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(pct, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%"</span>),</span>
<span id="cb9-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">perf_label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(performance, <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;">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;">5</span>,</span>
<span id="cb9-8">      <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;">"Needs Improvement"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Below Average"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meets Expectations"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Exceeds"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outstanding"</span>))</span>
<span id="cb9-9">  )</span>
<span id="cb9-10"></span>
<span id="cb9-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(perf_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> perf_label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> pct, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> perf_label)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.85</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-14">  <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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#e74c3c"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f39c12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#74c8ec"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#29abe2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1a7db5"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Performance Rating Distribution"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"% of Employees"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb9-18">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1a1a2e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/post-with-code/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="key-takeaways" class="level2">
<h2 class="anchored" data-anchor-id="key-takeaways">Key Takeaways</h2>
<p>These five metrics — <strong>headcount, turnover rate, tenure, compensation equity, and performance distribution</strong> — are the foundation of any people analytics practice. Once you have these running reliably, you can layer in more advanced work: predictive attrition models, engagement drivers, succession risk.</p>
<p>In upcoming posts I’ll show how to take this further with machine learning and real workforce datasets.</p>
<hr>
<p><em>All data in this post is simulated for illustration purposes.</em></p>


<!-- -->

</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{betancourt2026,
  author = {Betancourt, Felix},
  title = {HR {Metrics} {Every} {People} {Analytics} {Team} {Should}
    {Track}},
  date = {2026-04-01},
  url = {https://www.bluecognition.net/posts/post-with-code/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-betancourt2026" class="csl-entry quarto-appendix-citeas">
Betancourt, Felix. 2026. <span>“HR Metrics Every People Analytics Team
Should Track.”</span> April 1, 2026. <a href="https://www.bluecognition.net/posts/post-with-code/">https://www.bluecognition.net/posts/post-with-code/</a>.
</div></div></section></div> ]]></description>
  <category>people analytics</category>
  <category>HR metrics</category>
  <category>R</category>
  <category>tutorial</category>
  <guid>https://www.bluecognition.net/posts/post-with-code/</guid>
  <pubDate>Wed, 01 Apr 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.bluecognition.net/posts/post-with-code/image.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Network Analysis on Subreddit r/politics</title>
  <dc:creator>Felix Betancourt</dc:creator>
  <link>https://www.bluecognition.net/posts/reddit-network-analysis/</link>
  <description><![CDATA[ 




<section id="network-analysis-on-subreddit-rpolitics" class="level2">
<h2 class="anchored" data-anchor-id="network-analysis-on-subreddit-rpolitics">Network Analysis on subreddit r/politics</h2>
<section id="introduction" class="level3">
<h3 class="anchored" data-anchor-id="introduction">Introduction</h3>
<p>Social media, including Reddit, serves as a prominent platform for discourse and community engagement. The “Politics” subreddit (r/politics) is a hub for discussions on political matters, attracting users who share news articles and express opinions (Bail, 2016).</p>
<p>In recent years, Reddit discussions have intensified, especially regarding U.S. politics, notably around Joe Biden and Donald Trump. Analyzing user interactions in r/politics offers insight into digital political landscapes (Conover et al., 2013).</p>
<p>This research aims to explore Reddit users’ connections within r/politics, focusing on Biden and Trump discussions. We seek to uncover community formation patterns and influencers through social network analysis. Specifically, we’ll examine users’ connectivity, community emergence, and the relationship between post popularity and user influence.</p>
<p>By addressing these questions, we contribute to understanding political discourse on Reddit and social media’s role in shaping public opinion.</p>
</section>
<section id="research-question" class="level3">
<h3 class="anchored" data-anchor-id="research-question">Research Question</h3>
<ol type="1">
<li><p>How are Reddit users connected in the “Politics” subreddit (r/politics), particularly when it comes to topics related to Biden and Trump?</p></li>
<li><p>Are there different communities (networks) for Biden and Trump?</p></li>
<li><p>How are these group of users connected based on the sentiment of their comments?</p></li>
<li><p>Is there a relationship between Score (net value between upvotes and downvotes) for a post, and how the user is connected to other users?</p></li>
</ol>
</section>
<section id="hypothesis" class="level3">
<h3 class="anchored" data-anchor-id="hypothesis">Hypothesis</h3>
<p>This research is mainly exploratory, I am not expecting something in particular, so I don’t have an specific hypothesis, except for the research question number 4.</p>
<p>In relation to the fourth research question I can expect that:</p>
<p>H1: an user’s higher score should be highly related to a higher centrality in the network.</p>
</section>
<section id="data" class="level3">
<h3 class="anchored" data-anchor-id="data">Data</h3>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">suppressWarnings</span>({</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidytext))</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr))</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse))</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(quanteda))</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(quanteda.textplots))</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(janitor))</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(RCurl))</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(data.table))</span>
<span id="cb1-10">})</span></code></pre></div></div>
</details>
</div>
<section id="data-wrangling" class="level4">
<h4 class="anchored" data-anchor-id="data-wrangling">Data Wrangling</h4>
<ol type="1">
<li><p>I scraped data from the Politics subreddit (r/politics) on April 2nd 2024 using R (RedditExtractoR package) and saved the objects generated from the scrapping to csv files</p></li>
<li><p>This subreddit has 8.5 million users, so the data can be very extensive, however the package used here (RedditExtractoR) pulled the last 1000 post.</p></li>
</ol>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">getwd</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "/home/fbetanco/OneDrive/3 Blue Cognition/Blog/People_Insight/posts/reddit-network-analysis"</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read large CSV file using fread</span></span>
<span id="cb4-2">politik1 <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;">fread</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"politics_comments1.csv"</span>)</span>
<span id="cb4-3">politik2 <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;">fread</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"politics_comments2.csv"</span>)</span>
<span id="cb4-4">politik3 <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;">fread</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"politics_comments3.csv"</span>)</span>
<span id="cb4-5"></span>
<span id="cb4-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Checking the structure of the data sets</span></span>
<span id="cb4-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(politik1)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 983
Columns: 8
$ V1        &lt;chr&gt; "Supreme Court starts arguments as Biden administration defe…
$ date_utc  &lt;IDate&gt; 2024-03-26, 2024-03-26, 2024-03-26, 2024-03-26, 2024-03-26…
$ timestamp &lt;int&gt; 1711463500, 1711463310, 1711462666, 1711462651, 1711462570, …
$ title     &lt;chr&gt; "Supreme Court starts arguments as Biden administration defe…
$ text      &lt;chr&gt; "", "", "", "", "", "", "", "", "", "", "", "Oral argument i…
$ subreddit &lt;chr&gt; "politics", "politics", "politics", "politics", "politics", …
$ comments  &lt;int&gt; 34, 21, 194, 24, 43, 15, 150, 251, 18, 26, 10, 597, 27, 299,…
$ url       &lt;chr&gt; "https://www.reddit.com/r/politics/comments/1bo9ce0/supreme_…</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">glimpse</span>(politik2)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 983
Columns: 16
$ V1                    &lt;int&gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1…
$ url                   &lt;chr&gt; "https://www.reddit.com/r/politics/comments/1bo9…
$ author                &lt;chr&gt; "Cybertronian1512", "ban_hus", "coasterghost", "…
$ date                  &lt;chr&gt; "3/26/2024", "3/26/2024", "3/26/2024", "3/26/202…
$ timestamp             &lt;int&gt; 1711463500, 1711463310, 1711462666, 1711462651, …
$ title                 &lt;chr&gt; "Supreme Court starts arguments as Biden adminis…
$ text                  &lt;chr&gt; "", "", "", "", "", "", "", "", "", "", "", "Ora…
$ subreddit             &lt;chr&gt; "politics", "politics", "politics", "politics", …
$ score                 &lt;int&gt; 304, 127, 1250, 791, 421, 226, 4033, 4842, 197, …
$ upvotes               &lt;int&gt; 304, 127, 1250, 791, 421, 226, 4033, 4842, 197, …
$ downvotes             &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
$ up_ratio              &lt;dbl&gt; 0.95, 0.92, 0.95, 0.96, 0.91, 0.91, 0.97, 0.97, …
$ total_awards_received &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
$ golds                 &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
$ cross_posts           &lt;int&gt; 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 1, 1, 0, …
$ comments              &lt;int&gt; 34, 21, 194, 24, 43, 15, 150, 250, 18, 26, 10, 5…</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">glimpse</span>(politik3)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 95,879
Columns: 11
$ V1         &lt;int&gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, …
$ url        &lt;chr&gt; "https://www.reddit.com/r/politics/comments/1bo9ce0/supreme…
$ author     &lt;chr&gt; "AutoModerator", "EmmaLouLove", "ctguy54", "EmmaLouLove", "…
$ date       &lt;chr&gt; "3/26/2024", "3/26/2024", "3/26/2024", "3/26/2024", "3/26/2…
$ timestamp  &lt;int&gt; 1711463501, 1711465125, 1711466287, 1711466455, 1711467091,…
$ score      &lt;int&gt; 1, 79, 41, 13, 19, 13, 7, 6, 3, 4, 1, 4, 2, 5, 5, 1, 1, 28,…
$ upvotes    &lt;int&gt; 1, 79, 41, 13, 19, 13, 7, 6, 3, 4, 1, 4, 2, 5, 5, 1, 1, 28,…
$ downvotes  &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ golds      &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ comment    &lt;chr&gt; "\r\nAs a reminder, this subreddit [is for civil discussion…
$ comment_id &lt;chr&gt; "1", "2", "2_1", "2_1_1", "2_1_1_1", "2_1_1_1_1", "2_1_1_1_…</code></pre>
</div>
</div>
<p>As we can see the the information in object “politik1” is redundant with the information in “politik2” so I won’t use “politik1” at all. “Politik2” contain information about the title of the post, author, and some numeric information like up/down votes, number of replies to the post. “politik3” contain detailed comments on each post and the hierarchical sequence of comments to each post.</p>
<p>For the purpose of this research we will define the users or authors to posts and comments as the nodes, and edges are defined as comments made in the same post; it does mean that the network will be undirected as I will consider only authors commenting in the same post but I won’t capture the direction of the comment (B is commenting to A post).</p>
<p>Let’s do some data wrangling first:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;"># Cleaning and wrangling</span></span>
<span id="cb10-2"></span>
<span id="cb10-3">politik_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>V1, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>timestamp) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#eliminating non-relevant columns</span></span>
<span id="cb10-4">politik_df <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_tibble</span>(politik_df)</span>
<span id="cb10-5">politik_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>date <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.Date</span>(politik_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m/%d/%Y"</span>)</span>
<span id="cb10-6"></span>
<span id="cb10-7"></span>
<span id="cb10-8">politik_df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>V1, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>timestamp) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#eliminating non-relevant columns</span></span>
<span id="cb10-9">politik_df2 <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_tibble</span>(politik_df2)</span>
<span id="cb10-10">politik_df2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>date <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.Date</span>(politik_df2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m/%d/%Y"</span>)</span></code></pre></div></div>
</details>
</div>
<p>Looking at the comments from user “Automoderator”, it is like a Reddit moderator bot reminding rules of the forum, so I’ll delete the rows belonging to AutoModerator”. Also there are few commments where the author was “deleted”.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">politik_df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df2[<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;">which</span>(politik_df2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AutoModerator"</span>)),]</span>
<span id="cb11-2">politik_df3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df2[<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;">which</span>(politik_df2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[deleted]"</span>)),]</span></code></pre></div></div>
</details>
</div>
<p>Let’s see how many nodes (authors/users) we got in this data set:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">#first I created a count column</span></span>
<span id="cb12-2">politik_df3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">countid =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>)</span>
<span id="cb12-3">politik_df3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>countid <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.numeric</span>(politik_df3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>countid)</span>
<span id="cb12-4"></span>
<span id="cb12-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#How many authors (nodes) we have here?</span></span>
<span id="cb12-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(politik_df3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 31554</code></pre>
</div>
</div>
<p>In the data set there are about +31k users/authors (nodes), which is way too much nodes for the purpose of my research, so I’ll select a sample of posts to analyze.</p>
<p>I’ll select the top 1% posts with more comments.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#first let's see the distribution of number of comments</span></span>
<span id="cb14-2">percentiles <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;">quantile</span>(politik_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comments, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.99</span>))</span>
<span id="cb14-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(percentiles)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>   25%    50%    75%    90%    95%    99% 
  20.0   46.0  115.0  338.6  576.2 1439.1 </code></pre>
</div>
</div>
<p>Let’s subset the data set with the top 1% posts in terms of comments and let’s see how many posts we have.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1">subset_politik2 <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;">subset</span>(politik_df, comments <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;">1439</span> )</span>
<span id="cb16-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(subset_politik2)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 10
Columns: 14
$ url                   &lt;chr&gt; "https://www.reddit.com/r/politics/comments/1bo5…
$ author                &lt;chr&gt; "newsweek", "thenewrepublic", "UWCG", "twenafees…
$ date                  &lt;date&gt; 2024-03-26, 2024-03-26, 2024-03-27, 2024-03-27,…
$ title                 &lt;chr&gt; "Letitia James fires back after Donald Trump's b…
$ text                  &lt;chr&gt; "", "", "", "", "", "", "", "", "", ""
$ subreddit             &lt;chr&gt; "politics", "politics", "politics", "politics", …
$ score                 &lt;int&gt; 12409, 28546, 32935, 25237, 13487, 14411, 17102,…
$ upvotes               &lt;int&gt; 12409, 28546, 32935, 25237, 13487, 14411, 17102,…
$ downvotes             &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
$ up_ratio              &lt;dbl&gt; 0.92, 0.93, 0.91, 0.93, 0.91, 0.91, 0.91, 0.94, …
$ total_awards_received &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
$ golds                 &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
$ cross_posts           &lt;int&gt; 1, 2, 5, 7, 9, 2, 3, 3, 6, 3
$ comments              &lt;int&gt; 1476, 2018, 3564, 2419, 1523, 1677, 2291, 1668, …</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" 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;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(subset_politik2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 10</code></pre>
</div>
</div>
<p>We got a data set with 10 original posts and 10 authors, this is now a more “reasonable” data frame to analyze.</p>
<p>Now I need to identify these post into the “politik_df3” data set which contain all the hierarchical comments network.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">subset_politik3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb20-2">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(url <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> subset_politik2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url)</span>
<span id="cb20-3"></span>
<span id="cb20-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#let's see the df now </span></span>
<span id="cb20-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(subset_politik3)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 4,902
Columns: 10
$ url        &lt;chr&gt; "https://www.reddit.com/r/politics/comments/1bo5tnj/letitia…
$ author     &lt;chr&gt; "OokLeeNooma", "AusToddles", "dancode", "GrafZeppelin127", …
$ date       &lt;date&gt; 2024-03-26, 2024-03-26, 2024-03-26, 2024-03-26, 2024-03-26…
$ score      &lt;int&gt; 5480, 2444, 1054, 871, 792, 414, 212, 31, 2, 3, 8, 26, 3, 3…
$ upvotes    &lt;int&gt; 5480, 2444, 1054, 871, 792, 414, 212, 31, 2, 3, 8, 26, 3, 3…
$ downvotes  &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ golds      &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ comment    &lt;chr&gt; "\"\"Donald Trump is still facing accountability for his st…
$ comment_id &lt;chr&gt; "2", "2_1", "2_1_1_1", "2_1_1_1_1", "2_1_1_1_1_1", "2_1_1_1…
$ countid    &lt;dbl&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#how many nodes (authors)?</span></span>
<span id="cb22-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(subset_politik3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 3869</code></pre>
</div>
</div>
<p>We got 982 posts but still +3.8k nodes, it is still high number of nodes.</p>
<p>I’ll need a different approach.</p>
<p>I’ll select 2 specific posts with a “median” number of comments. One post will be about Trump and another about Biden, specifically I will filter posts by containing the word “Biden” and “Trump” in the title of the post.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressWarnings</span>({</span>
<span id="cb24-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#First selecting posts with "Trump" or "Biden" included in the title of the post</span></span>
<span id="cb24-3"></span>
<span id="cb24-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Filtering the titles that contain Trump</span></span>
<span id="cb24-5">trump_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trump"</span>, title))</span>
<span id="cb24-6">trump_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>candidate <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;">"Trump"</span></span>
<span id="cb24-7"></span>
<span id="cb24-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Let's check the distribution of number of comments</span></span>
<span id="cb24-9">percentiles_trump <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;">quantile</span>(trump_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comments, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.99</span>))</span>
<span id="cb24-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(percentiles_trump)</span>
<span id="cb24-11"></span>
<span id="cb24-12">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    25%     50%     75%     90%     95%     99% 
  30.50   74.00  206.00  575.40 1052.50 2176.34 </code></pre>
</div>
</div>
<p>The median comment for Trump’s post is 74 comments.Therefore I’ll select the post with 74 comments.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Trump</span></span>
<span id="cb26-2">trump_post <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;">subset</span>(trump_df, comments <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;">74</span> )</span></code></pre></div></div>
</details>
</div>
<p>Now let’s select Biden’s post</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressWarnings</span>({</span>
<span id="cb27-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Filtering the titles that contain Biden</span></span>
<span id="cb27-3">biden_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grepl</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Biden"</span>, title))</span>
<span id="cb27-4">biden_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>candidate <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;">"Biden"</span></span>
<span id="cb27-5"></span>
<span id="cb27-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Let's check the distribution of number of comments</span></span>
<span id="cb27-7">percentiles_biden <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;">quantile</span>(biden_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comments, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.99</span>))</span>
<span id="cb27-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(percentiles_biden)</span>
<span id="cb27-9">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    25%     50%     75%     90%     95%     99% 
  28.00   66.50  171.25  464.50  907.75 1818.00 </code></pre>
</div>
</div>
<p>Median is 66.5 comments, let’s use the post with 67 comments.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Biden</span></span>
<span id="cb29-2">biden_post <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;">subset</span>(biden_df, comments <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;">67</span> )</span></code></pre></div></div>
</details>
</div>
<p>Now I got the 2 main posts, let’s explore a bit those 2 posts.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#merging the previous df's</span></span>
<span id="cb30-2">trump_biden_df <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>(trump_post, biden_post)</span>
<span id="cb30-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(trump_biden_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "https://www.reddit.com/r/politics/comments/1bsdho2/us_election_workers_face_thousands_of_threats_so/"
[2] "https://www.reddit.com/r/politics/comments/1bsnq6l/are_black_and_brown_voters_really_fleeing_biden/" </code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#let's identify these posts in the politik3 df (containing all the details)</span></span>
<span id="cb32-2">subset_politik3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_df3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb32-3">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(url <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> trump_biden_df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url)</span>
<span id="cb32-4"></span>
<span id="cb32-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#creating a new column with the candidate related to the post</span></span>
<span id="cb32-6">subset_politik3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> subset_politik3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb32-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">candidate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb32-8">    url <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;">"https://www.reddit.com/r/politics/comments/1bsdho2/us_election_workers_face_thousands_of_threats_so/"</span> <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;">"Trump"</span>,</span>
<span id="cb32-9">    url <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;">"https://www.reddit.com/r/politics/comments/1bsnq6l/are_black_and_brown_voters_really_fleeing_biden/"</span> <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;">"Biden"</span>,</span>
<span id="cb32-10">  ))</span>
<span id="cb32-11"></span>
<span id="cb32-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#let's see the df now </span></span>
<span id="cb32-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(subset_politik3)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 119
Columns: 11
$ url        &lt;chr&gt; "https://www.reddit.com/r/politics/comments/1bsnq6l/are_bla…
$ author     &lt;chr&gt; "fxkatt", "AngusMcTibbins", "Knoxcore", "Hattopia", "AngusM…
$ date       &lt;date&gt; 2024-03-31, 2024-03-31, 2024-04-01, 2024-03-31, 2024-03-31…
$ score      &lt;int&gt; 20, 27, 3, -18, 23, -12, 18, -3, -14, 9, -7, 5, 2, 1, -4, 1…
$ upvotes    &lt;int&gt; 20, 27, 3, -18, 23, -12, 18, -3, -14, 9, -7, 5, 2, 1, -4, 1…
$ downvotes  &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ golds      &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ comment    &lt;chr&gt; "It's very possible that both Biden and Trump are losing so…
$ comment_id &lt;chr&gt; "2", "3", "3_1", "3_2", "3_2_1", "3_2_1_1", "3_2_1_1_1", "3…
$ countid    &lt;dbl&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
$ candidate  &lt;chr&gt; "Biden", "Biden", "Biden", "Biden", "Biden", "Biden", "Bide…</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Let's keep only the relevant columns</span></span>
<span id="cb34-2">politik_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;">select</span>(subset_politik3, <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;">"url"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"comment"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"comment_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"candidate"</span>))</span>
<span id="cb34-3"></span>
<span id="cb34-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extracting the levels of each comment and its hierarchy</span></span>
<span id="cb34-5">politik_final2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb34-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Level =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_count</span>(comment_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Count underscores to determine depth</span></span>
<span id="cb34-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ParentID =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(Level <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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(comment_id, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(x[<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>(x)], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>)), <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>))</span>
<span id="cb34-8"></span>
<span id="cb34-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 80</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>url))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 2</code></pre>
</div>
</div>
<p>Now we got 80 nodes (authors) from the 2 posts.</p>
</section>
<section id="analysis" class="level4">
<h4 class="anchored" data-anchor-id="analysis">Analysis</h4>
<p>Before proceeding with the network analysis, let’s explore a bit about the authors (users).</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#let's create some tables to see frequencies and totals</span></span>
<span id="cb38-2"></span>
<span id="cb38-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#first I created a count column</span></span>
<span id="cb38-4">politik_final2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">countid =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>)</span>
<span id="cb38-5">politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>countid <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.numeric</span>(politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>countid)</span>
<span id="cb38-6"></span>
<span id="cb38-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#preparing tables</span></span>
<span id="cb38-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(data.table)</span>
<span id="cb38-9">politik_table2 <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.table</span>(politik_final2)</span>
<span id="cb38-10"></span>
<span id="cb38-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#total posts grouped by author</span></span>
<span id="cb38-12">count_table2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_table2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(author) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total_posts =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(countid))</span>
<span id="cb38-13">count_table2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> count_table2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(Total_posts))</span>
<span id="cb38-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(count_table2)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 80 × 2
   author            Total_posts
   &lt;chr&gt;                   &lt;dbl&gt;
 1 BrtFrkwr                    7
 2 betterwoke                  5
 3 Hattopia                    4
 4 TheBodyPolitic1             4
 5 TheRandomInteger            4
 6 AngusMcTibbins              3
 7 Due-Shirt616                3
 8 NoDesinformatziya           3
 9 TheReddestOrange            3
10 DarkwingDuckHunt            2
# ℹ 70 more rows</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">summary_votes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_table2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(author) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Total_Score =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(score))</span>
<span id="cb40-2">summary_votes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_votes <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(Total_Score))</span>
<span id="cb40-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(summary_votes)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 80 × 2
   author             Total_Score
   &lt;chr&gt;                    &lt;int&gt;
 1 r-m-russell                 76
 2 AngusMcTibbins              68
 3 OverlyComplexPants          40
 4 BrtFrkwr                    33
 5 betterwoke                  28
 6 TheBodyPolitic1             24
 7 penis_berry_crunch          22
 8 Due-Shirt616                21
 9 NoDesinformatziya           20
10 YeaterdaysQuim              20
# ℹ 70 more rows</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Score as a proportion of comments</span></span>
<span id="cb42-2">summary_score_ratio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_table2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(author) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ratio_score_per_comment =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(score)<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;">sum</span>(countid))</span>
<span id="cb42-3">summary_score_ratio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_score_ratio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(Ratio_score_per_comment))</span>
<span id="cb42-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(summary_score_ratio)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 80 × 2
   author             Ratio_score_per_comment
   &lt;chr&gt;                                &lt;dbl&gt;
 1 r-m-russell                           76  
 2 OverlyComplexPants                    40  
 3 AngusMcTibbins                        22.7
 4 penis_berry_crunch                    22  
 5 YeaterdaysQuim                        20  
 6 fxkatt                                20  
 7 grixorbatz                            17  
 8 Sea_Engine4333                        16  
 9 Quiet_Dimensions                      14  
10 hdiggyh                               14  
# ℹ 70 more rows</code></pre>
</div>
</div>
<p>I would expect that nodes (users) with higher score and/or higher score per comment should be predominant (central) in the network.</p>
<p>For instance we got the following users in the top 5 in terms of score: “r-m-russell”, “AngusMcTibbins”, “OverlyComplexPants”, “BrtFrkwr” and “betterwoke”.</p>
<p>On the other hand here the top 5 users with highest score per comment: “r-m-russell”, “OverlyComplexPants”, “AngusMcTibbins”, “penis_berry_crunch”, and “YeaterdaysQuim”.</p>
<p>Now I am ready to work on this data set for the Network analysis.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Rename level column as it represent more how deep/far is the comment</span></span>
<span id="cb44-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#from the initial post, we will use this later as an attribute</span></span>
<span id="cb44-3">politik_final2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">distance =</span> Level)</span>
<span id="cb44-5"></span>
<span id="cb44-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#identify who is commenting on the same post</span></span>
<span id="cb44-7">politik_final2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(comment_id, <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="cb44-9"></span>
<span id="cb44-10">politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>level <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;">str_replace_all</span>(politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>level, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb44-11"></span>
<span id="cb44-12">politik_final2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(candidate, <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="cb44-14"></span>
<span id="cb44-15">politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comment_id2 <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>(politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>level2, politik_final2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>level, <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>
<span id="cb44-16"></span>
<span id="cb44-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Now I'll create a new object by keeping only the columns I need</span></span>
<span id="cb44-18"></span>
<span id="cb44-19">politik_final3 <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;">select</span>(politik_final2, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<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;">"comment_id"</span>, <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;">"ParentID"</span>, <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;">"level"</span>, <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;">"level2"</span>))</span>
<span id="cb44-20"></span>
<span id="cb44-21"></span>
<span id="cb44-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Will create a attribute only object to use later</span></span>
<span id="cb44-23">politik_attributes <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;">select</span>(politik_final3, <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;">"score"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"candidate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"distance"</span>))</span></code></pre></div></div>
</details>
</div>
<p>I’ll prepare the adjacency matrix:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1">politik_m <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;">select</span>(politik_final3, <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;">"comment_id2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author"</span>))</span>
<span id="cb45-2"></span>
<span id="cb45-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Identify unique names and codes</span></span>
<span id="cb45-4">unique_names <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;">unique</span>(politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author)</span>
<span id="cb45-5">unique_codes <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;">unique</span>(politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comment_id2)</span>
<span id="cb45-6"></span>
<span id="cb45-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create an empty adjacency matrix</span></span>
<span id="cb45-8">adj_matrix <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(unique_names), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(unique_names),</span>
<span id="cb45-9">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(unique_names, unique_names))</span>
<span id="cb45-10"></span>
<span id="cb45-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Populate the adjacency matrix based on shared codes</span></span>
<span id="cb45-12"><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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(unique_names)) {</span>
<span id="cb45-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (j <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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(unique_names)) {</span>
<span id="cb45-14">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Check if names i and j have the same code</span></span>
<span id="cb45-15">    shared_code <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;">intersect</span>(politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comment_id2[politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> unique_names[i]],</span>
<span id="cb45-16">                             politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comment_id2[politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> unique_names[j]])</span>
<span id="cb45-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(shared_code) <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;">0</span>) {</span>
<span id="cb45-18">      adj_matrix[unique_names[i], unique_names[j]] <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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set relationship to 1</span></span>
<span id="cb45-19">    }</span>
<span id="cb45-20">  }</span>
<span id="cb45-21">}</span>
<span id="cb45-22"></span>
<span id="cb45-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># I'll eliminate loops in advance</span></span>
<span id="cb45-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(adj_matrix) <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></code></pre></div></div>
</details>
</div>
<section id="network-analysis" class="level5">
<h5 class="anchored" data-anchor-id="network-analysis">Network Analysis</h5>
<p>Now let’s explore the Network.</p>
<p>It is important to mention that in this research we will assume an undirected network. We are only considering comments within the same post, not specific “direction” of each comment among users.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#load packages</span></span>
<span id="cb46-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(network))</span>
<span id="cb46-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sna)</span>
<span id="cb46-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(statnet)</span>
<span id="cb46-5"></span>
<span id="cb46-6">politik.n <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;">network</span>(adj_matrix, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">directed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb46-7">politik.n</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code> Network attributes:
  vertices = 80 
  directed = FALSE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  total edges= 158 
    missing edges= 0 
    non-missing edges= 158 

 Vertex attribute names: 
    vertex.names 

No edge attributes</code></pre>
</div>
</div>
<p>We got 80 nodes and 316 edges.</p>
<p>Let’s explore the network. I’ll calculate the census for Dyads and triads:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb48" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb48-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Dyads and Triads census</span></span>
<span id="cb48-2">sna<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;">dyad.census</span>(politik.n)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>     Mut Asym Null
[1,] 158    0 3002</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb50" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sna<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;">triad.census</span>(politik.n))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 82160</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb52" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1">sna<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;">triad.census</span>(politik.n)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>       003 012   102 021D 021U 021C 111D 111U 030T 030C 201 120D 120U 120C 210
[1,] 70689   0 10955    0    0    0    0    0    0    0 179    0    0    0   0
     300
[1,] 337</code></pre>
</div>
</div>
<p>In terms of Dyads, we got 158 mutual connections and 3002 null connections.</p>
<p>In terms of Triads, we got 82160 triads in total: about 70k null triads, 11k open triads (one connection exist), 179 where 2 connections exist, and 337 closed triads.</p>
<p>It seems a disperse network, but let’s see Transitivity and Density:</p>
<p>Let’s check the Transitivity coefficient</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb54" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb54-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#transitivity</span></span>
<span id="cb54-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gtrans</span>(politik.n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mode=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"graph"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.8495798</code></pre>
</div>
</div>
<p>The transitivity coefficient is 0.85 which indicates a high level of cohesion.</p>
<p>Let’s see the density:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb56" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb56-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># get network density: statnet</span></span>
<span id="cb56-2">network<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;">network.density</span>(politik.n) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#already exclude loops</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.05</code></pre>
</div>
</div>
<p>This density of 0.05 indicates a relatively sparse network with few connections between nodes.</p>
<p>This combination of high transitivity and low density might suggests the presence of strong community structure in the network, where nodes are densely connected within their respective communities but sparsely connected between communities.</p>
<p>Let’s visualize the network</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb58" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb58-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot the network</span></span>
<span id="cb58-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(politik.n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displaylabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.cex=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displayisolates=</span>T, <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;">"Authors Network"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/reddit-network-analysis/index_files/figure-html/unnamed-chunk-22-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Without isolated nodes and labels</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb59" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb59-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot the network</span></span>
<span id="cb59-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(politik.n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displaylabels =</span> F, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.cex=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displayisolates=</span>F, <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;">"Authors Network"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/reddit-network-analysis/index_files/figure-html/unnamed-chunk-23-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Let’s now include the Candidate as attribute. We will clasify the users as per their comments to Biden or Trump posts.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb60" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#I'll create a column with Biden true-false attribute</span></span>
<span id="cb60-2">politik_final3at <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb60-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb60-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biden =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(candidate <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;">"Biden"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span>)</span>
<span id="cb60-5">  )</span>
<span id="cb60-6"></span>
<span id="cb60-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#now let's see how authonrs in Biden and Trump are interacting</span></span>
<span id="cb60-8">nodeColors<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;">ifelse</span>(politik_final3at<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>biden,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodgerblue"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>)</span>
<span id="cb60-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(politik.n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displaylabels=</span>F,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.col=</span>nodeColors,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.cex=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displayisolates=</span>T, <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;">"Authors Network by Candidate"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#including isolated nodes</span></span>
<span id="cb60-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottomright"</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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Biden"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trump"</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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodgerblue"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</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;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Node Type"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/reddit-network-analysis/index_files/figure-html/unnamed-chunk-24-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Let’s exclude isolated nodes</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb61" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb61-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(politik.n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displaylabels=</span>F,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.col=</span>nodeColors,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.cex=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">displayisolates=</span>F, <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;">"Authors Network by Candidate (excluding isolated nodes)"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#excluding isolated nodes</span></span>
<span id="cb61-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottomright"</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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Biden"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trump"</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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dodgerblue"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</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;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Node Type"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/reddit-network-analysis/index_files/figure-html/unnamed-chunk-25-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>It looks like there are closed communities not connected among them. Which is consistent with the Transitivity vs Density finding before.</p>
<p>In particular Biden’s commentors tend to be together and Trump’s commentors seems more disperse.</p>
<p>Let’s see who are the authors with highest degree centrality</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb62" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb62-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a dataset of vertex names and degree: statnet</span></span>
<span id="cb62-2">politik.nodes.df <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>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> politik.n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%v%</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertex.names"</span>,</span>
<span id="cb62-3">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">degree =</span> sna<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;">degree</span>(politik.n))</span>
<span id="cb62-4"></span>
<span id="cb62-5">politik_table7 <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.table</span>(politik.nodes.df)</span>
<span id="cb62-6"></span>
<span id="cb62-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#order by centrality degree</span></span>
<span id="cb62-8">politik_table7 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(degree)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb62-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</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;">10</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>                  name degree
                &lt;char&gt;  &lt;num&gt;
 1:           Knoxcore     30
 2:  NoDesinformatziya     30
 3:           BrtFrkwr     28
 4:   TheRandomInteger     26
 5:    TheBodyPolitic1     20
 6:         Fasefirst2     20
 7:           cdiddy19     20
 8: Invincible_auxcord     20
 9:     Bulky-You-5657     20
10:        nickmiele22     20</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb64" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb64-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(politik_table7)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>        name        degree    
 Length   :80   Min.   : 0.0  
 N.unique :80   1st Qu.: 0.0  
 N.blank  : 0   Median : 6.0  
 Min.nchar: 6   Mean   : 7.9  
 Max.nchar:20   3rd Qu.:14.5  
                Max.   :30.0  </code></pre>
</div>
</div>
<p>Let’s explore the correlation between centrality degree and score (remember it is the net value between upvotes and downvotes).</p>
<p>I am expecting a significant positive relationship between soore and degree centrality.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb66" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb66-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(igraph))</span>
<span id="cb66-2"></span>
<span id="cb66-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create the igraph object</span></span>
<span id="cb66-4">politik.ig <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;">graph_from_adjacency_matrix</span>(adj_matrix, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mode =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"undirected"</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Undirected by default</span></span>
<span id="cb66-5"></span>
<span id="cb66-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate degree centrality for each node</span></span>
<span id="cb66-7">degree_centrality <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;">degree</span>(politik.ig, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mode =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb66-8"></span>
<span id="cb66-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If nodes do not have names, you can use node IDs</span></span>
<span id="cb66-10"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">V</span>(politik.ig)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name)) {</span>
<span id="cb66-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">V</span>(politik.ig)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name <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.character</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;">vcount</span>(politik.ig))</span>
<span id="cb66-12">}</span>
<span id="cb66-13"></span>
<span id="cb66-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Check node names</span></span>
<span id="cb66-15">node_names <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;">V</span>(politik.ig)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name</span>
<span id="cb66-16"></span>
<span id="cb66-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a sample data frame with some values for each node</span></span>
<span id="cb66-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ensure the data frame has the same node identifiers as the graph</span></span>
<span id="cb66-19">df <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>(</span>
<span id="cb66-20">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">author =</span> node_names,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Node names or IDs</span></span>
<span id="cb66-21">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcount</span>(politik.ig), <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;">100</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Random values between 1 and 100</span></span>
<span id="cb66-22">)</span>
<span id="cb66-23"></span>
<span id="cb66-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convert degree centrality to a data frame</span></span>
<span id="cb66-25">degree_centrality_df <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>(</span>
<span id="cb66-26">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">author =</span> node_names,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Node names or IDs</span></span>
<span id="cb66-27">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">degree_centrality =</span> degree_centrality  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Degree centrality values</span></span>
<span id="cb66-28">)</span>
<span id="cb66-29"></span>
<span id="cb66-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Merge the degree centrality data frame with the existing data frame</span></span>
<span id="cb66-31">merged_df <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;">merge</span>(df, degree_centrality_df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">all =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb66-32">merged_df2 <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;">merge</span>(merged_df, politik_final2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">all =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb66-33">degree_scoredf <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;">select</span>(merged_df2, <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;">"degree_centrality"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"score"</span>))</span>
<span id="cb66-34"></span>
<span id="cb66-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate the correlation coefficient between 'score' and 'degree_centrality'</span></span>
<span id="cb66-36">cor_matrix1 <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;">cor</span>(degree_scoredf, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"complete.obs"</span>)</span>
<span id="cb66-37">cor_matrix1</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>                  degree_centrality       score
degree_centrality       1.000000000 0.001921923
score                   0.001921923 1.000000000</code></pre>
</div>
</div>
<p>Seems that the relationship between score and degree centrality is very low (0.002).</p>
<p>So I can’t accept my hypothesis.</p>
<p>I am curious about the top 5 users with higher degree centrality.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb68" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb68-1">degree_scoredf3 <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;">select</span>(merged_df2, <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;">"degree_centrality"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author"</span>))</span>
<span id="cb68-2">subset_df <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;">distinct</span>(degree_scoredf3, author, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.keep_all =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb68-3"></span>
<span id="cb68-4">subset_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(degree_centrality))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>   degree_centrality               author
1                 15             Knoxcore
2                 15    NoDesinformatziya
3                 14             BrtFrkwr
4                 13     TheRandomInteger
5                 10       Bulky-You-5657
6                 10             cdiddy19
7                 10  Exciting_Slice_9492
8                 10           Fasefirst2
9                 10        hilljack26301
10                10   Invincible_auxcord
11                10             Kamelasa
12                10          nickmiele22
13                10      TheBodyPolitic1
14                 8   Admirable_Bad_5649
15                 8           betterwoke
16                 8     DarkwingDuckHunt
17                 8          Scarlettail
18                 8        Spara-Extreme
19                 8     TheReddestOrange
20                 8     Thick-Return1694
21                 7          bakeacake45
22                 6            AliMcGraw
23                 6       AngusMcTibbins
24                 6             Hattopia
25                 6    hellocattlecookie
26                 6   Mundane_Rabbit7751
27                 6   OverlyComplexPants
28                 6         Roasted_Butt
29                 6    SeegsonSynthetics
30                 6             Shaunair
31                 4             caserock
32                 4     CecilTWashington
33                 4            gefjunhel
34                 4   penis_berry_crunch
35                 4          r-m-russell
36                 3         Due-Shirt616
37                 3              hdiggyh
38                 3             iuthnj34
39                 3               JeffMo
40                 3        PineTreeBanjo
41                 3              Purify5
42                 3     Quiet_Dimensions
43                 3       YeaterdaysQuim
44                 1  Candid_Chicken_9246
45                 1   FijiFanBotNotGay69
46                 1        Happypappy213
47                 1            hindusoul
48                 1      InGreedWeTrust3
49                 1              LariRed
50                 1   physical_graffitti
51                 1            Tower6011
52                 0              bck1999
53                 0     bloombergopinion
54                 0          cryolongman
55                 0          Donut131313
56                 0              eldred2
57                 0      Empty-Rise-4409
58                 0     fore_skin_walker
59                 0               fxkatt
60                 0           grixorbatz
61                 0            Guttenber
62                 0        HonoredPeople
63                 0     ImportantNeck491
64                 0        inconsistent3
65                 0       JubalHarshaw23
66                 0             njman100
67                 0          No_Yak_6227
68                 0       Odd_Tiger_2278
69                 0 platanthera_ciliaris
70                 0        PoopieButt317
71                 0  Practical_Shop_4055
72                 0         RUIN_NATION_
73                 0       Sea_Engine4333
74                 0          SeaSuch2077
75                 0             spotspam
76                 0          stjoechief1
77                 0          StormOk7544
78                 0              syg-123
79                 0               th1961
80                 0         Willowgirl78</code></pre>
</div>
</div>
<p>Users with higher degree centrality are “Knoxcore”, “NoDesinformatziya”, “BrtFrkwr”, “TheRandomInteger”, and “Bulky-You-5657”</p>
<p>Out of these 5 nodes only one of them (“BrtFrkwr”) is also in the top 5 related to score. So it is consistent with the low correlation between score and centrality.</p>
<p>Let’s now check what clusters (communities) we do have in this network.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb70" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb70-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># run clustering algorithm: fast_greedy</span></span>
<span id="cb70-2">politik.fg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> igraph<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;">cluster_fast_greedy</span>(politik.ig)</span>
<span id="cb70-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># inspect clustering object</span></span>
<span id="cb70-4">politik.fg</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>IGRAPH clustering fast greedy, groups: 37, mod: 0.63
+ groups:
  $`1`
   [1] "AngusMcTibbins"      "Knoxcore"            "Hattopia"           
   [4] "Mundane_Rabbit7751"  "NoDesinformatziya"   "SeegsonSynthetics"  
   [7] "hellocattlecookie"   "TheBodyPolitic1"     "Fasefirst2"         
  [10] "cdiddy19"            "Invincible_auxcord"  "Bulky-You-5657"     
  [13] "nickmiele22"         "Exciting_Slice_9492" "hilljack26301"      
  [16] "Kamelasa"           
  
  $`2`
   [1] "OverlyComplexPants"  "AliMcGraw"           "bakeacake45"        
  + ... omitted several groups/vertices</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb72" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb72-1">igraph<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;">groups</span>(politik.fg)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>$`1`
 [1] "AngusMcTibbins"      "Knoxcore"            "Hattopia"           
 [4] "Mundane_Rabbit7751"  "NoDesinformatziya"   "SeegsonSynthetics"  
 [7] "hellocattlecookie"   "TheBodyPolitic1"     "Fasefirst2"         
[10] "cdiddy19"            "Invincible_auxcord"  "Bulky-You-5657"     
[13] "nickmiele22"         "Exciting_Slice_9492" "hilljack26301"      
[16] "Kamelasa"           

$`2`
 [1] "OverlyComplexPants"  "AliMcGraw"           "bakeacake45"        
 [4] "Roasted_Butt"        "BrtFrkwr"            "TheRandomInteger"   
 [7] "Shaunair"            "betterwoke"          "DarkwingDuckHunt"   
[10] "Thick-Return1694"    "Spara-Extreme"       "Admirable_Bad_5649" 
[13] "TheReddestOrange"    "Scarlettail"         "Tower6011"          
[16] "Candid_Chicken_9246"

$`3`
[1] "r-m-russell"        "penis_berry_crunch" "CecilTWashington"  
[4] "caserock"           "gefjunhel"         

$`4`
[1] "iuthnj34"       "YeaterdaysQuim" "hdiggyh"        "Purify5"       

$`5`
[1] "Quiet_Dimensions" "Due-Shirt616"     "JeffMo"           "PineTreeBanjo"   

$`6`
[1] "physical_graffitti" "hindusoul"         

$`7`
[1] "LariRed"         "InGreedWeTrust3"

$`8`
[1] "Happypappy213"      "FijiFanBotNotGay69"

$`9`
[1] "fxkatt"

$`10`
[1] "Sea_Engine4333"

$`11`
[1] "Practical_Shop_4055"

$`12`
[1] "PoopieButt317"

$`13`
[1] "inconsistent3"

$`14`
[1] "Empty-Rise-4409"

$`15`
[1] "stjoechief1"

$`16`
[1] "th1961"

$`17`
[1] "platanthera_ciliaris"

$`18`
[1] "No_Yak_6227"

$`19`
[1] "fore_skin_walker"

$`20`
[1] "HonoredPeople"

$`21`
[1] "bloombergopinion"

$`22`
[1] "RUIN_NATION_"

$`23`
[1] "ImportantNeck491"

$`24`
[1] "grixorbatz"

$`25`
[1] "spotspam"

$`26`
[1] "JubalHarshaw23"

$`27`
[1] "StormOk7544"

$`28`
[1] "njman100"

$`29`
[1] "Odd_Tiger_2278"

$`30`
[1] "cryolongman"

$`31`
[1] "Willowgirl78"

$`32`
[1] "Guttenber"

$`33`
[1] "SeaSuch2077"

$`34`
[1] "syg-123"

$`35`
[1] "bck1999"

$`36`
[1] "Donut131313"

$`37`
[1] "eldred2"</code></pre>
</div>
</div>
<p>There are 2 main clusters in the network.</p>
<p>Let’s see the density of each cluster using block model function.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb74" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb74-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">blockmodel</span>(politik.n, politik.fg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>membership)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>block.model,</span>
<span id="cb74-2">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>         Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 Block 8
Block 1     0.62    0.00       0       0       0       0       0       0
Block 2     0.00    0.48       0       0       0       0       0       0
Block 3     0.00    0.00       1       0       0       0       0       0
Block 4     0.00    0.00       0       1       0       0       0       0
Block 5     0.00    0.00       0       0       1       0       0       0
Block 6     0.00    0.00       0       0       0       1       0       0
Block 7     0.00    0.00       0       0       0       0       1       0
Block 8     0.00    0.00       0       0       0       0       0       1
Block 9     0.00    0.00       0       0       0       0       0       0
Block 10    0.00    0.00       0       0       0       0       0       0
Block 11    0.00    0.00       0       0       0       0       0       0
Block 12    0.00    0.00       0       0       0       0       0       0
Block 13    0.00    0.00       0       0       0       0       0       0
Block 14    0.00    0.00       0       0       0       0       0       0
Block 15    0.00    0.00       0       0       0       0       0       0
Block 16    0.00    0.00       0       0       0       0       0       0
Block 17    0.00    0.00       0       0       0       0       0       0
Block 18    0.00    0.00       0       0       0       0       0       0
Block 19    0.00    0.00       0       0       0       0       0       0
Block 20    0.00    0.00       0       0       0       0       0       0
Block 21    0.00    0.00       0       0       0       0       0       0
Block 22    0.00    0.00       0       0       0       0       0       0
Block 23    0.00    0.00       0       0       0       0       0       0
Block 24    0.00    0.00       0       0       0       0       0       0
Block 25    0.00    0.00       0       0       0       0       0       0
Block 26    0.00    0.00       0       0       0       0       0       0
Block 27    0.00    0.00       0       0       0       0       0       0
Block 28    0.00    0.00       0       0       0       0       0       0
Block 29    0.00    0.00       0       0       0       0       0       0
Block 30    0.00    0.00       0       0       0       0       0       0
Block 31    0.00    0.00       0       0       0       0       0       0
Block 32    0.00    0.00       0       0       0       0       0       0
Block 33    0.00    0.00       0       0       0       0       0       0
Block 34    0.00    0.00       0       0       0       0       0       0
Block 35    0.00    0.00       0       0       0       0       0       0
Block 36    0.00    0.00       0       0       0       0       0       0
Block 37    0.00    0.00       0       0       0       0       0       0
         Block 9 Block 10 Block 11 Block 12 Block 13 Block 14 Block 15 Block 16
Block 1        0        0        0        0        0        0        0        0
Block 2        0        0        0        0        0        0        0        0
Block 3        0        0        0        0        0        0        0        0
Block 4        0        0        0        0        0        0        0        0
Block 5        0        0        0        0        0        0        0        0
Block 6        0        0        0        0        0        0        0        0
Block 7        0        0        0        0        0        0        0        0
Block 8        0        0        0        0        0        0        0        0
Block 9      NaN        0        0        0        0        0        0        0
Block 10       0      NaN        0        0        0        0        0        0
Block 11       0        0      NaN        0        0        0        0        0
Block 12       0        0        0      NaN        0        0        0        0
Block 13       0        0        0        0      NaN        0        0        0
Block 14       0        0        0        0        0      NaN        0        0
Block 15       0        0        0        0        0        0      NaN        0
Block 16       0        0        0        0        0        0        0      NaN
Block 17       0        0        0        0        0        0        0        0
Block 18       0        0        0        0        0        0        0        0
Block 19       0        0        0        0        0        0        0        0
Block 20       0        0        0        0        0        0        0        0
Block 21       0        0        0        0        0        0        0        0
Block 22       0        0        0        0        0        0        0        0
Block 23       0        0        0        0        0        0        0        0
Block 24       0        0        0        0        0        0        0        0
Block 25       0        0        0        0        0        0        0        0
Block 26       0        0        0        0        0        0        0        0
Block 27       0        0        0        0        0        0        0        0
Block 28       0        0        0        0        0        0        0        0
Block 29       0        0        0        0        0        0        0        0
Block 30       0        0        0        0        0        0        0        0
Block 31       0        0        0        0        0        0        0        0
Block 32       0        0        0        0        0        0        0        0
Block 33       0        0        0        0        0        0        0        0
Block 34       0        0        0        0        0        0        0        0
Block 35       0        0        0        0        0        0        0        0
Block 36       0        0        0        0        0        0        0        0
Block 37       0        0        0        0        0        0        0        0
         Block 17 Block 18 Block 19 Block 20 Block 21 Block 22 Block 23
Block 1         0        0        0        0        0        0        0
Block 2         0        0        0        0        0        0        0
Block 3         0        0        0        0        0        0        0
Block 4         0        0        0        0        0        0        0
Block 5         0        0        0        0        0        0        0
Block 6         0        0        0        0        0        0        0
Block 7         0        0        0        0        0        0        0
Block 8         0        0        0        0        0        0        0
Block 9         0        0        0        0        0        0        0
Block 10        0        0        0        0        0        0        0
Block 11        0        0        0        0        0        0        0
Block 12        0        0        0        0        0        0        0
Block 13        0        0        0        0        0        0        0
Block 14        0        0        0        0        0        0        0
Block 15        0        0        0        0        0        0        0
Block 16        0        0        0        0        0        0        0
Block 17      NaN        0        0        0        0        0        0
Block 18        0      NaN        0        0        0        0        0
Block 19        0        0      NaN        0        0        0        0
Block 20        0        0        0      NaN        0        0        0
Block 21        0        0        0        0      NaN        0        0
Block 22        0        0        0        0        0      NaN        0
Block 23        0        0        0        0        0        0      NaN
Block 24        0        0        0        0        0        0        0
Block 25        0        0        0        0        0        0        0
Block 26        0        0        0        0        0        0        0
Block 27        0        0        0        0        0        0        0
Block 28        0        0        0        0        0        0        0
Block 29        0        0        0        0        0        0        0
Block 30        0        0        0        0        0        0        0
Block 31        0        0        0        0        0        0        0
Block 32        0        0        0        0        0        0        0
Block 33        0        0        0        0        0        0        0
Block 34        0        0        0        0        0        0        0
Block 35        0        0        0        0        0        0        0
Block 36        0        0        0        0        0        0        0
Block 37        0        0        0        0        0        0        0
         Block 24 Block 25 Block 26 Block 27 Block 28 Block 29 Block 30
Block 1         0        0        0        0        0        0        0
Block 2         0        0        0        0        0        0        0
Block 3         0        0        0        0        0        0        0
Block 4         0        0        0        0        0        0        0
Block 5         0        0        0        0        0        0        0
Block 6         0        0        0        0        0        0        0
Block 7         0        0        0        0        0        0        0
Block 8         0        0        0        0        0        0        0
Block 9         0        0        0        0        0        0        0
Block 10        0        0        0        0        0        0        0
Block 11        0        0        0        0        0        0        0
Block 12        0        0        0        0        0        0        0
Block 13        0        0        0        0        0        0        0
Block 14        0        0        0        0        0        0        0
Block 15        0        0        0        0        0        0        0
Block 16        0        0        0        0        0        0        0
Block 17        0        0        0        0        0        0        0
Block 18        0        0        0        0        0        0        0
Block 19        0        0        0        0        0        0        0
Block 20        0        0        0        0        0        0        0
Block 21        0        0        0        0        0        0        0
Block 22        0        0        0        0        0        0        0
Block 23        0        0        0        0        0        0        0
Block 24      NaN        0        0        0        0        0        0
Block 25        0      NaN        0        0        0        0        0
Block 26        0        0      NaN        0        0        0        0
Block 27        0        0        0      NaN        0        0        0
Block 28        0        0        0        0      NaN        0        0
Block 29        0        0        0        0        0      NaN        0
Block 30        0        0        0        0        0        0      NaN
Block 31        0        0        0        0        0        0        0
Block 32        0        0        0        0        0        0        0
Block 33        0        0        0        0        0        0        0
Block 34        0        0        0        0        0        0        0
Block 35        0        0        0        0        0        0        0
Block 36        0        0        0        0        0        0        0
Block 37        0        0        0        0        0        0        0
         Block 31 Block 32 Block 33 Block 34 Block 35 Block 36 Block 37
Block 1         0        0        0        0        0        0        0
Block 2         0        0        0        0        0        0        0
Block 3         0        0        0        0        0        0        0
Block 4         0        0        0        0        0        0        0
Block 5         0        0        0        0        0        0        0
Block 6         0        0        0        0        0        0        0
Block 7         0        0        0        0        0        0        0
Block 8         0        0        0        0        0        0        0
Block 9         0        0        0        0        0        0        0
Block 10        0        0        0        0        0        0        0
Block 11        0        0        0        0        0        0        0
Block 12        0        0        0        0        0        0        0
Block 13        0        0        0        0        0        0        0
Block 14        0        0        0        0        0        0        0
Block 15        0        0        0        0        0        0        0
Block 16        0        0        0        0        0        0        0
Block 17        0        0        0        0        0        0        0
Block 18        0        0        0        0        0        0        0
Block 19        0        0        0        0        0        0        0
Block 20        0        0        0        0        0        0        0
Block 21        0        0        0        0        0        0        0
Block 22        0        0        0        0        0        0        0
Block 23        0        0        0        0        0        0        0
Block 24        0        0        0        0        0        0        0
Block 25        0        0        0        0        0        0        0
Block 26        0        0        0        0        0        0        0
Block 27        0        0        0        0        0        0        0
Block 28        0        0        0        0        0        0        0
Block 29        0        0        0        0        0        0        0
Block 30        0        0        0        0        0        0        0
Block 31      NaN        0        0        0        0        0        0
Block 32        0      NaN        0        0        0        0        0
Block 33        0        0      NaN        0        0        0        0
Block 34        0        0        0      NaN        0        0        0
Block 35        0        0        0        0      NaN        0        0
Block 36        0        0        0        0        0      NaN        0
Block 37        0        0        0        0        0        0      NaN</code></pre>
</div>
</div>
<p>The blocks 1 and 2 in our network seems dense.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb76" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb76-1">df_comm <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>(</span>
<span id="cb76-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Node =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">V</span>(politik.ig)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name,</span>
<span id="cb76-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Community =</span> politik.fg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>membership,</span>
<span id="cb76-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Degree =</span> degree_centrality</span>
<span id="cb76-5">)</span>
<span id="cb76-6"></span>
<span id="cb76-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 4. Find maximum degree for each community</span></span>
<span id="cb76-8"></span>
<span id="cb76-9">highest_degree_nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> df_comm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb76-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Community) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb76-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Degree <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;">max</span>(Degree)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb76-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb76-13"></span>
<span id="cb76-14">highest_degree_nodes <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</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;">desc</span>(Community))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 51 × 3
   Node               Community Degree
   &lt;chr&gt;                  &lt;dbl&gt;  &lt;dbl&gt;
 1 Knoxcore                   1     15
 2 NoDesinformatziya          1     15
 3 BrtFrkwr                   2     14
 4 r-m-russell                3      4
 5 penis_berry_crunch         3      4
 6 CecilTWashington           3      4
 7 caserock                   3      4
 8 gefjunhel                  3      4
 9 iuthnj34                   4      3
10 YeaterdaysQuim             4      3
# ℹ 41 more rows</code></pre>
</div>
</div>
<p>Let’s now visualize the communities including the nodes with highest degree centrality for the main communities (1 and 2):</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb78" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb78-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Identify nodes with high degree centrality (e.g., top 3)</span></span>
<span id="cb78-2">top_nodes <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;">names</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(degree_centrality, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decreasing =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</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;">5</span>]</span>
<span id="cb78-3"></span>
<span id="cb78-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a custom labeling vector</span></span>
<span id="cb78-5">node_labels <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;">vcount</span>(politik.ig))</span>
<span id="cb78-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set the labels for the nodes with high degree centrality</span></span>
<span id="cb78-7">node_labels[top_nodes] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> top_nodes</span>
<span id="cb78-8"></span>
<span id="cb78-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Identify isolated nodes</span></span>
<span id="cb78-10">isolated_nodes <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;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">degree</span>(politik.ig) <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;">0</span>)</span>
<span id="cb78-11"></span>
<span id="cb78-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Remove isolated nodes from the network</span></span>
<span id="cb78-13">network_no_isolated <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;">delete_vertices</span>(politik.ig, isolated_nodes)</span>
<span id="cb78-14"></span>
<span id="cb78-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(network_no_isolated,</span>
<span id="cb78-16">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.label =</span> node_labels,  </span>
<span id="cb78-17">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.label.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>,</span>
<span id="cb78-18">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">membership</span>(politik.fg),</span>
<span id="cb78-19">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.label.color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb78-20">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.shape =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sphere"</span>,</span>
<span id="cb78-21">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout =</span> layout_with_fr,</span>
<span id="cb78-22">     <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;">"Communities without isolated nodes and labeling top 5 central nodes"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/reddit-network-analysis/index_files/figure-html/unnamed-chunk-32-1.png" class="img-fluid figure-img" width="1056"></p>
</figure>
</div>
</div>
</div>
<p>It looks like while we have 2 main communities the nodes with highest degree centrality are mostly in one of the communities.</p>
<p>It seems like that group of authors are close among them and at the same time are central in the network.</p>
</section>
<section id="sentiment-analysis-and-the-network" class="level5">
<h5 class="anchored" data-anchor-id="sentiment-analysis-and-the-network">Sentiment Analysis and the Network</h5>
<p>Lastly let’s add a new attribute to the network using text analysis, in particular sentiment analysis.</p>
<p>Let’s get the sentiment for each author’s comments.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb79" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb79-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sentimentr)</span>
<span id="cb79-2"></span>
<span id="cb79-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#labeling based on the sentiment score</span></span>
<span id="cb79-4">comments <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>comment</span>
<span id="cb79-5">get_sentiment_label <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>(ave_sentiment) {</span>
<span id="cb79-6">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (ave_sentiment <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) {</span>
<span id="cb79-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Positive"</span>)</span>
<span id="cb79-8">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (ave_sentiment <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</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.1</span>) {</span>
<span id="cb79-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Negative"</span>)</span>
<span id="cb79-10">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb79-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span>)</span>
<span id="cb79-12">  }</span>
<span id="cb79-13">}</span>
<span id="cb79-14">sentiment_scores <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;">sentiment_by</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> comments, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text.var =</span> comments)</span>
<span id="cb79-15"></span>
<span id="cb79-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#adding the label for each author in the data set</span></span>
<span id="cb79-17">politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sentiment <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;">sapply</span>(sentiment_scores<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ave_sentiment, get_sentiment_label)</span></code></pre></div></div>
</details>
</div>
<p>Now let’s visualize the network by sentiment of each node.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb80" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb80-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a graph object from the data frame</span></span>
<span id="cb80-2">g <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;">graph_from_data_frame</span>(politik.n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">directed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb80-3"></span>
<span id="cb80-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add node attributes to the graph</span></span>
<span id="cb80-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">V</span>(g)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sentiment <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sentiment[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">V</span>(g)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name, politik_final3<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author)]</span>
<span id="cb80-6"></span>
<span id="cb80-7"></span>
<span id="cb80-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define color palette for categories</span></span>
<span id="cb80-9">color_palette <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;">"Negative"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Positive"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgreen"</span>)</span>
<span id="cb80-10"></span>
<span id="cb80-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Visualize the network with colored nodes</span></span>
<span id="cb80-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.color =</span> color_palette[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">V</span>(g)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sentiment], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout =</span> layout_nicely, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.label =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vertex.size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">isolates=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <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;">"Authors Network by Sentiment"</span>)</span>
<span id="cb80-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottomright"</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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Positive"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Negative"</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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgreen"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</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;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Node Sentiment"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.bluecognition.net/posts/reddit-network-analysis/index_files/figure-html/unnamed-chunk-34-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>From this chart it looks like:</p>
<ol type="1">
<li>Most of the sentiments are either neutral or negative</li>
<li>Sentiments tend to get closer, or group among them.</li>
</ol>
</section>
</section>
</section>
<section id="conclusion" class="level3">
<h3 class="anchored" data-anchor-id="conclusion">Conclusion</h3>
<ol type="1">
<li><p>The network was found to be sparse (low density) but highly interconnected within subgroups (high transitivity), suggesting the presence of distinct communities.</p></li>
<li><p>The visualization of the network confirmed the presence of communities, showing separate clusters of users commenting on Biden and Trump posts. The network was divided into 37 distinct clusters, indicating multiple smaller communities within the larger Biden and Trump-focused groups.</p></li>
<li><p>The hypothesis that users with higher scores (more upvotes or higher score) would also have more central positions in the network was not supported. The correlation between score and centrality was negligible.</p></li>
<li><p>While score wasn’t a strong indicator of influence, degree centrality (number of connections) was used to identify the most connected users. These users may play important roles in shaping discussions within their respective communities.</p></li>
<li><p>In terms of the sentiment analysis it seems that most comments were neutral or negative. And, users with similar sentiments tended to interact with each other.</p></li>
</ol>
<p>This Network Analysis research offers interesting insights into the social dynamics of a politically charged online community. It highlights the presence of distinct communities, the complex interplay between user engagement (score) and influence (centrality), and the opportunity for further exploration of the factors shaping political discourse on platforms like Reddit.</p>
</section>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<p>Bail C. A. (2016). Combining natural language processing and network analysis to examine how advocacy organizations stimulate conversation on social media. Proceedings of the National Academy of Sciences of the United States of America, 113(42), 11823–11828. https://doi.org/10.1073/pnas.1607151113</p>
<p>Conover, M., Ratkiewicz, J., Francisco, M., Goncalves, B., Menczer, F., &amp; Flammini, A. (2021). Political Polarization on Twitter. Proceedings of the International AAAI Conference on Web and Social Media, 5(1), 89-96. https://doi.org/10.1609/icwsm.v5i1.14126</p>


<!-- -->

</section>
</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{betancourt2024,
  author = {Betancourt, Felix},
  title = {Network {Analysis} on {Subreddit} r/Politics},
  date = {2024-05-16},
  url = {https://www.bluecognition.net/posts/reddit-network-analysis/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-betancourt2024" class="csl-entry quarto-appendix-citeas">
Betancourt, Felix. 2024. <span>“Network Analysis on Subreddit
r/Politics.”</span> May 16, 2024. <a href="https://www.bluecognition.net/posts/reddit-network-analysis/">https://www.bluecognition.net/posts/reddit-network-analysis/</a>.
</div></div></section></div> ]]></description>
  <category>network analysis</category>
  <category>R</category>
  <category>social media</category>
  <guid>https://www.bluecognition.net/posts/reddit-network-analysis/</guid>
  <pubDate>Thu, 16 May 2024 04:00:00 GMT</pubDate>
  <media:content url="https://www.bluecognition.net/posts/reddit-network-analysis/net_image_post.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
