0% found this document useful (0 votes)
7 views4 pages

Icrm 5

Uploaded by

faaleha.irfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Icrm 5

Uploaded by

faaleha.irfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Introduction to Computational

Research Methods – Worksheet 5


This is the final worksheet for the course this semester. It is worth 10% of the overall grade
for the course.

1. The submitted file should be a combined file with all scripts, plots and the console output
showing the results of your activity.
2. The filename should be: ICRM-5.docx.
3. Do not include your name in any part of the worksheet.
4. Anything that is not designed for the computer to read should be commented out.
5. You may use any online resource to help you fulfil the worksheet requirements, but you
may not communicate to any other student in any way.
6. When you have completed all the tasks, create an R script and save it to your working
directory.
7. Open the R scripts in a word processor document and add all the plots and a copy of the
console output that you have done.
8. Upload the worksheet to Moodle (remember the file name should be ICRM-5.docx).
9. If you do not know how to do anything, then you must find the answer independently.
You cannot ask anyone for help during this practical session. Don’t forget the ever helpful
help() function.
10. You are allowed to use generative AI tools for this, but you are responsible for the code
that is included in your submission and you must acknowledge your use of AI at the top of
your submitted document. Provide the prompts that you used to generate the R code that
you then used in your script.

---Page Break---

Worksheet 5 Tasks

Basics

1. Set your working directory to a location on your computer in a folder called: Worksheet5
2. Use R to carry out arithmetic operations (addition, subtraction, multiplication, division).

a. Create 3 variable and assign to each of them the following data:


i. Your favourite actor’s age (if you don’t know, look it up).
ii. Your lucky number.
iii. The age of Cambridge University.

b. Using your 3 variables, carry out arithmetic operations and store the output to new
variables.
c. Determine the class of your new variables.
d. Load a time series dataset from the available datasets that come with R.
e. Plot the dataset.

R Script - Basics

# Set working directory


setwd("C:/Users/YourUserName/Documents/Worksheet5")

# Assign values to variables


actor_age <- 45 # Example: Age of favorite actor
lucky_number <- 7 # Example: Lucky number
cambridge_age <- 800 # Example: Age of Cambridge University

# Perform arithmetic operations


sum_result <- actor_age + lucky_number + cambridge_age
diff_result <- actor_age - lucky_number
prod_result <- actor_age * lucky_number
div_result <- actor_age / lucky_number

# Determine the class of the new variables


class(sum_result)
class(diff_result)
class(prod_result)
class(div_result)

# Load time series dataset and plot


data(AirPassengers) # Example dataset
plot(AirPassengers, main="AirPassengers Time Series")

---Page Break---

Statistics

1. Write an R script with the following:


a. Be sure to load any necessary libraries
b. Load the dataset USArrests
c. Run general descriptive statistics tests
d. Create a plot with UrbanPop on the x axis and Assault on the y axis

R Script - Statistics

# Load necessary libraries


library(ggplot2)

# Load the USArrests dataset


data(USArrests)

# Run descriptive statistics


summary(USArrests)

# Create a plot with UrbanPop on the x-axis and Assault on the y-axis
ggplot(USArrests, aes(x = UrbanPop, y = Assault)) +
geom_point() +
labs(title = "Urban Population vs Assault", x = "Urban Population", y = "Assault Rate")

---Page Break---

Networks

1. Write an R script with the following:


a. Using the scripts from previous practical sessions, create a network with <5
nodes/vertices and <10 links/edges.
b. Create names for the nodes/vertices.
c. Create variables to store:
i. average degree
ii. betweenness
d. Plot the graph object

R Script - Networks

# Load necessary libraries


library(igraph)

# Create a network with <5 nodes/vertices and <10 links/edges


nodes <- c("A", "B", "C", "D", "E")
edges <- c("A", "B", "B", "C", "C", "D", "D", "A", "E", "A")

# Create a graph object


g <- graph_from_edgelist(matrix(edges, ncol=2, byrow=TRUE), directed=FALSE)

# Assign names to nodes


V(g)$name <- nodes

# Calculate average degree


avg_degree <- mean(degree(g))

# Calculate betweenness centrality


betweenness_centrality <- betweenness(g)

# Plot the network graph


plot(g, main="Sample Network Graph")

You might also like