Basic Statistics Lab

Load Libraries

# remember, you might need to install packages

library(psych) # for the describe() command
library(expss) # for the cross_cases() command

Load Data

# WILL NEED TO UPDATE THIS FOR THE HW! USE MYDATA
d <- read.csv(file="Data/mydata.csv", header=T)
names(d)
[1] "gender"    "sibling"   "npi"       "belong"    "socmeduse" "stress"   

Univariate Plots: Histograms & Tables

table(d$gender)

   f    m   nb 
2313  785   54 
table(d$sibling)

at least one sibling           only child 
                2851                  301 
hist(d$npi)

hist(d$belong)

hist(d$socmeduse)

hist(d$stress)

Univariate Normality

Check skew and kurtosis.

describe(d)
          vars    n  mean   sd median trimmed  mad  min  max range  skew
gender*      1 3152  1.28 0.49   1.00    1.21 0.00  1.0  3.0   2.0  1.40
sibling*     2 3152  1.10 0.29   1.00    1.00 0.00  1.0  2.0   1.0  2.75
npi          3 3152  0.28 0.31   0.15    0.24 0.23  0.0  1.0   1.0  0.94
belong       4 3152  3.23 0.60   3.30    3.25 0.59  1.3  5.0   3.7 -0.26
socmeduse    5 3152 34.46 8.58  35.00   34.73 7.41 11.0 55.0  44.0 -0.31
stress       6 3152  3.05 0.60   3.00    3.05 0.59  1.3  4.7   3.4  0.03
          kurtosis   se
gender*       0.89 0.01
sibling*      5.57 0.01
npi          -0.68 0.01
belong       -0.12 0.01
socmeduse     0.27 0.15
stress       -0.17 0.01

Bivariate Plots

Crosstabs

cross_cases(d, gender, sibling)
 sibling 
 at least one sibling   only child 
 gender 
   f  2097 216
   m  705 80
   nb  49 5
   #Total cases  2851 301

Scatterplots

plot(d$npi, d$belong,
    main="Scatterplot of Narcissism and Need to Belong",
    xlab = "Narcissism",
    ylab = "Need to Belong")

plot(d$npi, d$socmeduse,
    main="Scatterplot of Narcissism and Social Media Use",
    xlab = "Narcissim",
    ylab = "Social Media Use")

plot(d$npi, d$stress,
    main="Scatterplot of Narcissim and Stress",
    xlab = "Narcissism",
    ylab = "Stress")

plot(d$belong, d$socmeduse,
    main="Scatterplot of Need to Belong and Social Media Use",
    xlab = "Need to Belong",
    ylab = "Social Media Use")

plot(d$belong, d$stress,
    main="Scatterplot of Need to Belong and Stress",
    xlab = "Need to Belong",
    ylab = "Stress")

plot(d$socmeduse, d$stress,
    main="Scatterplot of Social Media Use and Stress",
    xlab = "Social Media Use",
    ylab = "Stress")

Boxplots

# REMEMBER THAT CONTINUOUS VARIABLE COMES FIRST, CONTINUOUS~CATEGORICAL
boxplot(data=d, npi~gender,
        main="Boxplot of Narcissism and Gender",
        xlab = "Gender",
        ylab = "Narcissism")

boxplot(data=d, npi~sibling,
        main="Boxplot of Narcissism and Number of Siblings",
        xlab = "Siblings",
        ylab = "Narcissism")

Write-Up

We reviewed plots and descriptive statistics for our six chosen variables. All four of our continuous variables had skew and kurtosis within the accepted range (-2/+2).