Warning: package 'tidyverse' was built under R version 4.2.3
Warning: package 'ggplot2' was built under R version 4.2.3
Warning: package 'tibble' was built under R version 4.2.3
Warning: package 'tidyr' was built under R version 4.2.3
Warning: package 'readr' was built under R version 4.2.3
Warning: package 'purrr' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
Warning: package 'stringr' was built under R version 4.2.3
Warning: package 'forcats' was built under R version 4.2.3
Warning: package 'lubridate' was built under R version 4.2.3
── 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
Warning: package 'igraph' was built under R version 4.2.3
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 network
Warning: package 'visNetwork' was built under R version 4.2.3
library(DT)
Warning: package 'DT' was built under R version 4.2.3
library(plotly)
Warning: package 'plotly' was built under R version 4.2.3
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
Warning: package 'broom' was built under R version 4.2.3
students <-read.csv("C:/Users/katri/Downloads/R class/friendship_nodes.csv")student_links <-read.csv("C:/Users/katri/Downloads/R class/friendships.csv")
student_links |>group_by(nominator, nominated) |>summarize(Mean =round(mean(score), 1)) |>arrange(-Mean) |>datatable(rownames = F,caption ='Friendship ratings given by and to each student')
`summarise()` has grouped output by 'nominator'. You can override using the
`.groups` argument.
This table shows on average, how students would rate others and puts them from highest to lowest. Participants 11 and 56 were tied in rating others the highest. Students 1, 11, and 63 were tied for being ranked the highest. This means that they were perceived by others as being a closer friend.
Table showing how frequently subjects were named as a friend by others, how frequently they named others as a friend, and how popular each subject was.
students |>mutate(named_friends =degree((student_network), mode ="out")) |>mutate(named_by_others=degree((student_network), mode ="in")) |>plot_ly(x =~named_friends) |>add_histogram() |>layout(title ="How many friends participant named")
Histogram showing how many friends each participant named.
reciprocity(student_network, mode ="ratio")
[1] 0.527088
The reciprocity for this study was approximately 53%.
students |>mutate(value =degree(besties_network)) |>mutate(group =membership(infomap.community(besties_network))) |>visNetwork(besties, main ="Network of participant best friends") |>visIgraphLayout(layout ="layout_nicely") |>visEdges(arrows ="to") |>visOptions(highlightNearest = T, nodesIdSelection = T)
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `group = membership(infomap.community(besties_network))`.
Caused by warning:
! `infomap.community()` was deprecated in igraph 2.0.0.
ℹ Please use `cluster_infomap()` instead.
Visual of the network of only best friends color coordinated.