Exclude first factor from intercept in R










2















I'm doing a multi-variable regression in R, where one variable is set as a factor. If I do the regression, the intercept is set to the first factor and all following factors are set relative to that.
So if I do the following regression:



pe1n = lm(return_1_yr_abs~size+fe_year+retained_binary,data=rtn_1_yr)


I get following output:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 17.516160 15.031941 1.165 0.2457
size -0.001619 0.001214 -1.333 0.1845
fe_year2 -3.532222 16.954761 -0.208 0.8352
fe_year3 6.759767 16.303710 0.415 0.6790
fe_year4 -73.769141 39.464482 -1.869 0.0635 .
fe_year6 -27.113332 24.232382 -1.119 0.2649
fe_year7 -17.705589 26.214533 -0.675 0.5004
fe_year8 -12.726297 28.849918 -0.441 0.6597
fe_year9 1.832507 15.557559 0.118 0.9064
fe_year10 5.282221 12.871480 0.410 0.6821
fe_year11 13.584084 16.376386 0.829 0.4081
retained_binary -6.457557 12.922218 -0.500 0.6180


R takes the first year as intercept and now sets all other variables in relation to it. What I want to do is have the average return across all variables as intercept incl. statistical values. And all other variables should be set in relation to that. I already searched after a few solutions and tried them out, but nothing gives me my desired results:



  • change contrasts to sum instead treatment -> last year is missing since contrasts are one less than variables

  • offset intercept by the mean and have no intercept -> no statistical output regarding the mean

  • set intercept manually to mean -> no statistical output

The final result I'm looking for would look like this:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 11.70148 X X X
size X X X X
fe_year1 5.81468 X X X
fe_year2 2.27679 X X X


and so on, with every year until 11 included.



I hope the question is clear enough. Thanks!










share|improve this question
























  • Better formatting is pe1n = lm(return_1_yr_abs ~ size + fe_year + retained_binary, data=rtn_1_yr)

    – sindri_baldur
    Nov 13 '18 at 14:05











  • Edited it, thanks!

    – Densko
    Nov 13 '18 at 14:08











  • Your desired result may not be possible through an lm() call as at least one group in a categorical variable must be dropped (n-1) else you face perfect collinearity. You can possibly create a fe_year1 variable calculated during post-estimation.

    – Parfait
    Nov 13 '18 at 15:20











  • share you data please

    – Mike
    Nov 13 '18 at 16:31















2















I'm doing a multi-variable regression in R, where one variable is set as a factor. If I do the regression, the intercept is set to the first factor and all following factors are set relative to that.
So if I do the following regression:



pe1n = lm(return_1_yr_abs~size+fe_year+retained_binary,data=rtn_1_yr)


I get following output:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 17.516160 15.031941 1.165 0.2457
size -0.001619 0.001214 -1.333 0.1845
fe_year2 -3.532222 16.954761 -0.208 0.8352
fe_year3 6.759767 16.303710 0.415 0.6790
fe_year4 -73.769141 39.464482 -1.869 0.0635 .
fe_year6 -27.113332 24.232382 -1.119 0.2649
fe_year7 -17.705589 26.214533 -0.675 0.5004
fe_year8 -12.726297 28.849918 -0.441 0.6597
fe_year9 1.832507 15.557559 0.118 0.9064
fe_year10 5.282221 12.871480 0.410 0.6821
fe_year11 13.584084 16.376386 0.829 0.4081
retained_binary -6.457557 12.922218 -0.500 0.6180


R takes the first year as intercept and now sets all other variables in relation to it. What I want to do is have the average return across all variables as intercept incl. statistical values. And all other variables should be set in relation to that. I already searched after a few solutions and tried them out, but nothing gives me my desired results:



  • change contrasts to sum instead treatment -> last year is missing since contrasts are one less than variables

  • offset intercept by the mean and have no intercept -> no statistical output regarding the mean

  • set intercept manually to mean -> no statistical output

The final result I'm looking for would look like this:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 11.70148 X X X
size X X X X
fe_year1 5.81468 X X X
fe_year2 2.27679 X X X


and so on, with every year until 11 included.



I hope the question is clear enough. Thanks!










share|improve this question
























  • Better formatting is pe1n = lm(return_1_yr_abs ~ size + fe_year + retained_binary, data=rtn_1_yr)

    – sindri_baldur
    Nov 13 '18 at 14:05











  • Edited it, thanks!

    – Densko
    Nov 13 '18 at 14:08











  • Your desired result may not be possible through an lm() call as at least one group in a categorical variable must be dropped (n-1) else you face perfect collinearity. You can possibly create a fe_year1 variable calculated during post-estimation.

    – Parfait
    Nov 13 '18 at 15:20











  • share you data please

    – Mike
    Nov 13 '18 at 16:31













2












2








2








I'm doing a multi-variable regression in R, where one variable is set as a factor. If I do the regression, the intercept is set to the first factor and all following factors are set relative to that.
So if I do the following regression:



pe1n = lm(return_1_yr_abs~size+fe_year+retained_binary,data=rtn_1_yr)


I get following output:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 17.516160 15.031941 1.165 0.2457
size -0.001619 0.001214 -1.333 0.1845
fe_year2 -3.532222 16.954761 -0.208 0.8352
fe_year3 6.759767 16.303710 0.415 0.6790
fe_year4 -73.769141 39.464482 -1.869 0.0635 .
fe_year6 -27.113332 24.232382 -1.119 0.2649
fe_year7 -17.705589 26.214533 -0.675 0.5004
fe_year8 -12.726297 28.849918 -0.441 0.6597
fe_year9 1.832507 15.557559 0.118 0.9064
fe_year10 5.282221 12.871480 0.410 0.6821
fe_year11 13.584084 16.376386 0.829 0.4081
retained_binary -6.457557 12.922218 -0.500 0.6180


R takes the first year as intercept and now sets all other variables in relation to it. What I want to do is have the average return across all variables as intercept incl. statistical values. And all other variables should be set in relation to that. I already searched after a few solutions and tried them out, but nothing gives me my desired results:



  • change contrasts to sum instead treatment -> last year is missing since contrasts are one less than variables

  • offset intercept by the mean and have no intercept -> no statistical output regarding the mean

  • set intercept manually to mean -> no statistical output

The final result I'm looking for would look like this:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 11.70148 X X X
size X X X X
fe_year1 5.81468 X X X
fe_year2 2.27679 X X X


and so on, with every year until 11 included.



I hope the question is clear enough. Thanks!










share|improve this question
















I'm doing a multi-variable regression in R, where one variable is set as a factor. If I do the regression, the intercept is set to the first factor and all following factors are set relative to that.
So if I do the following regression:



pe1n = lm(return_1_yr_abs~size+fe_year+retained_binary,data=rtn_1_yr)


I get following output:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 17.516160 15.031941 1.165 0.2457
size -0.001619 0.001214 -1.333 0.1845
fe_year2 -3.532222 16.954761 -0.208 0.8352
fe_year3 6.759767 16.303710 0.415 0.6790
fe_year4 -73.769141 39.464482 -1.869 0.0635 .
fe_year6 -27.113332 24.232382 -1.119 0.2649
fe_year7 -17.705589 26.214533 -0.675 0.5004
fe_year8 -12.726297 28.849918 -0.441 0.6597
fe_year9 1.832507 15.557559 0.118 0.9064
fe_year10 5.282221 12.871480 0.410 0.6821
fe_year11 13.584084 16.376386 0.829 0.4081
retained_binary -6.457557 12.922218 -0.500 0.6180


R takes the first year as intercept and now sets all other variables in relation to it. What I want to do is have the average return across all variables as intercept incl. statistical values. And all other variables should be set in relation to that. I already searched after a few solutions and tried them out, but nothing gives me my desired results:



  • change contrasts to sum instead treatment -> last year is missing since contrasts are one less than variables

  • offset intercept by the mean and have no intercept -> no statistical output regarding the mean

  • set intercept manually to mean -> no statistical output

The final result I'm looking for would look like this:



 Estimate Std. Error t value Pr(>|t|) 
(Intercept) 11.70148 X X X
size X X X X
fe_year1 5.81468 X X X
fe_year2 2.27679 X X X


and so on, with every year until 11 included.



I hope the question is clear enough. Thanks!







r regression






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 14:07







Densko

















asked Nov 13 '18 at 13:50









DenskoDensko

113




113












  • Better formatting is pe1n = lm(return_1_yr_abs ~ size + fe_year + retained_binary, data=rtn_1_yr)

    – sindri_baldur
    Nov 13 '18 at 14:05











  • Edited it, thanks!

    – Densko
    Nov 13 '18 at 14:08











  • Your desired result may not be possible through an lm() call as at least one group in a categorical variable must be dropped (n-1) else you face perfect collinearity. You can possibly create a fe_year1 variable calculated during post-estimation.

    – Parfait
    Nov 13 '18 at 15:20











  • share you data please

    – Mike
    Nov 13 '18 at 16:31

















  • Better formatting is pe1n = lm(return_1_yr_abs ~ size + fe_year + retained_binary, data=rtn_1_yr)

    – sindri_baldur
    Nov 13 '18 at 14:05











  • Edited it, thanks!

    – Densko
    Nov 13 '18 at 14:08











  • Your desired result may not be possible through an lm() call as at least one group in a categorical variable must be dropped (n-1) else you face perfect collinearity. You can possibly create a fe_year1 variable calculated during post-estimation.

    – Parfait
    Nov 13 '18 at 15:20











  • share you data please

    – Mike
    Nov 13 '18 at 16:31
















Better formatting is pe1n = lm(return_1_yr_abs ~ size + fe_year + retained_binary, data=rtn_1_yr)

– sindri_baldur
Nov 13 '18 at 14:05





Better formatting is pe1n = lm(return_1_yr_abs ~ size + fe_year + retained_binary, data=rtn_1_yr)

– sindri_baldur
Nov 13 '18 at 14:05













Edited it, thanks!

– Densko
Nov 13 '18 at 14:08





Edited it, thanks!

– Densko
Nov 13 '18 at 14:08













Your desired result may not be possible through an lm() call as at least one group in a categorical variable must be dropped (n-1) else you face perfect collinearity. You can possibly create a fe_year1 variable calculated during post-estimation.

– Parfait
Nov 13 '18 at 15:20





Your desired result may not be possible through an lm() call as at least one group in a categorical variable must be dropped (n-1) else you face perfect collinearity. You can possibly create a fe_year1 variable calculated during post-estimation.

– Parfait
Nov 13 '18 at 15:20













share you data please

– Mike
Nov 13 '18 at 16:31





share you data please

– Mike
Nov 13 '18 at 16:31












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282521%2fexclude-first-factor-from-intercept-in-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282521%2fexclude-first-factor-from-intercept-in-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo