knitr::opts_chunk$set(echo = TRUE)
library(tibble) library(dplyr) #Literacy rate Y is predicted by number of X- newspapers bought per week, and T- televisions per family, per 1000 people in each country- Poland, Italy, Scotland , Sweden. country <- c("Poland", "Italy", "Scotland", "Sweden") Newspapers <- c(280,100,14,130) Television <- c(440,22,180,147) Literacy <- c(.15,.98,.49,.29) data <- tibble(X = c(280,100,14,130), T = c(440,22,180,147), Y = c(.15,.98,.49,.29)) (overall_model <- summary(lm(Literacy~Television+Newspapers, data=data))) cor(data)
lm.x <- lm(Literacy~Newspapers, data=data)
#correlation between both independent variables(newspaper and tv's) lm.newspaper_tv <- lm(X~T, data=data)
#part of newspapers that is not correlated with TV's.... residuals(lm.newspaper_tv)
cor(residuals(lm.newspaper_tv),data$Y)^2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.