- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是编码新手。我想在 R 中有一个必须通过给定点 (X, Y) 的回归图。例如,我想绘制一条穿过 (41, 2900) 的以下样本数据的线性回归线。引用this link ,我试过如下。但我的结果不同。红色是简单的线性模型,蓝色是理想的约束模型,与预期不符。有人可以帮助我吗?
library(ggplot2)
ggplot(data=sampledata, mapping=aes(x, y)) +
geom_point(data=sampledata, size=2) +
xlab("X") +
ylab("Y") +
geom_smooth(method="lm", size=2, colour="red", se=FALSE) +
geom_hline(yintercept=2900) +
geom_vline(xintercept=41) +
geom_smooth(size=2, colour="blue", method="lm",
formula=I(y-2900) ~ I(x-41), se=FALSE)
sampledata <- structure(list(x = c(253.84, 210.28, 192.81, 187.1, 181.43, 176.31,
172.62, 169.08, 164.53, 162.01, 160.19, 158.08, 156.43, 154.98,
153.16, 151.35, 149.29, 147.58, 144.98, 143.57, 142.45, 140.93,
140.08, 138.88, 137.79, 136.77, 136.05, 135.07, 134.35, 133.25,
132.5, 131.51, 130.68, 130.11, 128.84, 127.85, 126.28, 125.38,
124.49, 123.48, 122.32, 121.56, 120.47, 119.66, 118.68, 117.67,
116.51, 115.53, 114.62, 113.45, 112.35, 111.02, 109.02, 107.66,
106.95, 104.84, 103.8, 102.44, 101.33, 100.36, 98.96, 97.18,
95.79, 93.81, 91, 87.4, 84.43, 82.56, 79.53, 76.02, 70.97, 67.24,
63.71, 60.69, 58.37, 56.21, 53.74, 52.1, 50.29, 48.37, 46.87,
45.57, 43.92, 43.15, 42.13, 41.64), y = c(1056, 1140, 1200, 1308,
1188, 1368, 1380, 1536, 1608, 1440, 1428, 1716, 1632, 1692, 1680,
1512, 1440, 1632, 1716, 1656, 1584, 1872, 1812, 1884, 2004, 1692,
2100, 1740, 1980, 1944, 2100, 1896, 1956, 1692, 1812, 1920, 2076,
2148, 2076, 1908, 2028, 2268, 1944, 2052, 2196, 2184, 2436, 2124,
2076, 2040, 1980, 2280, 2232, 2340, 2328, 2292, 2232, 2184, 2580,
2424, 2304, 2364, 2460, 2592, 2568, 2436, 2616, 2796, 2640, 2808,
2988, 2808, 1884, 2844, 2856, 2868, 3132, 3108, 2880, 2856, 2916,
2892, 2772, 2844, 2784, 2664)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -86L))
最佳答案
问题是要相信 y
坐标会移动直线必须经过的点的纵坐标。事实上,它必须移动该点与对应于 x = 41
的预测 y
之间的差异。
fit <- lm(y ~ x, sampledata)
x0 <- 41
y0 <- 2900
(yshift <- predict(fit, data.frame(x = x0)) - y0)
# 1
#84.0286
现在在绘图代码中使用这些值,x0
、y0
和 yshift
。
library(ggplot2)
ggplot(data = sampledata, mapping = aes(x, y)) +
geom_point(size = 1) +
geom_vline(xintercept = x0, linetype = "dashed") +
geom_hline(yintercept = y0, linetype = "dashed") +
geom_point(x = x0, y = y0, size = 3, shape = 3, color = "blue") +
geom_smooth(method = "lm",
formula = y ~ x,
size = 1, colour = "red", se = FALSE) +
geom_smooth(method = "lm",
formula = I(y - yshift) ~ x,
size = 1, colour = "blue", se = FALSE) +
xlab("X") +
ylab("Y")
关于通过给定点的回归线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70553644/
在下面的代码中,我得到一个 uninitialized value警告,但仅限于第二个 given/when例子。为什么是这样? #!/usr/bin/env perl use warnings; u
整个“开关”功能是否已成为实验性的?在没有 Perl 的 future 版本破坏我的代码的情况下,我可以依赖其中的某些部分吗?一般来说,将稳定功能更改为实验性的政策是什么? 背景use feature
有没有办法在一个条件语句中写出如下语句? a和b不能同时等于5。 (a可以是5,b可以是5,但是a AND b不能是5) 最佳答案 正如克里斯指出的那样,您要查找的是逻辑异或,相当于逻辑不等于 !=:
我正在寻找一种算法来找到给定 n 条线段的所有交点。以下是来自 http://jeffe.cs.illinois.edu/teaching/373/notes/x06-sweepline.pdf 的伪
数组中有 N 个元素。我可以选择第一项最多 N 次,第二项最多选择 N-1 次,依此类推。 我有 K 个 token 要使用并且需要使用它们以便我可以拥有最大数量的项目。 arr = [3, 4, 8
我正在尝试修复法语文本中的语法性别,想知道是否有办法从某个词条中获取所有单词的列表,以及是否可以在此类列表中进行查找? 最佳答案 尝试: import spacy lemma_lookup = spa
我正在为 Win32 编写一个简单的自动化测试应用程序。它作为一个单独的进程运行,并通过 Windows API 访问目标应用程序。我可以阅读窗口层次结构,查找标签和文本框,并通过发送/发布消息等来单
在 nodeJs 中使用 Sequelize 时,我从 Sequelize 收到此错误,如下所示: { [SequelizeUniqueConstraintError: Validation erro
本文https://arxiv.org/pdf/1703.10757.pdf使用回归激活映射 (RAM) - 而不是类激活映射 (CAM) 来解决问题。有几篇文章描述了如何实现 CAM。但是我找不到
我正在研究 Mach 动态链接器 dyld。这个问题适用于所有 Apple 平台,但很高兴得到特定于平台的答案;我正在使用 ObjC,但如果对你有用的话,我也很乐意翻译 Swift。 The rele
我有一个包含数千个 Instagram 用户 ID 的列表。我如何获得他们的 Instagram 用户名/句柄? 最佳答案 你必须使用这个 Instagram API: https://api.ins
我在下面的代码: def main(args: Array[String]) { val sparkConf = new SparkConf().setAppName("Spark-Hbase").s
我有一个表格,其中包含从 1 到 10 的数字。(从 D2 到 M2) 假设A1中有03/09/2019 并且在B1中有06/09/2019 并且在C1中有Hello 在A 列中,我有多个系列的单词,
我想在给定服务对应的 URI 的情况下检索服务的注释(特别是 @RolesAllowed )。这是一个例子: 服务: @GET @Path("/example") @RolesAllowed({ "B
我看到 OraclePreparedStatementexecuteQuery() 表现出序列化。也就是说,我想使用相同的连接对 Oracle 数据库同时运行两个查询。然而,OraclePrepare
import java.util.Scanner; public class GeometricSumFromK { public static int geometricSum(int k,
我创建了一个抽象基类Page,它说明了如何构建动态网页。我正在尝试想出一种基于作为 HttpServletRequest 传入的 GET 请求生成 Page 的好方法。例如... public cla
我的字符串是一条短信,采用以下两种格式之一: 潜在客户短信: 您已收到 1 条线索 标题:我的领导 潜在客户 ID:12345-2365 警报设置 ID:890 短信回复: 您已收到 1 条回复 标题
我在 python 中有以下代码: class CreateMap: def changeme(listOne, lisrTwo, listThree, listFour, listfive):
这是在 Hibernate 上运行的 JPA2。 我想检索相同实体类型的多个实例,给定它们的 ID。其中许多已经在持久性上下文和/或二级缓存中。 我尝试了几种方法,但似乎都有其缺点: 当我使用 ent
我是一名优秀的程序员,十分优秀!