The scitb5 function version 1.6 (the interaction effect function P for interaction) early adopter version is released----used to generate an interaction effect table with one click

In SCI articles, the interaction effect table (usually Table 5) is almost a must for high-scoring SCI. Because of the addition of subgroup analysis, the credibility of the article is increased, which can add to the icing on the cake, increase the convincing power of the article, and can also carry out data mining.

insert image description here
In the previous version, the version 1 and 4 we have released can be used to generate an interaction effect table with one click, but it can only be used when the target variable X is an interaction effect function of a continuous variable, and the target variable is the data of a categorical variable It can't be used. Some hierarchical data can't be used if the layering is not good. I have re-improved the algorithm. In the new version, even if the subgroup data has only one classification, it can be calculated, and the calculation of categorical variables is supported. This should be a relatively complicated function that I have written so far. The main reason is that it is not easy to connect with other people’s function interfaces, so I basically wrote all the underlying functions by myself. Okay, without further ado, let’s demonstrate it. Let's do logistic regression first
and import our premature birth data

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 the data about premature low birth weight infants (official account reply: premature birth data, this data can be obtained), and the infants below 2500g are considered low birth weight infants. The data is interpreted as follows: low is a premature low birth weight baby less than 2500g, age is the age of the mother, lwt is the last menstrual weight, race is race, smoke is smoking during pregnancy, ptl is history of premature birth (count), ht is history of hypertension, ui is uterine allergy, ftv is early pregnancy The number of visits to the doctor, bwt newborn weight value

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")

Import function, here I directly write the function file 1.6final.R, just import it directly

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

After the import is successful, 7 functions should be generated

insert image description here
Generate a table, the same as version 1.4 data is your data, must be in the form of a 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 Factor, cov is your covariate. In my setting, cov should include Interaction, which is also in line with our habits. The family here is a bit different from the original one. Family="glm" is used uniformly, and logistic regression and linear regression are supported. Cox regression is not yet supported, and version 1.4 can be used if needed.

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

insert image description here
The new version adds an additional P value, behind the credible interval. Try another classification data, where ht is a classification data, indicating whether there is high blood pressure.

cov1<-c("lwt","smoke","ptl","ui","ftv","race")	
Interaction<-c("race","smoke","ui")
out<-scitb5(data=bc,x="ht",y="low",Interaction=Interaction,cov = cov1,family="glm") 

insert image description here
In the picture above, I want to explain that when making a categorical variable, you need to set a reference. When comparing race, ht.0_race.1 is recognized as a reference. What does it mean? That is, when ht is equal to 0 and race is equal to 1, the subgroup of the population is defaulted as a reference comparison, and other groups are compared with it. The last group has missing data because there is no data for this stratification, so It is NA.
Therefore, when categorical variables interact with subgroups, it is best not to have too many categories, or the data will be very large, and some layers cannot be divided into data. Let's demonstrate the fan data, let's import the data first

bc<-read.csv("E:/r/fensi/final1.csv",sep=',',header=TRUE)
dput(names(bc))

insert image description here
Categorical variables into factors

bc[,c("x2", "x3", "x4", "x5", "x6", "x7","y")] <- lapply(bc[,c("x2", "x3", "x4", "x5", "x6", "x7","y")], factor)

Define covariates and stratification variables

Interaction<-c("x2", "x3", "x4","x5")
cov<-c("x2", "x3", "x4", "x5", "x6", "x7")

In the previous version, X5 cannot be layered, as shown below

insert image description here
insert image description here
After changing the new algorithm, this problem does not exist. let's try

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

insert image description here
We can see that although a completely different algorithm is used, the values ​​of X2, X3, and X4 are the same as before, and X5Y, which cannot be calculated using conventional methods, is also calculated. We can see that in the 3 subgroups grouped by X5, the target variable and the outcome are linearly related. In theory, 3 articles can be written for analysis.
We are looking at another fan's data, the target variable is a categorical variable

bc<-read.csv("E:/r/fensi/DII_GROUP.csv",sep=',',header=TRUE)
dput(names(bc))

insert image description here
This data is very large, the above picture is only a part, and the categorical variable is converted into a factor

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) 

Define covariates and stratification variables

Interaction<-c("sex_02", "nianling_02", "marriage_02", "smoke_02")
cov<-c("sex_02", "nianling_02", "marriage_02", "smoke_02","wc_02")

generate form

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

insert image description here
We can see that some stratified variables are too few to produce results, so NA is displayed. Therefore, when the target variable is a categorical variable, it is best not to classify too much.
Let's demonstrate the data of a fan again, this time I won't explain it, just upload the code directly

bc<-read.csv("E:/r/fensi/yang.csv",sep=',',header=TRUE)
dput(names(bc))
bc[,c("Gender", "CVDs.death", "PIR.group", "smoker","X","State")] <- lapply(bc[,c("Gender", "CVDs.death", "PIR.group", "smoker","X","State")], factor)
str(bc)
Interaction<-c("smoker","PIR.group")
cov<-c("PIR.group","smoker","Age")
out<-scitb5(data=bc,x="X",y="CVDs.death",Interaction=Interaction,cov = cov,family="glm")

insert image description here
What I want to say is that X has 4 categories in this data, and smoker has 4 categories, so there are 16 categories in the smoker group alone.
Finally, let’s talk about how to export data to make a table. Take the first data as an example,
insert image description here
let’s save it in CSV format first.

write.csv(out,file = "1.csv",row.names = F)

insert image description here
Then copy it to WORD,
insert image description here
sort out a little, and
insert image description here
a table of interaction effects that can be used for publication is ready.

Those who have already purchased version 1.4 do not need to re-purchase, just use the original method to download, and the content has been updated.
If there is any problem with the new version, you are more than happy to let me know by private message

For scitb5 function code, please refer to this article:

The scitb5 function version 1.6 (the interaction effect function P for interaction) early adopter version is released----used to generate an interaction effect table with one click

Guess you like

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