Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Property - Casualty / General Insurance
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions


Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-20-2017, 09:44 AM
ronaldy27's Avatar
ronaldy27 ronaldy27 is offline
Member
CAS
 
Join Date: Jan 2012
Location: The South
Studying for the credential
Posts: 2,959
Default mapping in R (cat modelling?)

Hi,
I am trying to find a way to organize all the insureds by where they live within the US, perhaps group them by a fixed area using Longitude and Latitude so that if a natural disaster were to happen in certain regions, I can analyse the "total insureds value" impact on the insureds located in the areas.

I went over documentations for some mapping packages in R but I am kind of lost. I know the "maps" allow you to group regions by counties, states,etc. However, is there a way for me to add data into those regions?

I'm a newbie in R and I would appreciate it if anyone could provide me with a direction as to how to go about this project.
__________________
Spoiler - for size:



Reply With Quote
  #2  
Old 12-20-2017, 10:04 AM
Klaymen's Avatar
Klaymen Klaymen is offline
Member
CAS
 
Join Date: Oct 2001
Studying for 2018 Las Vegas NABC
Posts: 19,141
Default

Although I use the maps package, it is not very sophisticated. It gets me nice color maps by state and county, and I can lay overlay text or values and show a title and a legend.
I would like to learn the more sophisticated methods but it just hasn't been worth the time to me yet. I doubt that it will adequately meet your needs (i.e. lat and long), but it is an easy place to get started. I think you'll want ggplot2 but there is much more involved. (if someone else wants to provide code I would appreciate it)

Here's some sample code for the maps program. Copying the information directly from the screen didn't look right but if you go to the source of this message (quote it) it should work.

library(maps)
library(mapdata)

countycol<-cbind(
"#b35806","#b35806","#b35806","#d8daeb","#fee0b6", "#fee0b6","#998ec3","#998ec3","#542788","#d8daeb", "#b35806","#f1a340","#b35806","#d8daeb","#542788", "#542788","#998ec3","#f1a340","#998ec3","#fee0b6", "#b35806","#f1a340","#b35806","#b35806","#b35806", "#d8daeb","#d8daeb","#542788","#fee0b6","#f1a340", "#b35806","#b35806","#542788","#f1a340","black","# 542788","#542788","#b35806","#f1a340","#b35806","# b35806","#998ec3","#f1a340","#b35806","#d8daeb","# f1a340","#542788","#998ec3","#fee0b6","#542788","# 998ec3","#b35806","#f1a340","#998ec3","#fee0b6","# b35806","#542788","#b35806","#b35806","#fee0b6","# d8daeb","#542788","#542788","#d8daeb","#b35806","# 542788","black","#d8daeb","#d8daeb","#d8daeb","#d8 daeb","black","#fee0b6","#b35806","#f1a340","#d8da eb","#f1a340","black","#542788","#998ec3","#542788 ","#d8daeb","#b35806","#f1a340","#542788","#b35806 ","#d8daeb","#d8daeb","#b35806","#f1a340","#f1a340 ","#542788","#998ec3","#542788","#542788","#542788 ","#542788","#998ec3","#b35806","#b35806","#542788 ","#f1a340","#d8daeb","black","#f1a340","#b35806", "#f1a340","#f1a340","#fee0b6","#542788","#542788", "#542788","#f1a340","#b35806","#f1a340"
)

map('county','missouri',fill=TRUE,col=countycol)
title("American Family Missouri Outbuilding Relativities")
map.text('county','missouri',col="black",add=TRUE, cex=0.50)
legend(x='topright',legend = c("1.00","1.249","1.343","1.737","2.252","3.465"," N/A"),cex=1.00,
fill=cbind(
"#542788",
"#998ec3",
"#d8daeb",
"#fee0b6",
"#f1a340",
"#b35806",
"black"
))
__________________

You make known to me the path of life; you will fill me with joy in your presence, with eternal pleasures at your right hand. (Psalm 16:11)

Last edited by Klaymen; 12-20-2017 at 10:12 AM..
Reply With Quote
  #3  
Old 12-20-2017, 10:08 AM
ronaldy27's Avatar
ronaldy27 ronaldy27 is offline
Member
CAS
 
Join Date: Jan 2012
Location: The South
Studying for the credential
Posts: 2,959
Default

Quote:
Originally Posted by Klaymen View Post
Although I use the maps package, it is not very sophisticated. It gets me nice color maps by state and county, and I can lay overlay text or values and show a title and a legend.
I would like to learn the more sophisticated methods but it just hasn't been worth the time to me yet.
Yeah, I'm a newbie in this and even I knew maps was not going to help me get far. I did find another documentation for mapping in R: "Introduction to visualising spatial data in R"

This one went a little more in depth.
__________________
Spoiler - for size:



Reply With Quote
  #4  
Old 12-20-2017, 10:14 AM
ronaldy27's Avatar
ronaldy27 ronaldy27 is offline
Member
CAS
 
Join Date: Jan 2012
Location: The South
Studying for the credential
Posts: 2,959
Default

https://www.coursera.org/learn/r-data-visualization

Starts on Dec 25, on Christmas, if anyone is as lonely as I am and is interested in learning about mapping.

This might help me do this project.
__________________
Spoiler - for size:



Reply With Quote
  #5  
Old 12-20-2017, 10:59 AM
Klaymen's Avatar
Klaymen Klaymen is offline
Member
CAS
 
Join Date: Oct 2001
Studying for 2018 Las Vegas NABC
Posts: 19,141
Default

nice humblebrag about being lonely.
__________________

You make known to me the path of life; you will fill me with joy in your presence, with eternal pleasures at your right hand. (Psalm 16:11)
Reply With Quote
  #6  
Old 12-20-2017, 11:11 AM
Tacoactuary's Avatar
Tacoactuary Tacoactuary is offline
Member
CAS Non-Actuary
 
Join Date: Nov 2014
Location: Des Moines, IA
College: Vanderbilt, UIUC
Favorite beer: Yazoo Sue
Posts: 1,128
Default

In just the past few months I built a Shiny app to help visualize information related to a territorial rate review. It uses leaflet for interactive choropleths and plotly for interactive graphs. Let me know if you have any questions.
Attached Images
 
__________________
ACAS 7 8 9
Reply With Quote
  #7  
Old 12-20-2017, 12:04 PM
ronaldy27's Avatar
ronaldy27 ronaldy27 is offline
Member
CAS
 
Join Date: Jan 2012
Location: The South
Studying for the credential
Posts: 2,959
Default

Quote:
Originally Posted by Tacoactuary View Post
In just the past few months I built a Shiny app to help visualize information related to a territorial rate review. It uses leaflet for interactive choropleths and plotly for interactive graphs. Let me know if you have any questions.
That's some good stuff. I didn't even know what "Shiny" was until now.
I found a website with tutorial videos. Are they completely free?
__________________
Spoiler - for size:



Reply With Quote
  #8  
Old 12-20-2017, 12:16 PM
cowactuary cowactuary is offline
Member
SOA
 
Join Date: Dec 2011
Studying for FAP
Posts: 105
Default

Look at the ggmap package
Reply With Quote
  #9  
Old 12-20-2017, 12:24 PM
Tacoactuary's Avatar
Tacoactuary Tacoactuary is offline
Member
CAS Non-Actuary
 
Join Date: Nov 2014
Location: Des Moines, IA
College: Vanderbilt, UIUC
Favorite beer: Yazoo Sue
Posts: 1,128
Default

Quote:
Originally Posted by ronaldy27 View Post
That's some good stuff. I didn't even know what "Shiny" was until now.
I found a website with tutorial videos. Are they completely free?
Yes. Shiny, leaflet, and plotly are open source under various licenses of and free for commercial use subject to each licence's requirements.
__________________
ACAS 7 8 9
Reply With Quote
  #10  
Old 12-20-2017, 05:38 PM
clarinetist clarinetist is offline
Member
Non-Actuary
 
Join Date: Aug 2011
Studying for Rcpp, Git
Posts: 6,869
Default

I was using ggmap for a while, but I've stuck with using D3.js for mapping.
__________________
If you want to add me on LinkedIn, PM me.

Why I hate Microsoft Access.

Studying/Reading: Linear Optimization/Programming, Machine Learning and Pattern Recognition
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT -4. The time now is 11:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.44239 seconds with 10 queries