Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Factor analysis: Different outputs of R Studio and R Tool

helfenbeind
6 - Meteoroid

Hi, 

 

When running the factanal function in the R tool and in R Studio I get completely different outputs.

 

The code I am running in Alteryx:

variables <- read.Alteryx("variables", mode="data.frame")
factormodel <- factanal(variables, factors=3, scores='regression', rotation='none') x <- factormodel$scores

I am running it on the same dataset consisting of 8 normalised variables, and before using the function in the R tool I am making sure to explicitly convert these to floats, so I doubt it is a data type issue. I have attached extracts from the outputs.

 

Does anyone know what I am doing wrong in Alteryx?

Many thanks!

 

-Edit: I should probably add the format of my outputs:

RStudio: dataframe with dimensions: [Length_of_dataframe] x 3 --> what you would expect

R Tool: dataframe with dimensions: 1 x (3*[Length_of_dataframe]) --> for some reason it concatenated the results into one row vector

7 REPLIES 7
BenMoss
ACE Emeritus
ACE Emeritus

Can you please provide us with some sample data to test this against.

 

Ben

helfenbeind
6 - Meteoroid

Any dataset should work really. Example is attached.

BenMoss
ACE Emeritus
ACE Emeritus

I just tried this with your sample data and my results line up between Alteryx and R Studio.

 

Could you retest with your sample data?

 

Ben

helfenbeind
6 - Meteoroid

Hi Ben,

 

I tested it and still get the exact same issue. See capture attached.

BenMoss
ACE Emeritus
ACE Emeritus

The results are the same.

I think you are simply reading the output wrong.

Cell 2, line 1 in your alteryx output is referencing cell 1 line 2 in your R output.

So it's going down then across rather than across and down.

 

Ben

BenMoss
ACE Emeritus
ACE Emeritus

Attached workflow on how you can convert the single line data into the same table as your R output which gives the same values then.

 

Ben

 

 

helfenbeind
6 - Meteoroid

Thanks for your reply, Ben. I have found my error (I was pretty stupid and should have checked this earlier). The output of my R code is a matrix so I simply needed to convert it to a dataframe before passing it to the workflow.

 

Code is below (simply wrapping x inside data.frame()):

variables <- read.Alteryx("variables", mode="data.frame")
factormodel <- factanal(variables, factors=3, scores='regression', rotation='none')
x <- data.frame(factormodel$scores)
write.Alteryx(x, 1)

This gives me a dataframe with the factors as columns, exactly as in R Studio.

Labels