[R] [FORGED] Regression with factors ?

stn021 stn021 at gmail.com
Wed Jul 13 18:48:27 CEST 2016


> Is this what is intended?
>
>> observed_data$p1ab <- persons$ability[ match(observed_data$p1, persons$name) ]
>> observed_data$p2ab <- persons$ability[ match(observed_data$p2, persons$name) ]


Hello David,

thank you for your answer.


The code in my previous post was intended as an answer to the question
in an earlier post about example-data, quote:

> > Would you like me to make a complete example dataset with more records and noise ?
> Yes. And preferably do it with R code.

I should have re-stated this connection in the post.


The code generates a matrix 'observed_data' which is the data the
experimenter would get during the experiment.

This matrix is output in the last line. All other output is only meant
to document the generation-process.

So the only thing visible to the experimenter before analysis is
exactly that matrix 'observed_data'  (usually in the form of some
written documentation which is later entered into statistical
software). Everything before that last line simulates those unknown
parameters that the experiment is supposed to reveal.

The unknown parameters are specifically
- the matrix 'persons'
- and the variable 'multiplyer'

Both are supposed to be revealed by the analyis. p1ab and p2ab would
therefore depend on the unknown parameters and could not be added to
'observed_data' before the analysis.

Sorry again for omitting the back-reference.


I would like to know:

- how to get R to use p1 and p2 as levels of the same factor
(=persons) instead of levels of two different factors.

- how to get R to multiply the numerical levels of factors during the
search for the solution. Factors cannot be multiplied before running
lm() or some other package because before the analysis their numerical
values are not known.


THX, Stefan



More information about the R-help mailing list