Correlation Regression R Tutorial

docx

School

RMU *

*We aren’t endorsed by this school

Course

4265

Subject

Statistics

Date

Feb 20, 2024

Type

docx

Pages

5

Uploaded by EarlFlamingoMaster919

Report
MARK 4265 Correlation Regression R Tutorial Jeremiah Brosovic R version 4.2.1 (2022-06-23 ucrt) -- "Funny-Looking Kid" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Workspace loaded from ~/.RData] > # Or, you can download and save week-tutorial.csv, and open it as: > mydata<-read.csv("c:/MARK4265/data-tutorial.csv", header=TRUE, sep=",") > head(mydata) #Look at the data, the first 6 rows exam1 exam2 exam3 final 1 73 80 75 152 2 93 88 93 185 3 89 91 90 180 4 96 98 100 196
5 73 66 70 142 6 53 46 55 101 > str(mydata) #Look at the data, the data structure 'data.frame': 25 obs. of 4 variables: $ exam1: int 73 93 89 96 73 53 69 47 87 79 ... $ exam2: int 80 88 91 98 66 46 74 56 79 70 ... $ exam3: int 75 93 90 100 70 55 77 60 90 88 ... $ final: int 152 185 180 196 142 101 149 115 175 164 ... > final <- c(mydata$final) > exam1 <- c(mydata$exam1) > exam2 <- c(mydata$exam2) > exam3 <- c(mydata$exam3) > final [1] 152 185 180 196 142 101 149 115 175 164 141 141 184 152 148 192 147 183 [19] 177 159 177 175 175 149 192 > exam1 [1] 73 93 89 96 73 53 69 47 87 79 69 70 93 79 70 93 78 81 88 78 82 86 78 76 96 > exam2 [1] 80 88 91 98 66 46 74 56 79 70 70 65 95 80 73 89 75 90 92 83 86 82 83 83 93 > exam3 [1] 75 93 90 100 70 55 77 60 90 88 73 74 91 73 78 96 68 93 [19] 86 77 90 89 85 71 95 > plot(exam1, final) > #Draw a scatterplot. The paramters make sure the graph looks good. > plot(exam1, final, xlim=c(min(exam1)-5, max(exam1)+5), ylim=c(min(final)-10, max(final)+10)) > #Add a trending line > abline(lm(final ~ exam1), lwd=2) > #Add a fit curve > lines(lowess(exam1, final), col="blue") # lowess line (x,y)
> #We want to see the coefficients betwee final and other exams. > #Which one is highly correlated to final? > cor(final, exam1) [1] 0.9460708 > cor(final, exam2) [1] 0.9294714 > cor(final, exam3) [1] 0.9723275 > cor.test(final, exam1, method="pearson") Pearson's product-moment correlation data: final and exam1 t = 14.005, df = 23, p-value = 9.544e-13 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8798453 0.9762560 sample estimates: cor 0.9460708 > cor.test(final, exam2, method="pearson") Pearson's product-moment correlation data: final and exam2 t = 12.084, df = 23, p-value = 1.924e-11 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0.8444906 0.9687986 sample estimates: cor 0.9294714 > cor.test(final, exam3, method="pearson") Pearson's product-moment correlation data: final and exam3 t = 19.96, df = 23, p-value = 5.051e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.9373067 0.9879076 sample estimates: cor 0.9723275 > myregression<-lm(final~exam3, data=mydata) > # Check the regression output: > summary (myregression) Call: lm(formula = final ~ exam3, data = mydata) Residuals: Min 1Q Median 3Q Max -10.996 -4.138 0.069 3.095 11.746
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.13362 8.19228 0.016 0.987 exam3 1.98707 0.09955 19.960 5.05e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 5.738 on 23 degrees of freedom Multiple R-squared: 0.9454, Adjusted R-squared: 0.943 F-statistic: 398.4 on 1 and 23 DF, p-value: 5.051e-16