P-value correction: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 53:
 
Link with <code>-lm</code>
<langsyntaxhighlight Clang="c">#include <stdio.h>//printf
#include <stdlib.h>//qsort
#include <math.h>//fabs
Line 601:
return 0;
}
</syntaxhighlight>
</lang>
 
{{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).
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Line 887:
each_i(0, 8) adjusted(p_values, types[i]);
return 0;
}</langsyntaxhighlight>
 
{{output}}
Line 896:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 1,227:
}
}
}</langsyntaxhighlight>
{{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}}
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <functional>
#include <iostream>
Line 1,630:
 
return 0;
}</langsyntaxhighlight>
{{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]''.
<langsyntaxhighlight Dlang="d">import std.algorithm;
import std.conv;
import std.math;
Line 2,057:
writefln("\ntype %d = '%s' has a cumulative error of %g", type, types[type], error);
}
}</langsyntaxhighlight>
{{out}}
<pre>[ 1] 6.126681e-01 0.8521710465 0.1987205200 0.1891595417 0.3217789286
Line 2,140:
=={{header|Go}}==
{{trans|Kotlin (Version 2)}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,443:
fmt.Println(s)
}
}</langsyntaxhighlight>
 
{{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]''.
<langsyntaxhighlight Javalang="java">import java.util.Arrays;
import java.util.Comparator;
 
Line 2,895:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>[ 1] 6.126681e-01 0.8521710465 0.1987205200 0.1891595417 0.3217789286
Line 2,977:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using MultipleTesting, IterTools, Printf
 
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</langsyntaxhighlight>
 
{{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]''.
 
<langsyntaxhighlight lang="scala">// version 1.1.51
 
import java.util.Arrays
Line 3,339:
println(f.format(type, types[type], error))
}
}</langsyntaxhighlight>
 
{{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.
<langsyntaxhighlight lang="scala">// version 1.2.21
 
typealias DList = List<Double>
Line 3,572:
 
types.forEach { println(adjusted(pValues, it)) }
}</langsyntaxhighlight>
 
{{out}}
Line 3,604:
=={{header|Nim}}==
{{trans|Kotlin (Version 2)}}
<langsyntaxhighlight Nimlang="nim">import algorithm, math, sequtils, strformat, strutils, sugar
 
type
Line 3,758:
 
for ctype in CorrectionType:
echo adjusted(PVals, ctype)</langsyntaxhighlight>
 
{{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]''.
<langsyntaxhighlight lang="perl">#!/usr/bin/env perl
 
use strict;
Line 4,159:
printf("type $method has cumulative error of %g.\n", $error);
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 4,179:
=={{header|Phix}}==
Translation of Kotlin (version 2), except for the Hommel part, which is translated from Go.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{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]''.
<langsyntaxhighlight lang="python">from __future__ import division
import sys
 
Line 4,624:
error += abs(q[i] - correct_answers[key][i])
print '%s error = %g' % (key.upper(), error)
</syntaxhighlight>
</lang>
 
{{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].
 
<langsyntaxhighlight lang="rsplus">p <- c(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,
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")</langsyntaxhighlight>
 
{{out}}
Line 4,739:
{{works with|Rakudo|2019.03.1}}
 
<syntaxhighlight lang="raku" perl6line>########################### Helper subs ###########################
 
sub adjusted (@p, $type) { "\n$type\n" ~ format adjust( check(@p), $type ) }
Line 4,832:
{
say adjusted @p-values, $_
}</langsyntaxhighlight>
 
{{out}}
Line 4,921:
=={{header|Ruby}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">def pmin(array)
x = 1
pmin_array = []
Line 5,185:
puts "total error for #{method} = #{error}"
end
</syntaxhighlight>
</lang>
{{out}}
<pre>Benjamini-Yekutieli
Line 5,202:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use std::iter;
 
Line 5,435:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:60ex;overflow:scroll;">
Line 5,525:
=={{header|SAS}}==
 
<langsyntaxhighlight lang="sas">data pvalues;
input raw_p @@;
cards;
Line 5,542:
 
proc multtest pdata=pvalues bon sid hom hoc holm;
run;</langsyntaxhighlight>
 
'''output'''
Line 5,619:
First, install the package with:
 
<syntaxhighlight lang ="stata">ssc install qqvalue</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight lang="stata">clear
 
#delimit ;
Line 5,645:
}
 
list</langsyntaxhighlight>
 
'''output'''
Line 5,720:
{{libheader|Wren-math}}
{{libheader|Wren-sort}}
<langsyntaxhighlight ecmascriptlang="wren">import "./dynamic" for Enum
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)) }</langsyntaxhighlight>
 
{{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]''.
 
<langsyntaxhighlight lang="zkl">fcn bh(pvalues){ // Benjamini-Hochberg
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
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">pvalues:=T(
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();
}</langsyntaxhighlight>
{{out}}
<pre style="height:45ex">
9,482

edits