forked from mabafaba/surveyweights
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.Rhistory
100 lines (100 loc) · 3.13 KB
/
.Rhistory
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
# load file (loading from csv depreciated; just renaming)
sampling.frame<-as.data.frame(samplingframe,stringsAsFactors = FALSE)
samplingframe<-tibble(a=100)
samplingframe<-tibble::tibble(a=100)
# load file (loading from csv depreciated; just renaming)
sampling.frame<-as.data.frame(samplingframe,stringsAsFactors = FALSE)
sampling.frame
sampling.frame<-sf
devtools::install(build_vignettes = T)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(surveyweights)
# example data:
mydata<-data.frame(somevar1=c(1:5),
somevar2=c("one","more","test","variable",NA),
strata_names=c("a","a","b","b","a"),
cluster_names=c("x","y","z","z","y"))
# example sampling frame:
mysf<-data.frame(strata=c("a","b"),pops=c(100,1000))
clustersf<-data.frame(strata=c("x","y","z"),pops=c(50,100,200))
mydata
mysf
myweighting<-weighting_fun_from_samplingframe(sampling.frame = mysf,
data.stratum.column = "strata_names",
sampling.frame.population.column = "pops",
sampling.frame.stratum.column = "strata")
devtools::install(dependencies = F,build_vignettes = T)
print.tibble
devtools::install_github('sharonorengo/visualisationIMPACT')
devtools::install_github('sharonorengo/visualisationIMPACT', build_opts = c())
?dput
dput(c(1,2,3))
x<-c(1,2,3)
dput(x)
dput(x) %>% class
dput(names(data.frame(a=10,b=20)))
y %>% dplyr::select(starts_with("cooking_fuel.")) %>% select_if(is.numeric) %>% colnames() %>% dput()
TRUE==1
list(sf4)
average_or_percent<-function(survey, indicator_of_interest, by, na.action){
x<-survey
ioi<-indicator_of_interest
ioi_v<-x$variables[,ioi]
#CREATE FORMULA FOR INDICATOR
ioi_f<-paste0("~",ioi)
#IF TRUE REPLACE NAS WITH SOMETHING
if (z==TRUE){
x2<-x
x2$variables[,ioi]<-ifelse(is.na(ioi_v), "not_applicable", as.character(x2$variables[,ioi]))
x2$variables[,ioi]<-factor(x2$variables[,ioi])
x2<-x2
}
#IF FALSE LEAVE NAS
if(z==FALSE){
x2<-x
}
#DO ANALYSES WITH SURVEY PACKAGE FUNCTIONALITY
summary_statistic <- svymean(formula(ioi_f), x2,na.rm=TRUE, na.rm.by = FALSE, keep.var=FALSE )
summary_statistic
}
average_or_percent<-function(survey, indicator_of_interest, by, na.action){
x<-survey
ioi<-indicator_of_interest
ioi_v<-x$variables[,ioi]
bvar_fa<-paste0(bv1,collapse="+")
bvar_f<-paste("~",bvar_fa,collapse="")
#CREATE FORMULA FOR INDICATOR
ioi_f<-paste0("~",ioi)
#IF TRUE REPLACE NAS WITH SOMETHING
if (z==TRUE){
x2<-x
x2$variables[,ioi]<-ifelse(is.na(ioi_v), "not_applicable", as.character(x2$variables[,ioi]))
x2$variables[,ioi]<-factor(x2$variables[,ioi])
x2<-x2
}
#IF FALSE LEAVE NAS
if(z==FALSE){
x2<-x
}
#DO ANALYSES WITH SURVEY PACKAGE FUNCTIONALITY
summary_statistic <- svyby(formula(ioi_f),by = formula(bvar_f),FUN = svymean,na.rm = TRUE, na.rm.by = FALSE,design = x2, keep.var=FALSE) %>% data.frame()
summary_statistic
}
class(survey)
library(assertthat)
assert_that(is.character(9))
x<-94558
assert_that(is.character(x))
indicator_of_interest<-c("A","B")
indicator_of_interest
assert_that(is.string(indicator_of_interest))
assert_that(is.string(indicator_of_interest))
testdf<-data.frame(a = c(1:10),b= c(rep("A",5),rep("B",5)))
many_point_estimates
testdf<-data.frame(a = c(1:10),b= c(rep("A",5),rep("B",5)))
testdf
devtools::use_test()
browseVignettes('hypegrammaR')