Page 1 of 1

Data type of R factors opened in jamovi

Posted: Tue Mar 24, 2020 5:26 pm
by pgtpg
Hello,

If I open in jamovi a database in SPSS format generated with R and haven::write_sav (jamovi won't open the RData version of the same database), I realize that the data type of the factors is integer (as factors seems to be stored as integers in R). Is there a way to avoid having to change those data types in jamovi (from integer to text) ?

Thank you !

Pierre-Guillaume

Re: Data type of R factors opened in jamovi

Posted: Tue Mar 24, 2020 11:44 pm
by jonathon
hi,

so this would be to do with the behaviour of haven::write_sav(). try converting your factors to character vectors and see if that gets you the behaviour you want.

cheers

Re: Data type of R factors opened in jamovi

Posted: Wed Mar 25, 2020 11:42 am
by pgtpg
Thank you for your answer.

But the problem is, if I convert the factors to character vectors, I lose the benefit of factors, which are levels, very convenient to make R and also jamovi to produce analysis where variables values are sorted in a defined order.

Cheers

Pierre-Guillaume

Re: Data type of R factors opened in jamovi

Posted: Thu Mar 26, 2020 12:17 am
by jonathon
hi,

i'm sure there's a way to do what you want, but i'm 99% sure that jamovi is doing everything correctly here, and it's on the haven side of things that you want to get correct.

take a look here (it's a bug report, but the example shows how to attach labels to factors in data frames):

https://github.com/tidyverse/haven/issues/193

jonathon

Re: Data type of R factors opened in jamovi

Posted: Thu Mar 26, 2020 10:42 am
by pgtpg
Hi,

Thank you ! I'll try a few things to get that issue solved. And if I can't succeed, I'll just change the data types of the few variables "by hand" in jamovi.

Have a nice day !

Pierre-Guillaume

Re: Data type of R factors opened in jamovi

Posted: Thu Mar 26, 2020 11:58 am
by pgtpg
Hi again,

And I just saw that jamovi considers factors, ordered (ordered = TRUE) or not, as ordinal variables. All of this seems to be linked with the nature of factors in R.

Thanks again !

Pierre-Guillaume

Re: Data type of R factors opened in jamovi

Posted: Thu Mar 26, 2020 12:07 pm
by jonathon
you can see the code we use to infer the measure type here:

https://github.com/jamovi/jamovi/blob/m ... tat.py#L92

we do a little trickery, where we adjust things if the user appears to have the column set up incorrectly, but mostly we honour what's contained in the .sav file.

if it's coming through as ordinal, that probably means it's specified as a 'scale' variable in the .sav file, with labels attached to it. this usually means the user actually wants an ordinal variable. so you probably need to do a little more trickery with haven to get the desired result :)

cheers

jonathon