Last active
July 4, 2018 13:48
-
-
Save gagarine/b25aea385f741fff8e0492ff50878dfd to your computer and use it in GitHub Desktop.
survey.r
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
### Packages | |
install.packages(c( "rstudioapi", "corrplot")) | |
suppressWarnings( | |
suppressMessages({ | |
library(rstudioapi) | |
library(readr) | |
library(psych) | |
library(corrplot) | |
}) | |
) | |
### Setup | |
current_path = getActiveDocumentContext()$path | |
setwd(dirname(current_path )) | |
print( getwd() ) | |
# setup PDF output (multiple page) | |
pdf('survey.plot.pdf', paper='a4') | |
# Load data in a dataframe | |
dataset = read_delim("survey.data.csv", ";", locale = locale(), trim_ws = TRUE) | |
# Questions, used for graph title | |
questions = c( | |
firstheard = 'When did you first hear about Bitcoin?', | |
DateInvolved = 'Since when are you involved in Bitcoin?', | |
involvedStill = 'Are you still involved in Bitcoin?', | |
stopBeeingInvolved = 'When did you stop being involved in bitcoin?', | |
involvedBecause_SQ1 = 'You got invovled in bitcoin because of its techical aspects.', | |
involvedBecause_SQ2 = 'You got invovled in bitcoin because of its political aspect.', | |
involvedBecause_SQ3 = 'You got invovled in bitcoin to make money.', | |
involvedBecause_SQ5 = 'You got invovled in bitcoin because you share the ideology of the project', | |
todayInvolvedReason_SQ1 = 'Today you are involved in bitcoin because bitcoin can change the society', | |
todayInvolvedReason_SQ2 = 'Today you are involved in bitcoin because you are interested in the bitcoin technology', | |
todayInvolvedReason_SQ3 = 'Today you are involved in bitcoin because it\'s your job or part of your job.', | |
todayInvolvedReason_SQ4 = 'Today you are involved in bitcoin because you are investing in Bitcoin', | |
todayInvolvedReason_SQ5 = 'Today you are involved in bitcoin because you are mining a significant amount of bitcoin', | |
timeInvestedThisYear = 'How many hours of your personal time did you spend per week the last 6 months in the bitcoin project (In average)?', | |
motivationComment = 'Any comments about this section?', | |
libauth_li1 = 'A woman has to have children in order to be fulfilled|A woman can be fulfilled through her professional career', | |
libauth_li2 = 'A woman who does not want to have a child should be allowed to have a free and safe abortion|Abortion should not be allowed in any case', | |
libauth_li3 = 'Children should be taught to obey authority |Children should be encouraged to have an independent judgment', | |
libauth_li4 = 'People who break the law should get stiffer sentences|Stiffer sentences do not contribute to reducing criminality', | |
libauth_li5 = 'Homosexual couples should be able to adopt children|Homosexual couples should not be allowed to adopt children under any circumstances', | |
leftright_lr1 = 'Incomes should be made more equal|We need larger income differences as incentives', | |
leftright_lr2 = 'People should take more responsibility to provide for themselves|The government should take more responsibility to ensure that everyone is provided for', | |
leftright_lr3 = 'People who are unemployed should have to take any job available or lose their unemployment benefits|People who are unemployed should have the right to refuse a job they do not want', | |
leftright_lr4 = 'Competition is good. It stimulates people to work hard and develop new ideas|Competition is harmful. It brings the worst in people', | |
leftright_lr5 = 'The government should decrease taxes significantly and spend much less on social benefits and services|The government should increase taxes significantly and spend much more on social benefits and services', | |
importantActors_SQ1 = 'In your opinion, what are the most important/influential individuals involved in bitcoin (full name or pseudo)? [Most important]', | |
importantActors_SQ4 = 'In your opinion, what are the most important/influential individuals involved in bitcoin (full name or pseudo)? [Second important]', | |
importantActors_SQ1 = 'In your opinion, what are the most important/influential individuals involved in bitcoin (full name or pseudo)? [Third important]', | |
importantActors_SQ1 = 'In your opinion, what are the most important/influential individuals involved in bitcoin (full name or pseudo)? [Fourth important]', | |
culture_SQ1 = 'You are familiar with cyberpunk culture', | |
culture_SQ2 = 'You are familiar with cypherpunk culture', | |
culture_SQ3 = 'The book \'neuromancer\' is an important book', | |
belief_SQ1 = 'We need a decentralized currency/asset.', | |
belief_SQ2 = 'We cannot trust central banks.', | |
belief_SQ3 = 'We cannot trust governments.', | |
belief_SQ4 = 'Cryptocurrencies make central banks obsolete.', | |
belief_SQ5 = 'Cryptocurrencies are a solution to avoid inflation.', | |
belief_SQ6 = 'Privacy protection is an important feature of cryptocurrency.', | |
belief_SQ7 = 'Where access to financial institutions is lacking, cryptocurrency will field the gap.', | |
belief_SQ8 = 'Bitcoin is a digital gold.', | |
belief_SQ9 = 'The government of your country should have the right to keep people under video surveillance in public area.', | |
belief_SQ10 = 'The government of your country should have the right to monitor e-mails and any other information exchanged on the internet.', | |
belief_SQ11 = 'All government information should be publicly available, even if this means a risk to public security.', | |
gender = 'Your gender', | |
country = 'You live in', | |
age = 'Your age', | |
agreeToBeContacted = 'Interested to talk a bit more about this on chat or a call?', | |
feedback = 'Do you want to add a comment or feedback?' | |
) | |
### Factor some cols | |
dataset$country = factor(dataset$country, ordered = FALSE ) | |
dataset$gender = factor(dataset$gender, levels = c('Male', 'Female'), ordered = FALSE ) | |
dataset$agreeToBeContacted = factor(dataset$agreeToBeContacted, levels = c('Yes', 'No'), ordered = FALSE ) | |
dataset$involvedStill = factor(dataset$involvedStill, levels = c('Yes', 'No'), ordered = FALSE ) | |
### Factor likert scale | |
likertLevel = c("Strongly disagree", "Disagree", "Neither agree nor disagree", "Agree", "Strongly agree") | |
likertCols = c( | |
'involvedBecause_SQ1', | |
'involvedBecause_SQ2', | |
'involvedBecause_SQ3', | |
'involvedBecause_SQ5', | |
'todayInvolvedReason_SQ1', | |
'todayInvolvedReason_SQ2', | |
'todayInvolvedReason_SQ3', | |
'todayInvolvedReason_SQ4', | |
'todayInvolvedReason_SQ5', | |
'culture_SQ1', | |
'culture_SQ2', | |
'culture_SQ3', | |
'belief_SQ1', | |
'belief_SQ2', | |
'belief_SQ3', | |
'belief_SQ4', | |
'belief_SQ5', | |
'belief_SQ6', | |
'belief_SQ7', | |
'belief_SQ8', | |
'belief_SQ9', | |
'belief_SQ10', | |
'belief_SQ11' | |
) | |
dataset[likertCols] = lapply(dataset[likertCols], function(x) factor(x, levels = likertLevel, ordered = TRUE )) | |
## Check structure | |
str(dataset, give.attr=FALSE) | |
sapply(dataset, class) | |
### Correlation | |
#correlations = cor(dataset) # ERROR (must be numeric)! | |
#cor.test(dataset[,todayInvolvedReason_SQ4], dataset[,todayInvolvedReason_SQ5]) #ERROR WTF! | |
#corrplot(correlations, method="color", addCoef.col="gray") | |
### Plot all likert | |
for(likertCol in likertCols) { | |
likertCol | |
barplot(prop.table(table(dataset[,likertCol])) * 100, col=gray(0:5 / 5), main = paste(strwrap(paste(likertCol, ':', questions[likertCol]), width = 50), collapse = "\n") ,ylim=c(0,100),ylab="%") | |
} | |
######## | |
plot(dataset$gender, main = questions['gender']) | |
plot(dataset$country, main = questions['country']) | |
plot(dataset$agreeToBeContacted, main = questions['agreeToBeContacted']) | |
barplot(prop.table(table(format(as.Date(dataset$DateInvolved, format="%d/%m/%Y"),"%Y"))), main = questions['DateInvolved']) | |
barplot(prop.table(table(format(as.Date(dataset$firstheard, format="%d/%m/%Y"),"%Y"))), main = questions['firstheard']) | |
barplot(prop.table(table(format(as.Date(dataset$stopBeeingInvolved, format="%d/%m/%Y"),"%Y"))), main = questions['stopBeeingInvolved']) | |
plot(dataset$involvedStill, main = questions['involvedStill']) | |
boxplot(dataset$libauth_li1, | |
dataset$libauth_li2, # inverted | |
dataset$libauth_li3, | |
dataset$libauth_li4, | |
dataset$libauth_li5 # inverted | |
) | |
title("Libauth") | |
boxplot(dataset$leftright_lr1, | |
dataset$leftright_lr2, #right left | |
dataset$leftright_lr3, #right left | |
dataset$leftright_lr4, #right left | |
dataset$leftright_lr5 #right left | |
) | |
title("leftright") | |
# Write the PDF | |
dev.off() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment