8.4 Exercises#

1️⃣ Exploratory and confirmatory model comparison#

Goal: Assess model fit and compare an exploratory and confirmatory model version of the familiness.rda dataset on Stud.IP.
In this dataset, you’ll find data on 11 Likert items (6 points scale) for three dimensions of family involvement that characterize family businesses (“Ownership, Management, Control”= OMC, “Transgenerational Orientation”=TGO, “Family Business Involvement”= FBI) and two explanatory variables (the age of the firm and the size of the firm).

Instructions:

  1. Load the familiness.rda dataset and inspect it.

  2. Fit an exploratory 1-dimensional GPCM and a 3-dimensional GPCM. Is the 3D solution better?

  3. Fit a confirmatory model with no item cross-loading to other dimensions (so OMC only loads on OMC) etc. Would you say that the hypothesized model is worse than the exploratory model?

# Import packages
import numpy as np
import pandas as pd
from rpy2 import robjects as ro
from rpy2.robjects import pandas2ri, numpy2ri
from rpy2.robjects.packages import importr
import matplotlib.pyplot as plt
import seaborn as sns


# Miscellaneous
pandas2ri.activate()
numpy2ri.activate()
ro.r('set.seed(123)')
%load_ext rpy2.ipython


# R imports
importr('mirt')      # Quick fix if future (mirt dependency) is not installed automatically: ro.r('install.packages("future", repos="https://cloud.r-project.org")')
importr('MPsychoR')
importr('eRm')
importr('ltm')
importr('base')
importr('Gifi')

print("\n\n" + "Python & R packages imported successfully.")

# TODO Import dataset in R
ro.r("data(familiness.rda)")

print("\n\n" + "Dataset imported successfully.")

# TODO Inspect the data


# TODO Fit a 1D GPCM and a 3D GPCM
ro.r('modpcm1 <- mirt(familiness, model = ..., itemtype = "gpcm")')
ro.r('modpcm3 <- mirt(familiness, model = ..., itemtype = "gpcm", method = "MHRM")')



# TODO Assess model fit
print(ro.r('itemfit(...)'))
print(ro.r('itemfit(...)'))

print(ro.r('summary(...)'))

# TODO Fit a confirmatory model
ro.r('... <- "'
      'OMC = 1-4\n'
      'TGO = 5,6,7\n'
      'FBI = 8-11\n'
      'COV = OMC*TGO*FBI"')

ro.r("... <- mirt(..., ..., itemtype = 'gpcm', method = 'MHRM')")


# TODO Assess model fit
print(ro.r('summary(...)'))
print(ro.r('summary(...)'))

print(ro.r('itemfit(...)'))


# TODO Compare exploratory and confirmatory model
print(ro.r('anova(...)'))