Skip to content

Instantly share code, notes, and snippets.

mediapart<-userTimeline(user="mediapart",
n=500,cainfo="cacert.pem")
lemonde<-userTimeline(user="lemondefr",
n=500,cainfo="cacert.pem")
lefigaro<-userTimeline(user="Le_Figaro",
n=500,cainfo="cacert.pem")
leparisien<-userTimeline(user="le_Parisien",
n=500,cainfo="cacert.pem")
#Concaténation
Media.df<-rbind(mediapart.df,
lm_eqn = function(df) {
m = lm(pollution ~ pib, df);
l <- list(a = format(coef(m)[1], digits = 2),
b = format(abs(coef(m)[2]), digits = 2),
r2 = format(summary(m)$r.squared, digits = 3));
if (coef(m)[2] >= 0) {
eq <- substitute(italic(Pollution) == a + b %.% italic(PIB)*","~~italic(R)^2~"="~r2,l)
} else {
eq <- substitute(italic(Pollution) == a - b %.% italic(PIB)*","~~italic(R)^2~"="~r2,l)
}
# 18/05/2013
# Key words : TextMining, Elections, France, Debate, 2nd Round
# We use the packages qdap from (donner le lien) and
# tm to perform textmining analysis and the classical
# package like ggplot or RColorBrewer to get the graphics pretty.
suppressPackageStartupMessages(require(twitteR))
suppressPackageStartupMessages(require(XML))
suppressPackageStartupMessages(require(tm))
suppressPackageStartupMessages(require(rgdal))
plot(GROUPE~TAILLE)
abline(lm(GROUPE~TAILLE),col="tomato")
png("Log", width=6,height=7)
x = seq(0.00001,0.9999,length = 100)
logit<-function(t)
{
log(t/(1-t))
}
curve(logit(x),col = "tomato",lwd = 2)
curve(qnorm(x),col = "blue",lwd = 2,add=T)
curve(log(-log(1-x)),col = "purple",lwd = 2,add=T)
a=par("usr")
# Lik
lik.logit <- function(init,y,x)
{
x = as.matrix(x)
cste<- rep(1,length(x[,1]))
x <- cbind(cste,x) # Matrix of predictors
d <- init[1:ncol(x) ] # Number of parameters
xd<- x%*%d # Produit matriciel
sum( y*log(1+exp(-xd)) + (1-y)*log(1+exp(xd)))
}
viaglm<- glm(don$GROUPE~don$TAILLE,don,family="binomial") ; viaglm
# We compute the inverse logistic function
ilogit <- function (l) {
exp(l) / ( 1 + exp(l) )
}
attach(don)
viaglm<- glm(GROUPE~TAILLE,don,family="binomial")
png("Comparison.png", width=1280,height=800)
plot(TAILLE,GROUPE, pch=16)
new<- seq(min(TAILLE),max(TAILLE),by=1)
# Prev avec R