交互式3D图的可能包之一是rgl.我想要做的是根据某个因子变量构建带有颜色编码的3D散点图.3D维度散点图用于从plsr分析得到的加载量.
结果情节看起来像

该示例的数据在一个表中给出:
> loadings
| Comp 1 | Comp 2 | Comp 3 | Class
-------------------------------------------------------------------------------------------
TEMP | -0.0607044182964255 | "0.0437618450165671" |"0.045124991801441" | "global"
MW | "-0.13414890573833" | "-0.0970537799069731" |0.263043734662182" | "local"
DM |"-0.183751529577861" | "-0.102703237685933" |"0.0640549385564205" | "global"
CHG |"-0.0558781715833019"| "0.125155347350922" |"-0.119258450107321" | "local"
Run Code Online (Sandbox Code Playgroud)
或者可以生成:
loadings <- data.frame(Comp1 = c(1.2, 3.4, 5.6, 13.1), Comp2 = c(4.3, 1.2, 7.7, 9.8),
Comp3 = c(1.2,6.9,15.6,15.0),
row.names = c("TEMP", "MW", "DM", "CHG"),
Class = c("global", "local", "global", "local"))
scatter3d(x=loadings[[1]], y=loadings[[2]], …Run Code Online (Sandbox Code Playgroud) 我使用glm.fit()函数在R中构建了glm模型:
m <- glm.fit(x = as.matrix(df[,x.id]), y = df[,y.id], family = gaussian())
Run Code Online (Sandbox Code Playgroud)
之后,我尝试做一些预测,使用(我不确定我是否正确选择了s):
predict.glm(m, x, s = 0.005)
Run Code Online (Sandbox Code Playgroud)
并得到一个错误:
Error in terms.default(object) : no terms component nor attribute
Run Code Online (Sandbox Code Playgroud)
在这里https://stat.ethz.ch/pipermail/r-help/2004-September/058242.html我发现了一些问题的解决方案:
predict.glm.fit<-function(glmfit, newmatrix){
newmatrix<-cbind(1,newmatrix)
coef <- rbind(1, as.matrix(glmfit$coef))
eta <- as.matrix(newmatrix) %*% as.matrix(coef)
exp(eta)/(1 + exp(eta))
}
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚是否不可能使用glm.fit并事后预测.为什么有可能?如何正确选择?
注意如果使用glm()函数,可以省略该问题.但glm()函数要求公式,在某些情况下这不太方便.如果有人想使用glm.fit和预测,那么这里有一些解决方案:https://stat.ethz.ch/pipermail/r-help/2004-September/058242.html