forked from h2oai/h2o-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"offset" parameter glm runit test and dataset addition
- Loading branch information
1 parent
e6b4882
commit faa6b35
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f"))) | ||
source('../../findNSourceUtils.R') | ||
|
||
test.GLM.offset <- function(conn) { | ||
Log.info("Importing lung.csv data...\n") | ||
lung.hex = h2o.uploadFile(conn, locate("smalldata/glm_test/lung.csv")) | ||
lung.hex$log_pop <- log(lung.hex$pop) | ||
lung.sum = summary(lung.hex) | ||
print(lung.sum) | ||
|
||
lung.r = read.csv(locate("smalldata/glm_test/lung.csv"), header = TRUE) | ||
lung.r = na.omit(lung.r) | ||
|
||
Log.info(cat("H2O GLM (poisson)")) | ||
lung.glm.h2o = h2o.glm(y = 4, x = 1:2, data = lung.hex, family = "poisson", link = "log", offset = "log_pop") | ||
print(lung.glm.h2o) | ||
|
||
Log.info(cat("{stats} glm (poisson)")) | ||
lung.glm.r = glm(cases ~ city + age + offset(log(pop)), family = "poisson", data = lung.r) | ||
|
||
checkEqualsNumeric(lung.glm.h2o@model$deviance, lung.glm.r$deviance, tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$aic, lung.glm.r$aic, tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$null.deviance, lung.glm.r$null.deviance, tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$coefficients["city.Horsens"], lung.glm.r$coefficients["cityHorsens"], tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$coefficients["city.Kolding"], lung.glm.r$coefficients["cityKolding"], tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$coefficients["city.Vejle"], lung.glm.r$coefficients["cityVejle"], tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$coefficients["age"], lung.glm.r$coefficients["age"], tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$coefficients["Intercept"], lung.glm.r$coefficients["(Intercept)"], tolerance = 0.01) | ||
checkEqualsNumeric(lung.glm.h2o@model$coefficients["log_pop"], 1.0, tolerance = 1e-10) | ||
|
||
testEnd() | ||
} | ||
|
||
doTest("GLM offset test", test.GLM.offset) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"city","age","pop","cases" | ||
"Fredericia",47,3059,11 | ||
"Horsens",47,2879,13 | ||
"Kolding",47,3142,4 | ||
"Vejle",47,2520,5 | ||
"Fredericia",57,800,11 | ||
"Horsens",57,1083,6 | ||
"Kolding",57,1050,8 | ||
"Vejle",57,878,7 | ||
"Fredericia",62,710,11 | ||
"Horsens",62,923,15 | ||
"Kolding",62,895,7 | ||
"Vejle",62,839,10 | ||
"Fredericia",67,581,10 | ||
"Horsens",67,834,10 | ||
"Kolding",67,702,11 | ||
"Vejle",67,631,14 | ||
"Fredericia",72,509,11 | ||
"Horsens",72,634,12 | ||
"Kolding",72,535,9 | ||
"Vejle",72,539,8 | ||
"Fredericia",75,605,10 | ||
"Horsens",75,782,2 | ||
"Kolding",75,659,12 | ||
"Vejle",75,619,7 |