Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save naomispence/b587b793e30949707eebd4089359aae9 to your computer and use it in GitHub Desktop.
Save naomispence/b587b793e30949707eebd4089359aae9 to your computer and use it in GitHub Desktop.
#Lab: Scatterplots and Regression
#Load the libraries and data first
library(ggplot2)
library(dplyr)
library(lsr)
library(descr)
library(Hmisc)
library('lehmansociology')
data(gss123)
options(scipen = 999)
#Regression and scatterplots are for interval-ratio
#independent and interval-ratio dependent variables
#In this example, age will be our independent variable
#and spouse's highest education year will be our dependent variable.
#WHAT WOULD THE RESEARCH QUESTION, NULL HYPOTHESIS,
#AND RESEARCH HYPOTHESIS BE FOR THIS PAIR OF VARIABLES?
#Now we will do a statistical procedure called regression
#This is a linear model of an interval-ratio dependent variable with
#an intercept and an interval-ratio independent variable
# The indpendent variable is age, and the dependent variable is
#spouse's highest year of education attained.
results<-lm(gss123$speduc~age, data=gss123)
summary(results)
#WRITE AN INTERPRETATION OF THE RESULTS HERE
#WRITE AN INTERPRETATION OF THE ADJUSTED R SQUARED
#This is the code for getting the correlation coefficient
cor.test(gss123$speduc, gss123$age)
#WRITE AN INTERPRETATION OF THE CORRELATION COEFFICIENT OUTPUT HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment