我想知道是否以某种方式将线性回归线添加到TraMineR熵图中。
示例:
Private Function CreatePath(ByVal area As Rectangle) As GraphicsPath
'* Set fill mode to winding (see FillMode Help)
Dim gp As New GraphicsPath(FillMode.Winding)
Dim rect As Rectangle = New Rectangle(area.Location, New Size(area.Width, area.Height \ 3))
gp.AddEllipse(rect)
'* Reorder points so that path goes clockwise (see FillMode.Winding Help)
Dim hadj As Integer = area.Height \ 4
'Left side bottom -> top
'gp.AddLine(New Point(area.X, area.Y + area.Height - hadj), New Point(area.X, area.Y + (rect.Height \ 3) + 8))
'* Right side top -> bottom (clockwise)
'* NOTE: Top Y value was a bit too high, adjusted by -3. Adjust calculation or maybe use floating point math and used rounding, ceil, or floor
gp.AddLine(New PointF(area.X + area.Width, area.Y + (rect.Height \ 3) + 9 - 3), New PointF(area.X + area.Width, area.Y + area.Height - hadj))
Dim gh As Integer = area.Width \ 4
Dim pts(4) As PointF
'pts(0) = New PointF(area.X, area.Y + area.Height - hadj)
'pts(1) = New Point(area.X + gh, area.Y + area.Height - (hadj \ 2))
'pts(2) = New Point(area.X + gh * 2, area.Y + area.Height - (hadj \ 3))
'pts(3) = New Point(area.X + gh * 3, area.Y + area.Height - (hadj \ 2))
'pts(4) = New Point(area.X + area.Width, area.Y + area.Height - hadj)
'* Reordered points (clockwise)
pts(0) = New Point(area.X + area.Width, area.Y + area.Height - hadj)
pts(1) = New Point(area.X + gh * 3, area.Y + area.Height - (hadj \ 2))
pts(2) = New Point(area.X + gh * 2, area.Y + area.Height - (hadj \ 3))
pts(3) = New Point(area.X + gh, area.Y + area.Height - (hadj \ 2))
pts(4) = New PointF(area.X, area.Y + area.Height - hadj)
gp.AddCurve(pts)
'Right side top -> bottom
'gp.AddLine(New PointF(area.X + area.Width, area.Y + (rect.Height \ 3) + 9), New PointF(area.X + area.Width, area.Y + area.Height - hadj))
'* Left side bottom -> top (clockwise)
'* NOTE: Top Y value was a bit too high, adjusted by -2. Adjust calculation or maybe use floating point math and used rounding, ceil, or floor
gp.AddLine(New Point(area.X, area.Y + area.Height - hadj), New Point(area.X, area.Y + (rect.Height \ 3) + 8 - 2))
Return gp
End Function
我想要这样的东西:
我知道我可以用library(TraMineR)
data(biofam)
set.seed(10)
biofam <- biofam[sample(nrow(biofam),300),]
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
"Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)
seqplot(biofam.seq, type="Ht")
seqient()
但是由于数据是宽格式的,所以我不确定如何获取数据,以便执行biofam$ient <- seqient(biofam.seq, with.missing=TRUE)
方法。
abline(lm(y ~ x))
> head(biofam[c(1, 10:12, 28)])
idhous ... a15 a16 a17 ... Entropy
1234 NA ... 0 0 0 ... 0.3010904
1515 86261 ... 0 0 0 ... 0.3154649
276 17561 ... 0 0 0 ... 0.4012026
1212 69021 ... 0 0 0 ... 0.5517478
153 11391 ... 0 0 0 ... 0.2559298
1164 66641 ... 0 0 0 ... 0.4178207
似乎也没有提供像seqplot()
这样的数值矢量/矩阵:
plot()
答案 0 :(得分:1)
由seqHtplot
或seqplot(..., type="Ht")
渲染的截面熵存储在$Entropy
返回的对象的seqstatd
元素中。每个时间点的值是该时间点的截面状态分布的熵。因此,每个时间点只有一个值。
这与seqient
返回的纵向熵不同。每个序列有一个值。该值是序列内状态分布的熵。
因此,要绘制回归线,您只需要使用seqstatd
提取横截面熵,定义时间变量,然后在abline(lm())
中使用这些变量:
stat.bf <- seqstatd(biofam.seq)
ent <- stat.bf$Entropy
time <- 1:length(ent)
seqplot(biofam.seq, type = "Ht")
abline(lm(ent ~ time), col = "red", lty = 2)