Description Usage Arguments Details Note Author(s) References Examples
geoSIMEX
Implementation of the geoSIMEX algorithm for models
with spatial uncertainty. Package built to work with data from
AidData's data extraction tool.
1 2 3 4 5 6 | geoSIMEX(model, geoSIMEXvariable, roiData, aidData, aid.project.amount,
iterations=500, bins=3, fitting.method = "quadratic", roi.area="area",
roi.pc1.name="pc1.id", roi.pc2.name="pc2.id", roi.pc3.name="pc3.id",
roi.pc4.name="pc4.id", roi.pc5.name="pc5.id", roi.pc5.name="pc6.id",
aid.pc1.centroid.name="centroid.pc1.id", aid.precision.code="precision.code",
parallel=TRUE, mc.cores=2)
|
model |
the naive model |
geoSIMEXvariable |
character containing the name of the variable with spatial uncertainty |
aidData |
name of dataframe of aid project data |
aid.project.amount |
character containing the name of the variable in the aidData dataset which contains aid amounts (e.g., commitment, disbursement). Set value to 1 if interested in number of aid projects rather than dollars. |
aid.pc1.centroid.name |
character containing the name of the variable in the aidData dataset which contains names or IDs of a precision code 1 spatial area that the aid project falls within. "centroid.pc1.id" is the default name in datasets produced by AidData's data extraction tool |
aid.precision.code |
character containing the name of the variable in the aidData dataset which contains precision codes for each project. "pc1.id" is the default name in datasets produced by AidData's data extraction tool |
roiData |
name of dataframe of ROI data |
roi.area |
character containing the name of the variable in the ROI dataset which contains areas of ROIs. "area" is the default name in datasets produced by AidData's data extraction tool |
roi.prob.aid |
character containing the name of the variable in the ROI dataset which contains the probability of an ROI receiving aid. |
roi.pc1.name |
character containing the name of the variable in the ROI dataset which contains names or IDs of the precision code 1 spatial area that each ROI falls within. "pc1.id" is the default name in datasets produced by AidData's data extraction tool |
roi.pc2.name |
character containing the name of the variable in the ROI dataset which contains names or IDs of the precision code 2 spatial area that each ROI falls within. "pc2.id" is the default name in datasets produced by AidData's data extraction tool |
roi.pc3.name |
character containing the name of the variable in the ROI dataset which contains names or IDs of the precision code 3 spatial area that each ROI falls within. "pc3.id" is the default name in datasets produced by AidData's data extraction tool |
roi.pc4.name |
character containing the name of the variable in the ROI dataset which contains names or IDs of the precision code 4 spatial area that each ROI falls within. "pc4.id" is the default name in datasets produced by AidData's data extraction tool |
roi.pc6.name |
character containing the name of the variable in the ROI dataset which contains names or IDs of the precision code 6 and 8 spatial area that each ROI falls within. "pc6.id" is the default name in datasets produced by AidData's data extraction tool |
iterations |
number of simulated error iterations |
bins |
number of bins to group coefficients |
fitting.method |
fitting method for the extrapolation. linear and quadratic are implemented. |
mc.cores |
number of cores to use for parallelization |
The values contained within roi.pc1.name and aid.pc1.centroid.name variables should be the same.
The function is built to work with data from AidData's data extration tool. The extraction tool can be accessed here: [provide website].
Just like the lm() and glm() packages, geoSIMEX() is equipped to work with stargazer.
AidData
Cook, J.R. and Stefanski, L.A. (1994) Simulation-extrapolation estimation in parametric measurement error models. Journal of American Statistical Association, 89, 1314 – 1328
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 | library(devtools)
install_github("itpir/geoSIMEX")
set.seed(500)
##### Generating Country-Level Dataset #####
numSubcounties <- 120
numSubcountyInCounty <- 2
numCountyInDistrict <- 3
numDistrictInRegion <- 2
N <- numSubcounties
subcounty <- 1:N
county <- rep(1:(N/numSubcountyInCounty), each=numSubcountyInCounty)
district <- rep(1:(N/(numSubcountyInCounty*numCountyInDistrict)), each=(numSubcountyInCounty*numCountyInDistrict))
region <- rep(1:(N/(numSubcountyInCounty*numCountyInDistrict*numDistrictInRegion)), each=(numSubcountyInCounty*numCountyInDistrict*numDistrictInRegion))
country <- 1
subcountyArea <- runif(N)
probAid_assumed <- runif(N)
subcountyData <- as.data.frame(cbind(subcounty,county,district,region,country,probAid_assumed,subcountyArea))
##### Creating Aid Dataset #####
numberProjects = 50
aidData <- as.data.frame(matrix(NA,nrow=numberProjects,ncol=3))
names(aidData) <- c("aid","trueSubcounty","PC")
aidData$aid <- runif(nrow(aidData)) * 100
probAid_true <- runif(N)
aidData$trueSubcounty <- sample(size=numberProjects,x=c(1:N), prob=probAid_true, replace=TRUE)
aidData$PC <- sample(size=numberProjects, x=c(1,2,3,4,6), prob=runif(5), replace=TRUE)
# True Aid
aidData$PC.1s <- 1
subcountyData$trueAid <- expected_aid_ROI(aidData=aidData,
roiData=subcountyData,
roi.prob.aid="probAid_assumed",
aid.project.amount="aid",
aid.precision.code="PC.1s",
roi.pc1.name="subcounty",
roi.pc2.name="county",
roi.pc3.name="district",
roi.pc4.name="region",
roi.pc5.name="region",
roi.pc6.name="country",
aid.pc1.centroid.name="trueSubcounty")
# Wealth - 1 to 1 relation with aid
subcountyData$wealth <- subcountyData$trueAid + runif(nrow(subcountyData))
# Expected Value Aid
subcountyData$expectedAid <- expected_aid_ROI(aidData=aidData,
aid.project.amount="aid",
aid.precision.code="PC",
aid.pc1.centroid.name="trueSubcounty",
roiData=subcountyData,
roi.prob.aid="probAid_assumed",
roi.pc1.name="subcounty",
roi.pc2.name="county",
roi.pc3.name="district",
roi.pc4.name="region",
roi.pc5.name="region",
roi.pc6.name="country")
naive_model <- lm(wealth ~ expectedAid, data=subcountyData)
geoSIMEX_model <- geoSIMEX(model = naive_model,
geoSIMEXvariable = "expectedAid",
aidData = aidData,
aid.project.amount = "aid",
aid.pc1.centroid.name="trueSubcounty",
aid.precision.code="PC",
roiData = subcountyData,
roi.area = "subcountyArea",
roi.prob.aid = "probAid_assumed",
roi.pc1.name="subcounty",
roi.pc2.name="county",
roi.pc3.name="district",
roi.pc4.name="region",
roi.pc5.name="region",
roi.pc6.name="country")
##### Analyzing Results #####
summary(naive_model)
summary(geoSIMEX_model)
plot(geoSIMEX_model, variable="expectedAid")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.