Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jalbert, Joe
JoeTools
Commits
f575ffe9
Commit
f575ffe9
authored
Mar 02, 2021
by
Jalbert, Joe
Browse files
Bug fixes for pairwise
parent
0a35afc0
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/JoeToolFunctions.R
View file @
f575ffe9
...
...
@@ -269,7 +269,7 @@ pairwise <- function(df, Ind, Dep, Factor, Logit=FALSE){
mutate_
(
"Dependant"
=
Dep
,
"Independant"
=
Ind
,
"Levels"
=
Factor
)
%>%
group_by
(
Independant
,
Levels
)
%>%
summarize
(
Mean
=
mean
(
Dependant
,
na.rm
=
T
),
Count
=
n
(),
Measure
=
Dep
,
Dep_Values
=
list
(
Dependant
))
%>%
filter
(
Count
>
4
)
%>%
filter
(
Count
>
2
)
%>%
select
(
-
Count
)
%>%
ungroup
()
%>%
mutate
(
Independant
=
ifelse
(
Independant
==
1
,
"Treatment"
,
"No_Treatment"
))
%>%
...
...
@@ -278,7 +278,24 @@ pairwise <- function(df, Ind, Dep, Factor, Logit=FALSE){
filter
(
!
is.na
(
No_Treatment
)
&!
is.na
(
Treatment
))
%>%
mutate
(
Diff
=
Treatment
-
No_Treatment
)
%>%
group_by
(
Levels
)
if
(
Logit
==
TRUE
){
if
(
nrow
(
test
)
==
0
){
pvalue
=
df
%>%
# filter(if(Year!="All"){Cohort==Year} else {Cohort==Cohort})%>%
filter
(
!
is.na
(
!!
Dep
))
%>%
mutate_
(
"Dependant"
=
Dep
,
"Independant"
=
Ind
,
"Levels"
=
Factor
)
%>%
group_by
(
Independant
,
Levels
)
%>%
summarize
(
Mean
=
mean
(
Dependant
,
na.rm
=
T
),
Measure
=
Dep
,
Dep_Values
=
list
(
Dependant
))
%>%
# filter(Count>2)%>%
# select(-Count)%>%
ungroup
()
%>%
mutate
(
Independant
=
ifelse
(
Independant
==
1
,
"Treatment"
,
"No_Treatment"
))
%>%
pivot_wider
(
names_from
=
Independant
,
values_from
=
c
(
"Mean"
,
"Dep_Values"
))
%>%
rename
(
No_Treatment
=
Mean_No_Treatment
,
Treatment
=
Mean_Treatment
)
%>%
filter
(
!
is.na
(
No_Treatment
)
&!
is.na
(
Treatment
))
%>%
mutate
(
Diff
=
Treatment
-
No_Treatment
)
%>%
group_by
(
Levels
)
%>%
mutate
(
p_value
=
NA
)
}
else
if
(
Logit
==
TRUE
){
pvalue
=
test
%>%
mutate
(
data
=
map2
(
Dep_Values_No_Treatment
,
Dep_Values_Treatment
,
~
bind_rows
(
tibble
(
Independant
=
rep
(
1
,
length
(
.y
)),
Dependant
=
.y
),
tibble
(
Independant
=
rep
(
0
,
length
(
.x
)),
Dependant
=
.x
))))
%>%
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment