This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(readr)
library(ggm)
## Loading required package: igraph
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
##
## Attaching package: 'ggm'
## The following object is masked from 'package:igraph':
##
## pa
library(Rcmdr)
## Loading required package: splines
## Loading required package: RcmdrMisc
## Loading required package: car
## Loading required package: carData
## Loading required package: sandwich
## Loading required package: effects
## Registered S3 methods overwritten by 'lme4':
## method from
## cooks.distance.influence.merMod car
## influence.merMod car
## dfbeta.influence.merMod car
## dfbetas.influence.merMod car
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
## The Commander GUI is launched only in interactive sessions
##
## Attaching package: 'Rcmdr'
## The following object is masked from 'package:car':
##
## Confint
## The following object is masked from 'package:base':
##
## errorCondition
student_survey <- read_csv("C:/Users/Owner/Desktop/Lenin Files/Data Sciences/Assignments/student-survey.csv")
## Parsed with column specification:
## cols(
## TimeReading = col_double(),
## TimeTV = col_double(),
## Happiness = col_double(),
## Gender = col_double()
## )
View(student_survey)
cov(student_survey$TimeReading, student_survey$TimeTV)
## [1] -20.36364
cor(student_survey$TimeReading, student_survey$TimeTV, method = "pearson")
## [1] -0.8830677
cor(student_survey, use = "complete.obs", method = "pearson")
## TimeReading TimeTV Happiness Gender
## TimeReading 1.00000000 -0.883067681 -0.4348663 -0.089642146
## TimeTV -0.88306768 1.000000000 0.6365560 0.006596673
## Happiness -0.43486633 0.636555986 1.0000000 0.157011838
## Gender -0.08964215 0.006596673 0.1570118 1.000000000
cor.test(student_survey$TimeReading, student_survey$Happiness, alternative = "less", method = "pearson")
##
## Pearson's product-moment correlation
##
## data: student_survey$TimeReading and student_survey$Happiness
## t = -1.4488, df = 9, p-value = 0.09067
## alternative hypothesis: true correlation is less than 0
## 95 percent confidence interval:
## -1.0000000 0.1151482
## sample estimates:
## cor
## -0.4348663
cor.test(student_survey$TimeReading, student_survey$Happiness, alternative = "less", method = "pearson", conf.level = 0.99)
##
## Pearson's product-moment correlation
##
## data: student_survey$TimeReading and student_survey$Happiness
## t = -1.4488, df = 9, p-value = 0.09067
## alternative hypothesis: true correlation is less than 0
## 99 percent confidence interval:
## -1.0000000 0.3422209
## sample estimates:
## cor
## -0.4348663
cor(student_survey)
## TimeReading TimeTV Happiness Gender
## TimeReading 1.00000000 -0.883067681 -0.4348663 -0.089642146
## TimeTV -0.88306768 1.000000000 0.6365560 0.006596673
## Happiness -0.43486633 0.636555986 1.0000000 0.157011838
## Gender -0.08964215 0.006596673 0.1570118 1.000000000
cor(student_survey)^2
## TimeReading TimeTV Happiness Gender
## TimeReading 1.000000000 0.7798085292 0.18910873 0.0080357143
## TimeTV 0.779808529 1.0000000000 0.40520352 0.0000435161
## Happiness 0.189108726 0.4052035234 1.00000000 0.0246527174
## Gender 0.008035714 0.0000435161 0.02465272 1.0000000000
student_survey2 <- student_survey[, c("TimeReading","TimeTV","Happiness")]
pc_ss <- pcor(c("TimeReading", "TimeTV","Happiness"), var(student_survey2))
pc_ss
## [1] -0.872945
(pc_ss)^2
## [1] 0.762033
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.