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
a567587e
Commit
a567587e
authored
Aug 30, 2021
by
gdutz
Browse files
Options
Downloads
Patches
Plain Diff
Add leo_regresult()
parent
e4198f28
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
DESCRIPTION
+4
-2
4 additions, 2 deletions
DESCRIPTION
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/leo_regresult.R
+44
-0
44 additions, 0 deletions
R/leo_regresult.R
with
49 additions
and
2 deletions
DESCRIPTION
+
4
−
2
View file @
a567587e
Package: leo
Package: leo
Type: Package
Type: Package
Title: Useful functions for LEO surveys
Title: Useful functions for LEO surveys
Version: 0.2.
6
Version: 0.2.
7
Author: Gregor Dutz
Author: Gregor Dutz
Maintainer: Gregor Dutz <gregor.dutz@uni-hamburg.de>
Maintainer: Gregor Dutz <gregor.dutz@uni-hamburg.de>
Description: Implements simple functions to handle data from two German surveys
Description: Implements simple functions to handle data from two German surveys
...
@@ -15,9 +15,11 @@ RoxygenNote: 7.1.1
...
@@ -15,9 +15,11 @@ RoxygenNote: 7.1.1
Imports:
Imports:
dplyr,
dplyr,
labelled,
labelled,
mitml,
magrittr,
magrittr,
mitools,
mitools,
purrr,
purrr,
rlang,
rlang,
survey,
survey,
tidyselect
tidyselect,
tibble
This diff is collapsed.
Click to expand it.
NAMESPACE
+
1
−
0
View file @
a567587e
# Generated by roxygen2: do not edit by hand
# Generated by roxygen2: do not edit by hand
export(leo_regresult)
export(leo_svydesign)
export(leo_svydesign)
importFrom(rlang,.data)
importFrom(rlang,.data)
This diff is collapsed.
Click to expand it.
R/leo_regresult.R
0 → 100644
+
44
−
0
View file @
a567587e
#' Creates Tiny Data from regression results from svyglm/mitools.
#'
#' @param model A list of model estimates (fitted with with.imputationList).
#' @param conf.int A logical flag indicating if the confidence intervall should be calculated. Default is `FALSE`.
#' @param conf.level The confidence level. Default is `0.95`.
#' @param exponentiate A logical flag indicating if coefficients should be exponentiated (only useful for logistic regression). Default is `FALSE`.
#' @return A tibble with regression results as Tiny Data.
#'
#' @importFrom rlang .data
#' @export
leo_regresult
<-
function
(
model
,
conf.int
=
FALSE
,
conf.level
=
0.95
,
exponentiate
=
FALSE
)
{
ret
<-
tibble
::
as_tibble
(
mitml
::
testEstimates
(
model
)
$
estimates
,
rownames
=
"term"
)
ret
<-
dplyr
::
select
(
ret
,
-
.data
$
df
,
-
.data
$
RIV
,
-
.data
$
FMI
)
colnames
(
ret
)
<-
c
(
"term"
,
"estimate"
,
"std.error"
,
"statistic"
,
"p.value"
)
if
(
conf.int
)
{
ci
<-
tibble
::
as_tibble
(
mitml
::
confint.mitml.testEstimates
(
mitml
::
testEstimates
(
model
,
level
=
conf.level
)),
rownames
=
"term"
)
colnames
(
ci
)
<-
c
(
"term"
,
"conf.low"
,
"conf.high"
)
ret
<-
dplyr
::
left_join
(
ret
,
ci
,
by
=
"term"
)
}
if
(
exponentiate
)
ret
<-
leo_exponentiate
(
ret
)
ret
}
#' Exponentiates regression results from logistic regressions
#'
#' @param model A list of model estimates as Tiny Data.
#' @return A tibble with expontiated regression results as Tiny Data.
#'
#' @importFrom rlang .data
#' @keywords internal
leo_exponentiate
<-
function
(
model
)
{
model
<-
model
|>
dplyr
::
mutate
(
estimate
=
exp
(
.data
$
estimate
))
# exponentiate coefficients
if
(
"conf.low"
%in%
colnames
(
model
))
# exponentiate confidence interval (if present)
model
<-
model
|>
dplyr
::
mutate
(
dplyr
::
across
(
c
(
.data
$
conf.low
,
.data
$
conf.high
),
exp
))
model
}
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