Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please update inst/rkward/plugins/non_parametric_tests/kruskal_wallis.js #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Encoding: UTF-8
Package: rkTeaching
Type: Package
Title: A RKWard plugin with basic utilities for teaching Statistics
Version: 1.3.0
Date: 2019-09-01
Version: 1.3.5
Date: 2022-17-13
Author: Alfredo Sánchez Alberca <[email protected]>
Maintainer: Alfredo Sánchez Alberca <[email protected]>
Enhances: rkward
Expand All @@ -21,6 +21,7 @@ Depends:
Hmisc,
prob,
ez,
multcomp,
R (>= 3.5.0)
Description: Basic utilities for teaching statistics.
It contains procedures for:
Expand Down
16 changes: 7 additions & 9 deletions R/weightDataFrame.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
weightDataFrame <- function(data, freq){
if (ncol(data)<2) {
stop("The data frame must contain at least two variables.")
}
if (!is.numeric(data[["freq"]])) {
stop("The freq variable should contain frequencies and must be numeric.")
}
times <- as.integer(data[[freq]])
data[[freq]] <- NULL
result <- data[rep(seq_len(nrow(data)), times),]
reps <- data[[freq]]
data[[freq]] <- NULL
m <- as.matrix(data)
result <- as.vector(m)
result <- matrix(rep(result,rep(reps,ncol(m))),sum(reps),ncol(m));
result <- as.data.frame(result);
colnames(result) <- colnames(data)
return(result)
}

2 changes: 1 addition & 1 deletion inst/rkward/plugins/common/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ function getDataframe(vars) {
if (Array.isArray(vars)) {
return vars.join().split('[[')[0];
} else {
return vars.split('[[')[0];
return vars.toString().split('[[')[0];
}
}
33 changes: 18 additions & 15 deletions inst/rkward/plugins/data/data_weighting.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// author: Alfredo Sánchez Alberca ([email protected])
var dataframe,
freq,
newDataframe;

function setGlobalVars() {
dataframe = getString("dataframe");
freq = getString("freq.shortname");
newDataframe = getString("newDataframe");
}
// globals
var data, newdata, freq;

function preprocess() {
setGlobalVars();
echo("library(rkTeaching)\n");
function preprocess(){
// add requirements etc. here
echo("require(rkTeaching)\n");
}

function calculate() {
echo('.GlobalEnv$' + newDataframe + ' <- weightDataFrame(' + dataframe + ', "' + freq + '")\n');
function calculate () {
data = getString("dataframe");
newdata = getString("save");
freq = getString("freq.shortname");
echo ('.GlobalEnv$' + newdata + ' <- weightDataFrame(' + data + ', "' + freq + '")\n');
// Copy also the labels of original data set
echo('for(i in 1:length(names(' + newdata + '))){\n');
echo('\t if (names(' + newdata + ')[i]!= "' + freq + '"){\n');
echo('\t attr(.GlobalEnv$' + newdata + '[[names(' + newdata + ')[i]]],".rk.meta") = attr(' + data + '[[names(' + newdata + ')[i]]],".rk.meta")\n');
echo('\t }\n');
echo('}\n');
}

function printout() {
var header = new Header(i18n("Data weighting")).addFromUI("dataframe").addFromUI("freq").addFromUI("newDataframe").print();
function printout () {
echo ('rk.header ("Ponderaci&oacute;n de conjunto de datos", parameters=list("Conjunto de datos a ponderar" = "' + data + '", "Frecuencias de ponderaci&oacute;n" = "' + freq + '", "Nuevo conjunto de datos" = rk.get.description(' + newdata + ')))\n');
}
52 changes: 27 additions & 25 deletions inst/rkward/plugins/data/data_weighting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,45 @@
<help file="data_weighting.rkh"/>

<logic>
<connect governor="current_object" client="dataframe.available"/>
<connect governor="dataframe.available" client="selector.root"/>
<convert id="dataframeSelected" sources="dataframe.available" mode="notequals" standard=""/>
<connect governor="dataframeSelected" client="freq.enabled"/>
</logic>

<dialog label="Data weighting">
<row>
<varselector id="selector" label="Select data frame or variable"/>
<connect governor="current_object" client="dataframe.available" />
<connect governor="dataframe.available" client="selector.root" />
</logic>

<dialog label="Ponderar conjunto de datos" >
<row id="row_vars">
<varselector id="selector" label="Seleccionar conjunto de datos"/>
<column>
<varslot id="dataframe" label="Data frame to weight" source="selector" classes="data.frame" required="true"/>
<varslot id="freq" label="Weighting frequencies" source="selector" types="numeric" required="true"/>
<saveobject id="newDataframe" label="Save new data frame" initial="new.data.frame"/>
<varslot id="dataframe" label="Conjunto de datos a ponderar" source="selector" classes="data.frame" required="true" />
<varslot id="freq" label="Frecuencias de ponderación" source="selector" types="number" required="true" />
<saveobject id="save" label="Guardar conjunto de datos" initial="datos.nuevo" />
</column>
</row>
</dialog>

<wizard label="Data weighting">
<page id="pageData">
<wizard label="Ponderar conjunto de datos">
<page id="page_data">
<text>
Select the data frame to weight.
Seleccionar el conjunto de datos a ponderar.

</text>
<varselector id="selector2" label="Select data frame"/>
<varslot id="dataframe" label="Data frame to weight" source="selector2" classes="data.frame" required="true"/>
<varselector id="selector2" label="Seleccionar conjunto de datos"/>
<varslot id="dataframe" label="Conjunto de datos" source="selector2" classes="data.frame" required="true" />
</page>
<page id="pageFrequency">
<page id="page_frequency">
<text>
Select the variable that contains the weighting frequencies.
Seleccionar la variable que contiene las frecuencias de ponderación.
Debe haber tantas frecuencias como filas tenga el conjunto de datos a ponderar.

</text>
<copy id="selector"/>
<copy id="selector" />
</page>
<page id="pageSave">
<page id="page_new_data">
<text>
Enter the name for the new data set. By default the new data set is saved in the .GlobalEnv environment.
Introducir un nombre para el nuevo conjunto de datos.
Por defecto el nuevo conjunto de datos se guarda en el espacio de trabajo global .GlobalEnv.

</text>
<copy id="newDataframe"/>
<stretch/>
<copy id="save" />
</page>
</wizard>
</document>
10 changes: 5 additions & 5 deletions inst/rkward/plugins/data/variable_recoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function calculate() {
rules = rules.replace(/\n/gi, '; ').replace(/'/g, '"');
comment("Applying the recoding rules");
echo(".GlobalEnv$" + save + " <- Recode(" + variable + ", '" + rules + "'");
if (asfactor) {
echo(", as.factor=TRUE");
} else {
echo(", as.factor=FALSE");
}
//if (asfactor) {
// echo(", as.factor=TRUE");
//} else {
// echo(", as.factor=FALSE");
//}
echo(")\n");
}

Expand Down
4 changes: 2 additions & 2 deletions inst/rkward/plugins/non_parametric_tests/kruskal_wallis.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function printout() {
// Header
header = new Header(i18n("Kruskal-Wallis test for comparing the distribution of %1 according to %2", variableName, factorName));
header.add(i18n("Data frame"), dataframe);
header.add(i18n("Comparison of %1 according to %2", variableName, factorName));
header.add(i18n("Comparison of"), i18n("%1 according to %2", variableName, factorName));
header.add(i18n("Null hypothesis"), i18n("There is no significant difference between the populations"));
header.add(i18n("Alternative hypothesis"), i18n("There are significant difference between at least two populations"));
if (grouped) {
Expand Down Expand Up @@ -104,4 +104,4 @@ function printout() {
echo('))\n');
}
}
}
}