r语言怎么计算回归模型的置信区间

Python016

r语言怎么计算回归模型的置信区间,第1张

用predict就能做到。

predict的用法:

predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf,

interval = c("none", "confidence", "prediction"),

level = 0.95, type = c("response", "terms"),

terms = NULL, na.action = na.pass,

pred.var = res.var/weights, weights = 1, ...)

只要注意其中的object,newdata,interval,level,type就行。

object是你的回归模型。

newdata是使用的数据。

interval选confidence或者"c"。

level是置信水平。

type在计算响应变量时使用response,对变量计算使用terms。如果是terms,需要用后面的terms参数指定变量名(character类型向量形式)。

response的话返回一个数据框,三列,分别是预测值,区间下限和上限。

terms返回一个list。

实验内容一

1.固定样本量 和 ,观察重复次数100、200和400时置信区间包含真值 的频率是否接近置信度

2.设置 ,其他保持1不变,重复1,观察模拟结果;并观察与1中置信区间长度对比效果(随的变化)

3.将1中样本量变成n = 200,其他不变,重复1,观察模拟结果,并观察与1中置信区间长度对比效果(随n的变化)