summary(lm(In~ SA_C, RtC))
coefs(lm(In ~ SA_C, RtC))
#拟合复合变量间的多元回归模型
modelC <- psem(lm(In ~ pH+  SA_C + ST_C,RtC),
lm(SA_C ~pH ,RtC),
#lm(pH ~SA_C  ,RtC),#+ STMHX_C +
lm(ST_C ~pH ,RtC)
)
summary(modelC, .progressBar = F)
plot(modelC)
head(RtL)
### miLronutrients
model2_L <- lm(In ~ Al+Cu+Ca, RtL)
summary(model2_L)$coefficients
coefs(model2_L, standardize = 'scale')
beta_Al_L <- summary(model2_L)$coefficients[2, 1]
beta_Cu_L <-  summary(model2_L)$coefficients[3, 1] #+beta_Lu*Rt$Lu+Lu
beta_Ca_L <- summary(model2_L)$coefficients[4, 1]
ST_L <- beta_Al_L * RtL$Al + beta_Cu_L * RtL$Cu +beta_Ca_L*RtL$Ca
RtL$ST_L <- ST_L
summary(lm(In ~ ST_L, RtL))
coefs(lm(In ~ ST_L, RtL))
#土壤化学变量的组合
model3_L <- lm(In~A_Fe+A_Mg+A_Cu, RtL)
coefs(model3_L, standardize = 'scale')
beta_A_Fe_L <- summary(model3_L)$coefficients[2, 1]
beta_A_Mg_L <-summary(model3_L)$coefficients[3, 1]
beta_A_Cu_L <- summary(model3_L)$coefficients[4, 1]
SA_L <-  beta_A_Fe_L*RtL$A_Fe + beta_A_Mg_L*RtL$A_Mg + beta_A_Cu_L*RtL$A_Cu
RtL$SA_L <- SA_L
summary(lm(In~ SA_L, RtL))
coefs(lm(In ~ SA_L, RtL))
#拟合复合变量间的多元回归模型
modelL <- psem(lm(In ~ pH+  SA_L+ST_L ,RtL),
#lm(pH ~ST_L+SA_L ,RtL)#,+ ST_L
lm(SA_L ~pH  ,RtL),#+ STLHX_L +
lm(ST_L ~ pH ,RtL)
)
summary(modelL, .progressBar = F)
plot(modelL)
head(RtL)
### miLronutrients
model2_L <- lm(In ~ Al+Cu+Ca, RtL)
summary(model2_L)$coefficients
coefs(model2_L, standardize = 'scale')
beta_Al_L <- summary(model2_L)$coefficients[2, 1]
beta_Cu_L <-  summary(model2_L)$coefficients[3, 1] #+beta_Lu*Rt$Lu+Lu
beta_Ca_L <- summary(model2_L)$coefficients[4, 1]
ST_L <- beta_Al_L * RtL$Al + beta_Cu_L * RtL$Cu +beta_Ca_L*RtL$Ca
RtL$ST_L <- ST_L
summary(lm(In ~ ST_L, RtL))
coefs(lm(In ~ ST_L, RtL))
#土壤化学变量的组合
model3_L <- lm(In~A_Fe+A_Mg+A_Cu, RtL)
coefs(model3_L, standardize = 'scale')
beta_A_Fe_L <- summary(model3_L)$coefficients[2, 1]
beta_A_Mg_L <-summary(model3_L)$coefficients[3, 1]
beta_A_Cu_L <- summary(model3_L)$coefficients[4, 1]
SA_L <-  beta_A_Fe_L*RtL$A_Fe + beta_A_Mg_L*RtL$A_Mg + beta_A_Cu_L*RtL$A_Cu
RtL$SA_L <- SA_L
summary(lm(In~ SA_L, RtL))
coefs(lm(In ~ SA_L, RtL))
#拟合复合变量间的多元回归模型
modelL <- psem(lm(In ~ pH+  SA_L+ST_L ,RtL),
#lm(pH ~ST_L+SA_L ,RtL)#,+ ST_L
lm(SA_L ~pH  ,RtL),#+ STLHX_L +
lm(ST_L ~ pH ,RtL)
)
summary(modelL, .progressBar = F)
plot(modelL)
head(RtM)
### miMronutrientsCu+
model2_M <- lm(In ~ Mg+Al+B, RtM)
summary(model2_M)$coefficients
coefs(model2_M, standardize = 'scale')
beta_Mg_M <- summary(model2_M)$coefficients[2, 1]
beta_Al_M <- summary(model2_M)$coefficients[3, 1]
beta_B_M <-summary(model2_M)$coefficients[4, 1]
ST_M <-beta_Mg_M*RtM$Mg+ beta_Al_M * RtM$Al +beta_B_M * RtM$B
RtM$ST_M <- ST_M
summary(lm(In ~ ST_M, RtM))
coefs(lm(In ~ ST_M, RtM))
#土壤化学变量的组合
model3_M <- lm(In~ A_Cu+A_Ca+A_Mn, RtM)
coefs(model3_M, standardize = 'scale')
beta_A_Cu_M <-summary(model3_M)$coefficients[2, 1]
beta_A_Ca_M <- summary(model3_M)$coefficients[3, 1]
beta_A_Mn_M<- summary(model3_M)$coefficients[4, 1]
SA_M <- beta_A_Ca_M*RtM$A_Ca + beta_A_Cu_M*RtM$A_Cu + beta_A_Mn_M*RtM$A_Mn
RtM$SA_M <- SA_M
summary(lm(In~ SA_M, RtM))
coefs(lm(In ~ SA_M, RtM))
#拟合复合变量间的多元回归模型
modelM <- psem(lm(In ~ pH+  SA_M ,RtM),
#lm(pH ~ST_M+SA_M ,RtM)#,+ ST_M
lm(SA_M ~pH +ST_M ,RtM),#+ STMHX_M +
lm(ST_M ~ pH ,RtM)
)
summary(modelM, .progressBar = F)
plot(modelM)
head(RtS)
### miCronutrients
model2_S <- lm(In ~ Mg+B+Zn+Fe, RtS)
summary(model2_S)$coefficients
coefs(model2_S, standardize = 'scale')
beta_Mg_S <- summary(model2_S)$coefficients[2, 1]
beta_B_S <- summary(model2_S)$coefficients[3, 1]
beta_Zn_S <- summary(model2_S)$coefficients[4, 1]
beta_Fe_S <- summary(model2_S)$coefficients[5, 1]
ST_S <- beta_Mg_S*RtS$Mg+beta_B_S * RtS$B +beta_Zn_S * RtS$Zn +beta_Fe_S*RtS$Fe
RtS$ST_S <- ST_S
summary(lm(In ~ ST_S, RtS))
coefs(lm(In ~ ST_S, RtS))
#土壤化学变量的组合
model3_S <- lm(In~A_Cu+A_Al, RtS)
coefs(model3_S, standardize = 'scale')
beta_A_Cu_S <-  summary(model3_S)$coefficients[2, 1]
beta_A_Al_S <- summary(model3_S)$coefficients[3, 1]
SA_S <-  beta_A_Cu_S * RtS$A_Cu + beta_A_Al_S*RtS$A_Al# + beta_A_Zn_S*RtS$A_Zn + beta_A_Mn_S*RtS$A_Mn
RtS$SA_S <- SA_S
summary(lm(In~ SA_S, RtS))
coefs(lm(In ~ SA_S, RtS))
#拟合复合变量间的多元回归模型
modelS <- psem(lm(In ~ pH+  SA_S +ST_S,RtS),
#lm(pH ~ST_S+SA_S ,RtS)#,+ ST_S
lm(SA_S ~pH  ,RtS),#+ STSHX_S +
lm(ST_S ~ pH ,RtS)
)
summary(modelS, .progressBar = F)
plot(modelS)
PE6_dat
PE6_rfP
R3
library(psych)
f <- read.csv("juzheng_cor.csv",header=T)
f
cor.result<-corr.test(f1,method = "pearson")
cor.result<-corr.test(f,method = "pearson")
f <- read.csv("juzheng_cor.csv",header=T)
cor.result<-corr.test(f,method = "pearson")
cor.result<-corr.test(f,method = "pearson")
cor.result
library(psych)
library(corrplot)
#自定义渐变颜色；
col2 <- colorRampPalette(c("#77C034","white" ,"#C388FE"),alpha = TRUE)
#显著性计算：
res <- cor.mtest(cor.result, conf.level = .95)
cor.result$p
#显著性计算：
sig<- cor.mtest(cor.result, conf.level = .95)
p<-cor.result$p
###相关性分析---酶和元素之间的相关性分析
#读取数据
library(ggplot2)
library(ggthemes)
#提取P值
library(tidyverse)
#自定义渐变颜色；
col2<- colorRampPalette(c("#77C034","white","#C388FE"),alpha = TRUE)
cor.result$r
#添加下三角相关系数矩阵；
corrplot(cor.result,add = TRUE,method = 'number',
type= 'lower', col = col2(100),
order= c('hclust'), diag = T, number.cex = 0.9,
tl.pos = 'l', tl.col="grey20",cl.pos = 'n',
p.mat = p,
insig= "pch",pch.col="grey20",pch.cex=2)
cor.result
#计算mtcars数据框的相关性系数;
cor.result<-corr.test(f,conf.level = .95)
library(psych)
library(corrplot)
f <- read.csv("juzheng_cor.csv",header=T)
#计算mtcars数据框的相关性系数;
cor.result<-corr.test(f,conf.level = .95)
library(psych)
library(corrplot)
f <- read.csv("juzheng_cor.csv",header=T)
#计算mtcars数据框的相关性系数;
cor.result<-corr.test(f,method = "pearson")
#显著性计算：
p<-cor.result$p
r<-cor.result$r
p[1:6,1:5]
#自定义渐变颜色；
col2<- colorRampPalette(c("#77C034","white","#C388FE"),alpha = TRUE)
#添加下三角相关系数矩阵；
corrplot(cor.result,add = TRUE,method = 'number',
type= 'lower', col = col2(100),
order= c('hclust'), diag = T, number.cex = 0.9,
#tl.pos = 'l', tl.col="grey20",cl.pos = 'n',
p.mat = p,
insig= "pch",pch.col="grey20",pch.cex=2)
# 计算相关性系数和显著性
cor.result <- corr.test(f, method = "pearson")
r <- cor.result$r  # 相关性系数矩阵
p <- cor.result$p  # 显著性矩阵
# 自定义渐变颜色
col2 <- colorRampPalette(c("#77C034", "white", "#C388FE"), alpha = TRUE)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 2  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 2  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 2  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 2  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
#insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 2  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
#insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
#type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
#insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
corrplot(r,add = TRUE,method = 'number',
type= 'lower', col = col2(100),
order= c('hclust'), diag = T, number.cex = 0.9,
tl.pos = 'l', tl.col="grey20",cl.pos = 'n',
p.mat = p,
insig= "pch",pch.col="grey20",pch.cex=2)
corrplot(r,add = TRUE,method = 'number',
type= 'lower', col = col2(100),
order= c('hclust'), diag = T, number.cex = 0.9,
tl.pos = 'l', tl.col="grey20",cl.pos = 'n',
p.mat = p,
insig= "pch",pch.col="grey20",pch.cex=1)
corrplot(
r,  # 相关性系数矩阵
method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
tl.pos = 'l',  # 标签位置在左侧
tl.col = "grey20",  # 标签颜色
cl.pos = 'n',  # 不显示颜色条
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
# 添加相关性图
corrplot(
r,  # 相关性系数矩阵
add = TRUE,  # 添加到现有图形
method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
tl.pos = 'l',  # 标签位置在左侧
tl.col = "grey20",  # 标签颜色
cl.pos = 'n',  # 不显示颜色条
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
cor(mtcars)
corrplot(
r,  # 相关性系数矩阵
method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
tl.pos = 'l',  # 标签位置在左侧
tl.col = "grey20",  # 标签颜色
cl.pos = 'n',  # 不显示颜色条
p.mat = p,sig.level = c(0.001, 0.01, 0.05), # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
corrplot(
r,  # 相关性系数矩阵
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
tl.pos = 'l',  # 标签位置在左侧
tl.col = "grey20",  # 标签颜色
cl.pos = 'n',  # 不显示颜色条
p.mat = p,sig.level = c(0.001, 0.01, 0.05), # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
corrplot(r, order = "hclust",col = col2(100),
method= "pie",
cl.length=5, type = "upper",diag = T,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1.4,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "upper",diag = T,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1.4,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = T,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1.4,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = FALSE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = FALSE,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1.4,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = FALSE,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = F,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,sig.level = c(0.001, 0.01, 0.05),  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = F,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,sig.level = c(0.001, 0.01, 0.05),  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1，  # 符号大小
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = FALSE,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = FALSE,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
# 绘制相关性热图
corrplot(
r,  # 使用相关性系数矩阵
add = FALSE,  # 不叠加到现有图形
#method = 'number',  # 显示数值
type = 'lower',  # 只显示下三角
col = col2(100),  # 使用自定义颜色
order = 'hclust',  # 按层次聚类排序
diag = TRUE,  # 显示对角线
number.cex = 0.9,  # 数值字体大小
p.mat = p,sig.level = c(0.001, 0.01, 0.05),  # 显著性矩阵
insig = "pch",  # 不显著的值用符号标记
pch.col = "grey20",  # 符号颜色
pch.cex = 1  # 符号大小
)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = FALSE,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=1,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
corrplot(r, order = "hclust",col = col2(100),
#method= "pie",
cl.length=5, type = "lower",diag = FALSE,
p.mat = p,sig.level = c(0.001, 0.01, 0.05),
insig= "label_sig",pch.col="grey20",pch.cex=0.5,
tl.col="grey20",tl.cex = 1,cl.pos = "r",cl.ratio = 0.2)
