You are on page 1of 1

##Otro ejemplo

##Descargar http://data.princeton.edu/wws509/datasets/cuse.raw
##Reference: Little, R. J. A. (1978). Generalized Linear Models for Cross-Classi
fied Data from the WFS. World Fertility Survey Technical Bulletins, Number 5.
##Usar como variable dependiente la variable uso de anticonceptivo.
##The Contraceptive Use Data (L)
#This is the alternative version of the contraceptive use data,
#### Regresion logistica
#showing the distribution of 1607 currently married and fecund women interviewed
#in the Fiji Fertility Survey, according to age, education, desire for more
#children and current use of contraception.
#This version has 32 rows corresponding to all possible covariate and response
#patterns, and includes a weight indicating the frequency of each combination.
#The file has 5 columns with numeric codes:
#age (four groups, 1=<25, 2=25-29, 3=30-39 and 4=40-49)
#education (0=none, 1=some)
#desire for more children (0=more, 1=no more)
#contraceptive use (0=no, 1=yes)
#frequency (number of cases in this category)
library(foreign)
mydata <- read.dta("cuse.dta")
names(mydata)
mydata$age
mydata$educ
mydata$desire
mydata$n
mydata$age<-"=<25"="1"
attach(mydata)
modele<-glm(cuse~age+educ+desire+n,family = binomial)
summary(modele)
modele<-glm(cuse~n,family = binomial)
summary(modele)
#####Regresion multinomial
library(foreign)
install.packages("nnet") # paquete que permite realizar el mlogit
library(nnet)
install.packages("ggplot2")#paquete que permite realizar la grfica
library(ggplot2)
install.packages("reshape2")#paquete para escoger la categora de
library(reshape2)
ml <-read.dta("http://www.ats.ucla.edu/stat/data/hsbdemo.dta")
head(ml)
with(ml, table(ses, prog))
prog
with(ml, do.call(rbind, tapply(write, prog,function(x) c(M = mean(x), SD = sd(x)
))))
#para elegir la categoria de referencia se debe observar la tabla cruzada
ml$prog2 <- relevel(ml$prog, ref = "academic")
modelo <- multinom(prog2 ~ ses + write, data = ml)
summary(modelo)
z <-summary(modelo)$coefficients/summary(modelo)$standard.errors #Z=los coeficie
ntes entre los valores estandar
z
p <- (1 - pnorm(abs(z), 0, 1)) * 2 #pvalue tener en cuenta cual es menor 0.05

You might also like