Infidelity and econometrics
[This article was first published on Freakonometrics - Tag - R-english, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
On http://www.bakadesuyo.com, there was recently an interesting discussion about infidelity, the key question being “at what ages are men and women most likely to have affairs?” The discussion is based on some graphs, e.g.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
![](https://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/.screenshot_01.jpg.scaled1000_m.jpg?w=578)
> library(Ecdat) > data(Fair) > tail(Fair) sex age ym child religious education occupation 596 male 47 15.0 yes 3 16 4 597 male 22 1.5 yes 1 12 2 598 female 32 10.0 yes 2 18 5 599 male 32 10.0 yes 2 17 6 600 male 22 7.0 yes 3 18 6 601 female 32 15.0 yes 3 14 1 rate nbaffairs 596 2 7 597 5 1 598 4 7 599 5 2 600 2 2 601 5 1
> library(splines) > regM=glm(nbaffairs~bs(age),family=poisson, + data=Fair[Fair$sex=="male",]) > a=seq(20,60) > N=predict(regM,newdata=data.frame(age=a),type="response") > plot(a,N,type="l",lwd=2,col="red")
![](https://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_14.59.56_m.jpg?w=578)
> regF=glm(nbaffairs~bs(age),family=poisson, + data=Fair[Fair$sex=="female",]) > N=predict(regF,newdata=data.frame(age=a),type="response") > plot(a,N,type="l",lwd=2,col="red",lty=2)
![](https://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_15.00.47_m.jpg?w=578)
> library(pscl) > regM0=zeroinfl(nbaffairs~bs(age)|bs(age),family=poisson, + link="logit",data=Fair[Fair$sex=="male",]) > N0=predict(regM0,newdata=data.frame(age=a),type="zero") > plot(a,N0,type="l",lwd=2,col="blue")
![](https://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_14.59.42_m.jpg?w=578)
> Nc=predict(regM0,newdata=data.frame(age=a),type="count") > plot(a,Nc,type="l",lwd=2,col="purple")
![](https://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_15.04.24_m.jpg?w=578)
![](http://freakonometrics.blog.free.fr/index.php?post/2012/01/17/public/perso5/.Capture_d_ecran_2012-01-17_a_15.01.30_m.jpg)
![](https://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_15.03.24_m.jpg?w=578)
![](https://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_15.45.23_m.jpg?w=578)
![](https://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/.Capture_d_ecran_2012-01-17_a_15.05.05_m.jpg?w=578)
To leave a comment for the author, please follow the link and comment on their blog: Freakonometrics - Tag - R-english.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.