WhatIf/0000755000176200001440000000000013135626510011436 5ustar liggesusersWhatIf/inst/0000755000176200001440000000000013135304505012410 5ustar liggesusersWhatIf/inst/doc/0000755000176200001440000000000013135550634013163 5ustar liggesusersWhatIf/inst/doc/brabazon_pig_500.jpg0000644000176200001440000013363413135304505016712 0ustar liggesusersJFIFHHPhotoshop 3.08BIMx(HHA@J {hhx El2 EGP'd4E6TB 8BIMHH8BIM x8BIM8BIM 8BIM' 8BIM5-8BIM8BIM@@8BIM8BIM pOPgJFIFHHAdobed            Op"?   3!1AQa"q2B#$Rb34rC%Scs5&DTdE£t6UeuF'Vfv7GWgw5!1AQaq"2B#R3$brCScs4%&5DTdEU6teuFVfv'7GWgw ?7yǍZi%<_/ܮ}o^Q{ ŦZVVlcȽ׳ѻ֭f;>?׫ a]\I;<ckrٟVp#? q6`v:|+zV%: ]Sί^eyyzUhˡ7,2=̪?ڿWkn)\"UuR=~{k2_eUmx UMpX}f,zk. ťս*P)_sUWtѺeU[^;]cn%K߶-3X]&gPy8Wa~&>!{MDFG돻ҷ"s>>/Ƭö󓍏{qiWoUzcatF62`&{qvm ?Gh~^]}>K_[\zvNxo7Q[q=73e?Jh;+Yf+zmYeSQӫ#lŹǶk&"OO*k^eV\_my.6V*}ulGOQqu9{h+̪_dWn#uE'WXgY'^X__Pӌ-_׷ ksf?G] U>& ݎʃin>=W}X~%4Ii>'c:j]ujȲhp51{'7e}\c;Wk]fF6Kkl~ZSͬY{kc[5uYV3#zJpBͬl'[YqY e3jjn@ˬՕZ12 KX۪>JF>Soez͗ꆖUC+v؝_fgn_YU2(}LWU`C-v6=<.G}4}lD,r:hdKYS÷9MyU׿%>~'eXƙuV+ onv!z'Po^E_dG\r2)[eֳ}^*m8XWc.:~U,8Vt:k4oQ9T-· }b{o=7zzO5m_oʱX-}VM=XQKM_-%RkM m95t=5zRjuөmT:2s2C}u,8"YKߋ켼{Ib9M꾫?b3.v{nFƱ޿JjRSeGP [MuӲVwew6lE_}Mzoլ|>V&^)]e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e$30Ÿ}E|ouq_? &}ȑOOTQKG7+oܚ'S=MokIՔ_o3ƠK)o7SǺu} XtKo_WhatIf/inst/doc/index.shtml0000644000176200001440000000760413135304505015344 0ustar liggesusers WhatIf Software Website Heather Stoll, Gary King, Langche Zeng

Version:1.5-5


What would happen if pigs could fly? The first known attempt to answer this question was in 1909 by J.T.C. Moore-Brabazon, who earlier the same year was the first British pilot to fly in Britain. On the left is Moore-Brabazon in his personal French-built Voisin aero plane. On the right is a pig in a wicker basket behind a sign that says "I am the first pig to fly."

Inferences about counterfactuals are essential for prediction, answering "what if" questions, and estimating causal effects. However, when the counterfactuals posed are too far from the data at hand, conclusions drawn from well-specified statistical analyses become based largely on speculation hidden in convenient modeling assumptions that few would be willing to defend. Unfortunately, standard statistical approaches assume the veracity of the model rather than revealing the degree of model-dependence, which makes this problem hard to detect. WhatIf offers easy-to-apply methods to evaluate counterfactuals that do not require sensitivity testing over specified classes of models. If an analysis fails the tests offered here, then we know that substantive inferences will be sensitive to at least some modeling choices that are not based on empirical evidence, no matter what method of inference one chooses to use. WhatIf is also used to identify the areas of common support in causal inference. It is implemented in MatchIt and can easily process Zelig output objects so that counterfactuals can be evaluated, prior to computing quantities of interest, with only one additional command.

WhatIf implements the methods for evaluating counterfactuals discussed in Gary King and Langche Zeng, 2006, "The Dangers of Extreme Counterfactuals," Political Analysis 14 (2): 131-159; and Gary King and Langche Zeng, 2007, "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference," International Studies Quarterly 51 (March): 183-210.

WhatIf/tests/0000755000176200001440000000000013135304505012575 5ustar liggesusersWhatIf/tests/testthat.R0000644000176200001440000000010713135304505014556 0ustar liggesuserslibrary(testthat) library(WhatIf) library(Zelig) test_check("WhatIf") WhatIf/tests/testthat/0000755000176200001440000000000013135626510014440 5ustar liggesusersWhatIf/tests/testthat/test-whatif.R0000644000176200001440000000402313135304505017016 0ustar liggesusers## Tests for whatif function ## Error tests data("peacef") data("peacecf") test_that('FAIL Test: reject bad cfact inputs', { ## missing cfact test expect_error(whatif(data = peacef), regexp = 'argument "cfact" is missing, with no default') ## bad data type expect_error(whatif(cfact = 1, data = peacef), regexp = "'cfact' must be either a string, a R data frame, or a R non-character matrix") ## no rows cfact expect_error(whatif(cfact = data.frame(), data = peacef), regexp = "no counterfactuals supplied: 'cfact' contains zero rows") ## missing data error expect_error(whatif(cfact = matrix(),data = peacef), regexp = "there are no cases in 'cfact' without missing values") ## different data and cfact dimensions expect_error(whatif(cfact = matrix(data = 1, ncol = 10), data = peacef), regexp = "number of columns of 'cfact' and 'data' are not equal") }) test_that('FAIL Test: reject bad data inputs', { ## data argument is missing expect_error(whatif(cfact = peacecf), regexp = 'argument "data" is missing, with no default') ## bad list test expect_error(whatif(cfact = peacecf, data = list(x = "", y = "")), regexp = "the list supplied to 'data' is not a valid output object") ## empty data expect_error(whatif(cfact = peacecf, data = data.frame()), regexp = "no observed covariate data supplied: 'data' contains zero rows") ## all rows have missing data missing.data <- peacecf missing.data$bad <- NA expect_error(whatif(cfact = peacecf, data = missing.data), regexp = "there are no cases in 'data' without missing values") }) test_that('Fail Test: reject bad formulas',{ ## check formula label requirement expect_error(whatif(data = peacef, cfact = peacecf, formula = ~x), regexp = "variables in 'formula' either unlabeled or not present in 'data'") }) WhatIf/tests/testthat/test-whatif_convexhull.R0000644000176200001440000000114213135304505021264 0ustar liggesuserstest_that("REQUIRE TEST whatif with 1 counterfactual", { my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) expect_error(whatif(data = my.data, cfact = matrix(my.cfact[1,], nrow = 1), mc.cores = 1), NA) }) test_that("REQUIRE TEST multitreaded", { my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) with_mock( `WhatIf::whatif` = function(...) print("3 cores"), expect_error(whatif(data = my.data, cfact = my.cfact, mc.cores = 3), NA) ) }) WhatIf/tests/testthat/test-plot.R0000644000176200001440000000070113135304505016511 0ustar liggesusers## File for testing plot.whatif() test_that("ERROR TEST: check that bad inputs generate errors",{ data("peacecf") data("peacef") x <- whatif(cfact = peacecf, data = peacef, mc.cores = 1) expect_error(plot(x, numcf = "a"), regexp = "argument 'numcf' must be a numeric vector") expect_error(plot(x, type = "a"), regexp = "argument 'type' must be one of the characters ''l'', ''f'', or ''b''") }) WhatIf/tests/testthat/test-zelig.R0000644000176200001440000000334413135304505016653 0ustar liggesusers# REQUIRE TEST: Zelig integration ---------------------------------------------- test_that('REQUIRE TEST: Zelig integration', { # Without factors z.out <- zelig(Petal.Width ~ Petal.Length, data = iris, model = "ls") s.out <- setx(z.out, Petal.Length = 1:10) with_zelig <- whatif(data = s.out, mc.cores = 1) without_zelig <- whatif(data = data.frame(Petal.Length = iris$Petal.Length), cfact = data.frame(Petal.Length = 1:10), mc.cores = 1) expect_equivalent(with_zelig$sum.stat, without_zelig$sum.stat) # With factors f <- formula(Petal.Width ~ Petal.Length + Species) z.out.f <- zelig(f, data = iris, model = "ls") s.out.f <- setx(z.out.f, Petal.Length = 1:10, Species = 'virginica') with_zelig_f <- whatif(data = s.out.f, mc.cores = 1) f_no_response <- formula(delete.response(terms(f))) cfact_factors <- data.frame(Petal.Length = 1:10, Species = factor('virginica', levels = levels(iris$Species))) iris_sub <- iris[, c('Petal.Length', 'Species')] without_zelig_f <- whatif(formula = f_no_response, data = iris_sub, cfact = cfact_factors, mc.cores = 1) expect_equivalent(with_zelig_f$sum.stat, without_zelig_f$sum.stat) }) # FAIL TEST zelig object without setx or cdata --------------------------------- test_that('FAIL TEST zelig object without setx or cdata', { z.out.f <- zelig(Petal.Width ~ Petal.Length + Species, data = iris, model = "ls") expect_error(whatif(data = z.out.f, mc.cores = 1), 'Unable to find fitted \\(setx\\) values\\.') }) WhatIf/NAMESPACE0000644000176200001440000000143013135304505012650 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(plot,whatif) S3method(print,summary.whatif) S3method(print,whatif) S3method(summary,whatif) export(whatif) importFrom(Zelig,zelig_setx_to_df) importFrom(grDevices,dev.off) importFrom(grDevices,postscript) importFrom(graphics,lines) importFrom(graphics,plot) importFrom(lpSolve,lp) importFrom(parallel,detectCores) importFrom(parallel,mclapply) importFrom(pbmcapply,pbmclapply) importFrom(stats,complete.cases) importFrom(stats,delete.response) importFrom(stats,lowess) importFrom(stats,model.frame) importFrom(stats,model.matrix) importFrom(stats,na.fail) importFrom(stats,na.omit) importFrom(stats,terms) importFrom(stats,update.formula) importFrom(utils,read.table) importFrom(utils,setTxtProgressBar) importFrom(utils,txtProgressBar) WhatIf/demo/0000755000176200001440000000000013135304505012357 5ustar liggesusersWhatIf/demo/00Index0000644000176200001440000000006713135304505013514 0ustar liggesuserspeace Demo of U.N. peacekeeping example using WhatIf WhatIf/demo/peace.R0000644000176200001440000000265113135304505013563 0ustar liggesusers######## Example: WhatIf applied to Doyle and Sambanis (2000) U.N. peacekeeping data set ######## #Load sample observed covariate data data(peacef) #Load sample counterfactual data data(peacecf) #Run whatif using default options my.result <- whatif(data = peacef, cfact = peacecf) #Look at results of convex hull test my.result$in.hull #Look at geometric variance of covariates my.result$geom.var #Look at proportion of data points nearby all 122 counterfactuals my.result$sum.stat #Calculate mean proportion of data points nearby all 122 counterfactuals mean(my.result$sum.stat) #Look at default cumulative frequency distribution for first counterfactual #and data points my.result$cum.freq[1, ] #Plot raw cumulative frequency distribution for first counterfactual plot(my.result, numcf = 1) #Print summary on screen summary(my.result) #Identify control units not on support of treatment units my.result.cntrl <- whatif(formula = ~ decade + wartype + logcost + wardur + factnum + factnumsq + trnsfcap + treaty + develop + exp, data = peacef[peacef$untype4 == 1,], cfact = peacef[peacef$untype4 == 0,], ) #Print convex hull test results on screen my.result.cntrl$in.hull #Identify units on common support of both treatment and control groups peacef2cf <- peacef peacef2cf$untype4 <- 1 - peacef2cf$untype4 my.result.comb <- whatif(data = peacef, cfact = peacef2cf) #Print convex hull test results on screen my.result.comb$in.hull WhatIf/NEWS.md0000644000176200001440000000134113135304505012530 0ustar liggesusers> All changes to WhatIf are documented here. GitHub issue numbers are given after each change note when relevant. See /. External contributors are referenced with their GitHub usernames when applicable. WhatIf version 1.5-9 =============================== # Major changes - :rocket: convex hull test now run in parallel. The number of cores can be specified in the `whatif` call with the `mc.cores` argument. # Minor changes - Additional tests added. - Progress bar added to `whatif` convex hull test to indicate progress. - Travis CI added for continuous integration testing. WhatIf version 1.5-8 =============================== # Major changes - Returns Zelig integration. WhatIf/data/0000755000176200001440000000000013135304505012344 5ustar liggesusersWhatIf/data/peacecf.RData0000644000176200001440000002141413135304505014651 0ustar liggesusersRDX2 X  peacecf z zz@-ռn/@/Wz@d@6@)m݂@"k:@)|0@(n,fX@#Ε@+|iu@);y@6@gSE@)2 @$@'FJ@!9Cg^@ $Mʎ.,@'h73@gSE@$:@'&]cf@.&i-@'nCz@(i_@*>LX@"k:@'y|ß@*!D(N@)I+@*~鷿@,5@(e@-z@c@(Ov_خ@,@,y@$.2@$.2@"f@#Rş@+٩T@+A c @)0sWq@gSE@!Do@&!6@-v}Vl@+Tg8}@-#x @-Vr2L@&Э٩T@&e{z@&\Jw@+ݘ@gSE@*B`@#;J\t@(5LW@(I^5?@"5Ew@ B{[@gSE@6@!1z@*M@ B{[@%Ԇ-@"cO@+/KCW@$@եb@*9Xb@-l<@*T@*NƼS;@"5Ew@%Ԇ-@, ԕ+@!ͅYp@-LM>@*\{ Z\@gSE@*)b@@}@.gS@*orq6@)d8@- ?@+ͪOB@-@+kA@%Ԇ-@+@*orq6@*T@+e@+|T6@'ϕ@' B@$@/iu@-O @!ͅYp@#;J\t@*œwkQ@-@,MRJ@@}@(}9@(NzVC@."I@-@+Ƒ\л@(+ I@*Z@+V@-)v5B@ c0Q@)EEw@*W}@'zNzV@(@-jOv zH$$0` 8H$X ` <` $1$$<< x`0$:6x$  ` T$ l$TH($RT< #T< H z  z$y  $@$    $$  $ 1        1   $    z@2^@#v3ն@)@8\@!@9j?"T@?vh<)|@@.>Ր@R*d?)?qo@N@,@0X @q#x@%g@TP*@[xTɅ@|<@A7L@u!R@ BNY@3ڛԿ @#\@ "XZ@[C+@KC@M@.1@8If{_@XS&@8If{_?\Ukl_@8K@k@EU\R@EU\R@x7n.@,@:@:@Y@n@W`d@\(@Y@n@Q YJ@dZ@_Dj~#@Pϋ@@Mu=b@~$/@@A@Mu=b@09UDR@kڭU@r@v H˒@I5?|@n@m.qj@Q YJ@wQ@{ @D@\(@@@o3@4@I!F^"S@q@2@_Dj~#@z@G7K@EU\R@ qv@k@A@v H˒@@@wᰊ@r@F@`6Ov`@,>B@g @H@H@W@v H˒@l@EA5Tv@c@@EU\R@5@pZ@EA5Tv@{u?|h@,>B@r@A@5@@@l>T@jBZc @~$/@2@`6Ov`@@@W@@@o3@c@@jBZc @>8K@Mu=b@z@o3@Hz?)m?>?;dZ?5\?-V? =p ?A7Kƨ?tj~?O;dZ?\(?`A7?+?vȴ9?Q?zG{?`A7L?lC?nO;??+?qd)?O;dZ?333333?E?Q?tj~?Z1'?5?|h?Ѻ^5?|?bM?~"?`A7L?+ I^?QR?zG{?+ J?9#S?p =q?F;d?E?hr Ĝ?+ I??\(?lD? =p?/v?bM?M}32?7KƧ?hw}?bM?GzH?J?xF?`A7L?ěS?/v?ȴ9Xb?ěS?&x?S?̩^b?QR?tj?5?|h?GzH?щ7KƧ? =p?GS? =p?E?(\)?n?c?XNy? =p?tj~?k'Q?zG{?&x?Gu?Q?~j?hr Ĝ?zG{?xF names decade wartype logcost wardur factnum factnumsq trnsfcap 1-untype4 treaty develop exp class data.frame row.namesz 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122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U\R@ qv@k@A@v H˒@@@wᰊ@r@F@`6Ov`@,>B@g @H@H@W@v H˒@l@EA5Tv@c@@EU\R@5@pZ@EA5Tv@{u?|h@,>B@r@A@5@@@l>T@jBZc @~$/@2@`6Ov`@@@W@@@o3@c@@jBZc @>8K@Mu=b@z@o3@H|?)m?>?;dZ?5\?-V? =p ?A7Kƨ?tj~?O;dZ?\(?`A7?+?vȴ9?Q?zG{?`A7L?lC?nO;?+??+?qd)?O;dZ?333333?E?Q?tj~?Z1'?5?|h?Ѻ^5?|?bM?~"?`A7L?+ I^?QR?zG{?+ J?9#S?p =q?F;d?E?hr Ĝ?+ I??\(?lD? =p?/v?bM?M}32?7KƧ?hw}?bM?GzH?J?xF?`A7L?ěS?/v?ȴ9Xb?ěS?&x?S?̩^b?QR?tj?5?|h?GzH?щ7KƧ? =p?GS? =p?E?(\)?n?c?XNy? =p?tj~?k'Q?zG{?&x?Gu?Q?~j?hr Ĝ?zG{?xF names decade wartype logcost wardur factnum factnumsq trnsfcap untype4 treaty develop exp class data.frame row.names| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124WhatIf/R/0000755000176200001440000000000013135304505011634 5ustar liggesusersWhatIf/R/summary.whatif.R0000644000176200001440000000232213135304505014734 0ustar liggesusers#' Summary Whatif #' #' Summarizes the information produced by the function \code{whatif}. #' The summary generated is returned as an output object and also printed #' to the screen. #' #' @examples #' Create example data sets and counterfactuals #' #' my.cfact <- matrix(rnorm(3*5), ncol = 5) #' my.data <- matrix(rnorm(100*5), ncol = 5) #' #' Evaluate counterfactuals #' #' my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) #' #' Print summary #' summary(my.result) #' #' @export summary.whatif <- function (object, ...) { # Calculate number of counterfactuals m <- length(object$in.hull) # Calculate number of counterfactuals in convex hull m.inhull <- sum(object$in.hull) # Calculate average (over all counterfactuals) percent data `nearby' mean.near <- mean(object$sum.stat) # Create data frame combining results of convex hull test with percent data `nearby' sum.df <- data.frame(cfact = seq(1, m, by = 1), in.hull = object$in.hull, per.near = object$sum.stat) out <- list(call = object$call, m = m, m.inhull = m.inhull, mean.near = mean.near, sum.df = sum.df) class(out) <- "summary.whatif" return(out) } WhatIf/R/print.whatif.R0000644000176200001440000000333513135304505014400 0ustar liggesusers#' Print Whatif #' #' Prints the information produced by the function \code{whatif}, #' an object of class "whatif", to the screen. #' #' @examples #' my.cfact <- matrix(rnorm(3*5), ncol = 5) #' my.data <- matrix(rnorm(100*5), ncol = 5) #' #' Evaluate counterfactuals #' my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) #' #' Print output object #' print(my.result) #' #' @export print.whatif <- function(x, print.dist = FALSE, print.freq = FALSE, ...) { x$in.hull <- as.character(x$in.hull) #LOCAL VARIABLES m <- length(x$in.hull) #PRINT ON SCREEN cat("\nCall: ", deparse(x$call), sep="\n") cat("\n") cat("Counterfactual in Convex Hull, True or False:\n") prmatrix(data.frame(Counterfactual = seq(1, m, by = 1), "In Hull" = x$in.hull, check.names = FALSE), rowlab = rep("", m), quote = FALSE, right = TRUE) cat("\n") cat("Percent Data Nearby Counterfactual:\n") prmatrix(data.frame(Counterfactual = seq(1, m, by = 1), "Percent Nearby" = x$sum.stat, check.names = FALSE), rowlab = rep("", m), quote = FALSE, right = TRUE) cat("\n") cat("Geometric Variance of Covariates: ", x$geom.var, sep = "\n") cat("\n") if (print.dist) { if (is.null(x$dist)) { print("No distance matrix returned to print") } else { cat("Distances of Counterfactual to Data Points:\n") prmatrix(cbind(Counterfactual = seq(1, m, by = 1), x$dist), rowlab = rep("", m)) cat("\n") } } if (print.freq) { cat("Cumulative Frequencies of Distances:\n") prmatrix(cbind(Counterfactual = seq(1, m, by = 1), x$cum.freq), rowlab = rep("", m)) cat("\n") } return(invisible(x)) } WhatIf/R/print.summary.whatif.R0000644000176200001440000000262313135304505016073 0ustar liggesusers#' Print Summary Whatif #' #' Prints the information generated from the \code{whatif} output object #' by a call to \code{summary}, which is stored in an object of class #' "summary.whatif". #' #' @examples #' Create example data sets and counterfactuals #' #' my.cfact <- matrix(rnorm(3*5), ncol = 5) #' my.data <- matrix(rnorm(100*5), ncol = 5) #' #' Evaluate counterfactuals #' my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) #' #' Print summary output object #' #' my.result.sum <- summary(my.result) #' print(my.result.sum) #' #' @export print.summary.whatif <- function(x, ...) { x$sum.df$in.hull <- as.character(x$sum.df$in.hull) names(x$sum.df) <- c("Counterfactual", "In Hull", "Percent Nearby") #PRINT ON SCREEN cat("\nSummary of Counterfactual Inference Analysis\n") cat("\n") cat("Call: ", deparse(x$call), "\n", sep="") cat("\n") cat("Total Number of Counterfactuals: ", x$m, "\n", sep = "") cat("\n") cat("Number of Counterfactuals in Convex Hull: ", x$m.inhull, "\n", sep = "") cat("\n") cat("Average Percent 'Nearby': ", x$mean.near, "\n", sep = "") cat("\n") cat("Counterfactual in Convex Hull, True or False, and", " Percentage of Observed\n", sep = "") cat("Data Points 'Nearby' Counterfactual:\n") prmatrix(x$sum.df, rowlab = rep("", x$m), quote = FALSE) cat("\n") return(invisible(x)) } WhatIf/R/plot.whatif.R0000644000176200001440000000575513135304505014232 0ustar liggesusers#' Plot Whatif results #' #' Generates a cumulative frequency plot of distances from an #' object of class "whatif". The cumulative frequencies (the fraction #' of rows in the observed data set with either Gower or (squared) #' Euclidian distances to the counterfactuals less than the given value on the #' horizontal axis) appear on the vertical axis. #' #' @examples #' Create example data sets and counterfactuals #' #' my.cfact <- matrix(rnorm(3*5), ncol = 5) #' my.data <- matrix(rnorm(100*5), ncol = 5) #' #' Evaluate counterfactuals #' my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) #' #' Plot cumulative frequencies for the first two counterfactuals (rows #' 1 and 2) in my.cfact #' #' plot(my.result, type = "b", numcf = c(1, 2), mc.cores = 1) #' #' @importFrom grDevices dev.off postscript #' @importFrom graphics lines plot #' @importFrom stats lowess #' @export plot.whatif <- function(x, type = "f", numcf = NULL, eps = FALSE, ...) { #USER ERROR INPUT CHECKS #Check if plot argument is valid if (!((identical(type, "f") || identical(type, "l") || identical(type, "b")))) { stop("argument 'type' must be one of the characters ''l'', ''f'', or ''b''") } #Check if numcf is a numeric vector without missing data if #user supplies the argument if (!is.null(numcf)) { if (!(is.vector(numcf) && is.numeric(numcf))) { stop("argument 'numcf' must be a numeric vector") } na.fail(numcf) } #LOCAL VARIABLES x.val <- as.numeric(dimnames(x$cum.freq)[[2]]) #LOCAL FUNCTIONS do.plot <- function(x, type, x.val, i) { if (x$in.hull[i]) { if (identical(type, "f") || identical(type, "b")) { lines(x.val, x$cum.freq[i,], lty = 1) } if (identical(type, "l") || identical(type, "b")) { lines(lowess(x.val, x$cum.freq[i,], f = 0.3), lty = 1, col = 4) } } else { if (identical(type, "f") || identical(type, "b")) { lines(x.val, x$cum.freq[i,], lty = 2) } if (identical(type, "l") || identical(type, "b")) { lines(lowess(x.val, x$cum.freq[i,], f = 0.3), lty = 2, col = 4) } } } #PLOTTING if (eps) { if (is.null(numcf)) { filename <- paste("graph_", type, "_all", ".eps", sep="") } else { filename <- paste("graph_", type, "_", numcf[1], ".eps", sep="") } postscript(file=filename, onefile=FALSE, horizontal=FALSE) } plot(x.val, x$cum.freq[1,], xlab = "Distance", ylab = "Cumulative % of data within distance", ylim = c(0, 1), xlim = c(min(x.val), max(x.val)), type = "n", main = "Cumulative Frequencies of Distances to Counterfactual") if (is.null(numcf)) { for (i in 1:dim(x$cum.freq)[1]) { do.plot(x, type, x.val, i) } } else { for (j in 1:length(numcf)) { do.plot(x, type, x.val, numcf[j]) } } if (eps) { dev.off() } } WhatIf/R/load.first.R0000644000176200001440000000130213135304505014020 0ustar liggesusers #' @importFrom utils packageDescription # Conflicts with devtools::document() so commented out #.onAttach <- function(...) { # mylib <- dirname(system.file(package = "WhatIf")) # ver <- packageDescription("WhatIf", lib.loc = mylib)$Version # builddate <- packageDescription("WhatIf", lib.loc = mylib)$Date # WhatIf Info - do not exceed 80char/line # packageStartupMessage(paste("#######################################################\n", #"##\n", ##"## WhatIf (Version ", ver, ", built ", builddate, ")\n", #"## WhatIf\n", #"## Complete documentation available from http://gking.harvard.edu/whatif \n", #"##\n", #"#######################################################", sep="")) #} WhatIf/R/whatif.R0000644000176200001440000003572213135304505013252 0ustar liggesusers#' Whatif #' #' Implements the methods described in King and Zeng (2006a, 2006b) for #' evaluating counterfactuals. #' #' @examples #' Create example data sets and counterfactuals #' #' my.cfact <- matrix(rnorm(3*5), ncol = 5) #' my.data <- matrix(rnorm(100*5), ncol = 5) #' #' Evaluate counterfactuals #' #' my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) #' #' Evaluate counterfactuals and supply own gower distances for #' cumulative frequency distributions #' #' my.result <- whatif(cfact = my.cfact, data = my.data, #' freq = c(0, .25, .5, 1, 1.25, 1.5), mc.cores = 1) #' #' @importFrom parallel detectCores mclapply #' @importFrom pbmcapply pbmclapply #' @importFrom Zelig zelig_setx_to_df #' @importFrom utils read.table setTxtProgressBar txtProgressBar #' @importFrom lpSolve lp #' @importFrom stats complete.cases delete.response model.frame model.matrix na.fail na.omit terms update.formula #' @export whatif <- function(formula = NULL, data, cfact, range = NULL, freq = NULL, nearby = 1, distance = "gower", miss = "list", choice= "both", return.inputs = FALSE, return.distance = FALSE, mc.cores = detectCores(), ...) { if (mc.cores <= 0) stop("mc.cores must be an integer greater than 0.", call. = FALSE) #DATA PROCESSING AND RELATED USER INPUT ERROR CHECKING #Initial processing of cfact message("Preprocessing data ...") if (grepl('Zelig*', class(data)) & missing(cfact)) cfact <- zelig_setx_to_df(data) if (grepl('Zelig*', class(data)) & !missing(cfact)) { formula <- formula(delete.response(terms(data$formula))) data <- data$zelig.out$z.out[[1]]$model } if(!((is.character(cfact) && is.vector(cfact) && length(cfact) == 1) || is.data.frame(cfact) || (is.matrix(cfact) && !is.character(cfact)))) { stop("'cfact' must be either a string, a R data frame, or a R non-character matrix") } if (is.character(cfact)) { cfact <- read.table(cfact) } if (dim(cfact)[1] == 0) { stop("no counterfactuals supplied: 'cfact' contains zero rows") } if (!any(complete.cases(cfact))) { stop("there are no cases in 'cfact' without missing values") } if ("(Intercept)" %in% dimnames(cfact)[[2]]) { cfact <- cfact[, -(which(dimnames(cfact)[[2]] == "(Intercept)"))] } #Initial processing of data if (is.list(data) && !(is.data.frame(data))) { if (!((("formula" %in% names(data)) || ("terms" %in% names(data))) && (("data" %in% names(data)) || ("model" %in% names(data))))) { stop("the list supplied to 'data' is not a valid output object") } tt <- terms(data) attr(tt, "intercept") <- rep(0, length(attr(tt, "intercept"))) if ("data" %in% names(data)) { if (is.data.frame(data$data)) { data <- model.matrix(tt, model.frame(tt, data = data$data, na.action = NULL)) } else { data <- model.matrix(tt, model.frame(tt, data = eval(data$data, envir = .GlobalEnv), na.action = NULL)) } } else { data <- model.matrix(tt, data = data$model) } if (!(is.matrix(data))) { stop("observed covariate data could not be extracted from output object") } rm(tt) } else { if(!((is.character(data) && is.vector(data) && length(data) == 1) || is.data.frame(data) || (is.matrix(data) && !is.character(data)))) { stop("'data' must be either a string, a R data frame, a R non-character matrix, or an output object") } if (is.character(data)) { data <- read.table(data) } } if (dim(data)[1] == 0) { stop("no observed covariate data supplied: 'data' contains zero rows") } if (!any(complete.cases(data))) { stop("there are no cases in 'data' without missing values") } #Secondary processing of data and cfact: use formula if (!(is.null(formula))) { if (identical(class(formula), "formula")) { if (!(is.data.frame(as.data.frame(data)))) { stop("'data' must be coercable to a data frame in order to use 'formula'") } if (!(is.data.frame(as.data.frame(cfact)))) { stop("'cfact' must be coercable to a data frame in order to use 'formula'") } formula <- update.formula(formula, ~ . -1) ttvar <- all.vars(formula) for (i in 1:length(ttvar)) { if (!(ttvar[i] %in% dimnames(data)[[2]])){ stop("variables in 'formula' either unlabeled or not present in 'data'") } if (!(ttvar[i] %in% dimnames(cfact)[[2]])){ stop("variable(s) in 'formula' either unlabeled or not present in 'cfact'") } } rm(ttvar) data <- model.matrix(formula, data = model.frame(formula, as.data.frame(data), na.action = NULL)) cfact <- model.matrix(formula, data = model.frame(formula, as.data.frame(cfact), na.action = NULL)) } else { stop("'formula' must be of class 'formula'") } } if (!(identical(complete.cases(cfact), rep(TRUE, dim(cfact)[1])))) { cfact <- na.omit(cfact) message("Note: counterfactuals with missing values eliminated from cfact") } #Tertiary processing of data and cfact: convert to numeric matrices if (is.data.frame(data)) { if (is.character(as.matrix(data))) { stop("observed covariate data not coercable to numeric matrix due to character column(s)") } data <- suppressWarnings(data.matrix(data)) } else { data <- data.matrix(as.data.frame(data)) } if (is.data.frame(cfact)) { if (is.character(as.matrix(cfact))) { stop("counterfactual data not coercable to numeric matrix due to character column(s)") } cfact <- suppressWarnings(data.matrix(cfact)) } else { cfact <- data.matrix(as.data.frame(cfact)) } #Final checks on data and cfact if (!(is.matrix(data) && is.numeric(data))) { stop("observed covariate data not coercable to numeric matrix") } if (!(is.matrix(cfact) && is.numeric(cfact))) { stop("counterfactual data not coercable to numeric matrix") } na.fail(cfact) #NON DATA-PROCESSING RELATED USER INPUT ERROR CHECKING #Check if cfact, data have the same number of dimensions, k if (!identical(ncol(cfact), ncol(data))) { stop("number of columns of 'cfact' and 'data' are not equal") } #Check format of range if user supplies an argument if (!(is.null(range))) { if (!(is.vector(range) && is.numeric(range))) { stop("'range' must be a numeric vector") } if (!identical(length(range), ncol(data))) { stop("length of 'range' does not equal number of columns of 'data'") } } #Check format of freq if user supplies an argument if (!(is.null(freq))) { if (!(is.vector(freq) && is.numeric(freq))) { stop("'freq' must be a numeric vector") } na.fail(freq) } #Check if nearby argument is numeric, a scalar, and >= 0, if supplied if (!(is.null(nearby))) { if (!(is.numeric(nearby) && is.vector(nearby) && length(nearby) == 1 && nearby >= 0)) { stop("'nearby' must be numeric, greater than or equal to 0, and a scalar") } } #Check if miss argument is valid if (!(identical(miss, "list") || identical(miss, "case"))) { stop("'miss' must be either ''case'' or ''list''") } #Check if distance argument is valid if (!(identical(distance, "gower") || identical(distance, "euclidian"))) { stop("'distance' must be either ''gower'' or ''euclidian''") } #Check if choice argument is valid if (!(identical(choice, "both") || identical(choice, "hull") || identical(choice, "distance"))) { stop("'choice' must be either ''both'', ''hull'', or ''distance''") } #Check if return.distance argument is valid if (!(is.logical(return.inputs))) { stop("'return.inputs' must be logical, i.e. either TRUE or FALSE") } #Check if return.distance argument is valid if (!(is.logical(return.distance))) { stop("'return.distance' must be logical, i.e. either TRUE or FALSE") } #KEY LOCAL VARIABLES n = nrow(data) #Number of data points in observed data set (initially including missing) #LOCAL FUNCTIONS ------------------------------------------------------------- convex.hull.test <- function(x, z, mc.cores = mc.cores) { one_core_pb <- mc.cores == 1 #Create objects required by lp function, adding a row of 1s to #transposed matrix s and a 1 to counterfactual vector z[m,]. Note that "A" here #corresponds to "A'" in King and Zeng 2006, Appendix A, and "B" and #"C" to their "B" and "C", respectively. n <- nrow(x) k <- ncol(x) m <- nrow(z) if (one_core_pb && m == 1) one_core_pb <- FALSE if (one_core_pb) pb <- txtProgressBar(min = 1, max = m, style = 3) A <- rbind(t(x), rep(1, n)) C <- c(rep(0, n)) D <- c(rep("=", k + 1)) in_ch <- function(i, one_core_pb = FALSE) { B <- c(z[i,], 1) lp.result <- lp(objective.in = C, const.mat = A, const.dir = D, const.rhs = B) if (one_core_pb) setTxtProgressBar(pb, i) if (lp.result$status == 0) return(TRUE) else return(FALSE) } if (one_core_pb) { hull <- sapply(1:m, in_ch, one_core_pb = one_core_pb) } else { if (.Platform$OS.type == "windows") hull <- mclapply(1:m, in_ch, mc.cores = mc.cores) else hull <- pbmclapply(1:m, in_ch, mc.cores = mc.cores) # parallelised with progress bar hull <- unlist(hull) } if (one_core_pb) close(pb) return(hull) } calc.gd <- function(dat, cf, range) { #If range = 0 for a variable k, set the normalized difference #equal to 0 if, for a given observed data point p, its #kth element minus the kth element of the counterfactual is 0. #Otherwise set equal to NA, thus ignoring the contribution of the kth #variable to the calculation of Gower's distance. #Note that an element of the range vector should only be 0 in degenerate #cases. n <- nrow(dat) m <- nrow(cf) dat = t(dat) dist = matrix(0,m,n,dimnames=list(1:m,1:n)) for (i in 1:m) { temp<-abs(dat-cf[i,])/range if (any(range==0)) { temp[is.nan(temp)]<-0 temp[temp==Inf]<-NA } dist[i,] <- colMeans(temp,na.rm=T) } return(t(dist)) } calc.ed <- function(dat, cf) { n<-nrow(dat) m<-nrow(cf) dat<-t(dat) dist=matrix(0,m,n,dimnames=list(1:m,1:n)) for (i in 1:m) { temp<-(dat-cf[i,])^2 dist[i,]<-(colSums(temp)) } return(t(dist)) } geom.var <- function(dat,rang) { n <- nrow(dat) dat<-t(dat) ff<-function(x){ temp<-abs(dat-x)/rang if (any(rang==0)) { temp[is.nan(temp)]<-0 temp[temp==Inf]<-NA } tmp<-sum(colMeans(temp,na.rm=TRUE) ) return(tmp) } sum.gd.x<-sum(apply(dat,2,ff),na.rm=TRUE) gv.x <- (0.5 * sum.gd.x)/(n^2) return (gv.x) } calc.cumfreq <- function(freq, dist) { m<-length(freq) n<-ncol(dist) res<-matrix(0,n,m) for(i in 1:m) res[,i]<-(colSums(dist <= freq[i]))/nrow(dist) return(res) } #MISSING DATA if (identical(miss, "list")) { data <- na.omit(data) n <- nrow(data) } #CONVEX HULL TEST if ((choice=="both")|(choice=="hull")) { message("Performing convex hull test ...") test.result <- convex.hull.test(x = na.omit(data), z = cfact, mc.cores = mc.cores) } #CALCULATE DISTANCE if ((choice=="both")|(choice=="distance")) { message("Calculating distances ....") if (identical(distance, "gower")) { samp.range <- apply(data, 2, max, na.rm = TRUE) - apply(data, 2, min, na.rm = TRUE) if(!is.null(range)) { w<-which(!is.na(range)) samp.range[w]<-range[w] } if (identical(TRUE, any(samp.range == 0))) { message("Note: range of at least one variable equals zero") } dist <- calc.gd(dat = data, cf = cfact, range=samp.range) } else { dist <- calc.ed(dat = na.omit(data), cf = cfact) } #GEOMETRIC VARIANCE message("Calculating the geometric variance...") if (identical(distance, "gower")) { gv.x <- geom.var(dat = data,rang = samp.range) } else { gv.x<-.5*mean(calc.ed(dat = na.omit(data), cf = na.omit(data))) } #SUMMARY STATISTIC if (identical(miss, "case") && identical(distance, "euclidian")) { summary <- colSums(dist <= nearby*gv.x) * (1/nrow(na.omit(data))) } else { summary <- colSums(dist <= nearby*gv.x) * (1/n) } #CUMULATIVE FREQUENCIES message("Calculating cumulative frequencies ...") if (is.null(freq)) { if (identical(distance, "gower")) { freqdist <- seq(0, 1, by = 0.05) } else { min.ed <- min(dist) max.ed <- max(dist) freqdist <- round(seq(min.ed, max.ed, by = (max.ed - min.ed)/20), 2) } } else { freqdist <- freq } cumfreq <- calc.cumfreq(freq = freqdist, dist = dist) dimnames(cumfreq) <- list(seq(1, nrow(cfact), by = 1), freqdist) } message("Finishing up ...") #RETURN if (return.inputs) { if (choice=="both") { if (return.distance) { out <- list(call = match.call(), inputs = list(data = data, cfact = cfact), in.hull = test.result, dist = t(dist), geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } else { out <- list(call = match.call(), inputs = list(data = data, cfact = cfact), in.hull = test.result, geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } } if (choice=="distance") { if (return.distance) { out <- list(call = match.call(), inputs = list(data = data, cfact = cfact), dist = t(dist), geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } else { out <- list(call = match.call(), inputs = list(data = data, cfact = cfact), geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } } if (choice=="hull") { out <- list(call = match.call(), inputs = list(data = data, cfact = cfact), in.hull = test.result) } } else { if (choice=="both") { if (return.distance) { out <- list(call = match.call(), in.hull = test.result, dist = t(dist), geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } else { out <- list(call = match.call(), in.hull = test.result, geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } } if (choice=="distance") { if (return.distance) { out <- list(call = match.call(), dist = t(dist), geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } else { out <- list(call = match.call(), geom.var = gv.x, sum.stat = summary, cum.freq = cumfreq) } } if (choice=="hull") { out <- list(call = match.call(), in.hull = test.result) } } class(out) <- "whatif" return(invisible(out)) } WhatIf/README.md0000644000176200001440000000376313135304505012723 0ustar liggesusers## WhatIf **Release:** [![CRAN Version](http://www.r-pkg.org/badges/version/WhatIf)](https://CRAN.R-project.org/package=WhatIf) ![CRAN Monthly Downloads](http://cranlogs.r-pkg.org/badges/last-month/WhatIf) ![CRAN Total Downloads](http://cranlogs.r-pkg.org/badges/grand-total/WhatIf) **Development:** [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Travis-CI Build Status](https://travis-ci.org/IQSS/WhatIf.svg?branch=master)](https://travis-ci.org/IQSS/WhatIf) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/IQSS/WhatIf?branch=master&svg=true)](https://ci.appveyor.com/project/IQSS/WhatIf) Inferences about counterfactuals are essential for prediction, answering what if questions, and estimating causal effects. However, when the counterfactuals posed are too far from the data at hand, conclusions drawn from well-specified statistical analyses become based largely on speculation hidden in convenient modeling assumptions that few would be willing to defend. Unfortunately, standard statistical approaches assume the veracity of the model rather than revealing the degree of model-dependence, which makes this problem hard to detect. WhatIf offers easy-to-apply methods to evaluate counterfactuals that do not require sensitivity testing over specified classes of models. If an analysis fails the tests offered here, then we know that substantive inferences will be sensitive to at least some modeling choices that are not based on empirical evidence, no matter what method of inference one chooses to use. WhatIf implements the methods for evaluating counterfactuals discussed in Gary King and Langche Zeng, 2006, "The Dangers of Extreme Counterfactuals," *Political Analysis* 14 (2); and Gary King and Langche Zeng, 2007, "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference," *International Studies Quarterly* 51 (March). WhatIf/MD50000644000176200001440000000271213135626510011750 0ustar liggesusers3319e5bd5ceff0588ae488c60f4631a1 *DESCRIPTION 81140ebcc3d9566fbb77b73021c4d515 *NAMESPACE e3f6bfe49575b0aa35c39b32c66b44ff *NEWS.md 27a48d8161cfab79ad289177336077f6 *R/load.first.R 9f2792bd63c1fb311a49df4f106d0093 *R/plot.whatif.R 103eb1f24a60ba77d69ca1a176f5a7cb *R/print.summary.whatif.R d371f30889a95aeb7255e6fa3bfe3661 *R/print.whatif.R 607a6f999eeba95c86c44215adad954c *R/summary.whatif.R b36df48b6a866b914c74872fe5d0562d *R/whatif.R 914ffba8560f02eca0eae5aa1fef8bf0 *README.md e1c693134b7309fe9520639daca97c7f *data/peacecf.RData 96a8c9659dc1802f46330ea57d6241be *data/peacef.RData 69342616fbb32c20bda08489aadd6595 *demo/00Index 63a86b60adac086eb20570e1a5053128 *demo/peace.R bfcc503a60881ec35cb9087f425c43ad *inst/doc/brabazon_pig_500.jpg c32b9dcb7d589b0557bc88a5119f6b12 *inst/doc/index.shtml 4cfbc1ed54431596504d4e13b8a8098f *man/peacecf.Rd 51dbcaf1b4cd7473c44ae59d556d79eb *man/peacef.Rd e01afdac128af30308a550796cd8af47 *man/plot.whatif.Rd 553befc10ecb801afa8d830578caf6d5 *man/print.summary.whatif.Rd f30f112dc90505d699e7c3d3a25d0491 *man/print.whatif.Rd 23b6442fa0c6920ddd5776fb1b4f2a9f *man/summary.whatif.Rd b3a4c24d8248ec5767b8c81e65fc93e8 *man/whatif.Rd fb97e0aff238d86805e4fc0bca118c76 *tests/testthat.R 15989f8cc1979336bfe50721036009cf *tests/testthat/test-plot.R 63b804609342e3f2bf39693664c87326 *tests/testthat/test-whatif.R a36e902ed0d3bd466edcfa44fb4973d8 *tests/testthat/test-whatif_convexhull.R b236ebd9688744ae9dd80f172cb6c54f *tests/testthat/test-zelig.R WhatIf/DESCRIPTION0000644000176200001440000000443713135626510013154 0ustar liggesusersPackage: WhatIf Title: Evaluate Counterfactuals Version: 1.5-9 Date: 2017-07-25 Authors@R: c( person("Christopher", "Gandrud", email = "zelig.zee@gmail.com", role = c("aut", "cre")), person("Gary", "King", role = "aut"), person("Ben", "Sabath", role = "ctb"), person("Heather", "Stoll", role = "aut"), person("Langche", "Zeng", role = "aut") ) Description: Inferences about counterfactuals are essential for prediction, answering what if questions, and estimating causal effects. However, when the counterfactuals posed are too far from the data at hand, conclusions drawn from well-specified statistical analyses become based largely on speculation hidden in convenient modeling assumptions that few would be willing to defend. Unfortunately, standard statistical approaches assume the veracity of the model rather than revealing the degree of model-dependence, which makes this problem hard to detect. WhatIf offers easy-to-apply methods to evaluate counterfactuals that do not require sensitivity testing over specified classes of models. If an analysis fails the tests offered here, then we know that substantive inferences will be sensitive to at least some modeling choices that are not based on empirical evidence, no matter what method of inference one chooses to use. WhatIf implements the methods for evaluating counterfactuals discussed in Gary King and Langche Zeng, 2006, "The Dangers of Extreme Counterfactuals," Political Analysis 14 (2) ; and Gary King and Langche Zeng, 2007, "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference," International Studies Quarterly 51 (March) . License: GPL (>= 3) URL: http://gking.harvard.edu/whatif BugReports: https://github.com/IQSS/WhatIf/issues Depends: R (>= 2.3.1) Imports: lpSolve, pbmcapply, Zelig (>= 5.0-17) Suggests: testthat RoxygenNote: 6.0.1 NeedsCompilation: no Packaged: 2017-07-25 05:05:32 UTC; cgandrud Author: Christopher Gandrud [aut, cre], Gary King [aut], Ben Sabath [ctb], Heather Stoll [aut], Langche Zeng [aut] Maintainer: Christopher Gandrud Repository: CRAN Date/Publication: 2017-07-25 11:36:40 UTC WhatIf/man/0000755000176200001440000000000013135304505012206 5ustar liggesusersWhatIf/man/peacef.Rd0000644000176200001440000000242113135304505013717 0ustar liggesusers\name{peacef} \docType{data} \alias{peacef} \title{Factual Replication Data from King and Zeng 2006b} \description{ This data set is one of two that together allow the replication of the analysis in section 2.4 of King and Zeng 2006b. It contains \emph{factual} data from Doyle and Sambanis 2000 on 124 post-WWII civil wars. It should be used in conjunction with the data set of counterfactuals derived from it, \code{peacecf}. } \usage{data(peacef)} \format{A data frame with dimensions 124-by-11. Columns are covariates and rows are data points (or units). The covariates are \code{decade}, \code{wartype}, \code{logcost}, \code{wardur}, \code{factnum}, \code{factnumsq}, \code{trnsfcap}, \code{untype4}, \code{treaty}, \code{develop}, and \code{exp}, in that order. } \source{King and Zeng 2006b} \references{ King, Gary and Langche Zeng. 2006. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Doyle, Michael W. and Nicholas Sambanis. 2000. "International Peacebuilding: A Theoretical and Quantitative Analysis." \emph{American Political Science Review} 94, no.4: 779--801. } \keyword{datasets} WhatIf/man/print.whatif.Rd0000644000176200001440000000353113135304505015114 0ustar liggesusers\name{print.whatif} \alias{print.whatif} \title{Print "whatif" Object} \description{ Prints the information produced by the function \code{whatif}, an object of class "whatif", to the screen. } \usage{ \method{print}{whatif}(x, print.dist = FALSE, print.freq = FALSE, ...) } \arguments{ \item{x}{An object of class "whatif", the output of the function \code{whatif}.} \item{print.dist}{A Boolean; should the matrix of pairwise distances between each counterfactual and data point be printed to the screen, if it was returned? Default is \code{FALSE}.} \item{print.freq}{A Boolean; should the matrix of cumulative frequencies of distances for each counterfactual be printed to the screen? Default is \code{FALSE}.} \item{...}{Further arguments passed to and from other methods.} } \value{ A printout to the screen of the information contained in the \code{whatif} output object. } \references{King, Gary and Langche Zeng. 2006. "The Dangers of Extreme Counterfactuals." \emph{Political Analysis} 14 (2). Available from \url{http://gking.harvard.edu}. King, Gary and Langche Zeng. 2007. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Available from \url{http://gking.harvard.edu}.} \author{Stoll, Heather \email{hstoll@polsci.ucsb.edu}, King, Gary \email{king@harvard.edu} and Zeng, Langche \email{zeng@ucsd.edu}} \seealso{ \code{\link{whatif}}, \code{\link{plot.whatif}}, \code{\link{summary.whatif}}, \code{\link{print.summary.whatif}} } \examples{ ## Create example data sets and counterfactuals my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) ## Evaluate counterfactuals my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) ## Print output object print(my.result) } \keyword{print} WhatIf/man/summary.whatif.Rd0000644000176200001440000000443713135304505015463 0ustar liggesusers\name{summary.whatif} \alias{summary.whatif} \title{Summary of "whatif" Object} \description{ Summarizes the information produced by the function \code{whatif}. The summary generated is returned as an output object and also printed to the screen. } \usage{ \method{summary}{whatif}(object, ...) } \arguments{ \item{object}{An object of class "whatif", the output of the function \code{whatif}.} \item{...}{Further arguments passed to and from other methods.} } \value{ An object of class "summary.whatif", a list containing the following five elements: \item{call}{The original call to \code{whatif}.} \item{m}{A scalar. The total number of counterfactuals evaluated.} \item{m.inhull}{A scalar. The number of counterfactuals evaluated that are in the convex hull of the observed covariate data.} \item{mean.near}{A scalar. The average percentage of data nearby each counterfactual, where the average is taken over all counterfactuals.} \item{sum.df}{A data frame with three columns and \eqn{m} rows, where \eqn{m} is the number of counterfactuals. The first column, \code{cfact}, indexes the counterfactuals. The second column, \code{in.hull}, contains the results of the convex hull test. The third column, \code{per.near}, contains the percentage of data points nearby each counterfactual.} This object is printed to the screen. } \references{King, Gary and Langche Zeng. 2006. "The Dangers of Extreme Counterfactuals." \emph{Political Analysis} 14 (2). Available from \url{http://gking.harvard.edu}. King, Gary and Langche Zeng. 2007. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Available from \url{http://gking.harvard.edu}.} \author{Stoll, Heather \email{hstoll@polsci.ucsb.edu}, King, Gary \email{king@harvard.edu} and Zeng, Langche \email{zeng@ucsd.edu}} \seealso{ \code{\link{whatif}}, \code{\link{plot.whatif}}, \code{\link{print.whatif}}, \code{\link{print.summary.whatif}} } \examples{ ## Create example data sets and counterfactuals my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) ## Evaluate counterfactuals my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) ## Print summary summary(my.result) } \keyword{print} WhatIf/man/peacecf.Rd0000644000176200001440000000232113135304505014061 0ustar liggesusers\name{peacecf} \docType{data} \alias{peacecf} \title{Counterfactual Replication Data from King and Zeng 2006b} \description{ This data set is one of two that together allow the replication of the analysis in section 2.4 of King and Zeng 2006b. It contains data on 122 \emph{counterfactuals} derived by King and Zeng 2006b from the factual Doyle and Sambanis 2000 data set, \code{peacef}. It should be used in conjunction with the latter. } \usage{data(peacecf)} \format{A data frame with dimensions 122-by-11. Columns are covariates and rows are data points (or units). The covariates are as in \code{peacef} with the exception of the key causal variable, \code{untype4}, which is transformed to 1 - \code{untype4}.} \source{King and Zeng 2006b} \references{ King, Gary and Langche Zeng. 2006. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Doyle, Michael W. and Nicholas Sambanis. 2000. "International Peacebuilding: A Theoretical and Quantitative Analysis." \emph{American Political Science Review} 94, no.4: 779--801. } \keyword{datasets} WhatIf/man/print.summary.whatif.Rd0000644000176200001440000000314113135304505016605 0ustar liggesusers\name{print.summary.whatif} \alias{print.summary.whatif} \title{Print "summary.whatif" Object} \description{ Prints the information generated from the \code{whatif} output object by a call to \code{summary}, which is stored in an object of class "summary.whatif". } \usage{ \method{print}{summary.whatif}(x, ...) } \arguments{ \item{x}{An object of class "summary.whatif", the output of the function \code{summary.whatif}.} \item{...}{Further arguments passed to and from other methods.} } \value{ A printout to the screen of the \code{whatif} information summarized in the \code{summary.whatif} output object. } \references{King, Gary and Langche Zeng. 2006. "The Dangers of Extreme Counterfactuals." \emph{Political Analysis} 14 (2). Available from \url{http://gking.harvard.edu}. King, Gary and Langche Zeng. 2007. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Available from \url{http://gking.harvard.edu}.} \author{Stoll, Heather \email{hstoll@polsci.ucsb.edu}, King, Gary \email{king@harvard.edu} and Zeng, Langche \email{zeng@ucsd.edu}} \seealso{ \code{\link{whatif}}, \code{\link{plot.whatif}}, \code{\link{summary.whatif}}, \code{\link{print.whatif}} } \examples{ ## Create example data sets and counterfactuals my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) ## Evaluate counterfactuals my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) ## Print summary output object my.result.sum <- summary(my.result) print(my.result.sum) } \keyword{print} WhatIf/man/whatif.Rd0000644000176200001440000003466013135304505013770 0ustar liggesusers\name{whatif} \alias{whatif} \title{Counterfactual Evaluation} \description{ Implements the methods described in King and Zeng (2006a, 2006b) for evaluating counterfactuals. } \usage{ whatif(formula = NULL, data, cfact, range = NULL, freq = NULL, nearby = 1, distance = "gower", miss = "list", choice = "both", return.inputs = FALSE, return.distance = FALSE, mc.cores = detectCores(), ...) } \arguments{ \item{formula}{An optional formula without a dependent variable that is of class "formula" and that follows standard \code{R} conventions for formulas, e.g. ~ x1 + x2. Allows you to transform or otherwise re-specify combinations of the variables in both \code{data} and \code{cfact}. To use this parameter, both \code{data} and \code{cfact} must be coercable to data frames; the variables of both \code{data} and \code{cfact} must be labeled; and all variables appearing in \code{formula} must also appear in both \code{data} and \code{cfact}. Otherwise, errors are returned. The intercept is automatically dropped. Default is \code{NULL}.} \item{data}{May take one of the following forms: \enumerate{ \item A \code{R} model output object, such as the output from calls to \code{lm}, \code{glm}, and \code{zelig}. If it is not a \code{zelig} object, such an output object must be a list. It must additionally have either a \code{formula} or \code{terms} component and either a \code{data} or \code{model} component; if it does not, an error is returned. Of the latter, \code{whatif} first looks for \code{data}, which should contain either the original data set supplied as part of the model call (as in \code{glm}) or the name of this data set (as in \code{zelig}), which is assumed to reside in the global environment. If \code{data} does not exist, \code{whatif} then looks for \code{model}, which should contain the model frame (as in \code{lm}). The intercept is automatically dropped from the extracted \emph{observed covariate data} set if the original model included one. \item A \eqn{n}-by-\eqn{k} non-character (logical or numeric) matrix or data frame of \emph{observed covariate data} with \eqn{n} data points or units and \eqn{k} covariates. All desired variable transformations and interaction terms should be included in this set of \eqn{k} covariates unless \code{formula} is alternatively used to produce them. However, an intercept should not be. Such a matrix may be obtained by passing model output (e.g., output from a call to \code{lm}) to \code{model.matrix} and excluding the intercept from the resulting matrix if one was fit. Note that \code{whatif} will attempt to coerce data frames to their internal numeric values. Hence, data frames should only contain logical, numeric, and factor columns; character columns will lead to an error being returned. \item A string. Either the complete path (including file name) of the file containing the data or the path relative to your working directory. This file should be a white space delimited text file. If it contains a header, you must include a column of row names as discussed in the help file for the \code{R} function \code{read.table}. The data in the file should be as otherwise described in (2). } Missing data is allowed and will be dealt with via the argument \code{missing}. It should be flagged using \code{R}'s standard representation for missing data, \code{NA}.} \item{cfact}{A \code{R} object or a string. If a \code{R} object, a \eqn{m}-by-\eqn{k} non-character matrix or data frame of \emph{counterfactuals} with \eqn{m} counterfactuals and the same \eqn{k} covariates (in the same order) as in \code{data}. However, if \code{formula} is used to select a subset of the \eqn{k} covariates, then \code{cfact} may contain either only these \eqn{j \leq k}{j <= K} covariates or the complete set of \eqn{k} covariates. An intercept should not be included as one of the covariates. It will be automatically dropped from the counterfactuals generated by \pkg{Zelig} if the original model contained one. Data frames will again be coerced to their internal numeric values if possible. If a string, either the complete path (including file name) of the file containing the counterfactuals or the path relative to your working directory. This file should be a white space delimited text file. See the discussion under \code{data} for instructions on dealing with a header. All counterfactuals should be fully observed: if you supply counterfactuals with missing data, they will be list-wise deleted and a warning message will be printed to the screen.} \item{range}{An optional numeric vector of length \eqn{k}, where \eqn{k} is the number of covariates. Each element represents the range of the corresponding covariate for use in calculating Gower distances. Use this argument when covariate data do not represent the population of interest, such as selection by stratification or experimental manipulation. By default, the range of each covariate is calculated from the data (the difference of its maximum and minimum values in the sample), which is appropriate when a simple random sampling design was used. To supply your own range for the \eqn{k}th covariate, set the \eqn{k}th element of the vector equal to the desired range and all other elements equal to \code{NA}. Default is \code{NULL}.} \item{freq}{An optional numeric vector of any positive length, the elements of which comprise a set of distances. Used in calculating cumulative frequency distributions for the distances of the data points from each counterfactual. For each such distance and counterfactual, the cumulative frequency is the fraction of observed covariate data points with distance to the counterfactual less than or equal to the supplied distance value. The default varies with the distance measure used. When the Gower distance measure is employed, frequencies are calculated for the sequence of Gower distances from 0 to 1 in increments of 0.05. When the Euclidian distance measure is employed, frequencies are calculated for the sequence of Euclidian distances from the minimum to the maximum observed distances in twenty equal increments, all rounded to two decimal places. Default is \code{NULL}.} \item{nearby}{An optional scalar indicating which observed data points are considered to be nearby (i.e., withing `nearby' geometric variances of) the counterfactuals. Used to calculate the summary statistic returned by the function: the fraction of the observed data nearby each counterfactual. By default, the geometric variance of the covariate data is used. For example, setting \code{nearby} to 2 will identify the proportion of data points within two geometric variances of a counterfactual. Default is \code{NULL}.} \item{distance}{An optional string indicating which of two distance measures to employ. The choices are either \code{"gower"}, Gower's non-parametric distance measure (\eqn{G^2}), which is suitable for both qualitative and quantitative data; or \code{"euclidian"}, squared Euclidian distance, which is only suitable for quantitative data. The default is \code{"gower"}.} \item{miss}{An optional string indicating the strategy for dealing with missing data in the observed covariate data set. \code{whatif} supports two possible missing data strategies: \code{"list"}, list-wise deletion of missing cases; and \code{"case"}, ignoring missing data case-by-case. Note that if \code{"case"} is selected, cases with missing values are deleted listwise for the convex hull test and for computing Euclidian distances, but pairwise deletion is used in computing the Gower distances to maximally use available information. The user is strongly encouraged to treat missing data using specialized tools such as Amelia prior to feeding the data to \code{whatif}. Default is \code{"list"}.} \item{choice}{An optional string indicating which analyses to undertake. The options are either \code{"hull"}, only perform the convex hull membership test; \code{"distance"}, do not perform the convex hull test but do everything else, such as calculating the distance between each counterfactual and data point; or \code{"both"}, undertake both the convex hull test and the distance calculations (i.e., do everything). Default is \code{"both"}.} \item{return.inputs}{A Boolean; should the processed observed covariate and counterfactual data matrices on which all \code{whatif} computations are performed be returned? Processing refers to internal \code{whatif} operations such as the subsetting of covariates via \code{formula}, the deletion of cases with missing values, and the coercion of data frames to numeric matrices. Primarily intended for diagnostic purposes. If \code{TRUE}, these matrices are returned as a list. Default is \code{FALSE}.} \item{return.distance}{A Boolean; should the matrix of distances between each counterfactual and data point be returned? If \code{TRUE}, this matrix is returned as part of the output; if \code{FALSE}, it is not. Default is \code{FALSE} due to the large size that this matrix may attain.} \item{mc.cores}{The number of cores to use for the convex hull test, i.e. at most how many child processes will be run simultaneously. Must be at least one, and parallelization requires at least two cores. The default is set by \code{\link{detectCores}}}. \item{...}{Further arguments passed to and from other methods.} } \details{ This function is the primary tool for evaluating your counterfactuals. Specifically, it: \enumerate{ \item Determines whether or not your counterfactuals are in the convex hull of the observed covariate data. \item Computes the distance of your counterfactuals from each of the \eqn{n} observed covariate data points. The default distance function used is Gower's non-parametric measure. \item Computes a summary statistic for each counterfactual based on the distances in (2): the fraction of observed covariate data points with distances to your counterfactual less than a value you supply. By default, this value is taken to be the geometric variability of the observed data. \item Computes the cumulative frequency distribution of each counterfactual for the distances in (2) using values that you supply. By default, Gower distances from 0 to 1 in increments of 0.05 are used. } } \value{ An object of class "whatif", a list consisting of the following six or seven elements: \item{call}{The original call to \code{whatif}.} \item{inputs}{A list with two elements, \code{data} and \code{cfact}. Only present if \code{return.inputs} was set equal to \code{TRUE} in the call to \code{whatif}. The first element is the processed observed covariate data matrix on which all \code{whatif} computations were performed. The second element is the processed counterfactual data matrix.} \item{in.hull}{A logical vector of length \eqn{m}, where \eqn{m} is the number of counterfactuals. Each element of the vector is \code{TRUE} if the corresponding counterfactual is in the convex hull and \code{FALSE} otherwise.} \item{dist}{A \eqn{m}-by-\eqn{n} numeric matrix, where \eqn{m} is the number of counterfactuals and \eqn{n} is the number of data points (units). Only present if \code{return.distance} was set equal to \code{TRUE} in the call to \code{whatif}. The \eqn{[i, j]}th entry of the matrix contains the distance between the \eqn{i}th counterfactual and the \eqn{j}th data point.} \item{geom.var}{A scalar. The geometric variability of the observed covariate data.} \item{sum.stat}{A numeric vector of length \eqn{m}, where \eqn{m} is the number of counterfactuals. The \eqn{m}th element contains the summary statistic for the corresponding counterfactual. This summary statistic is the fraction of data points with distances to the counterfactual less than the argument \code{nearby}, which by default is the geometric variability of the covariates.} \item{cum.freq}{A numeric matrix. By default, the matrix has dimension \eqn{m}-by-21, where \eqn{m} is the number of counterfactuals; however, if you supplied your own frequencies via the argument \code{freq}, the matrix has dimension \eqn{m}-by-\eqn{f}, where \eqn{f} is the length of \code{freq}. Each row of the matrix contains the cumulative frequency distribution for the corresponding counterfactual calculated using either the distance measure-specific default set of distance values or the set that you supplied (see the discussion under the argument \code{freq}). Hence, the \eqn{[i, j]}th entry of the matrix is the fraction of data points with distances to the \eqn{i}th counterfactual less than or equal to the value represented by the \eqn{j}th column. The column names contain these values.} } \references{King, Gary and Langche Zeng. 2006. "The Dangers of Extreme Counterfactuals." \emph{Political Analysis} 14 (2). Available from \url{http://gking.harvard.edu}. King, Gary and Langche Zeng. 2007. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Available from \url{http://gking.harvard.edu}.} \author{Stoll, Heather \email{hstoll@polsci.ucsb.edu}, King, Gary \email{king@harvard.edu} and Zeng, Langche \email{zeng@ucsd.edu}} \note{This function requires the \pkg{lpSolve} package.} \seealso{ \code{\link{plot.whatif}}, \code{\link{summary.whatif}}, \code{\link{print.whatif}}, \code{\link{print.summary.whatif}} } \examples{ ## Create example data sets and counterfactuals my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) ## Evaluate counterfactuals my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) ## Evaluate counterfactuals and supply own gower distances for ## cumulative frequency distributions my.result <- whatif(cfact = my.cfact, data = my.data, freq = c(0, .25, .5, 1, 1.25, 1.5), mc.cores = 1) } \keyword{htest} \keyword{models} \keyword{regression} WhatIf/man/plot.whatif.Rd0000644000176200001440000000677513135304505014753 0ustar liggesusers\name{plot.whatif} \alias{plot.whatif} \title{Plot Cumulative Frequencies of Distances for "whatif" Objects} \description{ Generates a cumulative frequency plot of distances from an object of class "whatif". The cumulative frequencies (the fraction of rows in the observed data set with either Gower or (squared) Euclidian distances to the counterfactuals less than the given value on the horizontal axis) appear on the vertical axis. } \usage{ \method{plot}{whatif}(x, type = "f", numcf = NULL, eps = FALSE, ...) } \arguments{ \item{x}{An object of class "whatif", the output of the function \code{whatif}.} \item{type}{A character string; the type of plot of the cumulative frequencies of the distances to be produced. Possible types are: \code{"f"} for cumulative frequencies only; \code{"l"} for LOWESS smoothing of cumulative frequencies only; and \code{"b"} for both cumulative frequencies and LOWESS smoothing. The default is \code{"f"}.} \item{numcf}{A numeric vector; the specific counterfactuals to be plotted. Each element represents a counterfactual, specifically its row number from the matrix or data frame of counterfactuals. By default, all counterfactuals are plotted. Default is \code{NULL}.} \item{eps}{A Boolean; should an encapsulated postscript file be generated? Setting the argument equal to \code{TRUE} generates an \code{.eps} file, which is saved to your working directory with file name of form '\code{graph_'type'_'numcf'.eps}', where \code{'type'} and \code{'numcf'} are the values of the respective arguments. Specifically, \code{'numcf'} takes the value of the first element of the argument \code{numcf} unless all counterfactuals were plotted, in which case \code{all} appears in the place of \code{'numcf'}. Default is \code{FALSE}, which instead prints the graph to the screen.} \item{...}{Further arguments passed to and from other methods.} } \details{ LOWESS scatterplot smoothing using the function \code{lowess} is plotted in blue. Counterfactuals in the convex hull are plotted with a solid line and counterfactuals outside of the convex hull with a dashed line. } \value{ A graph printed to the screen or an encapsulated postscript file saved to your working directory. In the latter case, the file name has form '\code{graph_'type'_'numcf'.eps}', where \code{'type'} and \code{'numcf'} are the values of the respective arguments. } \references{King, Gary and Langche Zeng. 2006. "The Dangers of Extreme Counterfactuals." \emph{Political Analysis} 14 (2). Available from \url{http://GKing.Harvard.Edu}. King, Gary and Langche Zeng. 2007. "When Can History Be Our Guide? The Pitfalls of Counterfactual Inference." \emph{International Studies Quarterly} 51 (March). Available from \url{http://gking.harvard.edu}.} \author{Stoll, Heather \email{hstoll@polsci.ucsb.edu}, King, Gary \email{king@harvard.edu} and Zeng, Langche \email{zeng@ucsd.edu}} \seealso{ \code{\link{whatif}}, \code{\link{summary.whatif}}, \code{\link{print.whatif}}, \code{\link{print.summary.whatif}} } \examples{ ## Create example data sets and counterfactuals my.cfact <- matrix(rnorm(3*5), ncol = 5) my.data <- matrix(rnorm(100*5), ncol = 5) ## Evaluate counterfactuals my.result <- whatif(data = my.data, cfact = my.cfact, mc.cores = 1) ## Plot cumulative frequencies for the first two counterfactuals (rows ## 1 and 2) in my.cfact plot(my.result, type = "b", numcf = c(1, 2), mc.cores = 1) } \keyword{hplot} WhatIf/.Rinstignore0000644000176200001440000000004613135304505013737 0ustar liggesusersMakefile doc/.*[.]jpg$ Readme.markdown