--- title: "Lab 1" output: html_document: df_print: paged pdf_document: default --- ### Instructions Your solutions must be written in an R Markdown (Rmd) file called `lab-01.Rmd`. This file must...

1 answer below »
This assignment is in R and the rmd file is attached and needs to answer seven questions that are in it. I need help solving all of them. The data file is also attached, I need to upload the rmd file called lab01.rmd.


--- title: "Lab 1" output: html_document: df_print: paged pdf_document: default --- ### Instructions Your solutions must be written in an R Markdown (Rmd) file called `lab-01.Rmd`. This file must include your code and write up for each question. Your “submission” will be whatever is in your lab repository at the deadline. In order to receive full credit, your notebook must knit to HTML without any errors. This lab is open book, open internet, closed other people. You may use any online or book based resource you would like, but you must include citations for any code that you use. You may not consult with anyone else about this lab other than the Professor or TA for this course. You have until 11:59pm on Sunday, October 31 to complete this lab and turn it in via your personal GitHub repo - late work will not be accepted. Technical difficulties are not an excuse for late work - do not wait until the last minute to knit / commit / push. On questions asking you to produce a graph, be sure to include an appropriate title and labels. Graphs should include a brief (one or two sentence) narrative describing the graph and what it reveals about the data. For this lab, you can only use base R (**do not use any third-party libraries such as `ggplot`, `dplyr`, etc.**). ### Getting help You are not allowed to post any questions on the Canvas Discussion board. Any questions about the lab must be asked during office hours or via email to the Professor or the TA. ### Grading and feedback The total points for the questions add up to 90 points. The remaining 10 points are allocated to code style, overall organization, spelling, grammar, etc. There is also an extra credit question that is worth 5 points. You will receive feedback as an issue posted to your repository, and your grade will also be recorded on Canvas. ### The data The data can be found inside the `data` folder in the main directory. `ppauto_pos` contains information on private passenger auto liability/medical claims for various property-casualty insurers that write business in the US. A description of each field is below: - `GRCODE` NAIC company code (including insurer groups and single insurers) - `GRNAME` NAIC company name (including insurer groups and single insurers) - `AccidentYear` Accident year(1988 to 1997) - `DevelopmentYear` Development year (1988 to 1997) - `DevelopmentLag` Development year (AY-1987 + DY-1987 - 1) - `IncurLoss_B` Incurred losses and allocated expenses reported at year end - `CumPaidLoss_B` Cumulative paid losses and allocated expenses at year end - `BulkLoss_B` Bulk and IBNR reserves on net losses and defense and cost containment expenses reported at year end - `PostedReserve97_B` Posted reserves in year 1997 taken from the Underwriting and Investment Exhibit – Part 2A, including net losses unpaid and unpaid loss adjustment expenses - `EarnedPremDIR_B` Premiums earned at incurral year - direct and assumed - `EarnedPremCeded_B` Premiums earned at incurral year - ceded - `EarnedPremNet_B` Premiums earned at incurral year - net - `Single` 1 indicates a single entity, 0 indicates a group insurer ### Questions **Question 1 (5 points)**: Load the file `data/ppauto_pos.csv` into R and assign it to a variable `ppauto`. ```{r} ``` **Question 2 (20 points)**: Create a bar plot showing paid losses (`CumPaidLoss_B`) for `State Farm Mut Grp` by accident year at development lag (`DevelopmentLag`) 10. ```{r} ``` **Question 3 (10 points)**: Create a function, `incurred_loss_ratio`, which takes two parameters, `incurred_loss` and `earned_premium`. If `earned_premium` equals `0`, the function should return `NaN`, otherwise it should return the ratio of `incurred_loss` to `earned_premium`. ```{r} ``` **Question 4 (15 points)**: Using the function created in Question 3, add a new column, `IncurredLossRatio`, to `ppauto` which contains the ratio of incurred losses (`IncurLoss_B`) to net earned premiums (`EarnedPremNet_B`). ```{r} ``` **Question 5 (10 points)**: Which insurer (`GRNAME`) has the maximum, non-`NaN`, incurred loss ratio? ```{r} ``` **Question 6 (20 points)**: Create a boxpolot showing the distribution of `IncurredLossRatio` by accident year at development lag 10. *TIP: when creating your plot, try setting* `outline = FALSE` *to prevent showing outliers* ```{r} ``` **Question 7 (10 points)**: What’s the difference between `[`, `[[`, and `$` when applied to a list? **Extra Credit (5 points)**: Insurance claims are often presented in the form of a triangle structure, showing the development of claims over time for each accident year (see example below). *Note*: You will need to set `eval=TRUE` to run the code chunk below. ```{r eval=FALSE} options(width = 250) # reshape data into development triangle pivot_table <- reshape(="" data="ppauto[(ppauto$GRNAME" =="State Farm Mut Grp" )="" &="" (ppauto$developmentyear=""><= 1997),="" c("accidentyear",="" "developmentlag",="" "cumpaidloss_b")],="" direction="wide" ,="" idvar="AccidentYear" ,="" timevar="DevelopmentLag" ,="" v.names="CumPaidLoss_B" )="" #="" create="" matrix="" from="" data="" frame="" c=""><- data.matrix(pivot_table[2:11])="" dimnames(c)=""><- list(pivot_table$accidentyear,="" 1:10)="" c="" ```="" the="" most="" established="" method="" for="" predicting="" future="" claim="" payments="" (i.e.="" the="" `na`s="" in="" the="" triangle="" above)="" is="" known="" as="" the="" chain-ladder="" algorithm.="" the="" first="" step="" of="" the="" chain="" ladder="" algorithm="" is="" to="" calculate="" the="" development="" ratios,="" $f_k$,="" from="" the="" loss="" development="" triangle="" from="" one="" lag="" period="" to="" the="" next.="" the="" formula="" to="" calculate="" $f_k$="" is="" below.="" $$="" f_k="\frac{\sum_{i=1}^{n-k}" c_{i,="" k+1}}{\sum_{i="1}^{n-k}" c_{i,="" k}}="" $$="" where="" $c$="" is="" an="" $n="" \times="" n$="" claim="" development="" triangle="" (matrix).="" for="" example,="" using="" the="" claim="" development="" triangle="" above,="" the="" development="" ratio="" from="" development="" lag="" 1="" to="" development="" lag="" 2,="" $f_1$,="" is="" *note*:="" you="" will="" need="" to="" set="" `eval="TRUE`" to="" run="" the="" code="" chunk="" below.="" ```{r="" eval="FALSE}" f1=""><- sum(c[1:9, 2]) / sum(c[1:9, 1]) f1 ``` create a function `development_ratios`, which takes a $n \times n$ matrix parameter, `c`, and returns a vector of the development ratios calculated using the formula above. ```{r} ``` grcode,grname,accidentyear,developmentyear,developmentlag,incurloss_b,cumpaidloss_b,bulkloss_b,earnedpremdir_b,earnedpremceded_b,earnedpremnet_b,single,postedreserve97_b 43,ids property cas ins co,1988,1988,1,607,133,226,957,62,895,0,73044 43,ids property cas ins co,1988,1989,2,647,333,129,957,62,895,0,73044 43,ids property cas ins co,1988,1990,3,582,431,38,957,62,895,0,73044 43,ids property cas ins co,1988,1991,4,598,570,19,957,62,895,0,73044 43,ids property cas ins co,1988,1992,5,614,615,0,957,62,895,0,73044 43,ids property cas ins co,1988,1993,6,615,615,0,957,62,895,0,73044 43,ids property cas ins co,1988,1994,7,615,615,0,957,62,895,0,73044 43,ids property cas ins co,1988,1995,8,614,614,0,957,62,895,0,73044 43,ids property cas ins co,1988,1996,9,614,614,0,957,62,895,0,73044 43,ids property cas ins co,1988,1997,10,614,614,0,957,62,895,0,73044 43,ids property cas ins co,1989,1989,1,2254,934,495,3695,288,3407,0,73044 43,ids property cas ins co,1989,1990,2,2859,1746,515,3695,288,3407,0,73044 43,ids property cas ins co,1989,1991,3,2979,2365,357,3695,288,3407,0,73044 43,ids property cas ins co,1989,1992,4,2764,2579,47,3695,288,3407,0,73044 43,ids property cas ins co,1989,1993,5,2826,2763,0,3695,288,3407,0,73044 43,ids property cas ins co,1989,1994,6,3017,2966,0,3695,288,3407,0,73044 43,ids property cas ins co,1989,1995,7,2990,2940,0,3695,288,3407,0,73044 43,ids property cas ins co,1989,1996,8,2978,2978,0,3695,288,3407,0,73044 43,ids property cas ins co,1989,1997,9,2978,2978,0,3695,288,3407,0,73044 43,ids property cas ins co,1989,1998,10,2938,2938,0,3695,288,3407,0,73044 43,ids property cas ins co,1990,1990,1,5843,2030,1669,6138,249,5889,0,73044 43,ids property cas ins co,1990,1991,2,7424,4864,757,6138,249,5889,0,73044 43,ids property cas ins co,1990,1992,3,8307,6880,188,6138,249,5889,0,73044 43,ids property cas ins co,1990,1993,4,8671,8087,50,6138,249,5889,0,73044 43,ids property cas ins co,1990,1994,5,9066,8595,235,6138,249,5889,0,73044 43,ids property cas ins co,1990,1995,6,8926,8743,146,6138,249,5889,0,73044 43,ids property cas ins co,1990,1996,7,8767,8763,1,6138,249,5889,0,73044 43,ids property cas ins co,1990,1997,8,8765,8762,0,6138,249,5889,0,73044 43,ids property cas ins co,1990,1998,9,8732,8729,0,6138,249,5889,0,73044 43,ids property cas ins co,1990,1999,10,8802,8802,0,6138,249,5889,0,73044 43,ids property cas ins co,1991,1991,1,11422,4537,2941,17533,749,16784,0,73044 43,ids property cas ins co,1991,1992,2,16093,11527,951,17533,749,16784,0,73044 43,ids property cas ins co,1991,1993,3,18648,15123,1472,17533,749,16784,0,73044 43,ids property cas ins co,1991,1994,4,19095,16656,1179,17533,749,16784,0,73044 43,ids property cas ins co,1991,1995,5,18653,17321,307,17533,749,16784,0,73044 43,ids property cas ins co,1991,1996,6,18469,18076,98,17533,749,16784,0,73044 43,ids property cas ins co,1991,1997,7,18407,18308,-3,17533,749,16784,0,73044 43,ids property cas ins co,1991,1998,8,18640,18602,0,17533,749,16784,0,73044 43,ids property cas ins co,1991,1999,9,18472,18434,0,17533,749,16784,0,73044 43,ids property cas ins co,1991,2000,10,18464,18464,0,17533,749,16784,0,73044 43,ids property cas ins co,1992,1992,1,19933,7564,4885,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1993,2,24162,16061,2630,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1994,3,28739,22465,2998,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1995,4,28329,25204,1268,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1996,5,28071,26517,617,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1997,6,27722,27124,56,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1998,7,27580,27191,6,29341,1694,27647,0,73044 43,ids property cas ins co,1992,1999,8,27873,27680,2,29341,1694,27647,0,73044 43,ids property cas ins co,1992,2000,9,27662,27645,0,29341,1694,27647,0,73044 43,ids property cas ins co,1992,2001,10,27662,27662,0,29341,1694,27647,0,73044 43,ids property cas ins co,1993,1993,1,24604,8343,7823,37194,2056,35138,0,73044 43,ids property cas ins co,1993,1994,2,32130,19900,4691,37194,2056,35138,0,73044 43,ids property cas ins co,1993,1995,3,33575,26732,2539,37194,2056,35138,0,73044 43,ids property cas sum(c[1:9,="" 2])="" sum(c[1:9,="" 1])="" f1="" ```="" create="" a="" function="" `development_ratios`,="" which="" takes="" a="" $n="" \times="" n$="" matrix="" parameter,="" `c`,="" and="" returns="" a="" vector="" of="" the="" development="" ratios="" calculated="" using="" the="" formula="" above.="" ```{r}="" ```="" grcode,grname,accidentyear,developmentyear,developmentlag,incurloss_b,cumpaidloss_b,bulkloss_b,earnedpremdir_b,earnedpremceded_b,earnedpremnet_b,single,postedreserve97_b="" 43,ids="" property="" cas="" ins="" co,1988,1988,1,607,133,226,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1989,2,647,333,129,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1990,3,582,431,38,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1991,4,598,570,19,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1992,5,614,615,0,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1993,6,615,615,0,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1994,7,615,615,0,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1995,8,614,614,0,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1996,9,614,614,0,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1988,1997,10,614,614,0,957,62,895,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1989,1,2254,934,495,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1990,2,2859,1746,515,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1991,3,2979,2365,357,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1992,4,2764,2579,47,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1993,5,2826,2763,0,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1994,6,3017,2966,0,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1995,7,2990,2940,0,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1996,8,2978,2978,0,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1997,9,2978,2978,0,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1989,1998,10,2938,2938,0,3695,288,3407,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1990,1,5843,2030,1669,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1991,2,7424,4864,757,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1992,3,8307,6880,188,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1993,4,8671,8087,50,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1994,5,9066,8595,235,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1995,6,8926,8743,146,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1996,7,8767,8763,1,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1997,8,8765,8762,0,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1998,9,8732,8729,0,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1990,1999,10,8802,8802,0,6138,249,5889,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1991,1,11422,4537,2941,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1992,2,16093,11527,951,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1993,3,18648,15123,1472,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1994,4,19095,16656,1179,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1995,5,18653,17321,307,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1996,6,18469,18076,98,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1997,7,18407,18308,-3,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1998,8,18640,18602,0,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,1999,9,18472,18434,0,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1991,2000,10,18464,18464,0,17533,749,16784,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1992,1,19933,7564,4885,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1993,2,24162,16061,2630,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1994,3,28739,22465,2998,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1995,4,28329,25204,1268,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1996,5,28071,26517,617,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1997,6,27722,27124,56,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1998,7,27580,27191,6,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,1999,8,27873,27680,2,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,2000,9,27662,27645,0,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1992,2001,10,27662,27662,0,29341,1694,27647,0,73044="" 43,ids="" property="" cas="" ins="" co,1993,1993,1,24604,8343,7823,37194,2056,35138,0,73044="" 43,ids="" property="" cas="" ins="" co,1993,1994,2,32130,19900,4691,37194,2056,35138,0,73044="" 43,ids="" property="" cas="" ins="" co,1993,1995,3,33575,26732,2539,37194,2056,35138,0,73044="" 43,ids="" property="">
Answered 2 days AfterOct 25, 2021

Answer To: --- title: "Lab 1" output: html_document: df_print: paged pdf_document: default --- ### Instructions...

Mohd answered on Oct 28 2021
111 Votes
Lab 1
Lab 1
library(readr)
library(magrittr)
library(dplyr)
library(ggplot2)
library(rmarkdown)
library(MASS)
Instructions
Your solutions must be written in an R Markdown (Rmd) file
called lab-01.Rmd. This file must include your code and write up for each question. Your “submission” will be whatever is in your lab repository at the deadline. In order to receive full credit, your notebook must knit to HTML without any errors.
This lab is open book, open internet, closed other people. You may use any online or book based resource you would like, but you must include citations for any code that you use. You may not consult with anyone else about this lab other than the Professor or TA for this course.
You have until 11:59pm on Sunday, October 31 to complete this lab and turn it in via your personal GitHub repo - late work will not be accepted. Technical difficulties are not an excuse for late work - do not wait until the last minute to knit / commit / push.
On questions asking you to produce a graph, be sure to include an appropriate title and labels. Graphs should include a brief (one or two sentence) narrative describing the graph and what it reveals about the data. For this lab, you can only use base R (do not use any third-party libraries such as ggplot, dplyr, etc.).
Getting help
You are not allowed to post any questions on the Canvas Discussion board. Any questions about the lab must be asked during office hours or via email to the Professor or the TA.
Grading and feedback
The total points for the questions add up to 90 points. The remaining 10 points are allocated to code style, overall organization, spelling, grammar, etc. There is also an extra credit question that is worth 5 points. You will receive feedback as an issue posted to your repository, and your grade will also be recorded on Canvas.
The data
The data can be found inside the data folder in the main...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here