1 Introduction

Column 1:GRPID Group Identifier Column 2:JOBSAT Job Satisfaction (DV) Column 3:COHES Cohesion Column 4:POSAFF Positive Affect Column 5:PAY Pay Column 6:NEGLEAD Negative Leadership Column 7:WLOAD Workload Column 8:TASKSIG Task Significance Column 9:PHYSEN Physical Environment

2 Data management

In this section, we load the data set, select variables of interest, and examine the first 6 lines of the data frame object.

# load the data from the package
data(klein2000, package="multilevel")

3 Problem 01

#Explore how much variance in job satisfaction can be attributed to their difference in pay (ignoring the other predictors) among individuals belonging to the same group.

# save a copy with only selected variables
dta <- klein2000[, c("GRPID", "JOBSAT", "PAY", "NEGLEAD")]
str(dta)
'data.frame':   750 obs. of  4 variables:
 $ GRPID  : num  1 1 1 1 1 1 1 1 1 1 ...
 $ JOBSAT : num  -1.717 0.237 -2.098 2.933 0.145 ...
 $ PAY    : num  0.511 -1.967 -2.749 1.355 -1.185 ...
 $ NEGLEAD: num  0.3128 -1.9047 -0.1243 -1.2984 0.0646 ...
# show first 6 lines
head(dta)
  GRPID    JOBSAT       PAY    NEGLEAD
1     1 -1.717411  0.510543  0.3127974
2     1  0.237316 -1.967199 -1.9046836
3     1 -2.097958 -2.748838 -0.1243344
4     1  2.932552  1.355283 -1.2983974
5     1  0.144981 -1.185332  0.0646287
6     1 -1.995481 -0.399117  0.3870573

3.1 Visualization 01

We draw a scatter diagram of the job satisfaction against pay and add the regression line.

ggplot(dta, aes(PAY, JOBSAT))+
  geom_point(alpha=.5)+
  stat_smooth(method='lm', formula=y~x, se=TRUE)+
  labs(x="Pay",
       y="Job Satisfaction")+
  theme_minimal()

3.2 Model 01

m0 <- lm(JOBSAT ~1+ PAY, data=dta)
summary(m0)

Call:
lm(formula = JOBSAT ~ 1 + PAY, data = dta)

Residuals:
   Min     1Q Median     3Q    Max 
-6.590 -1.474  0.096  1.442  9.573 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.0382     0.0843    0.45     0.65
PAY           0.9037     0.0837   10.80   <2e-16

Residual standard error: 2.31 on 748 degrees of freedom
Multiple R-squared:  0.135, Adjusted R-squared:  0.134 
F-statistic:  117 on 1 and 748 DF,  p-value: <2e-16

每個人的平均工作滿意度為0.0382,每增加1單位薪資,工作滿意度會增加0.9037

4 Problem 02

#Determine how much variation in job satisfaction between groups can be attributed to differences in (group-level) negative leadership between groups.

library(tidyverse)
klein2000 %>% group_by(GRPID) %>% mutate(mneglead=mean(NEGLEAD)) -> dta
# save a copy with only selected variables
dta <- klein2000[, c("GRPID", "JOBSAT", "PAY", "NEGLEAD")]
str(dta)
'data.frame':   750 obs. of  4 variables:
 $ GRPID  : num  1 1 1 1 1 1 1 1 1 1 ...
 $ JOBSAT : num  -1.717 0.237 -2.098 2.933 0.145 ...
 $ PAY    : num  0.511 -1.967 -2.749 1.355 -1.185 ...
 $ NEGLEAD: num  0.3128 -1.9047 -0.1243 -1.2984 0.0646 ...
# show first 6 lines
head(dta)
  GRPID    JOBSAT       PAY    NEGLEAD
1     1 -1.717411  0.510543  0.3127974
2     1  0.237316 -1.967199 -1.9046836
3     1 -2.097958 -2.748838 -0.1243344
4     1  2.932552  1.355283 -1.2983974
5     1  0.144981 -1.185332  0.0646287
6     1 -1.995481 -0.399117  0.3870573

4.1 Visualization 02

We draw a scatter diagram of the job satisfaction against pay and add the regression line by group identifier.

ggplot(dta, aes(PAY, JOBSAT, group=GRPID))+
  geom_point(alpha=.5)+
  stat_smooth(method='lm', formula=y~x, se=FALSE, 
              col=1, size=rel(.5))+
  labs(x="Pay",
       y="Job Satisfaction",
       subtitle='Group Identifier')+
  theme_minimal()

4.2 Model 02

m1<-lme4::lmer(JOBSAT ~1+ PAY+ (1|GRPID), data=dta)
summary(m1)
Linear mixed model fit by REML ['lmerMod']
Formula: JOBSAT ~ 1 + PAY + (1 | GRPID)
   Data: dta

REML criterion at convergence: 3327.1

Scaled residuals: 
   Min     1Q Median     3Q    Max 
-2.919 -0.651  0.034  0.643  3.637 

Random effects:
 Groups   Name        Variance Std.Dev.
 GRPID    (Intercept) 0.835    0.914   
 Residual             4.505    2.123   
Number of obs: 750, groups:  GRPID, 50

Fixed effects:
            Estimate Std. Error t value
(Intercept)   0.0360     0.1507    0.24
PAY           0.9544     0.0785   12.16

Correlation of Fixed Effects:
    (Intr)
PAY -0.022

在Groups層次下,每個人的平均工作滿意度為0.036,每增加1單位薪資,工作滿意度會增加0.9544