To begin, the appropriate R packages that will do the work must be called forward. Also, it’s good bractice to establish a working directory where data can be accessed and results can be scored.
Of course, we need to call on the Firestone dat (fs_return_cov.csv), establish it as a data frame and make the variables easily accessible.
fs<- as.data.frame(read.csv("fs_return_cov.csv", sep=",", header=TRUE)) # reading in the data file
attach(fs)
We are simply validating that the values of v088 are all >0 and that the mean of v088>0.
fs %>% check_that(
min(v088) > 0
, max(v088) < 6
, mean(v088) > 0
) %>% summary()
## rule items passes fails nNA error warning expression
## 1 V1 1 1 0 0 FALSE FALSE min(v088) > 0
## 2 V2 1 1 0 0 FALSE FALSE max(v088) < 6
## 3 V3 1 1 0 0 FALSE FALSE mean(v088) > 0
recoding some variablers
Marital = recode(Marital, " 2= 'Single, never married'; 1='Married';
3='Widowed'; 4='Separated'; 5='Divorced'; ",
as.numeric.result=FALSE, as.factor.result=TRUE)
table(Marital, Gender)
## Gender
## Marital Female Male
## Divorced 7 5
## Married 75 267
## Separated 2 9
## Single, never married 35 46
## Widowed 5 1
a correlation network plot
library(corrr)
fs[,c(2,4:16)] %>% correlate() %>% network_plot(min_cor = .1,
colors = c("red", "green"), legend = TRUE)
fs[,c(2,4:16)] %>% correlate() %>% rplot(colors= c("red", "green"),
shape=16)
Now a scatter plot between willingness to return and ‘all services were done correctly’ with the dots jittered so that the density is shown.
The regression line is plotted in red and the regression equation and R2 are provided.
library(ggplot2)
library(ggpmisc)
p <- ggplot(data = fs, aes(x = v075, y = v088)) +
geom_smooth(method = "lm", se=FALSE, color="red" ) +
stat_poly_eq(formula = y~x,
eq.with.lhs = "italic(hat(y))~`=`~",
aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
parse = TRUE) +
geom_jitter(width=0.25, height=0.5)
p