# remember, you might need to install packages
library(psych) # for the describe() command
library(expss) # for the cross_cases() commandBasic Statistics Homework
Load Libraries
Load Data
# Will need to update this for the homework, use MYDATA
d <- read.csv(file="Data/mydata.csv", header=T)
names(d)[1] "gender" "age" "swb" "mindful" "belong" "socmeduse"
Univariate Plots: Histograms & Tables
table(d$gender)
f m nb
1582 543 31
table(d$age)
1 between 18 and 25 2 between 26 and 35 3 between 36 and 45 4 over 45
1985 115 38 18
# for the table use categorical and the hist for continuous
hist(d$swb)hist(d$mindful)hist(d$belong)hist(d$socmeduse)Univariate Normality
Check skew and kurtosis.
describe(d) vars n mean sd median trimmed mad min max range skew
gender* 1 2156 1.28 0.48 1.00 1.21 0.00 1.00 3 2.00 1.36
age* 2 2156 1.11 0.43 1.00 1.00 0.00 1.00 4 3.00 4.42
swb 3 2156 4.43 1.33 4.50 4.49 1.48 1.00 7 6.00 -0.35
mindful 4 2156 3.72 0.84 3.73 3.72 0.79 1.13 6 4.87 -0.04
belong 5 2156 3.21 0.61 3.20 3.23 0.59 1.30 5 3.70 -0.27
socmeduse 6 2156 34.26 8.59 35.00 34.52 7.41 11.00 55 44.00 -0.30
kurtosis se
gender* 0.71 0.01
age* 21.12 0.01
swb -0.50 0.03
mindful -0.15 0.02
belong -0.09 0.01
socmeduse 0.20 0.19
# cut offs for skew and kurtosis ranges from -2 to 2 Bivariate Plots
Crosstabs
cross_cases(d, gender, age)| age | ||||
|---|---|---|---|---|
| 1 between 18 and 25 | 2 between 26 and 35 | 3 between 36 and 45 | 4 over 45 | |
| gender | ||||
| f | 1473 | 69 | 28 | 12 |
| m | 482 | 46 | 9 | 6 |
| nb | 30 | 1 | ||
| #Total cases | 1985 | 115 | 38 | 18 |
Scatterplots
plot(d$swb, d$mindful,
main="Scatterplot of Satisfaction with Life and Mindfulness",
xlab = " Satisfaction with Life",
ylab = "Mindfulness")plot(d$swb, d$belong,
main="Scatterplot of Satisfaction with Life and Need to Belong",
xlab = " Satisfaction with Life",
ylab = "Need to Belong")plot(d$swb, d$socmeduse,
main="Scatterplot of Satisfaction with Life and Social Media Use",
xlab = " Satisfaction with Life",
ylab = "Social Media Use")plot(d$mindful, d$belong,
main="Mindfulness and Need to Belong",
xlab = "Mindfulness",
ylab = "Need to Belong")plot(d$mindful, d$socmeduse,
main="Scatterplot of Mindfulness and Social Media Use ",
xlab = "Mindfulness",
ylab = "Social Media Use")plot(d$belong, d$socmeduse,
main="Scatterplot of Need to Belong and Social Media Use ",
xlab = "Need to Belong",
ylab = "Social Media Use")#need code for all continuous 1-2,1-3,1-4, 2-3,2-4, 3-4Boxplots
# remember that continuous variable comes first, CONTINUOUS ~ CATEGORICAL
boxplot(data=d, socmeduse~gender,
main="Boxplot of Social Media Use and Gender ",
xlab = " Gender ",
ylab = "Social Media Use")boxplot(data=d, belong~age,
main="Boxplot of Need to Belong and Age",
xlab = "Age ",
ylab = "Need to Belong")Write-Up
I reviewed plots and descriptive statistics for my six chosen variables; gender, age, satisfaction with life, mindfulness, need to belong, and social media use. All four of my continuous variables; satisfaction with life, mindfulness, need to belong, and social media use had skew and kurtosis within the accepted range (-2/+2).