We have already talked about the interaction, so I won't talk about it in detail. It can play a finishing touch in SCI papers, and can further explore the subgroup relationship between data. Data mining is also very practical. The visualization of interactive items can clearly show the relationship between interactive data. In actual papers, absolutely It's a bonus item, not much nonsense, let's practice it.
This time we are using the data set of infertility caused by the flow of people that comes with the R language. Let's import it first.
bc<-infert
names(bc)
There are 8 indicators in the data, the last two are PSM matching results, we don’t care about them, the other six are:
Education: education level, age: age, parity, induced: abortion times, case: infertility, this is Outcome index, spontaneous: the number of spontaneous abortions.
Some variables are categorical variables, we need to convert them
bc$education<-ifelse(bc$education=="0-5yrs",0,ifelse(bc$education=="6-11yrs",1,2))
bc$spontaneous<-as.factor(bc$spontaneous)
bc$case<-as.factor(bc$case)
bc$induced<-as.factor(bc$induced)
bc$education<-as.factor(bc$education)
Build a model, if we want to know whether there is an interaction between the two indicators of miscarriage (including abortion and spontaneous abortion) and age
f1<- glm(case ~ age + education + parity + induced+spontaneous+age*induced*spontaneous,
family = binomial(link = logit), data = bc)
summary(f1)
We see that there may be an interaction between spontaneous abortion and age.
We import the R visualization package visreg
library("visreg")
library("visreg")
plot(visreg(f1,xvar = "age",by="spontaneous",plot=F),xlab="age",ylab="predict",
overlay = T,partial = F,rug=F,,line=list(lty=1:6))
legend("topleft",
c("没有流产","流产1次","流产2次以上"),
lty=c(1,1,1),
col=c("red","green","blue"),
lwd=c(2,1,1),
bty="n")
From this we can see that with age, the probability of infertility in patients with spontaneous abortion more than 2 times is significantly higher than in patients without spontaneous abortion.
For more exciting articles, please pay attention to the public number: zero-based scientific research