scitb5 function version 1.7 (interaction effect function P for interaction) released ---- used to generate interaction effect tables and forest plots with one click

In SCI articles, the interaction effect table (usually Table 5) can enhance the article, increase the persuasiveness of the article, increase the credibility of the results, and enable data mining.
Insert image description here
I have already introduced how to make an interaction effect table in my previous article "R Language Teaches You Step by Step to Make an Interaction Effect Table". You can take a look at it for details. In the previous article "scitb5 function version 1.6 (interaction effect function P for interaction) released - used to generate interaction effect tables with one click", I released the scitb5 function version 1.6 written by me. The response was pretty good, and I didn't find much Big problem. This issue releases the latest 1.7 version of the scitb5 function. Version 1.7 fixes some minor problems in version 1.6. The most important one is that when the result variable Y is a continuous variable, the generated table should be β instead of OR, although The result is correct, but the column name has not been changed. Version 1.7 fixes this problem. Version 1.7 also adds the plotforest function, which can generate a forest plot of interaction effects with one click. Let’s demonstrate it below.
Import our premature birth data. Let me mention here that converting the data into CSV format and importing it according to my method can reduce R errors

bc<-read.csv("E:/r/test/zaochan.csv",sep=',',header=TRUE)
bc <- na.omit(bc)
names(bc)
dput(names(bc))

Insert image description here
This is data about premature low-birth-weight infants (public account reply: Premature birth data, you can get this data), less than 2500g is considered low-weight infants. The data are explained as follows: low indicates whether it is a premature low-birth-weight infant weighing less than 2500g, age indicates mother’s age, lwt last menstrual weight, race race, smoke indicates smoking during pregnancy, ptl indicates premature birth history (count), ht indicates a history of high blood pressure, ui indicates uterine allergy, ftv indicates early pregnancy Number of visits to the doctor, bwt newborn weight value
Convert categorical variables into factors

bc$race<-ifelse(bc$race=="black",1,ifelse(bc$race=="white",2,3))
bc$smoke<-ifelse(bc$smoke=="nonsmoker",0,1)
bc$low<-factor(bc$low)
bc$race<-factor(bc$race)
bc$ht<-factor(bc$ht)
bc$ui<-factor(bc$ui)

Define covariates and stratification factors

cov1<-c("lwt","smoke","ptl","ui","ftv","race")	
Interaction<-c("race","smoke","ui")

To import the function, I write it directly as the function file 1.7final.R. Just import it directly.

source("E:/r/test/1.7final.R")

After successful import, 8 functions should be generated
Insert image description here
Generate table, same as version 1.6 data is your data, must be in the form of data frame, x is the target variable of your research, y is your outcome variable, Interaction is your stratification variable, this must be a categorical variable and converted into a factor, cov is your covariate, in my setting cov must include Interaction, which is also in line with our habits . Family here is a little different from the original one. Family="glm" is used uniformly, and logistic regression and linear regression are supported. Cox regression is not supported yet. If you need it, you can use version 1.4.

out<-scitb5(data=bc,x="age",y="low",Interaction=Interaction,cov = cov1,family="glm")

Insert image description here
I have further modified the column names to make them more beautiful. You can just generate the table directly without modifying the column names.
Use the plotforest function to draw a forest plot

plotforest(out)

Insert image description here
Here it is explained that the plotforest function calls the forestplot package and stringr package to draw the forest map, so these two packages must be installed, otherwise the drawing cannot be done.
Let’s try another categorical data. Here ht is a categorical data, indicating whether there is high blood pressure.

out<-scitb5(data=bc,x="ht",y="low",Interaction=Interaction,cov = cov1,family="glm")
plotforest(out)

Insert image description here
Insert image description here
We can see that the OR is too big and the X-axis in the above picture is too small, so it looks a bit strange. We can adjust the parameters.

plotforest(out,xticks=c(0,10,20))

Insert image description here
This is slightly better. In the future, plotforest will add more adjustment parameters. Of course, the forest diagram generated by this kind of integrated code is definitely not as beautiful as the one you draw yourself. It is mainly convenient and practical. You can also draw it yourself, which is more flexible. Let’s try changing the data of fans. I won’t explain the data here, just go to the code.

bc<-read.csv("E:/r/fensi/DII_GROUP.csv",sep=',',header=TRUE)
dput(names(bc))
bc[,c("sex_02", "nianling_02", "marriage_02", "GROUP",
      "smoke_02")] <- lapply(bc[,c("sex_02",  "nianling_02", "marriage_02","GROUP", "smoke_02")], factor)
str(bc)
Interaction<-c("sex_02", "nianling_02", "marriage_02", "smoke_02")
cov<-c("sex_02", "nianling_02", "marriage_02", "smoke_02","wc_02")

The generated result first comes with Y which is classified.

out<-scitb5(data=bc,x="GROUP",y="dm_19",Interaction=Interaction,cov = cov,family="glm")

Insert image description here
The data is very large, and the above picture is only a part of it. A forest diagram is generated.

plotforest(out)

Insert image description here
If Y is a continuous variable, β will be generated instead of OR.

Insert image description here
We can see that the scitb5 function has judged the data type itself and changed OR to β, which corrects the error that cannot be modified in version 1.6.
Let me say here that β generally does not draw forest plots, so I did not add the interface of β. If the data here is β, using the plotforest function to draw forest plots will fail.

plotforest(out)

Insert image description here
If you really need to draw a forest diagram about β, you can tell me in a private message.
How to export the table after generating it, you can read the previous article, there will be no more nonsense here. Those who originally purchased versions 1.4 and 1.6 do not need to re-purchase. You can just reply once. The link has been updated.

Please read this article to obtain version 1.7 functions.

scitb5 function version 1.7 (interaction effect function P for interaction) released ---- used to generate interaction effect tables and forest plots with one click

Guess you like

Origin blog.csdn.net/dege857/article/details/133854674