This file contains hidden or 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
| library("gmm") | |
| set.seed(1234567) | |
| N <- 1000 | |
| dd <- data.frame(id = 1:N) | |
| dd$u <- rnorm(N) | |
| dd$x <- 1 + rnorm(N) | |
| dd$y <- 1 + dd$x + dd$u | |
| m1 <- lm(y ~ x, data = dd) | |
| m2 <- gmm(y ~ x, x = ~ x, wmatrix = "ident", data = dd) | |
| coefficients(m1) |
This file contains hidden or 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
| mc <- lm(formula = SBR ~ Age, data = ch) | |
| m1 <- lm(formula = SBR ~ Age, data = subset(ch, Sex == "M")) | |
| m2 <- lm(formula = SBR ~ Age, data = subset(ch, Sex == "F")) | |
| sc <- sum(mc$residuals^2) | |
| s1 <- sum(m1$residuals^2) | |
| s2 <- sum(m2$residuals^2) | |
| k <- 2 | |
| # Test statistic | |
| fstat <- (sc - (s1 + s2)) / k / (s1 + s2) * (length(mc$residuals) - 2*k) | |
| fstat |
This file contains hidden or 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
| library("strucchange") | |
| library("lubridate") | |
| set.seed(1234567) | |
| N <- 60 | |
| df <- data.frame(id = 1:N) | |
| df$date <- seq(as.Date("2013-07-01"), by = "day", along = df$id) | |
| df$date2 <- difftime(df$date, ymd("2013-07-01"), units = "day") | |
| df$date3 <- difftime(df$date, ymd("2013-08-01"), units = "day") | |
| difftime(ymd("2013-08-01"), ymd("2013-07-01"), units = "day") |
This file contains hidden or 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
| library("lubridate") | |
| library("strucchange") | |
| library("segmented") | |
| set.seed(1234567) | |
| N <- 60 | |
| df <- data.frame(id = 1:N) | |
| df$date <- seq(as.Date("2013-07-01"), by = "day", along = df$id) | |
| df$date2 <- difftime(df$date, ymd("2013-07-01"), units = "day") | |
| df$date3 <- ifelse(df$date > as.Date("2013-08-01"), difftime(df$date, ymd("2013-08-01"), units = "day"), 0) |
This file contains hidden or 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
| N <- 100 | |
| fk <- data.frame(id = 1:N) | |
| fk$x <- 1 + rnorm(N) | |
| fk$y1 <- 1 + fk$x + rnorm(N) | |
| fk$y2 <- 2 + fk$x + rnorm(N) | |
| ggplot(data = fk, aes(x = x, y = y1)) + | |
| geom_line(color = "#339966", size = 2) + | |
| geom_line(aes(y = y2), color = "#990000", size = 2) + | |
| theme_tufte() |
This file contains hidden or 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
| categorie <- function(x, breaks) { | |
| c <- length(breaks) | |
| temp <- 0 | |
| temp[x <= breaks[1]] <- 1 | |
| for (k in 1:c-1) { | |
| temp[x > breaks[k] & x <= breaks[k+1]] <- k+1 | |
| } | |
| temp[x > breaks[c]] <- c + 1 | |
| return(temp) | |
| } |
This file contains hidden or 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
| ISO | country | |
|---|---|---|
| ABW | Aruba | |
| AFG | Afghanistan | |
| AGO | Angola | |
| AIA | Anguilla | |
| ALA | Åland Islands | |
| ALB | Albania | |
| AND | Andorra | |
| ARE | United Arab Emirates | |
| ARG | Argentina |
This file contains hidden or 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
| code | country | |
|---|---|---|
| AFG | Afghanistan | |
| RSA | South Africa | |
| ALB | Albania | |
| ALG | Algeria | |
| GER | Germany | |
| AND | Andorra | |
| ANG | Angola | |
| ANT | Antigua and Barbuda | |
| AHO | Netherlands Antilles |
This file contains hidden or 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
| library("dplyr") | |
| set.seed(123) | |
| N <- 100 | |
| df <- data.frame(id = 1:N, x = rnorm(N)) | |
| df$x[runif(N) < .1] <- NA | |
| table(is.na(tdf$x)) | |
| tdf <- tbl_df(df) | |
| out <- arrange(tdf, desc(x)) | |
| out2 <- tdf[order(tdf$x, decreasing = TRUE),] |
This file contains hidden or 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
| library("ggplot2") | |
| set.seed(1234) | |
| N <- 100 | |
| df <- data.frame(i = 1:N, x = rnorm(N)) | |
| df$y <- 1 + df$x + rnorm(N) | |
| df$z <- (runif(N) < .3) | |
| pdf("output/test.pdf") | |
| ggplot(data = df, aes(x = x, y = y, shape = z)) + | |
| geom_point(size = 3) + |
OlderNewer