@@ -381,38 +381,136 @@ test_that("Unit tests for DoubleMLData", {
381381)
382382
383383test_that(" Unit tests for invalid data" , {
384+ # PLR with IV
384385 msg = paste(" Incompatible data.\\ n" ,
385386 " z has been set as instrumental variable\\ (s\\ ).\\ n" ,
386387 " To fit a partially linear IV regression model use" ,
387388 " DoubleMLPLIV instead of DoubleMLPLR." )
388- expect_error(double_mlplr_obj <- DoubleMLPLR $ new(
389+ expect_error(DoubleMLPLR $ new(
389390 data = data_pliv $ dml_data ,
390391 ml_g = mlr3 :: lrn(' regr.rpart' ),
391392 ml_m = mlr3 :: lrn(' regr.rpart' )),
392393 regexp = msg )
393-
394- }
395- )
396394
397- test_that(" Unit tests for invalid data" , {
395+ # PLIV without IV
396+ msg = paste(" Incompatible data.\\ n" ,
397+ " At least one variable must be set as instrumental variable.\\ n" ,
398+ " To fit a partially linear regression model without instrumental" ,
399+ " variable\\ (s\\ ) use DoubleMLPLR instead of DoubleMLPLIV." )
400+ expect_error(DoubleMLPLIV $ new(
401+ data = data_plr $ dml_data ,
402+ ml_g = mlr3 :: lrn(' regr.rpart' ),
403+ ml_m = mlr3 :: lrn(' regr.rpart' ),
404+ ml_r = mlr3 :: lrn(' regr.rpart' )),
405+ regexp = msg )
406+
407+ # IRM with IV
398408 msg = paste(" Incompatible data.\\ n" ,
399409 " z has been set as instrumental variable\\ (s\\ ).\\ n" ,
400410 " To fit an interactive IV regression model use" ,
401411 " DoubleMLIIVM instead of DoubleMLIRM." )
402- expect_error(double_mlplr_obj <- DoubleMLIRM $ new(
412+ expect_error(DoubleMLIRM $ new(
403413 data = data_iivm $ dml_data ,
404414 ml_g = mlr3 :: lrn(' regr.rpart' ),
405415 ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
406416 regexp = msg )
417+
418+ # IIVM without IV
419+ msg = paste(" Incompatible data.\\ n" ,
420+ " To fit an IIVM model with DoubleML" ,
421+ " exactly one binary variable with values 0 and 1" ,
422+ " needs to be specified as instrumental variable." )
423+ expect_error(double_mlplr_obj <- DoubleMLIIVM $ new(
424+ data = data_irm $ dml_data ,
425+ ml_g = mlr3 :: lrn(' regr.rpart' ),
426+ ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
427+ regexp = msg )
407428
429+ # non-binary D for IRM
408430 df = data_irm $ df
409431 df [' d' ] = df [' d' ]* 5
410432 dml_data = double_ml_data_from_data_frame(df , y_col = " y" , d_cols = " d" )
411433 msg = paste(" Incompatible data.\\ n" ,
412434 " To fit an IRM model with DoubleML" ,
413435 " exactly one binary variable with values 0 and 1" ,
414436 " needs to be specified as treatment variable." )
415- expect_error(double_mlplr_obj <- DoubleMLIRM $ new(
437+ expect_error(DoubleMLIRM $ new(
438+ data = dml_data ,
439+ ml_g = mlr3 :: lrn(' regr.rpart' ),
440+ ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
441+ regexp = msg )
442+
443+ # non-binary D for IIVM
444+ df = data_iivm $ df
445+ df [' d' ] = df [' d' ]* 5
446+ dml_data = double_ml_data_from_data_frame(df , y_col = " y" ,
447+ d_cols = " d" ,
448+ z_cols = " z" )
449+ msg = paste(" Incompatible data.\\ n" ,
450+ " To fit an IIVM model with DoubleML" ,
451+ " exactly one binary variable with values 0 and 1" ,
452+ " needs to be specified as treatment variable." )
453+ expect_error(DoubleMLIIVM $ new(
454+ data = dml_data ,
455+ ml_g = mlr3 :: lrn(' regr.rpart' ),
456+ ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
457+ regexp = msg )
458+
459+ # non-binary Z for IIVM
460+ df = data_iivm $ df
461+ df [' z' ] = df [' z' ]* 5
462+ dml_data = double_ml_data_from_data_frame(df , y_col = " y" ,
463+ d_cols = " d" ,
464+ z_cols = " z" )
465+ msg = paste(" Incompatible data.\\ n" ,
466+ " To fit an IIVM model with DoubleML" ,
467+ " exactly one binary variable with values 0 and 1" ,
468+ " needs to be specified as instrumental variable." )
469+ expect_error(DoubleMLIIVM $ new(
470+ data = dml_data ,
471+ ml_g = mlr3 :: lrn(' regr.rpart' ),
472+ ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
473+ regexp = msg )
474+
475+ # multiple D for IRM
476+ df = data_irm $ df
477+ dml_data = double_ml_data_from_data_frame(df , y_col = " y" ,
478+ d_cols = c(" d" , " X1" ))
479+ msg = paste(" Incompatible data.\\ n" ,
480+ " To fit an IRM model with DoubleML" ,
481+ " exactly one binary variable with values 0 and 1" ,
482+ " needs to be specified as treatment variable." )
483+ expect_error(DoubleMLIRM $ new(
484+ data = dml_data ,
485+ ml_g = mlr3 :: lrn(' regr.rpart' ),
486+ ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
487+ regexp = msg )
488+
489+ # multiple D for IIVM
490+ df = data_iivm $ df
491+ dml_data = double_ml_data_from_data_frame(df , y_col = " y" ,
492+ d_cols = c(" d" , " X1" ),
493+ z_cols = " z" )
494+ msg = paste(" Incompatible data.\\ n" ,
495+ " To fit an IIVM model with DoubleML" ,
496+ " exactly one binary variable with values 0 and 1" ,
497+ " needs to be specified as treatment variable." )
498+ expect_error(DoubleMLIIVM $ new(
499+ data = dml_data ,
500+ ml_g = mlr3 :: lrn(' regr.rpart' ),
501+ ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
502+ regexp = msg )
503+
504+ # multiple Z for IIVM
505+ df = data_iivm $ df
506+ dml_data = double_ml_data_from_data_frame(df , y_col = " y" ,
507+ d_cols = " d" ,
508+ z_cols = c(" z" , " X1" ))
509+ msg = paste(" Incompatible data.\\ n" ,
510+ " To fit an IIVM model with DoubleML" ,
511+ " exactly one binary variable with values 0 and 1" ,
512+ " needs to be specified as instrumental variable." )
513+ expect_error(DoubleMLIIVM $ new(
416514 data = dml_data ,
417515 ml_g = mlr3 :: lrn(' regr.rpart' ),
418516 ml_m = mlr3 :: lrn(' classif.rpart' , predict_type = " prob" )),
0 commit comments