Skip to content

Commit

Permalink
fix paired tests (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
grlloyd authored Jun 25, 2021
1 parent 489170c commit dcb112a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 45 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: structToolbox
Type: Package
Title: Data processing & analysis tools for Metabolomics and other omics
Version: 1.4.0
Version: 1.4.1
Authors@R: c(
person(
c("Gavin","Rhys"),
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes 1.4.1
+ fix broken ttest and wilcoxon test when paired = TRUE

Changes 1.4.0
+ added VIP summary chart
+ add ellipse plotting options to pca_scores_plot
Expand Down
25 changes: 6 additions & 19 deletions R/ttest_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,14 @@ setMethod(f="model_apply",
}

}
D$data=D$data[!(D$sample_meta[[M$paired_factor]] %in% out),]
D$sample_meta=D$sample_meta[!(D$sample_meta[[M$paired_factor]] %in% out),]
#D$data=D$data[!(D$sample_meta[[M$paired_factor]] %in% out),]
#D$sample_meta=D$sample_meta[!(D$sample_meta[[M$paired_factor]] %in% out),]
D=D[!(D$sample_meta[[M$paired_factor]] %in% out),]
y=D$sample_meta[[M$factor_names]]

# sort the data by sample id so that theyre in the right order for paired ttest
X=apply(D$data,2,function(x) {
a=x[y==L[1]]
b=x[y==L[2]]
ay=y[y==L[1]]
by=y[y==L[2]]
a=a[order(ay)]
b=b[order(by)]
return(c(a,b))
})

# put back into DatasetExperiment object
D$data=as.data.frame(X)
D$sample_meta[[M$factor_names]]=D$sample_meta[[M$factor_names]][order(D$sample_meta[[M$paired_factor]])]
D$sample_meta[[M$paired_factor]]=D$sample_meta[[M$paired_factor]][order(D$sample_meta[[M$paired_factor]])]
y=D$sample_meta[[M$factor_names]]
temp=D$sample_meta[order(D$sample_meta[[M$factor_names]],D$sample_meta[[M$paired_factor]]),]
D=D[rownames(temp),]

# check number per class
# if less then 2 then remove
Expand All @@ -178,8 +166,7 @@ setMethod(f="model_apply",

# check equal numbers per class. if not equal then exclude.
IN=rownames(FF$count)[(FF$count[,1]==FF$count[,2]) & (FF$count[,1]>2) & (FF$count[,2]>2)]
D$data=D$data[,IN]
D$variable_meta=D$variable_meta[IN,]
D=D[,IN]

estimate_name='estimate.mean of the differences'
}
Expand Down
36 changes: 11 additions & 25 deletions R/wilcox_test_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,42 +121,28 @@ setMethod(f="model_apply",
if (ng != 2) {
out=c(out,k)
}

}
D$data=D$data[!(D$sample_meta[[M$paired_factor]] %in% out),]
D$sample_meta=D$sample_meta[!(D$sample_meta[[M$paired_factor]] %in% out),]
#D$data=D$data[!(D$sample_meta[[M$paired_factor]] %in% out),]
#D$sample_meta=D$sample_meta[!(D$sample_meta[[M$paired_factor]] %in% out),]
D=D[!(D$sample_meta[[M$paired_factor]] %in% out),]
y=D$sample_meta[[M$factor_names]]

# sort the data by sample id so that theyre in the right order for paired ttest
X=apply(D$data,2,function(x) {
a=x[y==L[1]]
b=x[y==L[2]]
ay=y[y==L[1]]
by=y[y==L[2]]
a=a[order(ay)]
b=b[order(by)]
return(c(a,b))
})

# put back into DatasetExperiment object
D$data=as.data.frame(X)
D$sample_meta[[M$factor_names]]=D$sample_meta[[M$factor_names]][order(D$sample_meta[[M$paired_factor]])]
D$sample_meta[[M$paired_factor]]=D$sample_meta[[M$paired_factor]][order(D$sample_meta[[M$paired_factor]])]
y=D$sample_meta[[M$factor_names]]

temp=D$sample_meta[order(D$sample_meta[[M$factor_names]],D$sample_meta[[M$paired_factor]]),]
D=D[rownames(temp),]

# check number per class
# if less then 2 then remove
FF=filter_na_count(threshold=2,factor_name=M$factor_names)
FF=model_apply(FF,D)
D=predicted(FF)

# check equal numbers per class. if not equal then exclude.
out=FF$count[,1]!=FF$count[,2]
D$data=D$data[,!out]
IN=rownames(FF$count)[(FF$count[,1]==FF$count[,2]) & (FF$count[,1]>2) & (FF$count[,2]>2)]
D=D[,IN]
}



X=D$data
y=D$sample_meta[[M$factor_names]]

Expand Down

0 comments on commit dcb112a

Please sign in to comment.