Data type of R factors opened in jamovi

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
pgtpg
Posts: 11
Joined: Tue Mar 24, 2020 5:16 pm

Data type of R factors opened in jamovi

Post 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
Last edited by pgtpg on Thu Mar 26, 2020 9:38 pm, edited 1 time in total.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Data type of R factors opened in jamovi

Post 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
pgtpg
Posts: 11
Joined: Tue Mar 24, 2020 5:16 pm

Re: Data type of R factors opened in jamovi

Post 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
Last edited by pgtpg on Thu Mar 26, 2020 9:38 pm, edited 1 time in total.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Data type of R factors opened in jamovi

Post 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
pgtpg
Posts: 11
Joined: Tue Mar 24, 2020 5:16 pm

Re: Data type of R factors opened in jamovi

Post 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
Last edited by pgtpg on Thu Mar 26, 2020 9:39 pm, edited 1 time in total.
pgtpg
Posts: 11
Joined: Tue Mar 24, 2020 5:16 pm

Re: Data type of R factors opened in jamovi

Post 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
Last edited by pgtpg on Thu Mar 26, 2020 9:39 pm, edited 1 time in total.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Data type of R factors opened in jamovi

Post 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
Post Reply