📖
lectures
  • All lectures and labs
    • Guidelines and rubrics
      • Lecture reflections
      • Office hours
      • Where are the readings, slides, and lecture videos?
      • How to submit an assignment
      • How to move a file in Google Drive
      • How to rename a file and folder in Google Drive
      • Highlighting and commenting assignment instructions
      • How to collaborate on the same Google document
      • How to embed an image in Canvas
      • Pomodoro technique
      • Which apps to download
      • How to use zbib.org for citations?
      • How to determine peer-reviewed journal articles?
      • Citation chaining procedure
      • ResearchRabbit: Literature discovery engine
      • Selective literature review
      • How to take a screenshot
      • Canvas notification settings
      • How to use Google Calendar
      • Presentation templates and samples
      • Qualitative (Content analysis) DRAFT research memo guideline and rubric
      • Qualitative (Content analysis) FINAL research memo guideline and rubric
      • How to use VPN (for Windows and macOS)
      • Letter of recommendation requests
    • Lectures
      • Social research
        • Social research: why and how
        • The ABC's of a research project
        • Introduction to datasets
        • Research ethics
        • Literature review I: Annual review articles and citations
        • Literature review II: citation chaining and discovery engine
        • Introduction to survey methodology
        • Probability sampling methods
        • Non-probability sampling methods
        • Asking questions
        • Qualitative interviewing
        • Self-completion questionnaires
        • Focus groups
        • Mass and social media research
        • Data collection in mass media research
        • Content analysis and coding with Google Docs
        • Effective presentation techniques
        • Concepts and indicators
        • Presentations 1
        • Presentations 2
        • Presentations 3
        • Presentations 4
        • Presentations 5
      • Immigration
        • Why do people migrate?
        • Who does migrate?
        • Introduction to assimilation theories
        • New and segmented assimilation theory
        • Group conflict
        • Group contact
        • Children of immigrants
        • Social identity of immigrants
        • Migrant networks
        • Intergenerational relationships
        • Grandparental involvement
        • Return migration
        • The sociology of border
        • Immigration and crime
        • Marriage migration and religiosity
        • The construction of ethnicity
      • Sociological thinking
        • The sociological eye
        • Foundations of social theory
        • Scientific sociology: social facts
        • Social structure
        • What is critical thinking?
        • Claims and evidence
        • Everyday arguments
        • Analyzing arguments
        • Network-based factors influencing critical thinking
        • Common errors of perspective in sociological thinking
        • Misinformation and disinformation
        • Propaganda
        • Conspiracy theories and sociology
        • Cognitive influences on critical thinking
        • Ethical reasoning
        • Deviance I: The role of deviance
        • Deviance II: Explaining deviance
        • Social class and inequality
        • Sociology of poverty
        • Sociological perspectives on substance abuse
    • R lab
      • Lab lectures
        • Introduction RStudio
        • Introduction to scripting
        • Descriptive statistics
        • Recoding
        • Computing
        • Chi-square
        • Sampling
        • T-test
        • Visualization
        • Correlation
        • Linear regression basics
        • Dummy variables
        • Logistic regression
        • Modeling exercises
        • Regression assumptions and diagnostics
      • Lab resources
        • How to create RStudio Cloud account and installing all the packages
        • How to open and use R script files in RStudio Cloud
        • Flashcards
        • All R script files
        • Variables in GSS
        • Code templates
        • Interpretation templates
        • How to use model codes
        • Data terminologies
        • Is my p-value less than 0.05?
        • Codebooks
        • How to use RStudio on a computer without using a browser
    • SPSS lab
      • SPSS lab resources
        • All syntax and data files
        • GSS codebook
        • Code templates
        • How to use VPN (for Windows and macOS) and use SPSS
        • How to download PSPP
      • SPSS lab lectures
        • Introduction to SPSS
        • Entering data
        • Recoding and computing I
        • Recoding and computing II
        • Probability sampling
        • Correlation
        • Chi-square
        • T-Test
        • Simple linear regression
        • Multiple linear regression
        • Multiple linear regression exercises
        • Logistic regression
        • Multiple linear and logistic regression exercises
    • NVIVO lab
      • NVIVO lab files
        • All NVIVO cheat files
        • NVIVO data
      • NVIVO lab lectures
        • Introduction to NVIVO
        • Coding basics I
        • Getting familiar with data
        • Getting familiar with own data
        • Coding basics II: initial, axial and focused coding
        • Cases, attributes, values, and visualization
        • Relationships
        • Framework matrices
        • Mind maps, concept maps, project maps
        • NVIVO file for final paper
    • Welcoming pages
      • Welcome to SBS321
      • Welcome to SOC399
      • Welcome to SOC120
Powered by GitBook
On this page
  • A. Setup
  • 1.
  • How to create RStudio Cloud account and installing all the packages
  • 2.
  • How to open and use R script files in RStudio Cloud
  • B. How to work with RStudio
  • 1.
  • Installing and loading packages
  • 2.
  • Loading the data
  • 3.
  • Working in the "Working space"
  • 4.
  • Working on codes in RStudio, not in assignment files
  • 5.
  • Using a model code
  • 6.
  • Pasting variable names
  • 7.
  • Highlighting all the lines when running codes
  • 8.
  • Putting hashtags (#) for our notes (how to work)
  • 9.
  • Not changing the original values of the dataset
  • C. Keyboard and mouse shortcuts
  • 1.
  • Using keyboard shortcuts
  • 2.
  • Keyboard shortcuts: hand and finger positions (how to work)
  • 3.
  • Using mouse shortcuts
  • D. Common recoding issues
  • 1.
  • Different recoding codes for different variables
  • 2.
  • Use the recoded (new) variable in analyses
  • 3.
  • Recoded variables are always categorical
  • 4.
  • Not using a model code
  • 5.
  • Pasting the original variable to the correct place
  • 6.
  • Load GSS data again if variables are misplaced in the codes and have thus overwritten the original values
  • E. Common computing issues
  • 1.
  • Use the new (recoded) variables in computation code
  • 2.
  • Computed variables are always continuous
  • F. Miscellaneous
  • 1.
  • Is my p-value less than 0.05?
  • 2.
  • Data terminologies
  • 3.
  • GSS codebooks
  • G. RStudio issues and usage
  • 1.
  • How to check how many hours left in RStudio Cloud?
  • 2.
  • What to do if RStudio Cloud crashes?
  • 3.
  • What to do if you exceed 25 hours per month?
  • 4.
  • What to do if you want your new free account to be identical (files, packages, etc.) to the previous account where you exceeded the time limit?
  • 5.
  • Using RStudio on a university lab computer
  • 6.
  • Downloading R and RStudio to a personal computer
  1. All lectures and labs
  2. R lab
  3. Lab resources

Flashcards

Last updated 5 months ago

Maximize your browser window to display the outline on the right side for easier navigation.

A. Setup

1.

How to create RStudio Cloud account and installing all the packages

Video guideline:

Textual guideline:


2.

How to open and use R script files in RStudio Cloud

Video guideline:

Textual guideline:

  1. Download the R script file you need:

    1. For example, if you need the "Descriptive Statistics" R script file. Click on it and download:

  1. 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."

  1. 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).

  1. 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).

  1. 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.

  1. 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).

  1. 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.

  1. 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)


B. How to work with RStudio

1.

Installing and loading packages

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).


2.

Loading the data

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.


3.

Working in the "Working space"

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)


4.

Working on codes in RStudio, not in assignment files

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.

5.

Using a model code

Whenever we run an analysis with a different variable, we create a model code and a working code.

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.


6.

Pasting variable names

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.


7.

Highlighting all the lines when running codes

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:


8.

Putting hashtags (#) for our notes (how to work)

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.


9.

Not changing the original values of the dataset

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.


C. Keyboard and mouse shortcuts

1.

Using keyboard shortcuts


2.

Keyboard shortcuts: hand and finger positions (how to work)


3.

Using mouse shortcuts


D. Common recoding issues

1.

Different recoding codes for different variables

Recoding a categorical variable and a continuous variable requires slightly different codes


2.

Use the recoded (new) variable in analyses

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.


3.

Recoded variables are always categorical

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.


4.

Not using a model code


5.

Pasting the original variable to the correct place


6.

Load GSS data again if variables are misplaced in the codes and have thus overwritten the original values

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.


E. Common computing issues

1.

Use the new (recoded) variables in computation code


2.

Computed variables are always continuous

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.

F. Miscellaneous

1.

Is my p-value less than 0.05?

Statistical significance

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

Use the following website


2.

Data terminologies

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.


3.

GSS codebooks


G. RStudio issues and usage

1.

How to check how many hours left in RStudio Cloud?

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.


2.

What to do if RStudio Cloud crashes?

This may happen if your RStudio Cloud session consumes too much ram.

  1. 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)

  1. Click the three dots next to the gear. Click "Relaunch Project."

3.

What to do if you exceed 25 hours per month?


4.

What to do if you want your new free account to be identical (files, packages, etc.) to the previous account where you exceeded the time limit?

  1. Go to the previous account where you exceeded the time limit.

  2. Click "Export" (see the highlighted part)

  1. Click "Download"

  1. It will download a zip file.

  2. Go to your new account.

  3. Upload that zip file just like you upload a R script file.


5.

Using RStudio on a university lab computer

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.

  1. Type "RStudio" on the search bar of the computer. Open RStudio.

  2. On RStudio, Click File ➜ Open File.

  3. Find the Script file that you just downloaded, and click Open.

  4. DO NOT DOUBLE CLICK R SCRIPT FILES. It may open R, instead of RStudio.


6.

Downloading R and RStudio to a personal computer

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.

Mac users

Mac Users (macOS 12+) and Apple silicon (M1-3) Macs:

Mac Users (macOS 12+) and older Intel Macs:

Mac Users (macOS El Capitan and older)

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)

Video guidance (macOS)

Windows Users

Windows users may need to change some of their settings.

Select Start > Settings > Apps > Apps & features. Under Installing apps, select "Allow apps from anywhere"

Video guidance (Windows)


Follow the procedures described in the .

Make sure you have a RStudio Cloud account. Otherwise, get one and install all the packages. .

Open and log in. Click "RStudio labs" under "Your content."

Go to Canvas ➜ Resources module page ➜ “Lab resources” ➜ “All R script files” ➜ Click on the R Script file you need and download that file. for your convenience.

Uploading R script files 1: On , click “Upload” (see highlighted part #2 below).

This is a view from the page. Triple click the code and copy, or click "Copy" (see the highlighted part).

Use the page and Model codes:

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 .

First, download the R Script file that you want to use. .

1. (4.4.1)

2. (2024.04.2+764)

1. (4.4.1)

2. (2024.04.2+764)

(3.6.3)

(1.4.1717)

1. (4.4.1)

2. (2024.04.2-764)

RStudio lab assignment: account and packages assignment instructions
See this guideline
RStudio Cloud website
“All script files” is here
RStudio Cloud website
Code templates
Code templates
[Variables in GSS]
GSS 2022 Codebook website
GSS 2022 Codebook pdf file
RStudio lab assignment: account and packages assignment instructions
All R Script files here
Check your macOS version
Download R
Download RStudio
Download R
Download RStudio
1. Download R
2. Download RStudio
Download R
Download RStudio
Which Number is Larger?