我有一个带有响应变量ADA的数据集,以及独立变量LEV,ROA和ROAL。数据称为dt。我使用以下代码来获取潜在类的系数。
m1 <- stepFlexmix(ADA ~ LEV+ROA+ROAL,data=dt,control= list(verbose=0),
k=1:5,nrep= 10);
m1 <- getModel(m1, "BIC");
一切都很好,直到我从http://rss.acs.unt.edu/Rdoc/library/flexmix/html/flexmix.html
中读到以下内容model Object of FLXM of list of FLXM objects. Default is the object returned by calling FLXMRglm().
我认为默认模型调用是广义线性模型,而我对线性模型感兴趣。我怎样才能使用线性模型而不是GLM?我搜索了很长一段时间,除了这个例子之外,有点无法得到它 http://www.inside-r.org/packages/cran/flexmix/docs/flexmix,我无法理解:
data("NPreg", package = "flexmix")
## mixture of two linear regression models. Note that control parameters
## can be specified as named list and abbreviated if unique.
ex1 <- flexmix(yn~x+I(x^2), data=NPreg, k=2,
control=list(verb=5, iter=100))
ex1
summary(ex1)
plot(ex1)
## now we fit a model with one Gaussian response and one Poisson
## response. Note that the formulas inside the call to FLXMRglm are
## relative to the overall model formula.
ex2 <- flexmix(yn~x, data=NPreg, k=2,
model=list(FLXMRglm(yn~.+I(x^2)),
FLXMRglm(yp~., family="poisson")))
plot(ex2)
有人请告诉我如何使用线性回归代替GLM。或者我已经使用LM并因为“默认模型线”而感到困惑?请解释。感谢。
答案 0 :(得分:1)
我做了数值分析以了解是否
m1 <- stepFlexmix(ADA ~ LEV+ROA+ROAL,data=dt,control= list(verbose=0)
确实产生了线性回归的结果。为了进行实验,我运行了以下代码并发现是的,估计的参数确实来自线性回归。实验帮助我减轻了我的预订。
x1 <- c(1:200);
x2 <- x1*x1;
x3 <- x1*x2;
e1 <- rnorm(200,0,1);
e2 <- rnorm(200,0,1);
y1 <- 5+12*x1+20*x2+30*x3+e1;
y2 <- 18+5*x1+10*x2+15*x3+e2;
y <- c(y1,y2)
x11 <- c(x1,x1)
x22 <- c(x2,x2)
x33 <- c(x3,x3)
d <- data.frame(y,x11,x22,x33)
m <- stepFlexmix(y ~ x11+x22+x33, data =d, control = list(verbose=0), k=1:5, nrep = 10);
m <- getModel(m, "BIC");
parameters(m);
plotEll(m, data = d)
m.refit <- refit(m);
summary(m.refit)