Skip to content

Commit 2879386

Browse files
committed
2 parents 787fdc2 + ebd24cb commit 2879386

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+4811
-4621
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ addons:
1111
packages:
1212
- libudunits2-dev
1313
- libgdal1-dev
14+
15+
script:
16+
- R -e 'install.packages("BiocManager")'
17+
- R -e 'BiocManager::install(version = "3.9")'

DESCRIPTION

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Collate:
3535
'ggplot_theme_pub.R'
3636
'glog_class.R'
3737
'grid_search_1d_class.R'
38+
'hca_class.R'
3839
'kfold_xval_class.R'
3940
'kfold_xval_charts.R'
4041
'knn_impute_class.R'
@@ -50,7 +51,7 @@ Collate:
5051
'r_squared_class.R'
5152
'rsd_filter.R'
5253
'split_data_class.R'
53-
'structtoolbox.R'
54+
'structToolbox.R'
5455
'ttest_class.R'
5556
'vec_norm_class.R'
5657
Depends: struct
@@ -67,12 +68,15 @@ Imports: ggplot2,
6768
reshape2,
6869
agricolae,
6970
emmeans,
70-
lme4,
7171
nlme,
7272
ggthemes
7373
RoxygenNote: 6.1.1
7474
Suggests:
7575
testthat,
76-
covr
76+
covr,
77+
knitr,
78+
rmarkdown
7779
Remotes: computational-metabolomics/pmp,
7880
computational-metabolomics/struct
81+
VignetteBuilder: knitr
82+
biocViews: WorkflowStep

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(ANOVA)
4+
export(HCA)
45
export(HSD)
56
export(HSDEM)
67
export(PCA)
@@ -35,6 +36,7 @@ export(fs_line)
3536
export(glog_transform)
3637
export(grid_search_1d)
3738
export(gs_line)
39+
export(hca_dendrogram)
3840
export(kfold_xval)
3941
export(kfoldxcv_grid)
4042
export(kfoldxcv_metric)
@@ -84,6 +86,7 @@ exportMethods(run)
8486
import(agricolae)
8587
import(car)
8688
import(emmeans)
89+
import(ggdendro)
8790
import(ggplot2)
8891
import(ggthemes)
8992
import(grid)

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# structToolbox 0.1.0
2+
3+
* Added a `NEWS.md` file to track changes to the package.

R/HSDEM_class.R

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -9,144 +9,144 @@
99
#' @include mixed_effect_class.R HSD_class.R
1010
#' @export HSDEM
1111
HSDEM<-setClass(
12-
"HSDEM",
13-
contains=c('method','stato'),
14-
slots=c(
15-
# INPUTS
16-
params.alpha='entity.stato',
17-
params.mtc='entity.stato',
18-
params.formula='entity',
19-
20-
# OUTPUTS
21-
outputs.p_value='entity.stato',
22-
outputs.significant='entity'
23-
),
24-
prototype = list(name='Tukey Honest Significant Difference using estimated marginal means',
25-
description='Tukey HSD post hoc tests for mixed effects models using estimated marginal means',
26-
type="univariate",
27-
predicted='p_value',
28-
stato.id="STATO:0000187",
29-
30-
params.alpha=entity.stato(name='Confidence level',
31-
stato.id='STATO:0000053',
32-
value=0.05,
33-
type='numeric',
34-
description='the p-value cutoff for determining significance.'
12+
"HSDEM",
13+
contains=c('method','stato'),
14+
slots=c(
15+
# INPUTS
16+
params.alpha='entity.stato',
17+
params.mtc='entity.stato',
18+
params.formula='entity',
19+
20+
# OUTPUTS
21+
outputs.p_value='entity.stato',
22+
outputs.significant='entity'
3523
),
36-
params.mtc=entity.stato(name='Multiple Test Correction method',
37-
stato.id='OBI:0200089',
38-
value='none',
39-
type='numeric',
40-
description='The method used to adjust for multiple comparisons.'
41-
),
42-
43-
outputs.p_value=entity.stato(name='p value',
44-
stato.id='STATO:0000175',
45-
type='numeric',
46-
description='the probability of observing the calculated t-statistic.'
47-
),
48-
outputs.significant=entity(name='Significant features',
49-
#stato.id='STATO:0000069',
50-
type='logical',
51-
description='TRUE if the calculated p-value is less than the supplied threhold (alpha)'
24+
prototype = list(name='Tukey Honest Significant Difference using estimated marginal means',
25+
description='Tukey HSD post hoc tests for mixed effects models using estimated marginal means',
26+
type="univariate",
27+
predicted='p_value',
28+
stato.id="STATO:0000187",
29+
30+
params.alpha=entity.stato(name='Confidence level',
31+
stato.id='STATO:0000053',
32+
value=0.05,
33+
type='numeric',
34+
description='the p-value cutoff for determining significance.'
35+
),
36+
params.mtc=entity.stato(name='Multiple Test Correction method',
37+
stato.id='OBI:0200089',
38+
value='none',
39+
type='numeric',
40+
description='The method used to adjust for multiple comparisons.'
41+
),
42+
43+
outputs.p_value=entity.stato(name='p value',
44+
stato.id='STATO:0000175',
45+
type='numeric',
46+
description='the probability of observing the calculated t-statistic.'
47+
),
48+
outputs.significant=entity(name='Significant features',
49+
#stato.id='STATO:0000069',
50+
type='logical',
51+
description='TRUE if the calculated p-value is less than the supplied threhold (alpha)'
52+
)
5253
)
53-
)
5454
)
5555

5656
#' @export
5757
setMethod(f="method.apply",
58-
signature=c("HSDEM",'dataset'),
59-
definition=function(M,D) {
60-
X=dataset.data(D)
61-
lmer_formula=aov2lme(M$formula)
62-
var_names=all.vars(M$formula)
63-
var_names_1=var_names[1]
64-
var_names=var_names[-1]
65-
y=dataset.sample_meta(D)[var_names]
66-
67-
# set the contrasts
68-
O=options('contrasts') # keep the old ones
69-
options(contrasts = c("contr.sum","contr.poly"))
70-
71-
# attempt to detect within factors
72-
within=which(var_names %in% all.names(M$formula)[which('Error'== all.names(M$formula))+2])
73-
if (length(within)>0) {
74-
var_names_ex=var_names[-within]
75-
} else {
76-
var_names_ex=var_names
77-
}
78-
79-
FF=full_fact(var_names_ex)
80-
FF=apply(FF,1,function(x) var_names_ex[x==1])
81-
FF=FF[-1]
82-
83-
output=apply(X,2,function(x) {
84-
temp=y
85-
temp[[var_names_1]]=scale(x,center = TRUE,scale=TRUE)
86-
87-
dona=FALSE
88-
89-
testlm=tryCatch({ # if any warnings/messages set p-values to NA as unreliable
90-
LM=lme(lmer_formula$f,random=lmer_formula$random,method='ML',data=temp,na.action=na.omit)
91-
}, warning = function(w) {
92-
NA
93-
}, message = function(m) {
94-
NA
95-
}, error = function(e) {
96-
NA
97-
})
98-
99-
output2=list()
100-
for (k in 1:length(FF)) {
101-
if (!is.na(testlm[[1]])) {
102-
testhsd=tryCatch({
103-
output2[[k]]=as.data.frame(pairs(emmeans(LM,FF[[k]],data=temp)))
104-
}, warning = function(w) {
105-
NA
106-
} , message = function(m) {
107-
NA
108-
}, error = function(e) {
109-
NA
110-
})
111-
112-
if (!is.data.frame(testhsd[1])) {
113-
output2[[k]]=NA
114-
}
58+
signature=c("HSDEM",'dataset'),
59+
definition=function(M,D) {
60+
X=dataset.data(D)
61+
lmer_formula=aov2lme(M$formula)
62+
var_names=all.vars(M$formula)
63+
var_names_1=var_names[1]
64+
var_names=var_names[-1]
65+
y=dataset.sample_meta(D)[var_names]
66+
67+
# set the contrasts
68+
O=options('contrasts') # keep the old ones
69+
options(contrasts = c("contr.sum","contr.poly"))
70+
71+
# attempt to detect within factors
72+
within=which(var_names %in% all.names(M$formula)[which('Error'== all.names(M$formula))+2])
73+
if (length(within)>0) {
74+
var_names_ex=var_names[-within]
11575
} else {
116-
output2[[k]]=NA
76+
var_names_ex=var_names
11777
}
118-
}
119-
120-
return(output2)
121-
})
122-
123-
p_value=lapply(output,function(x) {
124-
x=as.data.frame(x)
125-
return(x$p.value)
126-
})
127-
ln=length(p_value[[1]])
128-
p_value=lapply(p_value,function(x){
129-
if (length(x)!=ln) {
130-
return(p_value[[1]]*NA)
131-
} else {
132-
return(x)
133-
}
134-
})
135-
136-
p_value=do.call("rbind",p_value)
137-
p_value=data.frame(p_value)
138-
colnames(p_value)=as.data.frame(output[[1]])$contrast
139-
140-
# fdr correct
141-
M$p_value=apply(p_value,2,p.adjust,method=M$mtc)
142-
143-
M$significant=M$p_value<M$alpha
144-
145-
# reset contrasts
146-
options(O)
147-
148-
return(M)
149-
}
78+
79+
FF=full_fact(var_names_ex)
80+
FF=apply(FF,1,function(x) var_names_ex[x==1])
81+
FF=FF[-1]
82+
83+
output=apply(X,2,function(x) {
84+
temp=y
85+
temp[[var_names_1]]=scale(x,center = TRUE,scale=TRUE)
86+
87+
dona=FALSE
88+
89+
testlm=tryCatch({ # if any warnings/messages set p-values to NA as unreliable
90+
LM=lme(lmer_formula$f,random=lmer_formula$random,method='ML',data=temp,na.action=na.omit)
91+
}, warning = function(w) {
92+
NA
93+
}, message = function(m) {
94+
NA
95+
}, error = function(e) {
96+
NA
97+
})
98+
99+
output2=list()
100+
for (k in 1:length(FF)) {
101+
if (!is.na(testlm[[1]])) {
102+
testhsd=tryCatch({
103+
output2[[k]]=as.data.frame(pairs(emmeans(LM,FF[[k]],data=temp)))
104+
}, warning = function(w) {
105+
NA
106+
} , message = function(m) {
107+
NA
108+
}, error = function(e) {
109+
NA
110+
})
111+
112+
if (!is.data.frame(testhsd[1])) {
113+
output2[[k]]=NA
114+
}
115+
} else {
116+
output2[[k]]=NA
117+
}
118+
}
119+
120+
return(output2)
121+
})
122+
123+
p_value=lapply(output,function(x) {
124+
x=as.data.frame(x)
125+
return(x$p.value)
126+
})
127+
ln=length(p_value[[1]])
128+
p_value=lapply(p_value,function(x){
129+
if (length(x)!=ln) {
130+
return(p_value[[1]]*NA)
131+
} else {
132+
return(x)
133+
}
134+
})
135+
136+
p_value=do.call("rbind",p_value)
137+
p_value=data.frame(p_value)
138+
colnames(p_value)=as.data.frame(output[[1]])$contrast
139+
140+
# fdr correct
141+
M$p_value=apply(p_value,2,p.adjust,method=M$mtc)
142+
143+
M$significant=M$p_value<M$alpha
144+
145+
# reset contrasts
146+
options(O)
147+
148+
return(M)
149+
}
150150
)
151151

152152

0 commit comments

Comments
 (0)