P-value correction: Difference between revisions
m
→{{header|Wren}}: Minor tidy
m (→{{header|R}}) |
m (→{{header|Wren}}: Minor tidy) |
||
(One intermediate revision by one other user not shown) | |||
Line 53:
Link with <code>-lm</code>
<
#include <stdlib.h>//qsort
#include <math.h>//fabs
Line 601:
return 0;
}
</syntaxhighlight>
{{out}}
Line 693:
{{trans|Kotlin}}
To avoid licensing issues, this version is a translation of the Kotlin entry (Version 2) which is itself a partial translation of the Raku entry. If using gcc, you need to link to the math library (-lm).
<
#include <stdlib.h>
#include <math.h>
Line 887:
each_i(0, 8) adjusted(p_values, types[i]);
return 0;
}</
{{output}}
Line 896:
=={{header|C sharp|C#}}==
{{trans|Java}}
<
using System.Collections.Generic;
using System.Linq;
Line 1,227:
}
}
}</
{{out}}
<pre>[ 1] 6.126681E-001 8.521710E-001 1.987205E-001 1.891595E-001 3.217789E-001
Line 1,309:
=={{header|C++}}==
{{trans|Java}}
<
#include <functional>
#include <iostream>
Line 1,630:
return 0;
}</
{{out}}
<pre>[ 1] 0.6126681081 0.8521710465 0.1987205200 0.1891595417 0.3217789286
Line 1,718:
{{trans|Kotlin}}
''This work is based on R source code covered by the '''GPL''' license. It is thus a modified version, also covered by the GPL. See the [https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic FAQ about GNU licenses]''.
<
import std.conv;
import std.math;
Line 2,057:
writefln("\ntype %d = '%s' has a cumulative error of %g", type, types[type], error);
}
}</
{{out}}
<pre>[ 1] 6.126681e-01 0.8521710465 0.1987205200 0.1891595417 0.3217789286
Line 2,140:
=={{header|Go}}==
{{trans|Kotlin (Version 2)}}
<
import (
Line 2,443:
fmt.Println(s)
}
}</
{{out}}
Line 2,546:
{{works with|Java|8}}
''This work is based on R source code covered by the '''GPL''' license. It is thus a modified version, also covered by the GPL. See the [https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic FAQ about GNU licenses]''.
<
import java.util.Comparator;
Line 2,895:
}
}
}</
{{out}}
<pre>[ 1] 6.126681e-01 0.8521710465 0.1987205200 0.1891595417 0.3217789286
Line 2,977:
=={{header|Julia}}==
<
p = [4.533744e-01, 7.296024e-01, 9.936026e-02, 9.079658e-02, 1.801962e-01,
Line 3,001:
println("\n", corr)
printpvalues(adjust(p, corr))
end</
{{out}}
Line 3,058:
''This work is based on R source code covered by the '''GPL''' license. It is thus a modified version, also covered by the GPL. See the [https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic FAQ about GNU licenses]''.
<
import java.util.Arrays
Line 3,339:
println(f.format(type, types[type], error))
}
}</
{{out}}
Line 3,427:
To avoid licensing issues, this version follows the approach of the Raku entry of which it is a partial translation. However, the correction routines themselves have been coded independently, common code factored out into separate functions (analogous to Raku) and (apart from the Šidák method) agree with the Raku results.
<
typealias DList = List<Double>
Line 3,572:
types.forEach { println(adjusted(pValues, it)) }
}</
{{out}}
Line 3,604:
=={{header|Nim}}==
{{trans|Kotlin (Version 2)}}
<
type
Line 3,758:
for ctype in CorrectionType:
echo adjusted(PVals, ctype)</
{{out}}
Line 3,849:
{{trans|C}}
''This work is based on R source code covered by the '''GPL''' license. It is thus a modified version, also covered by the GPL. See the [https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic FAQ about GNU licenses]''.
<
use strict;
Line 4,159:
printf("type $method has cumulative error of %g.\n", $error);
}
</syntaxhighlight>
{{out}}
Line 4,179:
=={{header|Phix}}==
Translation of Kotlin (version 2), except for the Hommel part, which is translated from Go.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">enum</span> <span style="color: #000000;">UP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">DOWN</span>
Line 4,373:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s has cumulative error of %g\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">,</span><span style="color: #000000;">error</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
Matches Kotlin (etc) when some of those lines just above are uncommented.
Line 4,389:
{{trans|Perl}}
''This work is based on R source code covered by the '''GPL''' license. It is thus a modified version, also covered by the GPL. See the [https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic FAQ about GNU licenses]''.
<
import sys
Line 4,624:
error += abs(q[i] - correct_answers[key][i])
print '%s error = %g' % (key.upper(), error)
</syntaxhighlight>
{{out}}
Line 4,639:
The '''p.adjust''' function is built-in, see [https://stat.ethz.ch/R-manual/R-devel/library/stats/html/p.adjust.html R manual].
<
8.752257e-01, 2.922222e-01, 9.115421e-01, 4.355806e-01, 5.324867e-01,
4.926798e-01, 5.802978e-01, 3.485442e-01, 7.883130e-01, 2.729308e-01,
Line 4,667:
p.adjust(p, method = 'hommel')
writeLines("Hommel\n")</
{{out}}
Line 4,739:
{{works with|Rakudo|2019.03.1}}
<syntaxhighlight lang="raku"
sub adjusted (@p, $type) { "\n$type\n" ~ format adjust( check(@p), $type ) }
Line 4,832:
{
say adjusted @p-values, $_
}</
{{out}}
Line 4,921:
=={{header|Ruby}}==
{{trans|Perl}}
<
x = 1
pmin_array = []
Line 5,185:
puts "total error for #{method} = #{error}"
end
</syntaxhighlight>
{{out}}
<pre>Benjamini-Yekutieli
Line 5,202:
=={{header|Rust}}==
<
use std::iter;
Line 5,435:
}
}
</syntaxhighlight>
{{out}}
<pre style="height:60ex;overflow:scroll;">
Line 5,525:
=={{header|SAS}}==
<
input raw_p @@;
cards;
Line 5,542:
proc multtest pdata=pvalues bon sid hom hoc holm;
run;</
'''output'''
Line 5,619:
First, install the package with:
<syntaxhighlight lang
Given a dataset containing the p-values in a variable, the qqvalue command generates another variable with the adjusted p-values. Here is an example showing the result with all implemented methods:
<
#delimit ;
Line 5,645:
}
list</
'''output'''
Line 5,720:
{{libheader|Wren-math}}
{{libheader|Wren-sort}}
<
import "./fmt" for Fmt
import "./seq" for Lst
import "./math" for Nums
import "./sort" for Sort
var Direction = Enum.create("Direction", ["UP", "DOWN"])
Line 5,874:
2.177831e-04, 9.693054e-04, 6.610250e-05, 2.900813e-02, 5.735490e-03
]
types.each { |type| System.print(adjusted.call(pValues, type)) }</
{{out}}
Line 5,885:
''This work is based on R source code covered by the '''GPL''' license. It is thus a modified version, also covered by the GPL. See the [https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic FAQ about GNU licenses]''.
<
psz,pszf := pvalues.len(), psz.toFloat();
n_i := psz.pump(List,'wrap(n){ pszf/(psz - n) }); # N/(N-0),N/(N-1),..
Line 5,949:
}
psz.pump(List,'wrap(n){ pa[ro[n]] }); // Hommel q-values
}</
<
4.533744e-01, 7.296024e-01, 9.936026e-02, 9.079658e-02, 1.801962e-01,
8.752257e-01, 2.922222e-01, 9.115421e-01, 4.355806e-01, 5.324867e-01,
Line 5,975:
}
println();
}</
{{out}}
<pre style="height:45ex">
|