Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
leo
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dutz, Gregor
leo
Commits
e4198f28
Commit
e4198f28
authored
3 years ago
by
gdutz
Browse files
Options
Downloads
Patches
Plain Diff
Change first argument of leo_svydesign() to "data"
parent
1c4cb229
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
DESCRIPTION
+1
-1
1 addition, 1 deletion
DESCRIPTION
R/leo_svydesign.R
+10
-10
10 additions, 10 deletions
R/leo_svydesign.R
with
11 additions
and
11 deletions
DESCRIPTION
+
1
−
1
View file @
e4198f28
Package: leo
Type: Package
Title: Useful functions for LEO surveys
Version: 0.2.
5
Version: 0.2.
6
Author: Gregor Dutz
Maintainer: Gregor Dutz <gregor.dutz@uni-hamburg.de>
Description: Implements simple functions to handle data from two German surveys
...
...
This diff is collapsed.
Click to expand it.
R/leo_svydesign.R
+
10
−
10
View file @
e4198f28
#' Creates survey design objects for LEO 2010 and 2018.
#'
#' @param d
f
Survey data
#' @param d
ata
Survey data
#' @param survey Choose between leo2010 and leo2018 (leo2018hoch implements weighting based on population totals).
#' @param replist When true, the function returns an imputation list instead of survey design object.
#' @return A survey design or imputation list object.
#'
#' @importFrom rlang .data
#' @export
leo_svydesign
<-
function
(
d
f
,
survey
=
"leo2018"
,
replist
=
FALSE
)
{
names
(
d
f
)
<-
tolower
(
names
(
d
f
))
leo_svydesign
<-
function
(
d
ata
,
survey
=
"leo2018"
,
replist
=
FALSE
)
{
names
(
d
ata
)
<-
tolower
(
names
(
d
ata
))
# create survey design object for LEO 2010 or LEO 2018 ----
if
(
survey
==
"leo2010"
||
survey
==
"leo2018"
||
survey
==
"leo2018hoch"
)
{
if
(
survey
==
"leo2010"
)
{
# remove logits
d
f
<-
d
f
|>
dplyr
::
select
(
-
tidyselect
::
matches
(
"^pv[1-5]$"
))
d
ata
<-
d
ata
|>
dplyr
::
select
(
-
tidyselect
::
matches
(
"^pv[1-5]$"
))
# rename variables for pvs and levels
old
=
c
(
"pv1_62"
,
"pv2_62"
,
"pv3_62"
,
"pv4_62"
,
"pv5_62"
,
"pv1_alphalevel_62"
,
"pv2_alphalevel_62"
,
"pv3_alphalevel_62"
,
"pv4_alphalevel_62"
,
"pv5_alphalevel_62"
)
new
=
c
(
"pv1"
,
"pv2"
,
"pv3"
,
"pv4"
,
"pv5"
,
"alpha_pv1"
,
"alpha_pv2"
,
"alpha_pv3"
,
"alpha_pv4"
,
"alpha_pv5"
)
d
f
<-
d
f
|>
dplyr
::
rename_at
(
dplyr
::
vars
(
old
),
~
new
)
d
ata
<-
d
ata
|>
dplyr
::
rename_at
(
dplyr
::
vars
(
old
),
~
new
)
}
# some functions need a helper variable
d
f
$
a
<-
as.numeric
(
1
)
d
ata
$
a
<-
as.numeric
(
1
)
# get column names of pvs and levels
lit
<-
grep
(
"^pv[0-9]+"
,
colnames
(
d
f
),
value
=
TRUE
)
alp
<-
grep
(
"^alpha_pv[0-9]+"
,
colnames
(
d
f
),
value
=
TRUE
)
lit
<-
grep
(
"^pv[0-9]+"
,
colnames
(
d
ata
),
value
=
TRUE
)
alp
<-
grep
(
"^alpha_pv[0-9]+"
,
colnames
(
d
ata
),
value
=
TRUE
)
# column names of all other variables
all
<-
d
f
|>
dplyr
::
select
(
-
tidyselect
::
one_of
(
lit
),
-
tidyselect
::
one_of
(
alp
))
all
<-
d
ata
|>
dplyr
::
select
(
-
tidyselect
::
one_of
(
lit
),
-
tidyselect
::
one_of
(
alp
))
all
<-
colnames
(
all
)
# create list with one pv-variable and one level-variable each (and all other variables)
repList
<-
lit
|>
purrr
::
map
(
function
(
x
)
{
dplyr
::
select
(
d
f
,
all
,
paste0
(
"alpha_"
,
x
),
x
)
|>
purrr
::
map
(
function
(
x
)
{
dplyr
::
select
(
d
ata
,
all
,
paste0
(
"alpha_"
,
x
),
x
)
|>
dplyr
::
rename
(
pv
=
!!
x
)
|>
dplyr
::
rename
(
alpha_pv
=
!!
paste0
(
"alpha_"
,
x
))})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment