── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(igraph) # This is the package to analyze the network
Attaching package: 'igraph'
The following objects are masked from 'package:lubridate':
%--%, union
The following objects are masked from 'package:dplyr':
as_data_frame, groups, union
The following objects are masked from 'package:purrr':
compose, simplify
The following object is masked from 'package:tidyr':
crossing
The following object is masked from 'package:tibble':
as_data_frame
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
library(visNetwork) # Creates visualizations of the networklibrary(DT)library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:igraph':
groups
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library(broom) # includes some of our regression functions
friendships <-read_csv("friendships.csv")
Rows: 6972 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (4): nominator, nominated, score, expected_score
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 84 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (2): id, name
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
`summarise()` has grouped output by 'nominator'. You can override using the
`.groups` argument.
This data tables shows us average friendship scores that were given/nominated. We are also able to see the mean score of the friendships.
friendships_model <-lm(expected_score ~ score, data = friendships)friendships |>plot_ly(x =~score, y =~expected_score) |>add_markers() |>add_lines(y =fitted(friendships_model))
With this plot graph the data shows us the scores that were all given were spread out with one another. The line through the middle of the graph is a regression line. The regression line helps show us an average middle point with the line but there is no correlation because the plots are all spread out.
Above is a data table. The data table helps show the names which is in numbers by numbering the student. Then the next column is them naming their friend. The other column is named friends by others. And the final column is the popularity of that person.
friendship_nodes |>mutate(named_friends =degree((friend_network), mode ="out")) |>mutate(named_by_others=degree((friend_network), mode ="in")) |>plot_ly(x =~named_friends) |>add_histogram() |>layout(title ="How many college students named friends")
Above is a histogram of the college students that named other students as their friends. With this data we are able to see that the highest about friends named was 21. We are able to see that the histogram shows some outliers but a big chunk of friends named is towards the beginning of the histogram.
reciprocity(friend_network, mode ="ratio")
[1] 0.527088
Above is the reciprocity in the network of friends. The data helps show that it is 0.52. So this tells us that half of the friendships are reciprocal.
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `group = membership(infomap.community(best_friend_network))`.
Caused by warning:
! `infomap.community()` was deprecated in igraph 2.0.0.
ℹ Please use `cluster_infomap()` instead.
Above is a graph layout that is color coded and the arrows help show us who is best friends with who. By clicking on a circle you are able to see who is friends with who. We are able to see who they surround themselves with and we can see who the outliers are.