回归模型点估计

Regression model point estimation

我想根据参数值列表检索二阶多项式回归线的值。

这是模型:

fit <- lm(y ~ poly(age, 2) + height + age*height)

我想使用年龄值列表并检索回归线上的值,以及标准差和标准误差。 'age' 是一个连续变量,但我想创建一个离散值数组和 return 回归线的预测值。

示例:

age <- c(10, 11, 12, 13, 14)

由于您有一个交互项,线性或二次 age 项(或两者一起)的回归系数只有在您同时指定要考虑的 height 的值时才有意义.因此,要在高度处于平均值时获得预测,您可以这样做:

predict(fit, data.frame(age=c(10, 11, 12, 13, 14), height=mean(height) ) )

bouncyball 提出了一个很好的观点。您询问了 "standard deviation and standard errors",但系数和预测没有 "standard deviations" 作为通常使用的术语,但 ratehr "standard errors of the estimate" 通常缩短为标准误差。

predict(fit, data.frame(age=c(10, 11, 12, 13, 14), height=mean(height) ), se.fit=TRUE  )

我想如果你做了 bootstrap 运行 并查看了单独系数的标准偏差作为系数标准误差的估计值,这可能被认为是一个标准偏差,但它会在参数的范围内 space 而不是在变量的范围内。

您的数据有 2 个变量,因此您需要同时提供年龄和身高。

例如使用模拟数据:

age = sample(10)
height = sort(rnorm(10, 6, 1))
y = sort(rnorm(10, 150, 30))

fit <- lm(y ~ age + poly(age, 2) + height + age*height)

要获得预测值,请指定年龄和身高,然后进行预测:

# I'm using my own heights, you should choose the values you're interested in
new.data <- data.frame(age=c(10, 11, 12, 13, 14) , 
                  height=c(5.7, 6.3, 5.8, 5.9, 6.0) )

> predict(fit, new.data)
           1            2            3            4            5 
132.76675715 137.70712251 113.39494557 102.07262016  88.84240532 

获取每个预测的置信区间

> predict(fit, new.data, interval="confidence")
           fit            lwr          upr
1 132.76675715  96.0957812269 169.43773307
2 137.70712251  73.2174486246 202.19679641
3 113.39494557  39.5470153667 187.24287578
4 102.07262016   3.5466926099 200.59854771
5  88.84240532 -37.7404171712 215.42522781