-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
152 lines (107 loc) · 3.08 KB
/
README.Rmd
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# pipster
<!-- badges: start -->
<!-- badges: end -->
The goal of pipster is to make use of `{wbpip}` functions easily.
## Installation
You can install the development version of pipster from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("PIP-Technical-Team/pipster")
```
```{r example}
library(pipster)
library(collapse)
## basic example code
```
## Identify type of data
### Group Data
```{r build-group-data}
# W: Weights, share of population, sum up to 100
# X: welfare vector with mean welfare by decile
# P:Cumulative share of population
# L: Cumulative share of welfare
# R: share of welfare, sum up to 1.
W = c(0.92, 2.47, 5.11, 7.9, 9.69, 15.24, 13.64, 16.99, 10, 9.78, 3.96, 1.81, 2.49)
X = c(24.84, 35.8, 45.36, 55.1, 64.92, 77.08, 91.75, 110.64, 134.9, 167.76, 215.48, 261.66, 384.97)
P = c(0.0092, 0.0339, 0.085, 0.164, 0.2609, 0.4133, 0.5497, 0.7196, 0.8196, 0.9174, 0.957, 0.9751, 1)
L = c(0.00208, 0.01013, 0.03122, 0.07083, 0.12808, 0.23498, 0.34887, 0.51994, 0.6427, 0.79201, 0.86966, 0.91277, 1)
R = (W * X) / sum(W * X)
```
```{r itenditfy-gd}
# type 1 ------
## up to 1 ---------
identify_pip_type(welfare = L,
weight = P)
## up to 100 ---------
identify_pip_type(welfare = L*100,
weight = P)
# type 2 -----------
## up to 1 -----------
identify_pip_type(welfare = R,
weight = W/100)
## up to 100 ---------
identify_pip_type(welfare = R*100,
weight = W)
# type 5 -----------
identify_pip_type(welfare = X,
weight = W/100)
# type 3 -----------
identify_pip_type(welfare = X,
weight = P)
```
### Microdata
```{r build-microdata-data}
# l: length
# Y: welfare
# Q: population or weights
# I: imputation ID
l <- 300
Y <- sample(1000, l,replace = TRUE)
Q <- sample(35, l,replace = TRUE)
I <- sample(1:5, l,replace = TRUE)
```
```{r itenditfy-md}
identify_pip_type(welfare = Y,
weight = Q)
identify_pip_type(welfare = Y,
weight = Q,
imputation_id = I)
I2 <- rep(1, l)
identify_pip_type(welfare = Y,
weight = Q,
imputation_id = I2)
```
## Convert to PIP format
### Group Data
Convert Group Data Type-2 to Group Data Type-1 .
Notice that the whole dataframe is parsed to the function because we need the whole dataframe back. It is not enough with parsing just the welfare and weight vetors.
```{r convert-gd}
pip_gd |>
fselect(R,W)
gd <- as_pip(dt = pip_gd,
welfare_var = "R",
weight_var = "W",
pip_type = "gd_2")
gd |>
fselect(R,W)
class(gd)
```
### Micro Data
```{r}
md <- as_pip(dt = pip_md,
welfare_var = "welfare",
weight_var = "weight")
waldo::compare(md, roworderv(pip_md, "welfare"))
```