讲解:Maths Skills、R、LendingClub、RPython|R

Maths Skills 2 (Statistics) assessmentSpring Term 2019This assignment consists of two parts: in the first one you are asked to revisit the data onUK fishing vessels under 10 metres long; the second part instead concerns data on loans(granted as well as rejected) from LendingClub, one of the largest U.S. peer-to-peer financialcompanies. For each part, you will download data from a website, read them into R, performsome computations on them, and produce graphical displays.The process and results of the analysis should be documented in an R Markdown file, producingan output document in PDF format. Code alone is not acceptable: at each step, you need toexplain what you are doing and comment (briefly!) on the results. Your submission shouldconsist of a single zipped folder containing only:1. the R Markdown file (.Rmd file) and2. the output PDF document.Absence of one of the files will incur a very high penalty. Inclusion in the zipped folder ofother unrequested files, including the data files, will also attract a penalty.The maximum number of pages of the PDF document is 10, all inclusive. Because of this, itis best to do without a table of contents; however, sectioning of the document is stronglyencouraged. In particular, separate sections should be devoted to each of the two parts ofthe assignmemt.You are allowed to use and adapt for your purposes all the materials presented in the lecturesand posted on Moodle, including the R Markdown input files, without any need of referencingthem. However, you should provide, at the end of your report, references to the R packagesyou are using and to the data sources.You may informally discuss with fellow students how to perform a task. However, you arenot allowed to share your code, and should write the report on your own.The following is a more detailed description of what the assignment entails.Part A: UK Fishing vesselsThe goal of this part is provide a graphical representation of the geographical distribution ofUK fishing vessels under 10 metres in length.1. Use get_map() in package ggmap to obtain from Stamen Maps a map of the UK andsave it into an object UKmap. Make sure that Northern Ireland and the Shetland Islandsare included, this will require some experimentation to find an appropriate bounding box.2. Read into R the vessel data using read_csv(), then change the variables’ names asdone in the lectures.13. Produce a tibble AdminPortCount containing a tally of the numbers of vessels in eachAdministrative Port.4. Use geocode() on the first column of AdminPortCount to obtain a tibble with thecoordinates of each port. Then, with bind_cols(), bind together this tibble andAdminPortCount, and call the resulting tibble AdminPortCLL.Check that the coordinates of the ports in AdminPortCLL are all within the map’sbounding box; filter() may be useful for this purpose.If any of the coordinates are outside the map, use geocode() again for the correspondingports, adding , UK to the name of the port. Then replace the wrong coordinates inAdminPortCLL with the correct ones. Print the tibble AdminPortCLL.5. Plot UKmap with ggmap() and use geom_point() to overlay on it red filled circlescentered at the Administrative ports and with area proportional to the number of fishingvessels in each port. The size aesthetic is useful in this regard. Experiment with a fewvalues of alpha to control the transparency of the circles. What is the eectof addingscale_size_area() to the specification of your plot?Part B: LendingClub’s data on Loans and RejectionsThe general aim of this part is to produce some plots to compare the loans granted byLendingClub to the loan applications that were rejected. In order to do that, the data forLoans and Rejects, which are available in dierentformats, need to undergo preliminarytransformations.1. Pick a State in the U.S., a list is available at https://en.wikipedia.org/wiki/U.S._state.Send me an email at agostino.nobile@york.ac.uk with subject Maths Skills 2 -US State, to inform me of your choice: I may ask代做Maths Skills作业、代写R实验作业、代写LendingClub作业、代做R编程设计作业 代做Python程 you to change it, if it is unsuitable ortoo popular. By sending the email you are not committing yourself to that choice ofState (email me again to change it), or indeed to doing the Statistics assignment ofMaths Skills 2.2. Go to the LendingClub website https://www.lendingclub.com/info/download-data.actionand download the Loans data and the Rejections data for the four quarters of 2018.Also download the Data Dictionary available at the bottom of the same page. It maybe useful to explore a bit the LendingClub site, to get an idea of their business and ofpeer-to-peer lending more generally.The eight zipped csv files downloaded have a total size of about 170MB. Place them ina subfolder, say called DATA, of the folder where you keep the Rmd file for this project.Depending on how much disk space you have available, you may not wish to unzip allthe files at once, as their inflated size is about 1.1GB.23. For each of the zipped Rejects files: Unzip the file from within R using something likesystem(unzip DATA/filename.csv.zip) Read the data in the unzipped file into R, using read_csv(). Remove the unzipped file (to save disk space), with something likesystem(rm filename.csv) Filter the data in the resulting tibble, to keep only the records where the variable Stateequals the two letter code of your chosen state.Finally, use the function bind_rows() to collect all the data for your chosen state intoa single tibble called Rejects.4. Read the Loans data into R, following a procedure similar to the one for the Rejects.For the Loans data, you will need to deal with two additional complications: the csv files contain two summary rows at the bottom which must not be read, theargument n_max in read_csv() is helpful in this respect; the algorithm used by read_csv() to guess the type of each variable (chr, dbl, etc.)fails for these data, if one uses the default value of the argument guess_max (moredetails can be found in § 11.4 of Wickham and Grolemund, 2017). To fix this, in thecall to read_csv(), set guess_max to the same value as n_max.As for Rejects, collect all the Loans data for your chosen state in a single tibble calledLoans.5. The Loans tibble should contain 145 variables. Use select() to keep only the variablesloan_amnt, title, dti, zip_code, addr_state and emp_length, renamed respectivelyas Amount, Title, Debt2IncomeRatio, ZipCode, State and EmploymentLength.Perform the same operation on the Rejects data, by selecting the same six variables(note the dierentnames!) and renaming them as done for the Loans data.The variable Debt2IncomeRatio for the Rejects data is of type chr: remove thetrailing % symbols and transform the variable to type dbl.Replace any instance of n/a in the character variables in the two tibbles with NA.6. Use bind_rows() to collect together the Loans and Rejects data into a single tibblenamed LoanApps, with an additional character variable Granted that is equal to Yesfor Loans, and equal to No for Rejects. The argument .id of bind_rows() is ofhelp in this regard.Use mutate(), fct_recode() and fct_relevel() to replace, in the tibble LoanApps,the variable EmploymentLength with a factor EmploymentYears having levels 1, ..., 9, 10+.7. Make a barplot to explore whether the proportion of granted loans is related to the loantitle. Which type of loans are granted more (or less) often?Consider next how the proportion of granted loans varies across the levels of the factor3EmploymentYears. Make a plot and comment on the results.8. Use boxplots (and an appropriate scale) to compare the distributions of the variableAmount between granted and rejected loans. Are the variables Amount and Grantedrelated, and if so how?Compare next the distributions of the variable Debt2IncomeRatio between granted andrejected loans.9. Use geom_bar() to investigate whether the proportion of granted loans varies acrossZipCodes. As some ZipCodes have small counts, use fct_lump() to restrict attentionto the most common (30 or fewer) ZipCodes转自:http://ass.3daixie.com/2019030729243791.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容