Skip to content

Commit

Permalink
replace all 'sensemade' with 'sensemakr'
Browse files Browse the repository at this point in the history
with emphasis on class
  • Loading branch information
mikejacktzen committed Sep 5, 2017
1 parent 0741cfd commit da0cbe0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##' @title Sensitivity plots
##' @description Several sensitivity plots.
##'
##' @param x sensemade object
##' @param x sensemakr object
##' @param showvars chooses which subsets of benchmarks to display
##' Valid options are: 'masked', 'all', or list('foo1','foo2')
##' @param type type of the plot
Expand All @@ -11,7 +11,7 @@
##'
##' @return a ggplot object with the plot.
##' @export
plot.sensemade = function(x,
plot.sensemakr = function(x,
showvars='masked',
type = c("contour", "worst-case"),
...){
Expand Down Expand Up @@ -114,7 +114,7 @@ contourplot = function(x,
# subset the benchmark data
######################################################

# 'working benchmarks' assigned earlier in generic plot.sensemade()
# 'working benchmarks' assigned earlier in generic plot.sensemakr()
# based on showvars subset
# x$benchmarks$benchmarks_2plot1
# x$benchmarks$benchmarks_2plot2
Expand Down Expand Up @@ -271,7 +271,7 @@ worstcaseplot = function(x,
main = "Sensitivity of estimate to unobserved confounder(s)\n\"Worst-case\" scenarios of partial R2 with outcome"){


# 'working benchmarks' assigned earlier in generic plot.sensemade()
# 'working benchmarks' assigned earlier in generic plot.sensemakr()
# based on showvars subset
# x$benchmarks$benchmarks_2plot1
# x$benchmarks$benchmarks_2plot2
Expand Down
46 changes: 23 additions & 23 deletions R/print_and_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# A method must have arguments in exactly the same order as the generic.

##' @export
print.sensemade = function(x, str = TRUE){
print.sensemakr = function(x, str = TRUE){

cat("Sensitivity Analysis\n\n")
cat("Model:", trimws(deparse(formula(x$info$model))), "\n\n")
Expand All @@ -20,36 +20,36 @@ print.sensemade = function(x, str = TRUE){


##' @export
summary.sensemade = function(object, q=1,scenarios=c(1,.25)){
summary.sensemakr = function(object, q=1,scenarios=c(1,.25)){
# bunch of useful things
# return list with several useful things
# returns a obj of class summary.sensemade
# returns a obj of class summary.sensemakr
out = object
class(out) = "summary.sensemade"
print.summary.sensemade(out, q=q, scenarios=scenarios)
class(out) = "summary.sensemakr"
print.summary.sensemakr(out, q=q, scenarios=scenarios)
}

##' @export
interpret = function(sensemade, q = 1){
interpret = function(sensemakr, q = 1){

# from: sensemade$benchmarks$benchmark_eachvar$r2y
# to: sensemade$benchmarks$benchmark_eachvar$r2y
# from: sensemakr$benchmarks$benchmark_eachvar$r2y
# to: sensemakr$benchmarks$benchmark_eachvar$r2y

# make sure 'max()' is choosing right benchmark point
# currently points at 'female' not 'village',
# since 'village' is in (sense$benchmarks$benchmark_group)
# currently, only looking at (sensemade$benchmarks$benchmark_eachvar)
# currently, only looking at (sensemakr$benchmarks$benchmark_eachvar)

idxr2y = which.max(sensemade$benchmarks$benchmark_eachvar$r2y)
idxr2d = which.max(sensemade$benchmarks$benchmark_eachvar$r2d)
estimate = sensemade$treat.stats$estimate
se = sensemade$treat.stats$se
idxr2y = which.max(sensemakr$benchmarks$benchmark_eachvar$r2y)
idxr2d = which.max(sensemakr$benchmarks$benchmark_eachvar$r2d)
estimate = sensemakr$treat.stats$estimate
se = sensemakr$treat.stats$se
t = estimate/se
df = sensemade$treat.stats$df
varR2D = sensemade$benchmarks$benchmark_eachvar$covariate[idxr2d]
maxR2d = sensemade$benchmarks$benchmark_eachvar$r2d[idxr2d]
varR2Y = sensemade$benchmarks$benchmark_eachvar$covariate[idxr2y]
maxR2y = sensemade$benchmarks$benchmark_eachvar$r2y[idxr2d]
df = sensemakr$treat.stats$df
varR2D = sensemakr$benchmarks$benchmark_eachvar$covariate[idxr2d]
maxR2d = sensemakr$benchmarks$benchmark_eachvar$r2d[idxr2d]
varR2Y = sensemakr$benchmarks$benchmark_eachvar$covariate[idxr2y]
maxR2y = sensemakr$benchmarks$benchmark_eachvar$r2y[idxr2d]
r2dc = t^2/(t^2 + (maxR2y/q^2)*df)
r2yc = ((q*t)^2)*((1 - maxR2d)/(maxR2d*df))

Expand Down Expand Up @@ -82,11 +82,11 @@ interpret = function(sensemade, q = 1){
}

##' @export
worstcaseinterpret = function(sensemade, scenarios = c(1, 0.25), q = 1){
estimate = sensemade$treat.stats$estimate
se = sensemade$treat.stats$se
worstcaseinterpret = function(sensemakr, scenarios = c(1, 0.25), q = 1){
estimate = sensemakr$treat.stats$estimate
se = sensemakr$treat.stats$se
t = estimate/se
df = sensemade$treat.stats$df
df = sensemakr$treat.stats$df
r2dc = t^2/(t^2 + (scenarios/q^2)*df)

cat("Considering the extreme scenarios of unobserved confounders explaining ",
Expand All @@ -96,7 +96,7 @@ worstcaseinterpret = function(sensemade, scenarios = c(1, 0.25), q = 1){
}

##' @export
print.summary.sensemade = function(x, q = 1, scenarios = c(1,.25)){
print.summary.sensemakr = function(x, q = 1, scenarios = c(1,.25)){
# pretty print for the summary
cat("Sensitivity Analysis\n\n")
cat("Model:", trimws(deparse(formula(x$info$model))), "\n\n")
Expand Down
4 changes: 2 additions & 2 deletions R/sensemakr.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sensemakr.lm = function(model, treatment, group_list=NULL){
# stats = get stats()
# benchmarks = get benchmarks()
# compute bias and include ob data.frames
# returns pretty list with class "sensemade"
# returns pretty list with class "sensemakr"

treat.stats = getstats(model, D)
benchmarks = benchmarkr(model, D, # X,
Expand All @@ -97,7 +97,7 @@ sensemakr.lm = function(model, treatment, group_list=NULL){
treatment = D,
# maybe return 'treatment model'
model = model))
class(out) = "sensemade"
class(out) = "sensemakr"
return(out)
}

Expand Down

0 comments on commit da0cbe0

Please sign in to comment.