Reading the datasets

The dataset is saved on the desktop within the folder “writen_exam”. To do analysis, I have to read the dataset in to the software using the “readRDS” function and named as “CIRH”.

#Reading the dataset in to Rstudio and assigned to name "CIHR"
CIHR <- readRDS("C:/Users/Hp Laptop/Desktop/writen_exam/CIHR_IRSC_data_donnees_2023-09-01.rds")
View(CIHR)

Question 1

Create a table showing the total payments to each of the Canadian Provinces and Territories per fiscal year from 2013-14 to 2018-19.

Please provide:

  1. The code used to create the output, including concise and informative comments explaining any investigations and assumptions (in .R/.Rmd/.qmd script)

  2. A table showing the total payments per fiscal year per Canadian Province/Territory (in .PDF/.HTML output)

Answer for question 1 (a)

library(knitr)
## Warning: package 'knitr' was built under R version 4.3.1
#Filter the data data by the fiscal year
quest<-CIHR%>%filter(FISCAL_YEAR %in% c(201314:201819)) %>% # This code filtered the dataset and keep only for siscal years 201314, 201415, 201516, 201617, 201718, and 201819.
   group_by(PROVINCE) %>% # It does grouping by province
   summarize(TOTAL_FUNDING = sum(TOTAL_AWARDED_AMOUNT)) # Compute the total funding by province for the defined fiscal year (from 201314 to 201819)

quest
## # A tibble: 16 × 2
##    PROVINCE                  TOTAL_FUNDING
##    <chr>                             <dbl>
##  1 Alberta                     2767577311.
##  2 British Columbia            4179405650.
##  3 Manitoba                     692214644.
##  4 New Brunswick                 22512915 
##  5 Newfoundland and Labrador    133888307 
##  6 Northwest Territories         25040535 
##  7 Nova Scotia                  612654479.
##  8 Nunavut                          99429 
##  9 Ontario                    13668392775.
## 10 Prince Edward Island          16728441 
## 11 Quebec                      1230027601.
## 12 Québec                      7702107783.
## 13 Saskatchewan                 445143149.
## 14 Unknown                        1137970 
## 15 Unknown/Inconnu              223517382.
## 16 Yukon                           167034

Answer for question 1 (b)

The focus of this question lies on three variables; total payment, fiscal year and province. So, the table I am looking for should present the three variables.

#Code for the tabulating the province versus total payment per fiscal year 
quest2<-CIHR%>%filter(FISCAL_YEAR %in% c(201314:201819)) %>%
   group_by(PROVINCE, FISCAL_YEAR) %>% # group by province and fiscal year
   summarize(TOTAL_FUNDING = sum(TOTAL_AWARDED_AMOUNT)) # Agrigate total award amount for each year and province

quest2
## # A tibble: 85 × 3
## # Groups:   PROVINCE [16]
##    PROVINCE         FISCAL_YEAR TOTAL_FUNDING
##    <chr>                  <dbl>         <dbl>
##  1 Alberta               201314    407903566.
##  2 Alberta               201415    424695962.
##  3 Alberta               201516    442235059.
##  4 Alberta               201617    487395947.
##  5 Alberta               201718    481713770.
##  6 Alberta               201819    523633006.
##  7 British Columbia      201314    646882695.
##  8 British Columbia      201415    691457682.
##  9 British Columbia      201516    691923843.
## 10 British Columbia      201617    679294510.
## # ℹ 75 more rows

Question 2

Is there a statistically significant difference in the average size of grants awarded to Alberta versus Nova Scotia over all competitions from fiscal years 2014-15 to 2017-18? Please provide:

  1. The code used to create the output, including concise and informative comments explaining any investigations and assumptions (in .R/.Rmd/.qmd script)

  2. A graph comparing the average size of grants awarded to the two provinces in the specified timeframe (in .PDF/.HTML output)

  3. A brief explanation of your results, and rationale for how you tested for statistically significant differences, including your choice of statistical test (in .PDF/.HTML output)

Answer for question 2 (a)

# Filter the data
CIHR3<-CIHR%>%filter(FISCAL_YEAR %in% c(201415:201718),CIHR$PROVINCE %in% c("Alberta","Nova Scotia" )) 
# First we need to get the data for the period 2014-15 to 2017-18 for the two provinces. For this we used the function filter

# Table
table(CIHR3$FISCAL_YEAR,CIHR3$PROVINCE) # This code computes the table for the tow provinces; Alberta and Nova scotia
##         
##          Alberta Nova Scotia
##   201415     759         204
##   201516     740         195
##   201617     753         174
##   201718     719         159
#Independent t-test
TTest<-t.test(TOTAL_AWARDED_AMOUNT~PROVINCE, data=CIHR3,alternative = "two.sided",
                 var.equal = TRUE,conf.level = 0.95) #  
TTest
## 
##  Two Sample t-test
## 
## data:  TOTAL_AWARDED_AMOUNT by PROVINCE
## t = 1.5982, df = 3701, p-value = 0.1101
## alternative hypothesis: true difference in means between group Alberta and group Nova Scotia is not equal to 0
## 95 percent confidence interval:
##  -19182.57 188379.63
## sample estimates:
##     mean in group Alberta mean in group Nova Scotia 
##                  617987.5                  533388.9

Answer for Question 2 (b)

There are different alternatives to compare award grant size graphically. Line graph can be one option, but does not look good for the data due to the range difference over the fiscal year. Another option is box plot and works well for the data. Logarithm transformation is used to minimize the range. Accordingly the log-transformed total awarded amount was compared across the two provinces at each fiscal year. Based on the box-plot, there seems no difference in the log-transformed total awarded amount among the two provinces at each fiscal year. This is inline with the output from the independent t-test results.

CIHR3$FISCAL_YEAR<-as.factor(CIHR3$FISCAL_YEAR)

plots<- ggplot(CIHR3)+ geom_boxplot(aes(x=FISCAL_YEAR, y=log(TOTAL_AWARDED_AMOUNT), color=PROVINCE)) # Boxplot was used to compare 
plots

Answer for Question 2 (c)

The research question we want to answer is if there is significant difference between award grant size and provinces. In this case award grant size is an outcome variable which is numeric. The second variable is provinces that has only two categories (Alberta versus Nova Scotia). In this case, we want to test the hypothesis whether award grant size differs across the two provinces or not. This implies that the alternative hypothesis is two tailed.

Therefore, I considered two independent t-test with the following assumptions; 1) The outcome variable (amount of grant) is normally distributed, 2) The variance is equal across groups, and 3) The observations are independent. In addition, 95% level of confidence is considered.

Decision: we failed to reject the null hypothesis.

Conclusion: There is no significant statistical difference in the average award grant size across the two provinces (Alberta and Nova Scotia)

Question 3

Your colleague is given the following task: “Which 5 programs received the most funding overall in the last 3 fiscal years? Present the results in a table.” You are assigned as their code reviewer. Review and debug the following code created by your colleague.

  # load libraries and data
  library(tidyverse)
  exam_data <- readRDS("CIHR_IRSC_data_donnees_2023-09-01.rds")
  # Create output dataset
  output <- exam_data %>% 
     filter(between(FISCAL_YEAR, 201617, 201920)) %>%
     ##This code filter the last 4 fiscal years (201617 201718 201819 201920)!3 fiscal years
     group_by( PROGRAM_NAME,FISCAL_YEAR ) %>%## No needs of grouping by FISCAL_YEAR
     summarize(TOTAL_FUNDING = sum(TOTAL_AWARDED_AMOUNT)) %>%
     arrange(desc(TOTAL_FUNDING))%>%
     head()## This head function list the top 6 programs received the most funding overall in the last 3 fiscal years
## `summarise()` has grouped output by 'PROGRAM_NAME'. You can override using the
## `.groups` argument.
  table(output$FISCAL_YEAR)
## 
## 201617 201718 201819 201920 
##      1      1      2      2

Please provide a brief email that you would send to your colleague containing your feedback on their script (in .PDF/.HTML output). Only include the feedback in the email, not a salutation or closing.

Answer for Q3 (Brief email)

The r script looks fine and works well. However, there are few issues you need to correct. You are asked to to identify the 5 programs received the most funding overall in the last 3 fiscal years? The code you used filtered four years instead of three. The other issue the code you used to group by fiscal year. I don’t think you need to group by fiscal year as long as you filtered it by the fiscal year. One more simple comment is the code you used for produsing the heading. This specific function will list the top 6 programs instead of 5.

Question 4

Artificial Intelligence (AI) is a powerful tool with many possible applications. What do you see as the benefits and drawbacks of implementing AI in data analytics? Do the benefits and/or drawbacks change when the data analytics are being done by a government agency? (max 400 words)

Answer for Q4

These days, we commonly work with big data in almost all fields, being health, business, agriculture, etc. The dataset we want to analysis may be too big in volume, velocity, variety and veracity. Big data refers to a dataset that are too complex to be handled with traditional data analysis methods. In this case using AI algorism can help in processing complex data in making it suitable for analysis. It uses machine learning, natural language processing, and other techniques to process, interpret, and extract insights from structured and unstructured data sources. The Artificial intelligence tools can be used to;

  • Produce very beautiful visualization, which can be easily understood by implementer, policy makers, and practitioner and by the people who do not have much knowledge in the field.

  • To discover patterns, trends, and anomalies that human might overlook. It can help you to get deeper understanding of the data and generate actionable recommendations.

  • To support and improve decision making processes by providing data-driven and evidence-based solutions.

  • To learn from the feedback to refine and update decision over time, reduce errors, and inconsistencies.

These are some of the benefits, but there are many more that I did not listed here.

Although there are many benefits of AI in data analysis, there are also drawbacks. These includes;

  • Computational complexity in managing the dataset

  • May lead ethical and social concerns about privacy and security

  • May lack contixual understanding when the situation is ambiguous and complex

  • The tool equires significant investment and expertise to develop the algorithm

  • Limited human involvement when the situation require human judgment

Thank You