This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(ggplot2)
library(readr)
overall_usage <- read_csv("overall_usage.csv")
## Parsed with column specification:
## cols(
## cohort = col_character(),
## event_name = col_integer(),
## user_id = col_integer(),
## post_id = col_integer(),
## extra_info = col_integer(),
## time = col_integer(),
## device_type = col_integer(),
## time_started = col_integer()
## )
######## FIGURE 1
ggplot(overall_usage, aes(x= cohort, y =event_name)) + geom_bar(stat = 'identity', aes(fill = cohort)) + coord_cartesian(ylim =c(270000,300000)) + ggtitle('FIGURE 1')
You can also embed plots, for example:
user_activity <- read_csv("user_activity.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_integer(),
## cohort = col_character(),
## event_name = col_character(),
## user_id = col_character(),
## post_id = col_integer(),
## extra_info = col_integer(),
## time = col_integer(),
## device_type = col_integer(),
## time_started = col_integer()
## )
user_activity$cohort = as.factor(user_activity$cohort)
#user_activity$event_name = log(user_activity$event_name)
#######
ggplot(user_activity, aes(event_name)) +geom_density(aes(color = cohort, alpha = .25)) + coord_cartesian(xlim = c(0, 300)) + ggtitle('FIGURE 2')
#+ facet_wrap(~cohort)
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.
ggplot(user_activity, aes(event_name)) +geom_density(aes(color = cohort)) + coord_cartesian(xlim = c(0, 300)) + facet_wrap(~cohort) + ggtitle('FIGURE 3')
#+ facet_wrap(~cohort)
data= read_csv('group_activity.csv')
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_integer(),
## cohort = col_character(),
## event_name = col_character(),
## user_id = col_character(),
## post_id = col_integer(),
## extra_info = col_integer(),
## time = col_integer(),
## device_type = col_integer(),
## time_started = col_integer()
## )
ggplot(data, aes(x=event_name, y = post_id)) + geom_boxplot(aes(fill = event_name)) + facet_wrap(~cohort) + coord_cartesian(ylim=c(0,50)) + ggtitle('FIGURE 4')
library(foreign)
#install.packages('nnet')
library(nnet)
data_full = read_csv('data.csv')
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_integer(),
## cohort = col_character(),
## event_name = col_character(),
## user_id = col_character(),
## post_id = col_character(),
## extra_info = col_character(),
## time = col_datetime(format = ""),
## device_type = col_character(),
## time_started = col_datetime(format = ""),
## device = col_character()
## )
data_sample=data_full[sample(nrow(data_full), nrow(data_full)*.5), ]
test <- multinom(event_name ~ factor(cohort) + factor(extra_info) + factor(device), data = data_sample)
## # weights: 30 (18 variable)
## initial value 934189.579111
## iter 10 value 500468.241879
## iter 20 value 411701.037625
## iter 30 value 386515.856333
## final value 386503.563413
## converged
coef = summary(test)$coefficients
#table(data_sample$extra_info)
graph = data.frame(t(coef))
graph$names = row.names(graph)
graph =graph[c(2:7, 9),1:3]
ggplot(graph, aes(x=names, y=Heart)) + geom_bar(stat = 'identity', aes(fill = names)) + coord_cartesian(ylim = c(-.2,.2)) + ggtitle('FIGURE 5')
ggplot(graph, aes(x=names, y=Whisper.Created)) + geom_bar(stat = 'identity', aes(fill = names))+ coord_cartesian(ylim = c(-.2,.2)) + ggtitle('FIGURE 6')
coef
## (Intercept) factor(cohort)B factor(cohort)C
## Heart -0.9402028 0.03599948 -0.0005164111
## Whisper Created 8.7480892 0.95713441 0.7471708825
## factor(cohort)D factor(cohort)E factor(cohort)F
## Heart -0.126933 -0.01869487 0.00792366
## Whisper Created 1.026889 0.48621474 1.56561709
## factor(extra_info)top-level factor(extra_info)undefined
## Heart 2.991407 0.8671575
## Whisper Created 2.307160 -21.0845206
## factor(device)ios
## Heart -0.1341333
## Whisper Created 1.3001537
z <- summary(test)$coefficients/summary(test)$standard.errors
#z
p <- (1 - pnorm(abs(z), 0, 1)) * 2
p
## (Intercept) factor(cohort)B factor(cohort)C
## Heart 0.1186478 0.0001091292 0.9558588
## Whisper Created 0.0000000 0.1524312638 0.2511411
## factor(cohort)D factor(cohort)E factor(cohort)F
## Heart 0.000000 0.04444419 0.38920563
## Whisper Created 0.133297 0.44188497 0.02700969
## factor(extra_info)top-level factor(extra_info)undefined
## Heart 0.08126519 0.1500756
## Whisper Created 0.13436863 0.0000000
## factor(device)ios
## Heart 0.000000000
## Whisper Created 0.006890041
#p
#test <- multinom(prog2 ~ ses + write, data = ml)