Last active
October 31, 2016 18:16
-
-
Save gagarine/27199bd8aea08ef0ce404a5f61771a8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# TP1 | |
# Simon Perdrisat & Amantin Baruti- 2016 | |
# Replication table 4b p 494 of "ECONOMIC AND POLITICAL EXPLANATIONS OF HUMAN RIGHTS VIOLATIONS" by NEIL J. MITCHELL and JAMES M. McCORMICK | |
# | |
# Note: I'm using = instead of <- | |
# http://blog.revolutionanalytics.com/2008/12/use-equals-or-arrow-for-assignment.html | |
# | |
## | |
dataset = | |
read.table( | |
"/Users/simon/Documents/school/uni/cours uni/année 2 semestre 1/Méthodes appliquées au domaine international/tp1/Mitchell_et_al_1984_with_edu_index.csv", | |
header = TRUE, | |
sep = ",", | |
quote = "", | |
na.strings = "NA", | |
dec = ".", | |
strip.white = TRUE | |
) | |
# Remove duplicate observation | |
dataset = dataset[!duplicated(dataset[, c("CCode")]), ] | |
# Copy the torture_score in a new col | |
dataset$torture_score_new = dataset$torture_score | |
# Add a level to the factor torture_score_new so we can t | |
levels(dataset$torture_score_new) = c(levels(dataset$torture_score_new), "rarely or never") | |
### Recode and order variables | |
# Torture score | |
dataset$torture_score_new[dataset$torture_score == "rarely"] = "rarely or never" | |
dataset$torture_score_new[dataset$torture_score == "never"] = "rarely or never" | |
dataset$torture_score_new = droplevels(dataset$torture_score_new) | |
dataset$torture_score = ordered(dataset$torture_score, levels =c("never", "rarely", "sometimes", "often", "very often")) | |
dataset$torture_score_new = ordered(dataset$torture_score_new, levels =c("rarely or never", "sometimes", "often", "very often")) | |
### Text | |
dataset$colonialExperience = ifelse(dataset$british_colony == "yes", | |
"Former British Colony", | |
"Other Colonial Background") | |
## Use of torture | |
print("---- Use of torture ----") | |
useOfTortureByColonialExperience = table(dataset$torture_score_new, dataset$colonialExperience) | |
# Get the number of observation | |
addmargins(useOfTortureByColonialExperience,1); | |
# Contingency table with conditional probability | |
useOfTortureByColonialExperienceProp = prop.table(useOfTortureByColonialExperience,2) | |
print(addmargins(useOfTortureByColonialExperienceProp*100,1),3) | |
## TEST | |
chisq.test(useOfTortureByColonialExperience) | |
cramersV(useOfTortureByColonialExperience) | |
## SANS Asie pacifique | |
print("---- Use of torture WITOUTH ASIA----") | |
datasetWithoutAsia = subset(dataset, dataset$continent != "Asia") | |
useOfTortureByColonialExperienceWithoutAsia = table(datasetWithoutAsia$torture_score_new, datasetWithoutAsia$colonialExperience) | |
# Get the number of observation | |
addmargins(useOfTortureByColonialExperienceWithoutAsia,1); | |
# Contingency table with conditional probability | |
useOfTortureByColonialExperiencePropWithoutAsia = prop.table(useOfTortureByColonialExperienceWithoutAsia,2) | |
print(addmargins(useOfTortureByColonialExperiencePropWithoutAsia*100,1),3) | |
## TEST | |
chisq.test(useOfTortureByColonialExperienceWithoutAsia) | |
cramersV(useOfTortureByColonialExperienceWithoutAsia) | |
### ---- | |
# With education index | |
### --- | |
boxplot(dataset$EducationIndex ~ dataset$torture_score, | |
xlab="Use of Torture", | |
ylab='Education Index', | |
main="Use of Torture by Education Index") | |
# ANOVA TEST | |
oneway.test(dataset$EducationIndex ~ dataset$torture_score) | |
## Try to do some kind of regression with those ugly data | |
dataset$torture_score_int[dataset$torture_score == "never"] = 0 | |
dataset$torture_score_int[dataset$torture_score == "rarely"] = 10 | |
dataset$torture_score_int[dataset$torture_score == "somtimes"] = 55 | |
dataset$torture_score_int[dataset$torture_score == "often"] = 500 | |
dataset$torture_score_int[dataset$torture_score == "very often"] = 1000 | |
lm.out = lm(dataset$EducationIndex ~ dataset$torture_score_int) | |
oneway.test(dataset$EducationIndex ~ dataset$torture_score_int) | |
plot(dataset$torture_score_int, dataset$EducationIndex, xlab="Use of Torture", ylab="Education Index") | |
abline(lm.out, col="red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment