r:test_statistici:var-test
Test F sulle varianze (omoschedasticità)
Per controllare l'omoschedasticità di una variabile fra due gruppi, si può effettuare un test F con la funzione var.test():
# usiamo i dati del pacchetto LabRS library(LabRS) data(MYSLID)
var.test(Retribuzione ~ Genere, data = MYSLID)
## F test to compare two variances ## ## data: Retribuzione by Genere ## F = 0.73308, num df = 2076, denom df = 2069, p-value = 1.747e-12 ## alternative hypothesis: true ratio of variances is not equal to 1 ## 95 percent confidence interval: ## 0.6725834 0.7990191 ## sample estimates: ## ratio of variances ## 0.7330828
L'ipotesi nulla è che le varianze siano uguali, ovvero che il loro rapporto sia uguale a 1 (alternative hypothesis: true ratio of variances is not equal to 1).
Nel caso in specie, il rapporto è pari 0,733, e il valore 1 non ricade nell'intervallo di confidenza.
Quindi l'ipotesi nulla va scartata (p = 0): le varianze sono significativamente diverse.
Script di esempio
E' possibile scaricare ed eseguire lo script dell'esempio:
- Es-var-test.R
# usiamo i dati del pacchetto LabRS library(LabRS) data(MYSLID) # test var.test(Retribuzione ~ Genere, data = MYSLID)
r/test_statistici/var-test.txt · Ultima modifica: 11/08/2025 14:40 da Agnese Vardanega
