Assuming that x = 1,2, ... , N, N=10 and y = 2x + ε, ε ~ N(0,1) then you would write something like this:
N = 10;
set.seed(123)
x = 1:N
e = rnorm(N)
y = 2*x + e;
mod <- lm( y ~x);
Xmatrix = matrix( c(rep(1,N), x), ncol=2)
Please see the following link on Matrices and matrix computations in R for more details on tihs matter.
您可以将该矩阵输入R并执行Y〜X,也可以省略截距并执行Y〜$ {X} _i $ -1,其中$ X_i $只是一个向量。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.