0

Considering the model enter image description here, where enter image description here

And the matrix of $X$ is

enter image description here

How do I input this matrix into R?

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
user3443632
  • 17
  • 1
  • 6
  • @gung Why is this closed? This is certainly about statistics. We can use lm.fit() to do it. For example, model.matrix() then lm.fit(). The function lm.fit() takes a design matrix and fit a linear model, exactly what the question is about. – ABCD Oct 29 '15 at 00:10
  • How exactly do I do that, sorry im new to R – user3443632 Oct 29 '15 at 00:12
  • 1
    There is information on entering data into R [here](http://www.statmethods.net/input/) (note that that was the *very first* Google hit). From there, if your data are in a matrix called `X`, you can fit the model with `lm(Y~X[,2])`. – gung - Reinstate Monica Oct 29 '15 at 00:12
  • 1
    @StudentT, "How do I input this matrix into R?" is a question about *how to use* `R`, not a question about statistics. – gung - Reinstate Monica Oct 29 '15 at 00:13
  • @StudentT: I am more interested to know what people thought that this is NOT a SO question. I think most of the R question should be migrated there but if we just close them as off-topic here then we do not facilitate the OP at all. – usεr11852 Oct 29 '15 at 00:18
  • @usεr11852 I can't speculate on the specifics of individual choices here, but there are often reasons a post that looks like it might belong SO might not be able to be migrated there (e.g., if it's likely to close there because it doesn't fit the requirements for particular kinds of posts to be on topic, we shouldn't migrate until it does). In this case that''s probably not an issue. – Glen_b Oct 29 '15 at 00:36
  • @usεr11852, I voted to close but not migrate. In addition to the $\LaTeX$ issue, questions to be migrated need more than this: they need a [reproducible example](http://stackoverflow.com/q/5963269/1217536). What form is the OP's data in? Is it in a spreadsheet, a text file, written on a slip of paper, etc.? The data entry link I posted lists methods for many different sources. – gung - Reinstate Monica Oct 29 '15 at 00:46
  • @gung: Not all question necessitate a reproducible example. Especially in the case that the OP clearly says that he does not know how to use R so he cannot provide one.... (Clearly when one exists that is good :D ) – usεr11852 Oct 29 '15 at 00:50
  • @l'ombradel'atzavara, there is no LaTeX on [SO]. That's why Glen_b edited the thread before migrating it. – gung - Reinstate Monica Oct 29 '15 at 01:01
  • @gung We are not in Kansas any more... – Antoni Parellada Oct 29 '15 at 01:02
  • @usεr11852, the OP needs to at least state the form their data is in. 'How to enter data into R' is too broad to be answered. – gung - Reinstate Monica Oct 29 '15 at 01:03
  • @gung I took pains to get the latex in through a site that allows getting images out of the latex commands, and just as I posted it, the OP got modified in a really bizarre way. Right now there is nothing left of the OP. What went wrong? – Antoni Parellada Oct 29 '15 at 01:05
  • 1
    Lionel? Is that you? – Rich Scriven Oct 29 '15 at 01:06

2 Answers2

2

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.

usεr11852
  • 285
  • 10
  • 19
  • I voted to close this question as being off-topic here. I am answering this just so the OP can get moving towards the right direction. – usεr11852 Oct 29 '15 at 00:16
  • If you think the post should be migrated, you can flag it, but then you should avoid MathJax/LaTeX markup. – Glen_b Oct 29 '15 at 00:37
  • @Glen_b: I did vote to close and migrate it in SO. Check my voting. Flagging would to the same. – usεr11852 Oct 29 '15 at 00:51
1

You can either input this matrix into R and do Y~X, or omit the intercept and do Y~${X}_i$-1, where $X_i$ is only a vector.