Régressions linéaires

Régression linéaire du taux d’abstention en fonction du taux de chômage, pourcentage de logements vacants, pourcentage de logements principales et pourcentage de logements secondaires.

Par département

res <- lm(tab[,2]~tab[,3]+tab[,4]+tab[,5]+tab[,6] -1)
summary(res)
capture.output(summary(res), file = "test_departement.txt")

Par commune

chomage_par_commune <- read.csv2("chomage_par_commune.csv",sep=";",header=TRUE)
chomage_par_commune <- chomage_par_commune[,-1]

#####################################################################################
abstention_par_commune <- read.csv2("abstention_par_commune.csv",sep=";",header=TRUE)
abstention_par_commune <- abstention_par_commune[,-1]

#####################################################################################
logement_par_commune <- read.csv2("logement_par_commune.csv",sep=";",header=TRUE)
logement_par_commune <- logement_par_commune[,-1]


tab2 <- merge(abstention_par_commune,chomage_par_commune[,c(1,5)],by=intersect(names(abstention_par_commune),names(chomage_par_commune)))

tab2 <- merge(tab2,logement_par_commune[,c(1,7,8,9)],by=intersect(names(tab2),names(logement_par_commune)))

# but : remplacer les NA par la moyenne de la colonne pour le taux de chomage
chom2 <- tab2[,3]
remplacant2 <- mean(chom2[-which(is.na(chom2))])
chom2[which(is.na(chom2))] <- rep(remplacant2, length(which(is.na(chom2))))

# après avoir remplacer les NA, on remplace la colonne dans la table
tab2[,3] <- chom2

# Régression par commune

res2 <- lm(tab2[,2]~tab2[,3]+tab2[,4]+tab2[,5]+tab2[,6] -1)
summary(res2)
capture.output(summary(res2), file = "test_commune.txt")