Assessment 2 questions
Part 1 [22 marks]
Description of dataset
The dataset for this assessment is prepared based on data regarding crimes of Boston from Kaggle (source: https://www.kaggle.com/AnalyzeBoston/crimes-in-boston/version/2).
You can download the dataset from here.
Crime incident reports are provided by Boston Police Department (BPD) to document the initial details surrounding an incident to which BPD officers respond. This is a dataset containing records from the new crime incident report system, which includes a reduced set of fields focused on capturing the type of incident as well as when and where it occurred. The data was recorded in two data files: crime.csv and offence_codes.csv.
Instructions
Write R code in an Rmd file to answer the following questions. (Each question should be presented in one code chunk.)
Step | Marks | |
1. | Load the dataset from the given files into a two dataframes named crime and offence_codes. Rename columns to replace spaces with underscores if exist. Change OCCURRED_ON_DATE to the correct type. (Hint: use str_replace_all to do this automatically for all columns.) | 3 marks |
2. | In the crime dataframe:
– write R code to investigate whether there are duplicate rows – remove them if exist – display the number of remaining rows and columns. |
3 marks |
3. | Display the OFFENCE_CODE, OFFENCE_CODE_GROUP and OFFENCE_CODE occurred in August 2018. In the result table, remove the word ‘!ERROR’ at the end of the OFFENCE_CODE_GROUP if exist. | 3 marks |
4. | a) Find the five offense groups that have the highest number of total crimes. b) Display the number of offense groups and total of crimes of each year. | 3 marks |
5. | How many crimes having OFFENCE_CODE_GROUP containing ‘Drug’ and
OFFENCE_DESCRIPTION containing ‘HEROIN’? (Hint: use str_detect().) |
3 marks |
6. | Display INCIDENT_NUMBER, OCCURRED_ON_DATE, OFFENCE_DESCRIPTION, REPORTING_AREA
of crimes with description as ‘DRUGS - SALE / MANUFACTURING’ that occurred on BLUE HILL AVE, District B2. |
3 marks |
7. | Analyse the distribution of monthly crimes in the dataset. What is the difference before and after removing outliers? (Hint: draw a boxplot and a histogram and write a short paragraph (less than 100 words) to describe your insight.) | 4 marks |
Part 2 [18 marks]
Description of dataset
The given Excel file named SuicideRate.xlsx records the suicide rates among different cohorts globally, across the socioeconomic spectrum. The datafile contains two worksheets: SuicideByCohort and CountryProfile. The original data is available at Kaggle (source: https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016).
Instructions
You will see that the data are far from being ready for analysis and need to be ‘wrangled’. Please write R code to perform the following steps.
Step | Marks | |
1. | Load the data from the SuicideRate.xlsx (worksheet SuicideByCohort) into a dataframe named SuicideRate. Rename the columns to remove spaces. Quickly show the structure of SuicideRate. | 2 marks |
2. | You can see that most column names contain the information about the year which should be placed as row values.
– Use pivot_longer to transform the dataframe into three columns, namely SuicideCohort, Year and Value. – Drop all rows having NA in Value. – Display the number of columns and rows before and after transformation. |
2 marks |
3. | You can see that the data in column Value contain much information.
– Split the Value column into two columns named Suicide_no and Population. – Show the total number of cohorts and the number of distinct years. |
2 marks |
4. | Investigate and report if the dataset has any missing data for specific year(s). | 3 marks |
5. | Calculate the suicide rate using Suicide_no and Population for each cohort. Create four new columns using the values in Cohort: Country, Gender, Age, Generation. Display the countries with at least three cohorts presenting suicide rates higher than 150/100 000 population. | 3 marks |
6. | Load the data from the CountryProfile worksheet into a new dataframe called CountryProfile. Rename the columns to remove spaces. How many countries in the CountryProfile dataframe are not in the SuicideRate dataframe? | 3 marks |
7. | Draw a chart to compare the top ten cohorts which have the highest suicide rates in the SuicideRate dataframe. Order the bar from highest to lowest. Examine the cohorts against the socioeconomic spectrum in the CountryProfile dataframe. Write a small paragraph describing your insight got from this chart. | 3 marks |
Breathe a Sign of Relief with our Academic Assistance: Get instant help, 100% personalized and accurate solutions that make your study life better.
Expert's Answer
Chat with our Experts
Want to contact us directly? No Problem. We are always here for you
Your future, our responsibilty submit your task on time.
Order NowGet Online
Assignment Help Services