Exemplo n.º 1
0
    def compute_stats(self):
        ''' Compute several statistics and metrics. '''

        dataset = self.dataset

        # Inter-scale correlation matrix
        self.y_corrs = np.corrcoef(dataset.y, rowvar=0)

        if self.key is not None:
            # Cronbach's alpha
            self.alpha = stats.cronbach_alpha(dataset.X.values, self.key)

            # Predicted scores
            self.predicted_y = np.dot(dataset.X, self.key)

            # R-squared
            self.r_squared = (np.corrcoef(dataset.y,
                                          self.predicted_y,
                                          rowvar=0)[0:self.n_y,
                                                    self.n_y::]**2).diagonal()

            # Number of items per scale
            self.n_items_per_scale = np.sum(np.abs(self.key), 0)

            # Correlation matrix for predicted scores
            self.predicted_y_corrs = np.corrcoef(self.predicted_y, rowvar=0)
Exemplo n.º 2
0
 def test_cronbach_alpha(self):
     scores = np.array([[3, 4, 3, 3], [5, 4, 4, 3], [1, 3, 4, 5],
                        [4, 5, 4, 2], [1, 3, 4, 1], [3, 3, 3, 1],
                        [3, 4, 5, 1], [1, 2, 1, 3]])
     # Test three scales: one is sum of all items; second has reverse keyed items;
     # third omits an item. Correct alphas from the psych package in R. Values for
     # second and third examples are nonsensical, but that's okay for testing.
     alphas = gs.cronbach_alpha(
         scores[:, :4],
         np.array([[1, 1, 1, 1], [1, -1, -1, 1], [0, -1, 1, 0]]).T)
     npt.assert_array_almost_equal(alphas, np.array([0.409, -0.461,
                                                     -3.333]))
Exemplo n.º 3
0
 def test_cronbach_alpha(self):
     scores = np.array([[ 3,4,3,3],
               [ 5,4,4,3],
               [ 1,3,4,5], 
               [ 4,5,4,2],
               [ 1,3,4,1],
               [ 3,3,3,1],
               [ 3,4,5,1],
               [ 1,2,1,3]])
     # Test three scales: one is sum of all items; second has reverse keyed items;
     # third omits an item. Correct alphas from the psych package in R. Values for 
     # second and third examples are nonsensical, but that's okay for testing.
     alphas = gs.cronbach_alpha(scores[:,:4], np.array([
       [1,1,1,1],
       [1,-1,-1,1],
       [0,-1,1,0]]).T)
     npt.assert_array_almost_equal(alphas, np.array([0.409, -0.461, -3.333]))
Exemplo n.º 4
0
    def compute_stats(self):
        ''' Compute several statistics and metrics. '''

        dataset = self.dataset

        # Inter-scale correlation matrix
        self.y_corrs = np.corrcoef(dataset.y, rowvar=0)

        if self.key is not None:
            # Cronbach's alpha
            self.alpha = stats.cronbach_alpha(dataset.X.values, self.key)

            # Predicted scores
            self.predicted_y = np.dot(dataset.X, self.key)

            # R-squared
            self.r_squared = (np.corrcoef(dataset.y, self.predicted_y, rowvar=0)[0:self.n_y, self.n_y::] ** 2).diagonal()

            # Number of items per scale
            self.n_items_per_scale = np.sum(np.abs(self.key), 0)

            # Correlation matrix for predicted scores
            self.predicted_y_corrs = np.corrcoef(self.predicted_y, rowvar=0)