Plot 解释数据分析的结果

Plot 解释数据分析的结果,plot,Plot,我在为我的研究生论文寻找一些解释我的数据结果的帮助。我正在研究森林管理对繁殖鸣禽的影响。我收集了过去六年收集的数据,并使用具有随机和固定效应的多元线性回归模型进行了AICc分析。我已经获得了每个模型的AICc值,并确定了哪些模型最能描述数据中的变化,但我很难使用图形、数字和文字将这些结果转换成一种可呈现的格式。我如何以简洁的方式展示我的分析结果,是否有方法将这种类型的分析图表化,使其在论文中看起来很好?我对使用R绘制结果持开放态度,但我对这项技术仍然非常陌生,因此我不知道R中有哪些选项,或者我需

我在为我的研究生论文寻找一些解释我的数据结果的帮助。我正在研究森林管理对繁殖鸣禽的影响。我收集了过去六年收集的数据,并使用具有随机和固定效应的多元线性回归模型进行了AICc分析。我已经获得了每个模型的AICc值,并确定了哪些模型最能描述数据中的变化,但我很难使用图形、数字和文字将这些结果转换成一种可呈现的格式。我如何以简洁的方式展示我的分析结果,是否有方法将这种类型的分析图表化,使其在论文中看起来很好?我对使用R绘制结果持开放态度,但我对这项技术仍然非常陌生,因此我不知道R中有哪些选项,或者我需要采取哪些步骤才能使绘制效果逼真

使用ggplot2库可以直接从lme4::lmer和glmer对象的LMMs和GLMMs输出生成一些非常可发布的图形,但有一个学习曲线。如果你有连续和分类预测,这里是我在当前项目中使用的。那里有许多看起来很吓人的设置,但这是一个反复搜索解决方案并找到解决问题的正确代码段的问题。如果你有问题,请告诉我。我已经注释了很多帮助

我想知道,在不同环境(环境)和不同程度的酒精暴露下,在青春期(条件)饲养的老鼠,酒精的享乐价值是否会发生变化

我有4个变量“c.conc”(以集中度均值为中心,以避免由于多重共线性导致的方差膨胀问题)、“性别”、“条件”、“环境”。我的注意力变量在受试者范围内,因此,我的重复测量

#Load in the required libraries

library("MASS")
library("lattice")
library("boot")
library("car")
library("emmeans")
library("lme4")
library("zoo")
library("tidyr")
library("multcomp")
library("foreign")
library("msm")
library("ggplot2")
library("effects")
library("lmerTest")

#Run the model and put the results into an object i called "Ehed" for Ethanol Hedonics

Ehed <-glmer(Total.Hedonic ~ c.conc*Sex*Condition*Environment
                 + (c.conc|RatID), data=mydetoh, family=poisson)
    summary(Ehed)

#Always check the normality of your residuals so you don't violate assumptions of residual distributions.
#In my case, they were very normal and the graph below will be saved as a .png to my current working directory to visually compare my residual distribution to a normal curve.
#to view your current working directory enter "getwd()" 

    #Residual Graph
      #make PNG file
      png("COBRE-2 Ehed Res Plot.png", width = 300, height = 300)
      #plot residual density function
      plot(density(residuals(Ehed)), 
           main="", xlab="", frame= FALSE)
      #Add normal distribution to the residual plot for comparison
      Ehed.res = residuals(Ehed)
      Ehed.m = mean(Ehed.res)
      Ehed.std = sqrt(var(Ehed.res))
      curve(dnorm(x, mean=Ehed.m, sd=Ehed.std), col="darkblue", lwd=2, add=TRUE, yaxt="n")
      #close the file
      dev.off()
#加载到所需的库中
图书馆(“弥撒”)
图书馆(“格子”)
库(“启动”)
图书馆(“汽车”)
图书馆(“emmeans”)
图书馆(“lme4”)
图书馆(“动物园”)
图书馆(“tidyr”)
图书馆(“multcomp”)
图书馆(“外国”)
图书馆(“msm”)
图书馆(“ggplot2”)
图书馆(“效果”)
图书馆(“lmerTest”)
#运行模型并将结果放入一个我称为“Ehed”的乙醇享乐对象中

这很有帮助。非常感谢。如果我需要更多的帮助,我会回复这篇文章。所以,我所有的模型都是右尾的,这意味着它们违反了我用于它们的lmer函数的假设。有没有办法纠正这个问题?我还需要做些什么来纠正它吗?

#Predicted Graphs####

##Graph Setup####

##ETHANOL####
  #Axis and Break/Label Setup
    #Y Axis Breaks/Labels
      # generate hedonic (my predicted variable) Y axis break positions
      Ehed.ybreaks = c(0,50,100,150,200,250,300,350,400)
      # and Y labels; the ,"",100... omits the label for 50 but leaves the tick mark.
      # The length of the vectors must be the same so the ""s are necessary for this trick.
      Ehed.ylabels = as.character(c(0,"",100,"",200,"",300,"",400))

    #X Axis Breaks/Labels
      #assign X break positions for Concentration to object. My Concentration variable was 5%, 10%, 20%, etc... and appears below in the list (c())
      E.xbreaks = c(5,10,20,30,40)
      #assigns the values of the breaks to the X labels
      E.xlabels = as.character(E.xbreaks)

    ###Ethanol Hedonic Graph______________________________________________________
      #pull the effects from the GLMER model object & calculate confidence intervals for graphing
      Ehed.eff <- Effect(c("c.conc","Sex","Condition","Environment"),Ehed,
                         #se is std err and the level is the confidence level. .68 = actual std err for conf int. lower and upper.
                         se=list(level=.68),
                         #the xlevels command is used to increase the number of points calculated to smooth the error ribbons to look more curved (default = 5). I also center my concentration variable here to line up with the numbers that were analyzed as centered variables and remove this in the next step so everything is at their original values.
                         xlevels=list(c.conc=c(.05-mean.etoh.conc,
                                               .075-mean.etoh.conc,
                                               .10-mean.etoh.conc,
                                               .125-mean.etoh.conc,
                                               .15-mean.etoh.conc,
                                               .175-mean.etoh.conc,
                                               .20-mean.etoh.conc,
                                               .225-mean.etoh.conc,
                                               .25-mean.etoh.conc,
                                               .275-mean.etoh.conc,
                                               .30-mean.etoh.conc,
                                               .325-mean.etoh.conc,
                                               .35-mean.etoh.conc,
                                               .375-mean.etoh.conc,
                                               .40-mean.etoh.conc)))
#Writing Ehed.eff to a data frame to more easily use it with other functions later.
      Ehed.eff.df <-as.data.frame(Ehed.eff)
      #Converting back from the centering and rescaling.
      Ehed.eff.df$Concentration <- (Ehed.eff.df$c.conc+mean.etoh.conc)*100
      #Instead of trying to relabel these values in the ggplot2 object just recode them here and save some trouble
      Ehed.eff.df$Sex <-car::recode(Ehed.eff.df$Sex, "'F' = 'Female'; 'M' = 'Male'")
#The mydetoh is the original data set. If i want to show points for each individual I can use this data set layered on top of my other graph.
      mydetoh$Sex <-car::recode(mydetoh$Sex, "'F' = 'Female'; 'M' = 'Male'")

      #Check that everything looks right.
      View(Ehed.eff.df)
      View(mydetoh)

      #make a new file
      png("Fig Sample Ethanol Hedonic lines.png", width = 800, height = 600)
      #Start your plot and write it to an object for later reference. I chose Ehed.ggp because it is the Ehed model's ggplot. The fit variable below is generated when you pull the effects from the model. It is the predicted values.
#Because I am spliting the plot into two panes by sex, only Condition and Environment need to appear in my group, col (color), fill, and linetype arguments. The names must match the names of your variables from your model EXACTLY. The scale_color_manual etc... all align with these values. I used Hex colors, you can also just type "red" with the quotes instead.

      Ehed.ggp <-ggplot(Ehed.eff.df,
                        aes(Concentration,fit,
                            group=interaction(Condition,Environment),
                            col=interaction(Condition,Environment),
                            fill=interaction(Condition,Environment),
                            linetype=interaction(Condition,Environment),
                            shape=interaction(Condition,Environment)))+
        #adds each individual's points to the data. Leave this commented out if you dont need to do that.
        #geom_point(data=mydetoh,aes(x=Concentration, y=Total.Hedonic),stroke=1.5,size=4,alpha=0.60)+
        geom_smooth(data=Ehed.eff.df, se=FALSE, method="glm", method.args = list(family = "poisson"),size=1.5)+
        ## colour=NA suppresses edges of the ribbon
        geom_ribbon(data=Ehed.eff.df,colour=NA,alpha=0.25,
                    aes(ymin=lower,ymax=upper))+
        #labs(tag="A.")+  #If you do not need a panel tag (e.g. A., B., C. etc...) for a graph that will become part of a larger plot, comment this command out
        scale_color_manual("",values=c("#0000ff", "#7d7dff","#ff0000","#ff7d7d","#000000","#808080"), labels=c('EC+ETOH','EC+SAL','IC+ETOH','IC+SAL','SC+ETOH','SC+SAL'))+
        scale_fill_manual("",values=c("#0000ff", "#7d7dff","#ff0000","#ff7d7d","#000000","#808080"), labels=c('EC+ETOH','EC+SAL','IC+ETOH','IC+SAL','SC+ETOH','SC+SAL'))+
        scale_linetype_manual("",values=c("solid","twodash","solid","twodash","solid","twodash"), labels=c('EC+ETOH','EC+SAL','IC+ETOH','IC+SAL','SC+ETOH','SC+SAL'))+
        scale_shape_manual("",values=c(15,0,16,1,17,2), labels=c('EC+ETOH','EC+SAL','IC+ETOH','IC+SAL','SC+ETOH','SC+SAL'))+
        scale_x_continuous(expand=c(0,0), limits = c(0,42), breaks=E.xbreaks, labels=E.xlabels)+
        scale_y_continuous(expand=c(0,0), limits = c(0,410), breaks=Ehed.ybreaks, labels=Ehed.ylabels)+
        theme_classic()+
        theme(strip.background = element_rect(colour="white"),
              strip.text.x = element_text(size=18,face="bold"),
              panel.spacing = unit(1,"cm"),
              axis.title = element_text(size=22),
              axis.text = element_text(size=21,color="black",face="bold"),
              axis.line = element_line(size=1.3),
              axis.ticks = element_line(size=1.3, color="black"),
              axis.ticks.length = unit(0.2, "cm"),
              axis.title.y = element_text(margin = margin(t = 0, r = 18, b = 0, l = 0)),
              axis.title.x = element_text(margin = margin(t = 13, r = 0, b = 0, l = 0)),
              legend.title = element_blank(),
              legend.text = element_text(size=18, face="bold"),
              legend.justification = "top",
              legend.key.size = unit(1, "cm"),
              #legend.position = c(0.75, .85),
              #plot.tag = element_text(size=36, face="bold"),
              plot.tag.position = c(0.05, 0.95))+
        facet_grid(. ~ Sex)+
        xlab("Ethanol % (v/v)")+
        ylab("Hedonic Responses (+/-SEM)")

      Ehed.ggp

      #close the file
      dev.off()