file <- "C:/Users/krizp/Documents/vyuka MFF/NMFM402 - Nezivotni pojisteni 2/Cviceni/CV6/reseni/data_claimSeverity.csv" ##change the path### #read data: ClaimData <- read.csv(file , header = TRUE, sep = ";") #declare columns as factors, will not be treated as numerical variables in GLM: ClaimData <- within(ClaimData , { CarType <- factor(CarType ) DriverAge<- factor(DriverAge) }) #fitting the model: model.InverseGaussianLog <- glm(Claim ~ CarType + DriverAge, data = ClaimData, family = inverse.gaussian("log")) summary(model.InverseGaussianLog) #coefficients estimated by MLE model.InverseGaussianLog$coefficients # 95% confidence interval for coefficients = solution to a) confint(model.InverseGaussianLog) #corresponding risk factors exp(model.InverseGaussianLog$coefficients) #95% confidence intervals for risk factors = solution to b) exp(confint(model.InverseGaussianLog)) #predictions on log link scale (for linear predictor) incl. standard error logY <- predict(model.InverseGaussianLog, se.fit = TRUE)$fit logY.stdErrors <- predict(model.InverseGaussianLog, se.fit = TRUE)$se.fit #confidence intervals for claims in original scale = solution to c) alpha <- 0.05 u <- qnorm(1-alpha/2, 0, 1) lowerY <- exp(logY - u*logY.stdErrors) upperY <- exp(logY + u*logY.stdErrors) ClaimData["PredictClaim"] <- exp(logY) ClaimData["Claim_lowerBound"] <- lowerY ClaimData["Claim_upperBound"] <- upperY ClaimData