Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / r / PlotSpecifMacro.groovy @ 499

History | View | Annotate | Download (3.4 kB)

1
package org.txm.macro.r;
2
// Copyright © 2013-2016 ENS de Lyon, University of Franche-Comté.
3
// Copyright © 2010-2013 ENS de Lyon.
4
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
5
// Lyon 2, University of Franche-Comté, University of Nice
6
// Sophia Antipolis, University of Paris 3.
7
// 
8
// The TXM platform is free software: you can redistribute it
9
// and/or modify it under the terms of the GNU General Public
10
// License as published by the Free Software Foundation,
11
// either version 2 of the License, or (at your option) any
12
// later version.
13
// 
14
// The TXM platform is distributed in the hope that it will be
15
// useful, but WITHOUT ANY WARRANTY; without even the implied
16
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17
// PURPOSE. See the GNU General Public License for more
18
// details.
19
// 
20
// You should have received a copy of the GNU General
21
// Public License along with the TXM platform. If not, see
22
// http://www.gnu.org/licenses.
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28

    
29
import org.kohsuke.args4j.*
30
import groovy.transform.Field
31
import org.txm.rcp.swt.widget.parameters.*
32
import org.txm.rcp.commands.*
33
import org.txm.Toolbox
34
import org.txm.statsengine.r.core.RWorkspace
35

    
36
/**
37
 * 
38
 * @authors Matthieu Decorde, Serge Heiden, Achille Falaise.
39
 * 
40
 * Sample default values from:
41
 *  Lafon, P. “Sur la variabilité de la fréquence des formes dans un corpus.” Mots, no. 1 (1980):
42
 *  Robespierre 'peuple' word in D9 part example (see Figure 1), pp 140-141.
43
 *  <http://www.persee.fr/web/revues/home/prescript/article/mots_0243-6450_1980_num_1_1_1008>.
44
 *  
45
**/
46

    
47
@Field @Option(name="f", usage="La fréquence de la forme dans la partie", widget="Integer", required=true, def="11")
48
def f;
49

    
50
@Field @Option(name="F", usage="La fréquence totale de la forme dans le corpus", widget="Integer", required=true, def="296")
51
def F;
52

    
53
@Field @Option(name="t", usage="Le nombre d'occurrences de la partie", widget="Integer", required=true, def="1084")
54
def t;
55

    
56
@Field @Option(name="T", usage="Le nombre total d'occurrences du corpus", widget="Integer", required=true, def="61449")
57
def T;
58

    
59
// Open the parameters input dialog box
60
if (!ParametersDialog.open(this)) return;
61

    
62
// END OF PARAMETERS
63

    
64
def r = RWorkspace.getRWorkspaceInstance()
65
def file = File.createTempFile("txm", ".svg", new File(Toolbox.getParam(Toolbox.USER_TXM_HOME), "results"))
66

    
67
/// BEGIN SCRIPTS
68
def script ="""
69
library(textometry)
70
res <- specificities.distribution.plot($f, $F, $t, $T)
71
"""
72
/// END SCRIPTS
73
r.plot(file, script)
74

    
75
def px = r.eval('res$px').asDouble()
76
def mode = r.eval('res$mode').asInteger()
77
def pfsum = r.eval('res$pfsum'+"[$f+1]").asDouble()
78
def isPositiveSpecificity = (f > mode.abs())  // True if S+
79
def proba = pfsum.abs()  // Compute actual probability (should be a positive number, even for negative specificities, where pfsum = -probability)
80
def specifSign = (isPositiveSpecificity ? "+" : "-")
81
def specif = Math.log10(proba).abs()  // Compute actual specificity
82
def operatorForDisplay = isPositiveSpecificity ? '>=' : '<='
83

    
84
println """
85
P(f'=f) et P(f' $operatorForDisplay f)
86
f        F        t        T
87
$f        $F        $t $T
88
P(f' = $f) = $px
89
mode = $mode
90
P(f' $operatorForDisplay $f) = $proba
91
Specificity S$specifSign = $specif
92
"""
93
println "Result saved in: "+file.getAbsolutePath()
94

    
95
//display the graphic
96
monitor.syncExec(new Runnable() {
97
        @Override
98
        public void run() {        OpenSVGGraph.OpenSVGFile(file.getAbsolutePath(), "Specificity distribution") }
99
});