forked from wxwx1993/GPSmatching
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wxwx1993
committed
Jan 14, 2020
0 parents
commit f870f3a
Showing
113 changed files
with
2,598 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,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
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,2 @@ | ||
[ | ||
] |
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,6 @@ | ||
{ | ||
"debugBreakpointsState" : { | ||
"breakpoints" : [ | ||
] | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"path" : "~/Dropbox/continuous GPS/GPSmatching/R", | ||
"sortOrder" : [ | ||
{ | ||
"ascending" : true, | ||
"columnIndex" : 2 | ||
} | ||
] | ||
} |
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,3 @@ | ||
{ | ||
"activeTab" : 2 | ||
} |
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,14 @@ | ||
{ | ||
"left" : { | ||
"panelheight" : 862, | ||
"splitterpos" : 361, | ||
"topwindowstate" : "NORMAL", | ||
"windowheight" : 903 | ||
}, | ||
"right" : { | ||
"panelheight" : 862, | ||
"splitterpos" : 541, | ||
"topwindowstate" : "NORMAL", | ||
"windowheight" : 903 | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"TabSet1" : 3, | ||
"TabSet2" : 3, | ||
"TabZoom" : { | ||
} | ||
} |
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,8 @@ | ||
build-last-errors="[]" | ||
build-last-errors-base-dir="~/Dropbox/continuous GPS/GPSmatching/" | ||
build-last-outputs="[{\"output\":\"==> R CMD INSTALL --preclean --no-multiarch --with-keep.source GPSmatching\\n\\n\",\"type\":0},{\"output\":\"* installing to library ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library’\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"* installing *source* package ‘GPSmatching’ ...\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** R\\n\",\"type\":1},{\"output\":\"** byte-compile and prepare package for lazy loading\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** help\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** installing help indices\\n\",\"type\":1},{\"output\":\"** building package indices\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package can be loaded\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"* DONE (GPSmatching)\\n\",\"type\":1},{\"output\":\"\",\"type\":1}]" | ||
compile_pdf_state="{\"errors\":[],\"output\":\"\",\"running\":false,\"tab_visible\":false,\"target_file\":\"\"}" | ||
files.monitored-path="" | ||
find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":true,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOff\":[],\"matchOn\":[]},\"running\":false}" | ||
imageDirtyState="1" | ||
saveActionState="-1" |
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,5 @@ | ||
|
||
|
||
|
||
|
||
|
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 @@ | ||
{"active_set":"","sets":[]} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "7,1", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "6,16", | ||
"scrollLine" : "0" | ||
} |
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,2 @@ | ||
{ | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "16,0", | ||
"scrollLine" : "0" | ||
} |
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,2 @@ | ||
{ | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "26,51", | ||
"scrollLine" : "9" | ||
} |
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,2 @@ | ||
{ | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "5,0", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "3,25", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "16,4", | ||
"scrollLine" : "5" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "14,17", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "4,0", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "36,91", | ||
"scrollLine" : "29" | ||
} |
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,5 @@ | ||
{ | ||
"cursorPosition" : "16,22", | ||
"scrollLine" : "4", | ||
"tempName" : "Untitled1" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "10,32", | ||
"scrollLine" : "5" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "30,1", | ||
"scrollLine" : "16" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "0,77", | ||
"scrollLine" : "0" | ||
} |
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,5 @@ | ||
{ | ||
"cursorPosition" : "13,12", | ||
"scrollLine" : "0", | ||
"tempName" : "Untitled1" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "9,13", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "8,0", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "11,10", | ||
"scrollLine" : "0" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "48,0", | ||
"scrollLine" : "24" | ||
} |
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,4 @@ | ||
{ | ||
"cursorPosition" : "4,12", | ||
"scrollLine" : "0" | ||
} |
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,23 @@ | ||
~%2FDesktop%2FGPSmatching-package.Rd="2B5B49F0" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FDESCRIPTION="D21B565D" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FNAMESPACE="81C40F4B" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FR%2FCovariate_balance.R="C0F9D2EC" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FR%2FGPSmatching-package.R="6547FC1E" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FR%2FGPSmatching.R="D48D6DC5" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FR%2FGPSmatching_smooth.R="3E36F6D7" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2FR%2FoptimIA-package.R="3A8D2CFC" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2FGPSmatching-package.Rd="C315FAD" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2FGPSmatching.Rd="95C028E1" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2FGPSmatching_smooth.Rd="9C407BEA" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2Fabsolute_corr_fun.Rd="2A3EF788" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2Fcreate_matching.Rd="F0B69EF1" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2Fmatching_l1.Rd="B3B4CE9F" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FGPSmatching%2Fman%2Fmatching_smooth.Rd="10859896" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FApplication%2FCovariate_balance.R="93AC7835" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FCovariate_balance.R="44BB7997" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FGPSmatching.R="22C1E8DB" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FOdessey%2FBenchmark200.R="337CD24F" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FOdessey%2Fbalance1000.R="3C0F604E" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FOdessey%2Fbalance200.R="C3A20D2A" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2FTest_balance.R="2603739E" | ||
~%2FDropbox%2Fcontinuous%20GPS%2FResubmission%2Fdata_generate.R="D760D727" |
Empty file.
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,54 @@ | ||
library("wCorr") | ||
library("parallel") | ||
library(fst) | ||
library(data.table) | ||
library("xgboost") | ||
load("/nfs/home/X/xwu/shared_space/ci3_xwu/National_Causal/data2016/balance/covariates.RData") | ||
|
||
|
||
cor_origin<-c(abs(cor(prematch_data$treat,prematch_data$year,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$mean_bmi,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$smoke_rate,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$hispanic,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$pct_blk,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$medhouseholdincome,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$medianhousevalue,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$poverty,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$education,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$popdensity,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$pct_owner_occ,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$pct_female,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$pct_dual,method = c("spearman"))), | ||
abs(cor(prematch_data$treat,prematch_data$mean_entry_age,method = c("spearman")))) | ||
|
||
cor_matched<-c(abs(cor(match_data$treat,match_data$year,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$mean_bmi,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$smoke_rate,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$hispanic,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$pct_blk,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$medhouseholdincome,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$medianhousevalue,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$poverty,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$education,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$popdensity,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$pct_owner_occ,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$pct_female,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$pct_dual,method = c("spearman"))), | ||
abs(cor(match_data$treat,match_data$mean_entry_age,method = c("spearman")))) | ||
#match_data2 <- match_data_xgb[((nrow(match_data_xgb)/50)*(4-1)+1):((nrow(match_data_xgb)/50)*(30)),] | ||
order<-sort(as.numeric(cor_origin), index.return =T)$ix | ||
par(mar=c(7.1, 10.1, 2.1, 2.1)) | ||
#par(mar=c(8.1,4.1,4.1,4.1)) | ||
par(mgp=c(5,1,0)) | ||
histcolors = c(rgb(0,0,1,.8), rgb(0,1,0,.8),rgb(1,0,0,.5),rgb(0.0,0.8,0,.5)) | ||
plot((as.numeric(cor_origin))[order],c(1:length(order)),yaxt="n",xlab="Absolute Correlation",ylab="",type = "b",lty=2,pch=3,xlim=c(0,0.55), col = histcolors[1],main="",lwd=3,cex.lab=2.5,cex.axis=2,cex.main=3) | ||
#lines((as.numeric(cor_origin2))[order],c(1:length(order)), col = histcolors[1],lwd=3,lty=2,pch=1) | ||
lines((as.numeric(cor_matched))[order],c(1:length(order)), col = histcolors[2],lwd=3,lty=2,pch=1) | ||
#lines((as.numeric(cor_matched2))[order],c(1:length(order)), col = histcolors[2],lwd=3,pch=1) | ||
#lines(((cor_weight))[order],c(1:length(order)), col = histcolors[3],lty=2,lwd=3) | ||
#lines(((cor_weight2))[order],c(1:length(order)), col = histcolors[3],lwd=3) | ||
axis(2, at=c(1:length(order)), labels=c("year","mean_bmi","smoke_rate","hispanic","pct_blk","MdHsIcm","MdVIHs", | ||
"poverty","education","popdensity","pct_owner_occ","pct_female","pct_dual","mean_entry_age")[order],cex.axis=1.5,las=1) | ||
legend("bottomright",legend = c("original","matched (boost)"), | ||
col = histcolors[c(1,2)], lty= c(1,2)) | ||
abline(v=0.1,lty=3,lwd=3) |
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,24 @@ | ||
#' The 'GPSmatching' package. | ||
#' | ||
#' @description An R package for implementing matching on generalized propensity scores with continuous exposures. | ||
#' @details We developed an innovative approach for estimating causal effects using observational data in settings with continuous exposures, and introduce a new framework for GPS caliper matching. | ||
#' | ||
#' @docType package | ||
#' @name GPSmatching-package | ||
#' @aliases GPSmatching | ||
#' @author Xiao Wu | ||
#' @import parallel | ||
#' @import data.table | ||
#' @import SuperLearner | ||
#' @import xgboost | ||
#' @import earth | ||
#' @import ranger | ||
#' @import gam | ||
#' @import KernSmooth | ||
#' | ||
#' @references | ||
#' Wu, X., Mealli, F., Kioumourtzoglou, M.A., Dominici, F. and Braun, D., 2018. Matching on generalized propensity scores with continuous exposures. arXiv preprint arXiv:1812.06575. | ||
#' | ||
#' Kennedy, E.H., Ma, Z., McHugh, M.D. and Small, D.S., 2017. Non‐parametric methods for doubly robust estimation of continuous treatment effects. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 79(4), pp.1229-1245. | ||
#' | ||
NULL |
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,41 @@ | ||
#' Estimate smoothed exposure-response function (ERF). | ||
#' | ||
#' @param matched_Y a vector of outcome variable in matched set. | ||
#' @param matched_w a vector of continuous exposure variable in matched set. | ||
#' @param bw.seq a vector of bandwidth values (Default is seq(0.2,2,0.2)). | ||
#' @param w.vals a vector of exposure levels that ERF curves was evaluated. | ||
#' @return | ||
#' \code{erf}: The function returns a vector saved the output values of exposure-response function (ERF) given input \code{w.vals}. | ||
#' @export | ||
|
||
# Fit non-parametric kernel smoothing on matched set | ||
matching_smooth<-function(matched_Y, | ||
matched_w, | ||
bw.seq=seq(0.2,2,0.2), | ||
w.vals){ | ||
## The specified Gaussian kernel | ||
kern_fun <- function(t){ dnorm(t) } | ||
w_fun <- function(bw){ | ||
w.avals <- NULL | ||
for (w.val in w.vals){ | ||
w.std <- (matched_w-w.val)/bw | ||
kern.std <- kern_fun(w.std)/bw | ||
w.avals <- c(w.avals, mean(w.std^2*kern.std)*(kern(0)/bw) / | ||
(mean(kern.std)*mean(w.std^2*kern.std)-mean(w.std*kern.std)^2)) | ||
} | ||
return(w.avals/length(matched_w)) | ||
} | ||
hatvals <- function(bw){approx(w.vals,w_fun(bw),xout=matched_w,rule=2)$y} | ||
smooth_fun <- function(out,bw){ | ||
approx(locpoly(w,out,bandwidth=bw, gridsize=1000),xout=matched_w,rule=2)$y | ||
} | ||
## | ||
risk_fun <- function(h){ | ||
hats <- hatvals(h); mean( ((matched_Y - smooth_fun(matched_Y,bw=h))/(1-hats))^2) | ||
} | ||
risk.val <- sapply(bw.seq, risk_fun) | ||
h.opt <- bw.seq[which.min(risk.val)] | ||
|
||
erf <- approx(locpoly(matched_w, matched_Y, bandwidth=h.opt), xout=w.vals)$y | ||
return(erf) | ||
} |
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,41 @@ | ||
#' Estimate smoothed exposure-response function (ERF). | ||
#' | ||
#' @param matched_Y a vector of outcome variable in matched set. | ||
#' @param matched_w a vector of continuous exposure variable in matched set. | ||
#' @param bw.seq a vector of bandwidth values (Default is seq(0.2,2,0.2)). | ||
#' @param w.vals a vector of exposure levels that ERF curves was evaluated. | ||
#' @return | ||
#' \code{erf}: The function returns a vector saved the output values of exposure-response function (ERF) given input \code{w.vals}. | ||
#' @export | ||
|
||
# Fit non-parametric kernel smoothing on matched set | ||
matching_smooth<-function(matched_Y, | ||
matched_w, | ||
bw.seq=seq(0.2,2,0.2), | ||
w.vals){ | ||
## The specified Gaussian kernel | ||
kern_fun <- function(t){ dnorm(t) } | ||
w_fun <- function(bw){ | ||
w.avals <- NULL | ||
for (w.val in w.vals){ | ||
w.std <- (matched_w-w.val)/bw | ||
kern.std <- kern_fun(w.std)/bw | ||
w.avals <- c(w.avals, mean(w.std^2*kern.std)*(kern_fun(0)/bw) / | ||
(mean(kern.std)*mean(w.std^2*kern.std)-mean(w.std*kern.std)^2)) | ||
} | ||
return(w.avals/length(matched_w)) | ||
} | ||
hatvals <- function(bw){approx(w.vals,w_fun(bw),xout=matched_w,rule=2)$y} | ||
smooth_fun <- function(out,bw){ | ||
approx(locpoly(matched_w,out,bandwidth=bw, gridsize=1000),xout=matched_w,rule=2)$y | ||
} | ||
## | ||
risk_fun <- function(h){ | ||
hats <- hatvals(h); mean( ((matched_Y - smooth_fun(matched_Y,bw=h))/(1-hats))^2) | ||
} | ||
risk.val <- sapply(bw.seq, risk_fun) | ||
h.opt <- bw.seq[which.min(risk.val)] | ||
|
||
erf <- approx(locpoly(matched_w, matched_Y, bandwidth=h.opt), xout=w.vals)$y | ||
return(erf) | ||
} |
Oops, something went wrong.