Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Mood's pairwiseMedianTest in R - how get a nice output in Alteryx?

enylen
5 - Atom

Hi!

As I am quite new here I would like to get all the help I can get. Sorry if this is the wrong thread. This is about R and Alteryxx

 

I try to compare medians and as Alteryx from what I know do not have a function for that, I tried to import some R libraries (RVAideMemoire and rcompanion) to try to use the functions Mood medtest and Pairwise Medtest to do so. I have figured out how to get them to run, but I have not figured out how I could make a neat output to some tables. For Mood's medtest it does not matter much since I will only get one R-value, but from the Pairwise Medtest I would like to get the output in order like something like this for the Pairwise Medtest:

 

Comparisonp.value
A - B0.41...
A - C0.73...
A - D0.73..
B - C0.31...
B - D1
C - D1

 

That is very similar to what the program prints in the "Message screen" (see below)

 

R (1) Comparison p.value p.adjust

R (1) 1 A - B = 0 0.4142 1

R (1) 2 A - C = 0 0.7389 1

R (1) 3 A - D = 0 0.7389 1

R (1) 4 B - C = 0 0.3173 1

R (1) 5 B - D = 0 1 1

R (1) 6 C - D = 0 1 1

Since I am a novice however, I only manage to get the p.values printed out in this fashion (see below), which severely impacts the ability to use the function/R-program for 50+ different examination.

 

X.0.4142.X.0.7389.X.0.7389.1X.0.3173.X.1.X.1..1
0.41420.73890.73890.317311

 

Do you have any ideas on how to get to the first table?

 

Best regards,

 

an R noob in need

 

 

2 REPLIES 2
JohnJPS
15 - Aurora

Hi @enylen,tried running it and couldn't get the packages imported into Alteryx; (our security is something else).

 

However, I did get it running in R-Studio, and I don't see the amount of detail shown in your question...

JohnJPS_0-1579100322273.png

Did you have any additional code to support what referenced as showing in your "Message screen" and/or the output you managed to get?

enylen
5 - Atom

Hi!

This is what I did to solve it: 

 

  1. Import the packages (https://community.alteryx.com/t5/Alteryx-Designer-Knowledge-Base/Install-R-Packages/ta-p/41265)
  2. Run the code below and use the function capture to get all output data albeit in a very unstructured way 
  3. Use functions in Alteryx to clean the data
    1. Transpose
    2. Regex_Replace Regex_Replace([Value],"\s{1,}",'|')
    3. Column Split to divide it up by |
    4. Select interesting comments

In order to make it work I had to keep the names in the column type without spaces. Otherwise the Alteryx output would not be able to be handled by Regex_replace above. I also kept the names very short. For some strange reason long names would split the output that belonged together (name of pairwise comparison, p value, adjusted p value) into different rows even if they belonged to the same comparison.   

 

Code used:
input.data <- read.Alteryx.First("#1", 5000, mode = "data.frame")


if(!require(rcompanion)){install.packages("rcompanion")}
library(rcompanion)

 

PT = pairwiseMedianTest(Value ~ Type,
     data = input.data,
     exact = NULL,
     method = "fdr")
     # Adjusts p-values for multiple comparisons;
    # See ?p.adjust for options

 

PT #not sure if necessary
ut <- capture.output(PT)


data.out1 <- ut

write.Alteryx(data.out1, nOutput = 1)

 

Labels