Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#################################################### # 5 . 3 Assessing Fit of Line # # Run in Groups and discuss # #################################################### install.packages ( ggplot 2 )
####################################################
# Assessing Fit of Line #
# Run in Groups and discuss #
####################################################
install.packagesggplot
install.packagesdplyr
install.packagesbroom
install.packagesggpubr
libraryggplot
librarydplyr
librarybroom
libraryggpubr
#
##STEP IMPORT THE DATA SET
#
# Download the file from blackboard and then, in RStudio, go to File Import dataset From Text base
# Choose the data file you have downloaded incomedata and an Import Dataset window pops up
# In the Data Frame window, you should see an X index column and columns listing the data for each of the variables income and happiness
# Click on the Import button and the file should appear in your Environment tab on the upper right side of the RStudio screen.
# After youve loaded the data, check that it has been read in correctly using summary
summaryincomedata
#Because both our variables are quantitative, when we run this function we see a table in our console with a numeric summary of the data. This tells us the minimum, median, mean, and maximum values of the independent variable income and dependent variable happiness:
#
#STEP CHECK FOR NORMALITY OF THE DEPENDENT VARIABLE
#
histincomedata$happiness
##QUESTION answer on BB: What is the shape of this distribution? Can we proceed with the linear regression? Yes or No
#STEP LINEARITY CHECK THE RELATIONSHIP BETWEEN IND AND DEP VARIABLES
plothappiness ~ income, data income.data
##QUESTION answer on BB: What is the shape of this distribution? Can we proceed with the linear regression? Yes or No
#
#STEP Is there an linear relationship between income and happiness?
#
#The first line of code makes the linear model
income.happiness.lm lmhappiness ~ income, data income.data
#Notice nothing really happens. When we do the next line of code, we will see an output.
summaryincomehappiness.lm
#There's a lot of stuff here.
#QUESTION answer on BB: There's a lot of stuff here. What is the value of the yintercept hint it's the Estimate Std intercept What is the tvalue tstatistic What is the pvalue? What is the x coefficient? What is the equation of the line in slope intercept form?
#From these results, we can say that there is a significant positive relationship between income and happiness p value with a unit increase in happiness for every unit increase in income.
#
#STEP GRAPH THE EQUATION OF THE LINE
#
#Next, we can plot the data and the regression line from our linear regression model so that the results can be shared.
#we're going to graph the line, the points, and then include the linear regression line on the graph along with the equation of the line and titles to make it ready for publication.
ggplotincomedata, aesxincome, yhappiness geompoint geomsmoothmethod lm col"red" statreglineequationlabelx label.y themebw labstitle "Reported happiness as a function of income", x "Income $ y "Happiness score to
income,happiness
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started