Articles

Affichage des articles du janvier, 2017

delta method using numerical derivative. An example

The main conclusions are : - Use delta method with or without analytic derivative, it does not change anything - Do not use simple resampling using SD - You can use resampling taking into variance-covariance matrix library(car) m1 <- lm(time ~ t1 + t2, data = Transact) result <- deltaMethod(coef(m1), "t1/t2", vcov.=vcov(m1)) rownames(result) <- "Delta method, analytic derivative" library("nlWaldTest") r <- nlConfint(obj = NULL, texts="b[2]/b[3]", level = 0.95, coeff = coef(m1),           Vcov = vcov(m1), df2 = TRUE, x = NULL) result <- rbind(result, t(as.data.frame(c(Estimate=r[, 1], SE=NA, '2.5 %'=r[, 2], '97.5 %'=r[, 3])))) rownames(result)[2] <- "Delta method, analytic derivative in nlWaldTest" ############# Now numerical derivative is used. The result is the same. try_g <- function(...) {   par <- list(...)   return(par[[1]]/par[[2]]) } r <- nlConfint2(texts="tr

What is my encoding?

Imagine that you have a file but you don't know what is the encoding. Here is a way to determine it: Let create a file with Excel using the function "Save as" and then choose, Text (separator : tabulation) (.txt) How to read it ? > file.name <- "path to the file" > x <- unlist(lapply(iconvlist(), function(enc) try(read.table(file.name, fileEncoding=enc, nrows=1, header=FALSE, sep="\t"), silent = TRUE))) If the first cell contains Ebodjé for example: > z <- lapply(x, function(y) {y=="ebodjé"}) > which(unlist(z))      CSMACINTOSH              MAC        MACARABIC MACCENTRALEUROPE      MACCROATIAN         MACGREEK               126              330              331              332              333              335         MACHEBREW       MACICELAND        MACINTOSH         MACROMAN       MACROMANIA       MACTURKISH               336              337              338              339              340        

Do the next 365 days include a 29 February or not ? Can be used also for: Is the year bissextile or not?

A year is bissextile if it has 366 days. Years that can be divided by 4 are bissextiles except for secular years (ends by 00) except each 400 years. If you have a date in dt variable, just do ifelse(as.POSIXlt(dt+365)$mday== as.POSIXlt(dt)$mday , 365, 366).  It will tell you if  among the 12 months after this date, you had a 29 February: > dt <- as.Date("2005-01-01") >  ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366) [1] 365 > dt <- as.Date("2008-01-01") >  ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366) [1] 366 > dt <- as.Date("2000-01-01") >  ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366) [1] 366 > dt <- as.Date("1900-01-01") >  ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366) [1] 365 > dt <- as.Date("1999-07-01") >  ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366) [1] 366 > dt <- as.Date(&qu