This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#================================================================================================== | |
# User-friendly constructor | |
# This is a giant pile of code which basically does the following: | |
# * Ensure that we have a proper date for the loss period start | |
# * Ensure that we have a column for the development lag | |
# * Once those have been established, create columns for loss period start and end, create a column | |
# for development period (based on lubridate Period class), compute the evaluation date. | |
Triangle = function(TriangleData | |
, TriangleName | |
, LossPeriodType = "accident" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data(NAIC) | |
bigCompany = as.character(NAIC[which(NAIC$CumulativePaid == max(NAIC$CumulativePaid)),"GroupName"]) | |
df.BigCo = subset(NAIC, GroupName == bigCompany) | |
df.UpperTriangle = subset(df.BigCo, DevelopmentYear <=1997) | |
MeasureName = colnames(df.UpperTriangle)[5:10] | |
MeasureMeta = data.frame(MeasureName = as.character(MeasureName), Cumulative = as.character(c(rep("Cumulative", 2), rep("Neither", 4)))) | |
rm(MeasureName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#File created 1/31/13 | |
#contains R code to | |
#-read in Kaggle Competition Titanic Data csv file | |
#-create a simple logistic regression model | |
#-make predictions on training and test data | |
#-write out test predictions to csv file | |
# | |
#Replace the <your path here> with the full path to your copy of train and test csv files. | |
################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* udfBeginningOfYear **********************************************************/ | |
IF OBJECT_ID (N'udfBeginningOfYear') IS NOT NULL | |
DROP FUNCTION udfBeginningOfYear | |
GO | |
CREATE FUNCTION udfBeginningOfYear (@DateIn datetime) | |
RETURNS datetime | |
AS | |
BEGIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @TestDate datetime | |
SET @TestDate = CAST('08-15-2000' AS datetime) | |
SELECT dbo.udfBeginningOfYear(@TestDate) AS BeginningOfYear | |
, dbo.udfEndOfYear(@TestDate) AS EndOfYear | |
, dbo.udfBeginningOfSemi(@TestDate) AS BeginningOfSemi | |
, dbo.udfEndOfSemi(@TestDate) AS EndOfSemi | |
, dbo.udfBeginningOfQuarter(@TestDate) AS BeginningOfQuarter | |
, dbo.udfEndOfQuarter(@TestDate) AS EndOfQuarter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
someFunction = function(y, data = NULL) | |
{ | |
arguments <- as.list(match.call()) | |
y = eval(arguments$y, data) | |
sum(y) | |
} | |
myData = data.frame(A = c(1,2,3), B = c(10,9,8)) | |
someFunction(A, data=myData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myData = data.frame(State = c("NY","NY", "TX", "TX") | |
, Premium = c(100,200,150,75) | |
, Loss = c(80,175,80,80)) | |
myData | |
moreData = data.frame(Premium = myData$P, Loss = myData$L) | |
moreData | |
rm(moreData) | |
colNames = c("Premium", "Loss") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sourceFiles = "https://raw.github.com/PirateGrunt/MRMR/master/R/NAIC.R" | |
dummy = lapply(paste0(myDirectory, sourceFiles), source) | |
rm(myDirectory, sourceFiles, dummy) | |
dfAuto = GetNAICData(dataSetName = "comAuto_pos.csv") | |
dfWC = GetNAICData(dataSetName = "wkcomp_pos.csv") | |
dfGL = GetNAICData(dataSetName = "othliab_pos.csv") | |
dfProd = GetNAICData(dataSetName = "prodliab_pos.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get a set of "error" terms | |
set.seed(1234) | |
N = 100 | |
E = rnorm(N, mean = 0, sd = 2) | |
lnLike = function(x, mu, sigma) | |
{ | |
n = length(x) | |
lnLike = -n / 2 * log(2*pi) | |
lnLike = lnLike - n/2 * log(sigma ^2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kids1 = as.array(c("Bob", "Joe")) | |
kids2 = as.array(c("Steve", "Beth", "Kim")) | |
setClass("person", representation(name="character", age="numeric", children = "list")) | |
setMethod( | |
f = "[", | |
signature="person", | |
definition=function(x,i,j,...,drop=TRUE){ | |
initialize(x, name=x@name[i], age = x@age[i], children = list(x@children[i])) |
OlderNewer