1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| rm(list=ls())#vider la memoire
#Premier tableau
Y<-as.matrix(sample(1:0,248,replace=T))
N<<-NROW(Y)#variable globale
X0<-c(rep(1,N))
X1<-sample(1:10,248,replace=T)
X2<-sample(1:10,248,replace=T)
X<-cbind(X0,X1,X2)
P<<-NCOL(X)-1
#second tableau
Y<-infert$case
N<<-NROW(Y)#variable globale
X0<-c(rep(1,N))
X1<-infert$induced
X2<-infert$spontaneous
X<-cbind(X0,X1,X2)
P<<-NCOL(X)-1
#fonction Logit
Logit<-function(i,beta,X){
temp<-exp(X[i,]%*%beta)
return(temp/(1+temp))
}
#apply problematique a essayer avec les deux différents tableaux X
beta<-t(t(rnorm(P+1,mean=0,sd=0.7))) #vecteur colonne de taille P+1
apply(as.matrix(c(1:N)),MARGIN=1,FUN=Logit,beta=beta,X=X) |
Partager