lsmeans :: lsmip:如何正确绘制连续值?

时间:2017-04-07 14:33:55

标签: r interaction lsmeans

Private Sub exporttoexcel(excelFileName) excelFileName = 'File in my local' Dim mySheetList() As String Dim WS As Worksheets Dim WB As Workbook MsgBox excelFileName 'Dim sourceWB As Workbook 'Dim destWB As Workbook ' 'Set sourceWB = ActiveWorkbook 'sourceWB.Sheets.Copy ' 'Set WB = Workbooks(excelFileName) ReDim mySheetList(0 To (ThisWorkbook.Sheets.Count) - 1) Dim a As Integer a = 0 For Each WS In ActiveWorkbook.Worksheets mySheetList(a) = WS.Name a = a + 1 Next Dim Fileobj Set Fileobj = CreateObject("Scripting.FileSystemObject") If Fileobj.FileExists(excelFileName) Then Fileobj.DeleteFile excelFileName End If ' 'actually save Worksheets(mySheetList).Copy '<<<<<<< RUN-TIME ERROR 9 RAISED HERE ActiveWorkbook.SaveAs FileName:=excelFileName 'MsgBox excelFileName 'ThisWorkbook.SaveAs FileName:=excelFileName, FileFormat:=xlXMLSpreadsheet Application.Wait (Now + TimeValue("0:00:15")) WB.Close End Sub 包中的lsmip()命令似乎将x轴上的连续预测变量视为分类预测变量。

如果我以离散但不均匀的间隔从我的连续预测器中观察到(例如当你从燕麦数据中移除0.2水平的硝基时),lsmip无论如何都会以均匀的间隔绘制它们。

lsmeans

enter image description here

如果我想在实际观察数据的硝基水平上显示模型预测,这对我来说似乎很重要。从理论上讲,我应该能够在任何硝基水平上显示预测值。

data("Oats", package = "nlme")
Oats.lmer2sub <- lmer(log(yield) ~ Variety + poly(nitro,2)
               + (1|Block/Variety),  data = subset(Oats, nitro!=0.2))
lsmip(Oats.lmer2sub, Variety ~ nitro, ylab = "Predicted log(yield)", cov.reduce=FALSE)

enter image description here

有没有办法设置x轴将nitro的值设置为适合连续变量的标度?含义在第一个图中跳过0.2的空格,或者在第二个图中将点聚为0.45,0.46?

1 个答案:

答案 0 :(得分:1)

您可以将绘制的数据保存在数据框中,然后根据需要绘制这些结果。在您的示例中:

plotdf <- lsmip(Oats.lmer2sub, Variety ~ nitro, 
          at=list(nitro=c(0, 0.2, 0.4, 0.45, 0.46,  0.6)), 
          plotit = FALSE)

library(lattice)
xyplot(lsmean ~ nitro, groups = ~Variety, 
       type = "o", ylab = "Predicted log(yield)", data = plotdf)

Resulting plot