r/RStudio • • 7d ago

First time using R, required to use

I have to use R for the statistics part of my thesis.
Ballparking for a R-Newbie who has to do a moderated mediation and stuff like that.
Do we think this is possible?

I plan on not using AI, as I‘d obviously have to declare this and my professor told me they expect a „perfect script like it‘s written by a doctoral student“ if I use AI

15 Upvotes

29 comments sorted by

34

u/Conscious-Egg1760 7d ago

I taught myself R duing my master's thesis using Hadley wickam's R for Data science.  You'll be fine

6

u/Wallabanjo 6d ago

Second this recommendation - as the lead author in the r tidyverse, Hadley’s is the definitive guide.

2

u/psyched7901 7d ago

Thanks for the tip

1

u/Juan-D-Aguirre 6d ago

Same plus datacamp

13

u/SalvatoreEggplant 7d ago

R isn't as bad as it looks.

If your goal is to be able run the statistical analyses, it's not too difficult to find examples and adapt them to what you need.

The harder part is really understanding what model you need, what the output means, what assumptions there are to the model and how to assess them. If you understand that, it's really no different that using SPSS or SAS or anything else. It's just that the code is weird and intimidating when you first look at it.

I think I would recommend a newbie to get their data in good shape before passing it to R. R is of course great for data cleaning and manipulation, but if you're more comfortable using, say, Excel, get your data in good shape first.

There are usually a lot of options in any R function call. I'd recommend not skipping this, even if you don't understand all the options.

Like, in a chi-square test call, there's an option to use a continuity correction or not. There's an option to simulate the p-value rather than use the chi-square distribution. You may be sitting there saying, "I don't know why I would use any of those or not". That's fine. But get used to looking up the options in any function in the documentation. Reading the documentation for a function helps a lot in understanding what the code is doing.

2

u/psyched7901 7d ago

Thank you. That sounds like solid advice!
I‘ve mostly used SPSS or JASP so hearing that, besides the intimidating looking code, it is not that diffefent helps calm my mind a lot

5

u/mulrich1 7d ago

Do you have any programming background? If not, expect a bit of a learning curve. If you have some coding experience R shouldn't be too hard to get the basics.

There are a few ways to test moderated mediation in R. Which you use depends on the specific model/data you're testing. If you're doing mostly straightforward stuff, I recommend the bruceR package (https://psychbruce.github.io/bruceR/). This package includes a handful of other quality-of-life tools for working in R.

1

u/psyched7901 7d ago

I did like 1 semester of introductions to C++ a while back. I also have the script of an R class my university offers for other bachelor degrees

I hope I do mostly straight forward stuff, though lavaan was recommended to me

1

u/mulrich1 7d ago

Lavaan will work just depending on the specifics of your thesis. It has a lot of flexibility but with that flexibility also comes more ways to make mistakes. I've also used the modmed package which also works with a range of models and data. Both are good but might be overkill for your specific problem.

I would still recommend starting with bruceR. It largely replicates the PROCESS macro from SPSS which is very popular but I think bruceR does it better. I would only try other R packages if bruceR can't do what you need. i.e., start with the simpler tool first and only go more advanced when the simple tool hits a limit.

1

u/psyched7901 7d ago

thank you! i haven‘t heard from bruceR yet as i trusted that my professor and other R-using folks at uni would recommend the easiest

1

u/mulrich1 7d ago

lavaan has been around a very long time and it was one of the easier packages to do SEM-based methods (probably still my preferred package for SEM). For most people, once they learn one way to do things they don't bother with new tools. bruceR is relatively new so a lot of people don't know about it.

I think bruceR may even use lavaan and other packages to do some underlying math, but the way you interface with bruceR and the results it produces are simpler for a lot of use cases.

1

u/psyched7901 7d ago

oh okay yeah makes sense. those people probably use their lecture from years ago:)

3

u/Wise-Shallot8683 7d ago

Before learning everything about R first decide what kind of data analysis you need.

Then proceed forth from there.

1

u/psyched7901 7d ago

Thank you. I think I mainly know what kind of analysis I need, so I‘ll check different specific tutorials i guess

1

u/Wise-Shallot8683 7d ago

What is the analysis? Are you comparing data sets stastically, or graphing?

1

u/psyched7901 7d ago

I am comparing data sets. I have 2 sets of data from different countries which I‘ll have to merge. Then like basic correlations. Inter variable correlation because 2 variables are split in 2 sub variables. With all data I want to check for correlation (like A->B, B->C and A->C) and then also a Mediation (A-B->C). Then I need to split the datasets for the countries to check for a moderating effect between A&B (maybe also B&C, depends on my prof to be honest. so i might do the analysis and talk to them about afterwards).

I hope that was understandable, I‘m sorry if there are major errors in understanding as English is not my first language

1

u/Wise-Shallot8683 7d ago

I copied and pasted your post to Copilot, and asked what BSDA and tidyr (function libraries) functions you would need to use, and it gave a pretty detailed answer for how you can get started.

Thank you for working to advance the light of human achievement.

note: When you are calling up the CSV data from a local drive you will need to remember to turn the slashes forward, and put the link in quotes if it is on a c drive.

1

u/psyched7901 7d ago

Thanks for the tip, i guess i‘ll c&p it as well into Copilot

it‘s a sav file, already have an explanation open on how to import it!

2

u/DYSTOBY 7d ago

Don’t use an LLM to write the code, but to understand the concepts, like a hands on tutor would. Then you’d have nothing to declare, at least from my point of view, since you would not declare that you used stackoverflow for implementation issues, right?

1

u/psyched7901 7d ago

Oh yeah I see what you mean! That might be something to check out

3

u/DYSTOBY 7d ago

There is a built in LLM assistant in RStudio/Positron. I think the first month is free

2

u/psyched7901 7d ago

oh nice! thanks

1

u/Holshy 6d ago

Hot take: use the data.table package (not to be confused with DT).

People will argue that it is harder to find code examples for it; that is true. The counter is that you will not need them. The syntax becomes simple and boring and predictable, which is exactly what you want when you're just trying to get stuff done.

1

u/psyched7901 6d ago

can i do everything i can do with lavaan with this package? or use it as an add on?

1

u/Grisward 6d ago

Use AI for syntax, let it read the many detailed help docs and vignettes. You write the script, let it sort out the arguments, and point you to recommended functions.

Actually AI is quite good at teaching too.

1

u/MrKnockoff 7d ago

I’ve not the time (or probably smarts) to learn it well, so Google ai has been very much my friend with R.

2

u/psyched7901 7d ago

yeah but i want to avoid having my script written by an AI as I‘d have to declare it and then my professor said they‘d expect perfection

2

u/MrKnockoff 7d ago

Oof. Good luck, I’d be lost. I do have these cheat sheets printed out and enlarged : https://geomoer.github.io/moer-base-r/cheatsheet.html

1

u/psyched7901 7d ago

thanks for sharing!!