예제 #1
0
    def test_asymptotic_behaviour(self):
        dataset = fetch_gait()
        fd = dataset['data'].coordinates[1]
        fd1 = fd[0:5]
        fd2 = fd[5:10]
        fd3 = fd[10:15]

        n_little_sim = 10

        sims = np.array([oneway_anova(
            fd1, fd2, fd3, n_reps=500, random_state=i)[1]
            for i in range(n_little_sim)])
        little_sim = np.mean(sims)
        big_sim = oneway_anova(fd1, fd2, fd3, n_reps=2000, random_state=100)[1]
        self.assertAlmostEqual(little_sim, big_sim, delta=0.05)

        fd = fd.to_basis(Fourier(n_basis=5))
        fd1 = fd[0:5]
        fd2 = fd[5:10]

        sims = np.array([oneway_anova(
            fd1, fd2, n_reps=500, random_state=i)[1]
            for i in range(n_little_sim)])
        little_sim = np.mean(sims)
        big_sim = oneway_anova(fd1, fd2, n_reps=2000, random_state=100)[1]
        self.assertAlmostEqual(little_sim, big_sim, delta=0.05)
예제 #2
0
 def test_oneway_anova_args(self):
     with self.assertRaises(ValueError):
         oneway_anova()
     with self.assertRaises(ValueError):
         oneway_anova(1, '2')
     with self.assertRaises(ValueError):
         oneway_anova(FDataGrid([0]), n_reps=-2)
예제 #3
0
                            stop=stop)
fd2 = make_gaussian_process(n_samples,
                            mean=m2,
                            cov=cov,
                            n_features=n_features,
                            random_state=2,
                            start=start,
                            stop=stop)
fd3 = make_gaussian_process(n_samples,
                            mean=m3,
                            cov=cov,
                            n_features=n_features,
                            random_state=3,
                            start=start,
                            stop=stop)
stat, p_val = oneway_anova(fd1, fd2, fd3, random_state=4)
print("Statistic: {:.3f}".format(stat))
print("p-value: {:.3f}".format(p_val))

##########################################################################
# In the following, the same process will be followed incrementing sigma
# value, this way the differences between the averages of each group will be
# lower and the p-values will increase (the null hypothesis will be harder to
# refuse).

##########################################################################
# Plot for :math:`\sigma^2 = 0.1`:
sigma2 = 0.1
cov = WhiteNoise(variance=sigma2)

fd1 = make_gaussian_process(n_samples,
예제 #4
0
fd_hip3 = fd_hip[26:39]
fd_hip.plot(group=[0 if i < 13 else 1 if i < 26 else 39 for i in range(39)])

means = [fd_hip1.mean(), fd_hip2.mean(), fd_hip3.mean()]
fd_means = skfda.concatenate(means)
fig = fd_means.plot()

###############################################################################
# At this point is time to perform the *ANOVA* test. This functionality is
# implemented in the function :func:`~skfda.inference.anova.oneway_anova`. As
# it consists in an asymptotic method it is possible to set the number of
# simulations necessary to approximate the result of the statistic. It is
# possible to set the :math:`p` of the :math:`L_p` norm used in the
# calculations (defaults 2).

v_n, p_val = oneway_anova(fd_hip1, fd_hip2, fd_hip3)

################################################################################
# The function returns first the statistic :func:`~skfda.inference.anova
# .v_sample_stat` used to measure the variability between groups,
# second the *p-value* of the test . For further information visit
# :func:`~skfda.inference.anova.oneway_anova` and [1].

print('Statistic: ', v_n)
print('p-value: ', p_val)

################################################################################
# This was the simplest way to call this function. Let's see another example,
# this time using knee angles, this time with data in basis representation.
fig = fd_knee.plot()