Flashcards
Last updated
Last updated
Maximize your browser window to display the outline on the right side for easier navigation.
Follow the procedures described in the RStudio lab assignment: account and packages assignment instructions.
Make sure you have a RStudio Cloud account. Otherwise, get one and install all the packages. See this guideline.
Open RStudio Cloud website and log in. Click "RStudio labs" under "Your content."
Download the R script file you need:
Go to Canvas ➜ Resources module page ➜ “Lab resources” ➜ “All R script files” ➜ Click on the R Script file you need and download that file. “All script files” is here for your convenience.
For example, if you need the "Descriptive Statistics" R script file. Click on it and download:
Uploading R script files 1: On RStudio Cloud website, click “Upload” (see highlighted part #2 below).
Uploading R script files 2: Click “Choose File.” Find the R script file you just downloaded (script_descriptive.R) in the previous step, click “Open” and "OK."
Opening R script files: The file is uploaded and at the bottom of the "Files" list (see highlighted part #1). When you click on it, the descriptive R script file will open (see highlighted part #2).
Installing and loading packages: Whenever we open RStudio, we highlight all the lines under the “Install and load packages” (see highlighted part #1) and click run (see highlighted part #2).
Loading data: When the process of installing and loading packages is completed, we highlight all the lines under the “Load data” (see highlighted part #1) and click “Run” (see highlighted part #2). When you see “gss” and “key” (see highlighted part #3), it means we successfully installed and loaded the packages, and loaded the GSS data.
Running the analysis codes: We highlight the codes (see highlighted part #1) and click “Run” (see highlighted part #2). Clicking “Run” generates the analysis (see highlighted part #3).
Using R script files - “working space” and outline view: We do not edit or change anything on R script files except under “working space”(see highlighted part #1). Anything above the “working space” is teaching material!
The codes for assignments will be put under the “working space”
For easy navigation click “Outline” (see highlighted part #2) to see the headings and subheadings.
Saving R script files: When we make any changes, the font of the file name (shown in the highlighted part #2 above) will be red with an asterisk (*) - (see the highlighted part #1 below). To save our progress, we click save (see the highlighted part #2 below)
We need specific packages to conduct our analyses. Running the "install and run packages" is always the first step.
We can check the installed packages under “Packages.” Checkmark means that the specific packages are loaded for the session. If there is no checkmark, we have the package but it was not loaded.
For troubleshooting, make sure to run "install and run packages" codes, wait until the “STOP” sign in the console disappears, no more code is running in the console, and see "Package already installed: package name" (under the console in red font, see the first figure).
Every time we open RStudio, we must load the data. Even if we see "gss" under “Environment,” we should run "load data" code again. If we do not see "gss" under "Environment," our codes will not work.
If the data is not loaded, we will get the following error (under the console):
For troubleshooting, make sure to run "install and run packages" codes and "load data" codes in order.
We do not edit or change anything on R script files except under “working space”(see highlighted part #1). Anything above the “working space” is teaching material!
The codes for assignments will be put under the “working space”
For easy navigation click “Outline” (see highlighted part #2) to see the headings and subheadings.
If we accidentally delete something from the R script file (above the working space), we can undo the changes using ctrl + Z for Windows or command + Z for macOS. If we lose track of the changes or cannot undo them, we simply re-upload the original R script file.
If this happens, we should first rename the current R script file because re-uploading the file will overwrite it and we lose our previous progress. Based on the sample below, we can rename the file to 'script_scripting_previous.R' (make sure not to delete the ".R" file extension at the end). Click "check box" (see highlighted part #1) and click "Rename" (see highlighted part #2)
The lab assignments will ask you to paste the code for specific questions. Write and test the code in RStudio, and once it works, paste it into the assignment file. Do not write codes directly in the assignment file.
Whenever we run an analysis with a different variable, we create a model code and a working code.
This is a view from the Code templates page. Triple click the code and copy, or click "Copy" (see the highlighted part).
If we don’t use model code for comparison, it is likely that we accidentally delete something extra. In this example, the comma was deleted.
Instead, we keep the use model code and compare it with our working code. Here we clearly see that the comma is missing in line 79. Note that RStudio warns us that something is wrong with that red cross.
After identifying what is missing, we can fix the working code. Once the working code functions correctly, we can delete the model code.
We NEVER type variable names! It is very common to miswrite codes, forget commas, etc. We always copy the variable names (from the code templates page or assignments), and paste into our codes.
There is no variable called “maritaal”, but “marital.” RStudio warns us that “maritaal” is “unknown.” We copy and paste variable names to avoid this possibility.
We need to highlight all the lines and click “Run.”
For single lines, we triple click (clicking three times really fast).
For multiple lines, we highlight the codes with mouse.
Here's what happens if we don't:
It simply shows what we highlighted and run (check the console part), not the analysis (check the plots part).
Instead, we should have highlighted all the line:
Typing notes on our R script files is encouraged. When we type a note, we must put a hashtag (#) first (we can put # anywhere we want). Not putting a hashtag (#) will confuse RStudio.
While line 29 will work, line 27 won’t. Here RStudio warns us that there is something wrong. Look at the red cross on line 27. When there is a red cross on the left side of the line number, there is something wrong with our codes.
We never save our data, but our R script files. From time to time, we may accidentally change the values of original variables (especially when we recode variables).
When this happens, we go to the very top of the R script file and load the data again. If we created new variables previously, we will need to run those codes under our working space again in order since it will be a fresh data.
Recoding a categorical variable and a continuous variable requires slightly different codes
When we want to display, for example, the frequency distribution of a recoded (new) variable, we must use the recoded (new) variable’s name in the frequency code.
This is because, for our analysis, the original variable is no longer relevant. We recoded the original variable and created a new one for our analysis needs.
When we recode a continuous variable, the new (recoded) variable is no longer continuous.
It becomes CATEGORICAL because we have merged the real numbers, and they no longer remain as real numbers.
Therefore, for example, we use the FRQ code to see the frequency distribution.
Use the Code templates page and Model codes:
If variables are misplaced in the codes and have overwritten the original values, we have to “Load GSS” again, because we lost the values of the original variable and we need a fresh data.
When we compute variables and create an index, the new (computed) variable is continuous.
It becomes CONTINUOUS because we have created a score, and we treat it as a real number.
Therefore, we use the DESCR code to see the distribution (mean and standard deviation)
When we recode a continuous variable, the new (recoded) variable is no longer continuous.
It becomes CATEGORICAL because we have merged the real numbers, and they no longer remain as real numbers. Therefore, for example, we use the FRQ code to see the distribution.
Statistical significance is a measure of whether your research findings are meaningful. In other words, if the independent variable causes a change in the dependent variable in a statistically significant way.
The lower the p-value, the greater the statistical significance of the observed difference.
We refer to statistical significance as p < 0.05
Questionnaire: A set of written questions used for collecting information from respondents.
Respondents: Individuals who respond to the questions in a questionnaire.
Dataset: The information collected from respondents. The numbers to be analyzed.
Full wording of question: The exact text of a question as it appears in the questionnaire.
Variable name: Unique words assigned to each question. We use variable names in data analysis software.
Values: Numbers such as 1, 2, 3, etc., that appear in the dataset representing specific responses.
Labels: What those values (numbers) mean, e.g., 1: yes, 2: no, etc.
Response set: The combination of values and their corresponding labels.
An RStudio Cloud free account allows you 25 hours of connect time per month. Every second the RStudio Cloud is open counts towards this allocated time.
Therefore, whenever you are not running code or generating analyses, close the RStudio Cloud browser
Click on your name (see highlighted part #1). The highlighted part #2 shows the time period (e.g., "I will have 25 more hours on Aug 8, 2024"). The highlighted part #3 shows how many hours you have spent.
This may happen if your RStudio Cloud session consumes too much ram.
Save your unsaved RScript file.
Saving R script files: When we make any changes, the font of the file name (shown in the highlighted part #2 above) will be red with an asterisk (*) - (see the highlighted part #1 below). To save our progress, we click save (see the highlighted part #2 below)
Click the three dots next to the gear. Click "Relaunch Project."
25 hours of connect time is enough for this class. If you exceed this limit, open another free account using a different email address. Follow the procedures described in the RStudio lab assignment: account and packages assignment instructions.
Go to the previous account where you exceeded the time limit.
Click "Export" (see the highlighted part)
Click "Download"
It will download a zip file.
Go to your new account.
Upload that zip file just like you upload a R script file.
Every time you log in to a lab computer, you have to run "install and load packages" codes.
Because when you log out, lab computers revert to their factory settings and deletes the installed packages.
First, download the R Script file that you want to use. All R Script files here.
Type "RStudio" on the search bar of the computer. Open RStudio.
On RStudio, Click File ➜ Open File.
Find the Script file that you just downloaded, and click Open.
DO NOT DOUBLE CLICK R SCRIPT FILES. It may open R, instead of RStudio.
You can download R and RStudio to your personal computer. "Install and load packages" codes will install the packages once, but every time you open RStudio on your personal computer, you should run "Install and load packages" again.
1. Download R (4.4.1)
2. Download RStudio (2024.04.2+764)
1. Download R (4.4.1)
2. Download RStudio (2024.04.2+764)
1. Download R (3.6.3)
2. Download RStudio (1.4.1717)
macOS may want you to allow it to download. Open System Preferences, navigate to Security & Privacy, and then General. See the photo below and hit allow (you may need to click the lock at the bottom to unlock)
1. Download R (4.4.1)
2. Download RStudio (2024.04.2-764)
Windows users may need to change some of their settings.
Select Start > Settings > Apps > Apps & features. Under Installing apps, select "Allow apps from anywhere"