Skip to content

Commit

Permalink
update R tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfryda committed Jan 16, 2024
1 parent 8a2df79 commit 1a809bd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ train_models <- function(simData, tweedie_p, phi) {


test_helper <- function(p, phi, offset) {
eps <- 1e-3

simData <- generate_data(p, phi, offset)

attach(train_models(simData, p, phi))
Expand All @@ -109,7 +111,7 @@ test_helper <- function(p, phi, offset) {
p = p,
phi = hdispersion
) - h2o.loglikelihood(hfit)
) < 1e-5)
) < eps)

# are we better than R's implementation or at least the same? smaller the negative likelihood the better
hnll <- nll(
Expand All @@ -124,10 +126,10 @@ test_helper <- function(p, phi, offset) {
p = p,
phi = rdispersion
)
expect_true(hnll <= rnll || abs(hnll - rnll) < 1e-5)
expect_true(hnll <= rnll || abs(hnll - rnll) < eps)

# check dispersion
allowed_dispersion_difference <- 1.01*abs(phi - rdispersion)
allowed_dispersion_difference <- 1.05*abs(phi - rdispersion)
print(allowed_dispersion_difference)
cat("H2o: ", hdispersion,"; R: ", rdispersion, "\n")
expect_true(abs(phi - hdispersion) < allowed_dispersion_difference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ test_glm_gammas <- function() {

generate_dataset<-function(f1R, numRows, numCols, pow, phi, mu) {
resp <- tweedie::rtweedie(numRows, xi=pow, mu, phi, power=pow)
f1h2o <- as.h2o.data.frame(f1R)
resph2o <- as.h2o.data.frame(as.data.frame(resp))
f1h2o <- as.h2o(f1R)
resph2o <- as.h2o(as.data.frame(resp))
finalFrame <- h2o.cbind(f1h2o, resph2o)
return(finalFrame)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ test_glm_gamma_fix_dispersion_parameter <- function() {

generate_dataset<-function(f1R, numRows, numCols, pow, phi, mu) {
resp <- tweedie::rtweedie(numRows, xi=pow, mu, phi, power=pow)
f1h2o <- as.h2o.data.frame(f1R)
resph2o <- as.h2o.data.frame(as.data.frame(resp))
f1h2o <- as.h2o(f1R)
resph2o <- as.h2o(as.data.frame(resp))
finalFrame <- h2o.cbind(f1h2o, resph2o)
return(finalFrame)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ test_gamma_null_model <- function() {

generate_dataset<-function(f1R, numRows, numCols, pow, phi, mu) {
resp <- tweedie::rtweedie(numRows, xi=pow, mu, phi, power=pow)
f1h2o <- as.h2o.data.frame(f1R)
resph2o <- as.h2o.data.frame(as.data.frame(resp))
f1h2o <- as.h2o(f1R)
resph2o <- as.h2o(as.data.frame(resp))
finalFrame <- h2o.cbind(f1h2o, resph2o)
return(finalFrame)
}
Expand Down

0 comments on commit 1a809bd

Please sign in to comment.