Code
sudo dnf install 'dnf-command(copr)'
sudo dnf copr enable iucar/rstudio
sudo dnf install rstudio-desktop
You should program your statistical analysis, and we will cover some of the basics of how to do this in R. You also want your work to be replicable
You can read more about the distinction in many places, including
We focus on R because it is good for complex stats, concise figures, and coherent organization. It is built and developed by applied statisticians for statistics, and used by many in academia and industry. For students, think about labor demand and what may be good for getting a job. Do some of your own research to best understand how much to invest.
My main sell to you is that being reproducible is in your own self-interest.
First Steps…
Step 1: Some ideas and data about how variable \(X_{1}\) affects variable \(Y_{1}\), which we denote as \(X_{1}\to Y_{1}\)
Step 2: Pursuing the lead for a week or two
A Little Way Down the Road …
1 month later: someone asks about another factor: \(X_{2}\)
4 months later: someone asks about another factor \(X_{3}\to Y_{1}\)
6 months later: you want to explore another outcome \(X_{2} \to Y_{2}\).
2 years later: your boss wants you to replicate \(\{ X_{1}, X_{2}, X_{3} \} \to Y_{1}\)
Suppose you decided to code what you did beginning with Step 2.
It does not take much time to update or replicate your results.
Your results are transparent and easier to build on.
First Install R. Then Install Rstudio.
For help setting up, see any of the following links
For Fedora users, note that you need to first enable the repo and then install
sudo dnf install 'dnf-command(copr)'
sudo dnf copr enable iucar/rstudio
sudo dnf install rstudio-desktop
Make sure you have the latest version of R and Rstudio for class. If not, then reinstall.
Rstudio is perhaps the easiest to get going with. (There are other GUI’s.)
In Rstudio, there are 4 panes. (If you do not see 4, click “file > new file > R script” on the top left of the toolbar.)
The top left pane is where you write your code. For example, type
1+1
The pane below is where your code is executed. Keep you mouse on the same line as your code, and then click “Run”. You should see
> 1+1
[1] 2
If you click “Run” again, you should see that same output printed again.
As we proceed, you can see both my source code and output like this:
1+1
## [1] 2
You should add comments to your codes, and you do this with hashtags. For example
## This is my first comment!
1+1 # The simplest calculation I could think of
## [1] 2
You can execute each line one-at-a-time. Or you can highlight them both, to take advantage of how R executes commands line-by-line.
You can create “variables” that store values. For example,
<- 1 # Make your first variable
x + 1 # The simplest calculation I could think of
x ## [1] 2
<- 23 #Another example
x + 1
x ## [1] 24
<- x + 1 #Another example
y
y## [1] 24
Your variables must be defined in order to use them. Otherwise you get an error. For example,
+ 1 # notice that R is sensitive to capitalization but not spacing
X ## Error: object 'X' not found
Your variable names do not matter technically, but they should be informative
<- 1 # good variable name
one
one## [1] 1
<- 43 # bad variable name
one
one## [1] 43
Good names avoid confusion later
<- one + 2 #bad names propogate
one_plus_2
<- 43
x <- x + 2 # better x_plus_two
R Script
file as My_First_Script.R in your folderAs you work through the material, make sure to both execute and save your scripts. Add lots of commentary to your scripts. Name your scripts systematically.
There are often many ways to accomplish the same goal. You first scripts will be very basic and rough, but you can edit them later based on what you learn. And you can always ask R for help
sum(x, 2) # x + 2
?sum
There are many good and free programming materials online.
The most common tasks can be found https://github.com/rstudio/cheatsheets/blob/main/rstudio-ide.pdf
Some of my programming examples originally come from https://r4ds.had.co.nz/ and I recommend https://intro2r.com.
I have also used online material from many places over the years, as there are many good yet free-online tutorials and courses specifically on R programming. See e.g.,
For more on why to program in R, see