This is an individual assignment. You must record a presentation about commodity forecasting. See “Assessment Details” below for eligible commodities.
This task will assess your skills in research, analysis, communication, time management, and organisation. If in doubt, contact your Module Leader Cam Calderon.
📝 Marking Criteria
Criteria
Weight
Effective introduction
10%
Key literature, citations, and referencing
10%
Appropriate use of Refinitiv software
10%
Appropriate use of RStudio software
10%
Subject knowledge of forecasting methods
20%
Recommendations, policy alternatives, plans
20%
Appropriate conclusions
10%
Professional presentation
10%
Descriptions for each criterion and expectations are explained in the original brief.
🎓 Learning Objectives
Critically analyse econometrics and business methods, including alternative approaches.
Apply forecasting techniques to predictive economic problems.
Communicate forecasting techniques clearly through diverse media.
Apply theory in specialised economic domains using statistical tools.
📋 Assessment Details
Record a 10–15 min individual video presentation with your face, voice, and slides.
Submit via Turnitin.
You may use Panopto, PowerPoint, or other tools.
Keep file sizes low using online compression tools.
Only submit ONE of the following topics:
Topic 1: Gold
Topic 2: Copper
Topic 3: 2-Year Treasury Bond
Topic 4: Oil
Topic 5: Wheat
📤 Submission Instructions
Submit by 12:00 noon (GMT/BST) on TBC
Submission is via Turnitin only.
Use Microsoft Office or PDF format.
Late submissions are capped or marked as zero based on lateness.
You may apply for an extension or deferral if needed.
Keep backups of all work.
🔍 Return of Marks
Feedback will be available by TBC.
All marks are provisional until reviewed by External Examiners.
🤖 Academic Integrity & AI Use
You must not use generative AI to write this assignment. The only exception is using AI to assist with your R script creation, with clear acknowledgment.
Example AI statement: > I used ChatGPT to help structure R code related to plotting forecasts. Prompt: “Create an R function to forecast wheat prices using exponential smoothing.”
🎓 Support & Referencing
Use correct referencing throughout (Harvard or OSCOLA as applicable).
Seek academic or wellbeing support via the Student Gateway or your personal tutor.
✍️ Practice
Lab 2: Approaching Forecasting & Data Collection”
📊 Learning Objectives
By the end of this lab, you will be able to:
Define economic forecasting and explain its importance in decision-making
Identify different types of forecasting methods used by economists
Analyze real-world forecasting performance and limitations
Evaluate data collection strategies for forecasting purposes
Apply critical thinking to assess forecast accuracy and reliability
🔍 What is Forecasting?
Forecast: Predicting the future value of a time series - data collected over time intervals.
Economic forecasting is the process of making predictions about economic conditions based on historical data, statistical models, and economic theory. It’s used by:
Central banks for monetary policy decisions
Government agencies for fiscal planning and budgeting
Businesses for strategic planning and investment decisions
International organizations for policy recommendations
🎯 Types of Economic Forecasts
By Time Horizon:
Short-term (up to 1 year): GDP growth, inflation rates, employment figures
📈 Real-World Application: The Office for Budget Responsibility
The Office for Budget Responsibility (OBR) is the UK’s independent fiscal watchdog, established in 2010 to provide independent analysis of the public finances and the economy.
Step 2: Under ‘Publications’ → ‘Working Papers’, find Working Paper No.19: The OBR’s forecast performance
Step 3: Read the abstract carefully and prepare to answer the reflection questions below
🤔 Critical Analysis Questions
After reading the OBR Working Paper abstract, consider these questions:
Forecast Accuracy
Performance Evaluation: How does the OBR measure the accuracy of its forecasts?
Comparison Standards: Against what benchmarks does the OBR compare its forecast performance?
Error Patterns: What types of systematic errors, if any, does the OBR identify in its forecasting?
Methodological Insights
Forecast Horizons: How does forecast accuracy change with different time horizons?
Economic Variables: Which economic variables are most difficult to forecast accurately, and why?
Model Limitations: What limitations does the OBR acknowledge in its forecasting models?
Real-World Implications
Policy Impact: How might forecast errors affect government policy decisions?
Uncertainty Communication: How should forecast uncertainty be communicated to policymakers and the public?
Continuous Improvement: What steps does the OBR take to improve its forecasting accuracy over time?
Discussion Point
Consider discussing these questions with your peers during the lab session. Different perspectives can provide valuable insights into the complexity of economic forecasting.
Scenario Analysis: Best/worst/most likely case scenarios
Composite Indicators: Leading economic indicators, diffusion indices
Preview: R Implementation
In upcoming labs, you’ll learn to implement these methods using R. For example, we’ll use the forecast package for time series analysis and vars package for Vector Autoregression models.
Lab 3: Videos about R (Linked with MCQs assessment)
🎥 Introduction: How to Download and Install R & RStudio, Step-by-Step Guide ✨
🎥 Setting a Working Directory and Subfolders 🧙♂️
🎥 Using RStudio or R for the first time 👑
🎥 Packages, Vocabulary 🐣, Structure and Commenting in R or RStudio for Beginners
🎥 Functions 📊, Vectors 📈 and Other Structures in R or RStudio for Beginners
Lab 4: Performance and Evaluation
Performance and Evaluation
Data Partitioning
Lab 5: Prerequisite - A Quick intro to R
💾 Install R and RStudio on your laptops/gadgets
RStudio is a wrapper for R; we are using RStudio because it makes looks R more organised and straightforward. Follow the following instructions:
go to https://www.r-project.org
click on ‘CRAN mirror’
choose one of the two UK mirrors - https://www.stats.bris.ac.uk/R/ or https://cran.ma.imperial.ac.uk/
Click on ‘Download R for Windows’ or ‘Download R for macOS’
Click on ’install R for the first time
Click on ‘Download R-… for Windows’, the current version is R-4..5.1. Or alternatively, download the executable file for macOS.
double-click the downloaded file, then click on ‘Run’, ‘language:English’, ‘OK’, and read and follow the instructions of installation until you click on ‘Next’ for installing and ‘Finish’
Then proceed to Installing RStudio.
Go to rstudio.com
click on ‘download’
download the Free version, download RStudio for Windows or macOS
Click on ‘Next’ if you agree and on ‘Install’ and ‘Finish’ to complete the process.
📘 Introduction to R
After downloading and installing open RStudio, we will cover now some tutorials.
👨💻 Long Tutorial
We would cover a brief introduction on this labs, students would like to cover a longer tutorial to get use to R quickly. Click on this link: https://cran.r-project.org/doc/manuals/r-release/R-intro.pdf
👨💻 Quick tutorial - RStudio Screen
You need to have installed R and RStudio to continue with this lab.
Open Rstudio in your computer.
On this picture, there are three panels ‘the Console’, ‘The Environment’, and ‘The Plots, Help and Files’ panel.
Let’s choose a better appeareance for our RStudio. Click on “Tools” and then “Global Options.”
In RStudio, click on ‘Tools’ and ‘Global Options’
Afterwards, in the window “Options”, click on “Appearance”, RStudio theme: “Modern”, Editor font: “Courier”, Editor theme: Cobalt. Finally, click on “Apply”
You are here by clicking on Tools>Global Options..>Appereance>Modern>Courier>Cobalt>Apply
Now, we want to open a file to save the code that we are learning during this session. Click on ‘File’, ‘New File’, and ‘R Script’; or simply press Ctrl+Shift+N; this will open a new panel called ‘Script’ where we are going to write the commands for R. The name of the script is Untitled 1. At the end of this session save the script in a folder for this module.
Click on File>New File>R Script
Let’s learn how to write our own comments in our R code/ script.
On the script panel, type the caracter # and then write 'LAB ONE – ECON2545 – AND THE DATE TODAY'.
R will ignore any line of command starting with #. You can use # to add comments, titles, reminders within your R code/ R Script. If you did it right, your R Script shall look like this:
Comments are crucial to learn R
The Rstudio screen has four windows or panels: 1. Console. 2. Environment and history. 3. Files, plots, packages and help. 4. The R script(s) and data view. The R script is where you keep a record of your work or commands - in a line by line basis. For Stata users this would be like the do-file, for SPSS users is like the syntax and for SAS users the SAS program.
Let’s type getwd() in line number ‘2’ and hit the keys ‘ctrl+enter’ in your keyboard at the same time - The + indicates ‘do it at the same time’, you dont need to press the key ‘+’ . If you did this correctly you will see in the console panel the folder or working directory that R is using to download and upload data.
This image shows how your R Script should look and the outcome in the console -bottom panel after using ctrl+enter
Let’s create a folder in Windows for your course using 📁 File Explorer. I called my folder ‘R code – LABs’. Afterwards, in RStudio’ go to ‘Session’, ‘Set Working Directory’, ‘Choose Directory’, and select the folder ‘R code – LABs’ or the name you used.
Create your folder and then click on Session>Set Working Directory>Choose Directory
The above will render a result within the ‘Console’ panel, this is the code setwd(and a path/directory to your chosen folder in your computer). Copy and paste that in your R code; next time you will only need to hit ‘ctrl+enter’ on ‘setwd(your directory)’ to set the directory or folder where you are going to work in R.
This is the code you shall copy and paste in your R Script, ignore ‘>’
Copy and paste the outcome of you console in your R code; next time you will only need to hit ‘ctrl’ and ‘enter’ to set working directory.
setwd() example in your R Script
In line number 4, type 5*5 and hit ‘ctrl’ and ‘enter’, the console will show the code and the result, 25.
Let’s also create a matrix. Use the in the picture below -lines 5 and 6, put them on your script and hit ctrl+enter to line 5 and then 6.
A multiplication and your first matrix
If you did it correctly, the outcome in the console will be as follows:
Multiplication and matrix output in your Console
In the line 5, you asked R to create a matrix called ‘A’, with numbers from 1 to 8, with four rows and two columns.
Have a look at the ‘Environment’ panel, you can see in there all active objects(e.g. matrix A), and the panel ‘History’ shows a list of commands used do far.
Environment Panel
To see the matrix A in a new window, type the command View(A) in line 7 and hit the keys ‘ctrl+enter’ to run line 7, this will send you to a different tab. Afterwards, come back to your R script by clicking on ‘Untitled 1’.
Sample of function View()
Packages tab
The package tab shows the list of add-ons included in the installation of RStudio. If checked, the package is loaded into R, if not, any command related to that package won’t work, you will need select it. You can also install other add-ons by clicking on the ‘Install Packages’ icon.
Another way to install add-ons is to type the function install.packages("name of the package"), and then you will be able to open the library of commands of that package.
In line 8, to install the package forecast, type install.packages(“forecast”) and hit ctrl+enter. In the next window, you can hit yes to restart RStudio. See the picture below, you shall not get errors in the console, and at the end, the sign ‘>’ will let you know the instalation run OK.
Function install.packages() and installing package ‘forecast’
You must activate the package by typing ‘library(the package)’, for example, library(forecast) and ctrl+enter. In this case, this will automatically open all functions within the ‘forecast’ package.
library() function and sample with package ‘forecast’
The Console will show this result after ‘running’ library(“forecast”)
We will use the package forecast in this course to analyse and predict economic time series.
Script/Data View Window:
• Begin scripts with a comment for title and description using the hash character (#). Anything after the hash on the same line is considered a comment and is ignored by R. • Code can continue to the next line without a special character, but only if the previous line ends in a way that suggests continuation (e.g., a comma or unclosed brackets). • To run a line of code, position the cursor on the line and press Ctrl+Enter. For multiple lines, select them and press Ctrl+Enter.
Console/Output Window:
• It’s recommended to work in script mode for reusability. • Commands outside the script context can be typed at the bottom of the console, indicated by the “>” sign. • Press Enter to execute a command. • Use the up and down arrows to revisit and edit older lines of code previously typed into the console.
Do not forget to 💾 save your R script in your own course folder! Use the icon to save, I called my file “lab001” and now is available , folder ‘R code – LABs’
Remember to save your R Scripts, this will save you a lot time!
Lab 6 – R certification & Package swirl
📜 Getting your first R Certification
Access LinkedIn Learning – First time logging in
Adapted from the library resources
https://www.library.dmu.ac.uk
Open any web browser and navigate to https://www.linkedin.com/learning/login
Sign In
Enter your DMU email address: For students – your login credentials will be your DMU email address in the format Pnumber@my365.dmu.ac.uk
For DMU staff this is your Outlook full email address.
Select Continue
Select the ‘Sign in with Single Sign On’ blue button.
Sign in with Single Sign-On
You will be taken to DMU’s Single Sign in screen. Sign in with your login details.
DMU Students:
Username: Pnumber,
Password:
(Same login details that you use for MyDMU or LearningZone)
DMU Staff:
Username/Password – same for Single-sign.
(Same login details that you use for Staff Portal or LearningZone)
Sign in with your DMU credentials
You will be presented with a LinkedIn learnings welcome screen. You are given two options, select the one that applies:
If you do have an existing LinkedIn profile account you can select ’Connect my LinkedIn account.
OR select the option ‘Continue without LinkedIn’.
Option to connect LinkedIn Account
If you selected ‘Continue without LinkedIn’, you will be prompted to ensure you don’t want to connect with LinkedIn - a social professional network – which allows you to build your professional profile and connect with other professionals. Select the option’Don’t connect my account’.
Confirm connecting to LinkedIn Learning account
Next you will be prompted to further personalise your learning experience. This can be helpful so that relevant content is accessible to you. Note that you can always add further course, skills from LinkedIn Learnings home page. Select the ‘Sounds good’ blue button.
Welcome to LinkedIn Learning
You will be offered pathways to set skill targets (see Figure 7 Set Goals Screen below). You can don’t need to set these now and can come back to these later if you wish. Select ‘I’m not sure’.
Set Goals Screen
Choose at least three skills by selecting any of the categories (as a minimum you should select at least three, you can always add more later). Once selected, select the ‘Continue’ button.
Set some Skills
You can set weekly viewing goals if you wish. These allow you to prioritise your learning and set time aside for watching course videos and track your progress. Or you can choose to set this later by selecting ‘Skip for now’
Set Weekly Learning Goals
“You’re all set!” You will be able to view some recommended courses and videos from LinkedIn Learning.
Ready!
In your LinkedIn Learning personalised dashboard, the top main navigation bar will remain throughout as you watch video resources and resume videos when needed. The home icon appear will take you to your main LinkedIn Learning home page, where you can view recommended content, search resources.
Now that your account is activated – just bookmark this direct URL link to login to LinkedIn Learning http://www.linkedin.com/learning/login
To find out more about using LinkedIn Learning, please refer to the ‘LinkedIn Learning guide’ and the help resources.
LinkedIn Learning!
✍️ Practice
Hands-on 🛠️ , you must upload as part of your assessment an screenshot of a certification in R from LinkedIn. The deadline is three days after the face-to-face delivery date of this lab via Turnitin.
🎒 Bonus Section - Optional 🤷
There are hundreds of R Programming Certifications, Tutorials, Courses and Training Online, etc. Explore further online:
Free Course Trial – R Programming Certification by Johns Hopkins University (Coursera)
Data Science: R Basics Certificate by Harvard University (edX)
Free Course Trial – Statistics with R Certification by Duke University (Coursera)
Free Course Trial – Software Development in R Certification by Johns Hopkins University (Coursera)
Programming for Data Science with R Nanodegree Certification (Udacity)
R Programming Course A-Z™: R For Data Science With Real Exercises (Udemy)
Data Science and Machine Learning Bootcamp with R (Udemy)
R Programming: Advanced Analytics In R For Data Science
Statistics with R – Beginner Level
R Programming Courses & Tutorials Online (Pluralsight)
💻 Package Swirl 🌀
Prerequisite: you need to open RStudio before hand and follow the instructions below.
‘swirl’ is an R package designed to teach you R programming and data science interactively. Here’s a step-by-step guide on how to use swirl:
👣 Step 1: Install and Load the swirl Package
You only need to install the packages for the very first time in personal computers. If you are using a public computer you need to install everytime you start a session.
💡 If you don’t have the swirl package already installed, you can install it using the following command:
install.packages("swirl")
Once installed, load the ‘swirl’ package with the following command:
library(swirl)
Warning: package 'swirl' was built under R version 4.4.3
| Hi! I see that you have some variables saved in your workspace. To keep
| things running smoothly, I recommend you clean up before starting swirl.
| Type ls() to see a list of the variables in your workspace. Then, type
| rm(list=ls()) to clear your workspace.
| Type swirl() when you are ready to begin.
👣 Step 2: Start swirl and Follow the Prompts
To start swirl, enter the following command:
swirl()
After entering this command, you will be prompted to enter your name. Type your name and press enter.
Type your name and hit enter
Then, swirl says that the three dots … means ‘read and hit enter’; you also need to press enter after answering exercises.
… the three dots: Read the prompt and hit enter
Afterwards, swirl will carry on telling you how to numbers to choose topics, etc. Just read the prompts and follow the instructions until you need to choose a course. Remember to use ESC key if you plan to exit swirl, otherwise you will not be able to use R for programming.
If you are already at the prompt, type bye() to exit and save your progress. When you exit properly, you’ll see a short message letting you know you’ve done so.
👣 Step 3: Choose a Course Next, you’ll be prompted to choose a course. If this is your first time using swirl, you’ll need to install a course. To install a course, type: Replace “Course Name” with the name of the course you want to install. A list of available courses can be found on the swirl website. You will need to install the R Programming course. Type: After the course is installed, start swirl again: You will be prompted to select a course. Choose “R Programming” from the list.
install_from_swirl(“Course Name”)
install_from_swirl("R Programming")swirl()
👣 Step 4: Complete Lessons You will now be prompted to select a lesson. Choose the first lesson and follow the instructions to complete it. The lesson will consist of interactive exercises that will introduce you to the basics of R programming. As you progress, swirl will guide you through different lessons to gradually build up your R programming skills.
👣 Step 5: Progress Tracking swirl keeps track of your progress. You can check your progress at any time by running: swirl::progress() This will show you which lessons you’ve completed and which ones you still need to work on. And that’s it! By following these steps, you’ll be well on your way to learning R programming with swirl. Happy learning!
Lab 7 – Uploading 🧮 Excel Files to R and 📈 Basic Plotting
🤝 Introduction to R - 📤 uploading Data from Excel and CSV files
Go to ONS.gov.uk
Click on ‘data’ In the GDP quarter-on-quarter section.
Click on Download full-time series as .xls
Go to your folder ‘downloads’
Rename the file as “gdp qoq”
Save the file in your subfolder’ data’ on your folder “econ2545”. We created this folder during the previous lab.
Open the excel file and set column names to ‘quarters’ and ‘gdp’ in columns A and B. Save the file and close.
In yellow: the changes we made on the Excel file, names for the variables
In Rstudio (recall not to open R), click on ‘Import Dataset’, ‘from excel’, and choose the appropriate file on your folder ‘datasets’.
Click on ‘Import Dataset’
On the box ‘Skip’ type the number 7. We do not want to import rows 1 to 7.
Copy the R code by clicking on the ‘copy’ icon.
We changed the box ‘Skip:’ to 7 and copy the code using the icon 📋
Click on ‘Import’.
Go to your R script and paste by using the keys ‘ctrl+v’. You shall have the following code:
We pasted the lines 13 to 15
Plot the time series. Use the command plot.
Function plot()
Find the unemployment dataset in ONS, but this time download the full-time series as ‘.csv’ file, can you paste the appropriate code for csv files in your R script?
Type ?plot on the console, this opens the help panel for ‘plot’. Click on the link ‘Generic X-Y’ Plotting on the console to review more arguments you can use in the function plot().
📂 Opening files from the book Principles of 🔢📈Econometrics with R
*This section is adapted from Hill, Griffiths, and Lim 2011 To open a data file for the Principles of Econometrics textbook, (Hill, Griffiths, and Lim 2011):
remotes::install_github("ccolonescu/PoEdata")library(PoEdata)data("andy") *# makes the dataset "**andy**" ready to use *?andy *# shows information about the dataset**# Show head of dataset, with variables as column names: ***head**(andy)*# Show a few rows in dataset: ***some**(andy)
📦 Installing packages
Run the following code once in your R console to install needed packages:
rm(list=ls()) # Caution: this clears the Environmentinstall.packages("devtools")install.packages("remotes")
📈 Creating Graphs in R
R provides a suite of functions to create and customize graphs. Here’s a brief overview:
Basic Plotting: Function: plot() Usage: To plot data points and lines. Arguments: x, y: Variables to be plotted. xlab, ylab: Labels for x and y-axis. type: Determines the style of the plot. Options include: “p”: Points only “l”: Lines only “b”: Both points and lines “n”: No plot, creates an empty graph. Useful as a foundation for other plot elements.
🔢 Plotting Mathematical Curves:
Function: curve() Usage: To plot a curve based on a mathematical function over a specified range. Example: Key Argument: “add”: If set to TRUE, the curve is added to an existing graph.
# Plot the first curve: y = xcurve(x^1, from =-2, to =2, xlab ="x", ylab ="y", ylim =c(-2, 10))# Add a second curve: y = x^2curve(x^2, add =TRUE)
# y = sqrt(x)# This function is only defined for x ≥ 0curve(sqrt(x), from =0, to =10)
📉 Adding Lines:
Function: abline() Usage: To add lines defined by specific parameters to a graph. Arguments: a, b: Defines a line based on its intercept (a) and slope (b). h: Specifies the y-value for drawing a horizontal line. v: the x-value for drawing a vertical line. x-value for a vertical line; coef, the name of a simple linear regression object, which includes the intercept and slope of a regression line.
plot(1:10, type="n") # creates an empty graphabline(a=8, b=-0.5, h=3.5, v=4) # Add straight lines to graph
curve(x^2, from=0, to=20) abline(v=10)
🧪 Try It: Curve Playground
Use the interactive tool below to experiment with mathematical functions.
Lab 8 – 👀 Data Visualisation
Adapted from: https://towardsdatascience.com/a-guide-to-data-visualisation-in-r-for-beginners-ef6d41a34174 Link to files:
Let’s explore R datasets using a basic level tutorial in visualisation. We will work in RStudio. You can type data() and enter in the RStudio console, this opens a new tab with very interesting datasets.
data() #Explore the built-in datasets
Now, load the built-in dataset ‘airquality’ into RStudio - type data(airquality) in the console:
data(airquality)
If everything is OK, in the console panel you will see the airquality dataset.
Let’s perform data exploration.
str(airquality) #the function 'str()' displays the internal structure of an R object
'data.frame': 153 obs. of 6 variables:
$ Ozone : int 41 36 12 18 NA 28 23 19 8 NA ...
$ Solar.R: int 190 118 149 313 NA NA 299 99 19 194 ...
$ Wind : num 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...
$ Temp : int 67 72 74 62 56 66 65 59 61 69 ...
$ Month : int 5 5 5 5 5 5 5 5 5 5 ...
$ Day : int 1 2 3 4 5 6 7 8 9 10 ...
The output of str(airquality) shows the numer of observations (153) and number of variables (6). There is also information about variable names, type integer (int) or number (num), and a some sample observations.
We can also Explore the beginning of the data and the end of the data with the funcions head() and tail().
One easy way to check for key descriptive statistics is to use the function summary(), check this descriptive statitics for the dataset ‘ariquality’ as follows:
summary(airquality)
Ozone Solar.R Wind Temp
Min. : 1.00 Min. : 7.0 Min. : 1.700 Min. :56.00
1st Qu.: 18.00 1st Qu.:115.8 1st Qu.: 7.400 1st Qu.:72.00
Median : 31.50 Median :205.0 Median : 9.700 Median :79.00
Mean : 42.13 Mean :185.9 Mean : 9.958 Mean :77.88
3rd Qu.: 63.25 3rd Qu.:258.8 3rd Qu.:11.500 3rd Qu.:85.00
Max. :168.00 Max. :334.0 Max. :20.700 Max. :97.00
NA's :37 NA's :7
Month Day
Min. :5.000 Min. : 1.0
1st Qu.:6.000 1st Qu.: 8.0
Median :7.000 Median :16.0
Mean :6.993 Mean :15.8
3rd Qu.:8.000 3rd Qu.:23.0
Max. :9.000 Max. :31.0
Use the graphics for plotting basic graphs. Plot the ozone column from airquality. Plot a graph between ozone and wind to visualise a possible relation. Is there a negative correlation between ozone and air speed?
library(help ="graphics")plot(airquality$Ozone)
plot(airquality$Ozone, airquality$Wind)
Plot the entire dataset. Is there a positive correlation between temperature and ozone level?
plot(airquality)
You can also plot graphs ‘points and lines’ or ‘high density lines’ graphs.
plot(airquality$Ozone, type="b")
plot(airquality$Ozone, type="h")
Now, type ?plot(), this will open the help for the function plot(). It is important to read this help files as they have many more arguments that you can use when using the functions.
We can also change graph labels and titles:
plot(airquality$Ozone, xlab ='ozone Concentration', ylab ='No of Instances', main ='Ozone levels in NY city', col ='green')
The following code shows how to create Horizontal bar plots, vertical bar plots:
barplot(airquality$Ozone, main ='Ozone Concenteration in air',xlab ='ozone levels', col='green',horiz =TRUE)
barplot(airquality$Ozone, main ='Ozone Concenteration in air',xlab ='ozone levels', col='red',horiz =FALSE)
hist(airquality$Solar.R, main ='Solar Radiation values in air',xlab ='Solar rad.', col='red')
We can also create a histogram of the column solar radiation. Try to explain the output:
hist(airquality$Solar.R)
Let’s generate a boxplot of solar radiation. Explain the output.
par(mfrow=c(3,3), mar=c(2,5,2,1), las=1, bty="n")plot(airquality$Ozone)plot(airquality$Ozone, airquality$Wind)plot(airquality$Ozone, type="c")plot(airquality$Ozone, type="s")plot(airquality$Ozone, type="h")barplot(airquality$Ozone, main ='Ozone Concenteration in air',xlab ='ozone levels', col='green',horiz =TRUE)hist(airquality$Solar.R)boxplot(airquality$Solar.R)boxplot(airquality[,0:4], main='Multiple Box plots')
Other visualisation packages include lattice (good for kernel density plots) , ggplot2, plotty, maps (to plot country maps). Explore more on the link:https://towardsdatascience.com/a-guide-to-data-visualisation-in-r-for-beginners-ef6d41a34174
Lab 9 - Mock/Practice test & AI AND R
📝 MOCK/PRACTICE TEST
Go to the module site in the LZ. Go to the tile ‘Assessments’ and click on “Mock/Practice MCQs”. Students can take the test as many times they want. Each time, students will receive many new questions.
🤖 Using AI (e.g. ChatGPT) to Write and Debug Simple R Scripts
Introduction This lab will guide students through the process of writing and debugging simple R scripts with the assistance of ChatGPT. Whether you’re a beginner or an experienced R user, ChatGPT can provide valuable insights and help streamline your coding process.
Prerequisites Basic understanding of R syntax and programming concepts. R and RStudio installed on your computer.
Writing R Scripts with ChatGPT
👣 Step 1: Define Your Objective Start by clearly stating what you want to achieve with your R script. For example: “I want to calculate the mean of a numeric vector.” “I need to create a histogram of a dataset.”
👣 Step 2: Ask ChatGPT for Code Snippets Once your objective is clear, ask ChatGPT for a code snippet that accomplishes your task. For instance:
“Can you provide an R script to calculate the mean of a vector?”
“Show me how to create a histogram in R.”
Ask ChatGPT: “Can you provide an R script to calculate the mean of a numeric vector?”
ChatGPT might provide a snippet like this:
Sample snippet in Chatgpt about R
👣Step 3: Analyze the Provided Code ChatGPT will give you a code snippet. Read through it carefully and make sure you understand each part. You can ask ChatGPT to explain any lines or functions that are unclear.
👣 Step 4: Run the Code in RStudio
Copy the code snippet into RStudio (use an script) and run it. Observe the output to see if it meets your expectations.
🐞 Debugging R Scripts with ChatGPT
👣 Step 1: Identify the Problem
If the code doesn’t work as expected, identify the error message or the unexpected output. For example:
Error messages in the console.
Results that don’t match your expectations.
You run the script, but you receive an error: Error in mean(height): object ‘height’ not found.
👣 Step 2: Ask ChatGPT for Help Describe the problem to ChatGPT. Be specific about the error or the issue. For example:
“I received an error message that says ‘object not found’. What does this mean?”
“The histogram is not displaying any data. Can you help me fix it?”
“I tried to calculate the mean of a vector, but I got an error saying ‘object not found’.
Here’s my code…”
👣 Step 3: Implement the Suggested Solutions ChatGPT will suggest solutions or ask further questions to clarify the issue. Follow the suggestions step by step, adjusting your code as needed. ChatGPT might respond with: “It looks like there’s a typo in your code. The object you’re trying to calculate the mean for is ‘heights’, not ‘height’.”
👣 Step 4: Test the Adjusted Code After implementing the changes, rerun your script. If issues persist, describe the new output to ChatGPT, and continue the debugging process.
Ask AI to adjust your code
Best Practices for Using ChatGPT with R Incremental Development: Write and test your code in small chunks to catch errors early. Clear Communication: When asking for help, provide clear and detailed information about your code and the issues you’re facing. Understanding Over Copy-Pasting: Try to understand the code snippets provided rather than just copying and pasting them. This will improve your R programming skills over time.
Conclusion With the above steps, you can effectively use ChatGPT to write and debug simple R scripts. Remember, practice is key to becoming proficient in R, and using ChatGPT can accelerate your learning by providing instant assistance and feedback.
Additional Resources: The R Manuals: https://cran.r-project.org/manuals.html RStudio Cheatsheets: https://www.rstudio.com/resources/cheatsheets/
Happy coding!
Lab 10 – Introduction to Refinitiv Workspace (LSEG)
Workshop – Introduction to Refinitiv Eikon
Adapted from: Darren Sparkes and Tom Webster’s ACFI3307
Complete the following activities to set up your Refinitiv Workspace account and learn the software’s features.
Activity 1. If registered, you should have received an email from Refinitiv that gives you your user ID (should be your DMU email address) and a link for you to access Refinitiv workspace as in Figure 1 below (Fig. 1). If you do not seem to have received this email then please check your junk and/or spam folders. If you still think that you have not received the email then please contact me by email to let me know at cam.calderon@dmu.ac.uk
Please be aware that ‘Refinitiv Workspace’ is compatible with Google Chrome and Apple Safari. If you are on a Microsoft Windows computer please download Chrome to your device if you do not use it already. You may need to make it your default browser for the purposes of setting up Refinitiv Eikon after which you can reset back to your usual default browser, remembering that you will need to use Chrome whenever using Refinitv Eikon.
Welcome email
Activity 2. You will be taken to Chrome to set up a password to use with your ID as in Fig. 2 below. Please ensure that you choose a password that you can remember and/or write it down somewhere (perhaps on your phone) so that you will be able to access Eikon in the future.
Note password requirements
Activity 3.
Select ‘Open in Web’
Activity 4.
Your choice!
Activity 5.
About you!
Select ‘Student’
Your profile
Activity 6.
Work through the ‘Welcome’ app features
Features
Activity 7. You should be presented with your home screen. If your screen does not look exactly the same, there is no need to worry. You will have the chance to set your homescreen to what you want in the future.
Home screen
Activity 8.
Select settings!
Image 64
Image 65
Activity 9
Image 66
Activity 10
Image 67
As sown in Fig. 16, Refinitiv have a series of training videos for you to watch that will cover how to use the Refinitiv software. Most of these are only a couple of minutes long. The first time that you click on a video you will be asked to sign in with your DMU EMAIL ADDRESS. The training videos will enhance your ability to use the software and will, therefore, directly impact upon your ability to manage your presentation** assignment**** and final examination**. However, I recommend that once you have signed in, you go to Activity 11 to view the videos as part of the user ‘Certification’ process rather than doing them as a standalone exercise.
Image 68
Activity 11. Refinitiv also has a user ‘Certification’ qualification. This can be accessed from the menu bar as shown in Fig.18.
Image 74
Image 75
The ‘Certification’ screen, as shown in Fig.19, gives details on how to complete the certificate. In brief, to obtain certification status, you must complete training videos and e-learning modules and then pass a 60-minute test including 30 multiple-choice questions. You will need to select the Eikon Product Certification (Fig 19.) and this will take you to the required Learning Materials.
Students must begin to complete the Refinitiv Workspace certification during the lab. Not only will this help students for their assessment, but it will also enhance their CV’s for presentation to potential employers.
Activity 12. Continue to work through the Refinitv Eikon training materials and explore the software as part of your self-study. The quicker you become familiar with using the software, the easier you will find our labs throughout the academic year.
Image 76
Workshop – Terminal Access to Bloomberg This is an OPTIONAL material; students can download the lab for Access to Bloomberg Terminals access in bb, folder ‘LABs’ Handbook’. The lab can also be downloaded from the shared folder for on .
Lab 11 – Refinitiv :News, forecasts, Macrox
Open the user manual on bb, module site, find the folder ‘Labs’. Students must cover pages 9 to 13; “Setting up Thomson Reuters Eikon”.
Activity 1 – Read the news for the UK.
In the search box, type ‘TOPNEWS’ and also ‘TOPNWS’. Within ‘TOPNEWS’, discuss the news you are following with your colleagues and review’ trending topics’. Explore further the labels of this app. Search ‘IFR Markets’ in google; what it is? Click under the label ‘Markets’ and click on IFR and review the ‘Refinitiv NEWSCASTS’ for interesting international financing review briefings. Finally, create your own new Refinitiv Digest.
Activity 2 – Find upcoming forecasts for the upcoming and highly important US economic events for w/c 1 Nov.
Explore economic news from specific groups of markets or countries. Use the Economic Monitor by typing ‘EM’. Apply filters to perform this activity.
Activity 3 – Discuss with your peers: in what country would you invest your savings today?
Explore the Economics Application’ EC’. Investors usually use this top-down approach to choose whether to invest in a specific market. In what country would you invest your savings?
Activity 4 – Interesting shares to invest
The application ‘MACROX’ provides outstanding visual elements. In the tab ‘REGION’ and ‘countries and regions in Universe’ choose Europe; then go to the tab ‘SECTOR’ and select ‘Internet and Catalog Retail’; afterwards, click on the tab ‘SECURITY’ and sort the companies by ‘COMPANY MARKET CAP (USD)’. Browse for some attractive shares to invest in.
Activity 5 – Are we going to get negative interest rates in the UK? I thought so one year ago; however, after recent developments in the supply side, it would look more appropriate a hawkish stance. Are we going to get higher interest rates next year in the UK?
Review forecasts of Centrals Bank’s interest rates. Use the application Central Bank Poll ’CBP.’ ‘US FED INTEREST’ provides more detailed information relevant to Central Banks.