首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从土质模型中提取边坡

从土质模型中提取边坡
EN

Stack Overflow用户
提问于 2017-04-12 15:58:16
回答 1查看 66关注 0票数 0

我有一些使用earth模型的数据。我对不同线条的斜率感兴趣,但是看看模型摘要,我没有得到我的预期值。

代码语言:javascript
运行
复制
library(earth)
library(dplyr)
library(ggplot2)

d = structure(list(x = c(9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), y = c(0.151534750704409, 
0.0348452707597105, -0.0913494247372798, -0.214465577974757, 
-0.365251164825619, -0.528214103496014, -0.614970081844732, 
-0.922572314358796, 
-1.15911158401926, -1.36432638285029, -1.51587576144429, -1.63708705686248, 
-1.7530889072188, -1.86142968143915, -1.98159646754281, -2.0994478459505, 
-2.23037530743309, -2.3421669680425, -2.40621060828366, -2.55432043723978, 
-2.73246980567199, -2.92496136528975)), .Names = c("x", "y"), row.names = 
c(NA, -22L), class = c("tbl_df", "tbl", "data.frame"))

mod = earth(y ~ x, data = d)

d$pred = predict(mod, newdata = d)

summary(mod, style = 'pmax')

以下是我的总结:

代码语言:javascript
运行
复制
Call: earth(formula=y~x, data=d)

y =
  -1.314958
  - 0.06811314 * pmax(0,  x - 16) 
  +  0.1518165 * pmax(0, 19 -  x) 
  - 0.05124021 * pmax(0,  x - 19) 

Selected 4 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: x
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 0.004496406    RSS 0.04598597    GRSq 0.9953947    RSq 0.9976504

然而,当我看我的模型时,三个不同的斜率看起来都是负面的:

代码语言:javascript
运行
复制
ggplot(d, aes(x, y)) +
    geom_point() +
    geom_line(aes(x, pred)) + 
    theme(aspect.ratio = 1)  

我如何得到这三个负斜率的数值?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-12 16:21:13

mod$coefficients给出了系数。如果系数在-x上,te斜率将是系数的负值。你可以做mod$coefficients %>% {ifelse(grepl('-x', rownames(.)) , -., .)}来得到斜坡(或者只是在思想上颠倒了-x的部分)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43374384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档