Plotting nlme results and getting different interceptsPlot two graphs in same plot in RError in model prediction with lmeHow to plot a subset of the factor levels of a mixed model in RPlotting predicted values from a lme model (with polynomials) in RRandom effect predictions from gamm model error: cannot evaluate groups for desired levels on 'newdata'R: how to extract information from summary model fitHow to calculate predictions with both standard errors and random effects for ggplot?I get an error with functions of nlme package in RHow do I plot and pull out my slope and intercept values for different groups from lmer?lmer Model failing to converge with random effects structure

Who are the people reviewing far more papers than they're submitting for review?

Why does an orbit become hyperbolic when total orbital energy is positive?

Are there any “Third Order” acronyms used in space exploration?

Are all men created equal according to Hinduism? Is this predominant western belief in agreement with the Vedas?

Impossible Scrabble Words

What are some examples of research that does not solve a existing problem (maybe the problem is not obvious yet) but present a unique discovery?

Wouldn't Kreacher have been able to escape even without following an order?

What does the Free Recovery sign (UK) actually mean?

Other than good shoes and a stick, what are some ways to preserve your knees on long hikes?

Rare Earth Elements in the outer solar system

Does Forgotten Realms setting count as “High magic”?

Hobby function generators

Statistical tests for benchmark comparison

Is there a theorem in Real analysis similar to Cauchy's theorem in Complex analysis?

Is it possible that the shadow of the moon is a single dot during solar eclipse?

Random restarts for unsatisfiable problems

Tips for remembering the order of parameters for ln?

What did the first ever Hunger Games look like?

Which version of the Pigeonhole principle is correct? One is far stronger than the other

Why is the year in this ISO timestamp not 2019?

Why is the UK still pressing on with Brexit?

Writing a system of Linear Equations

What does the "capacitor into resistance" symbol mean?

What is the source of "You can achieve a lot with hate, but even more with love" (Shakespeare?)



Plotting nlme results and getting different intercepts


Plot two graphs in same plot in RError in model prediction with lmeHow to plot a subset of the factor levels of a mixed model in RPlotting predicted values from a lme model (with polynomials) in RRandom effect predictions from gamm model error: cannot evaluate groups for desired levels on 'newdata'R: how to extract information from summary model fitHow to calculate predictions with both standard errors and random effects for ggplot?I get an error with functions of nlme package in RHow do I plot and pull out my slope and intercept values for different groups from lmer?lmer Model failing to converge with random effects structure






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm running a lme in nlme and when I try to plot the results (using the code from one of the answered questions here), I'm getting different results than the resulting model coefficients, namely the intercept. Is this plotting the random effects intercept and not the fixed effects intercept?



model<-lme(Y~A+ Group + A*Group, random=~1|Subject, data.in2)



 > summary(model)
Linear mixed-effects model fit by REML
Data: data.in2
AIC BIC logLik
3203.191 3227.229 -1595.596

Random effects:
Formula: ~1 | Subject
(Intercept) Residual
StdDev: 17.6086 10.03305

Fixed effects: Y ~ A + Group + A * Group
Value Std.Error DF t-value p-value
(Intercept) 42.36244 7.122246 360 5.947905 0.0000
A -1.05472 0.144155 360 -7.316565 0.0000
Group1 -7.49777 12.920964 46 -0.580279 0.5646
A:Group1 0.00180 0.291035 360 0.006195 0.9951
Correlation:
(Intr) A Group1
A -0.902
Group1 -0.551 0.497
A:Group1 0.447 -0.495 -0.888

Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-2.99649773 -0.50936511 -0.01409361 0.55007319 4.11784199

Number of Observations: 410
Number of Groups: 48


And the graph code is:



newdata<-expand.grid(Group=unique(data.in2$Group), A=c(min(data.in2$A), max(data.in2$A)))



[![ggplot(data.in2, aes(x=A, y=Y, colour=Group)) + geom_point(size=1) +
geom_line(aes(y=predict(model), group=Subject, size="Subjects"))+
geom_line(data=newdata, aes(y=predict(model, level=0, newdata=newdata), size="Population")) +
scale_size_manual(name="Predictions", values=c("Subjects"=0.5, "Population"=3), guide="none")][2]][2]


I'm also trying to attach the image but I'm not sure how. https://i.stack.imgur.com/rfNwP.png










share|improve this question














migrated from stats.stackexchange.com Mar 28 at 12:54


This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.

























    1















    I'm running a lme in nlme and when I try to plot the results (using the code from one of the answered questions here), I'm getting different results than the resulting model coefficients, namely the intercept. Is this plotting the random effects intercept and not the fixed effects intercept?



    model<-lme(Y~A+ Group + A*Group, random=~1|Subject, data.in2)



     > summary(model)
    Linear mixed-effects model fit by REML
    Data: data.in2
    AIC BIC logLik
    3203.191 3227.229 -1595.596

    Random effects:
    Formula: ~1 | Subject
    (Intercept) Residual
    StdDev: 17.6086 10.03305

    Fixed effects: Y ~ A + Group + A * Group
    Value Std.Error DF t-value p-value
    (Intercept) 42.36244 7.122246 360 5.947905 0.0000
    A -1.05472 0.144155 360 -7.316565 0.0000
    Group1 -7.49777 12.920964 46 -0.580279 0.5646
    A:Group1 0.00180 0.291035 360 0.006195 0.9951
    Correlation:
    (Intr) A Group1
    A -0.902
    Group1 -0.551 0.497
    A:Group1 0.447 -0.495 -0.888

    Standardized Within-Group Residuals:
    Min Q1 Med Q3 Max
    -2.99649773 -0.50936511 -0.01409361 0.55007319 4.11784199

    Number of Observations: 410
    Number of Groups: 48


    And the graph code is:



    newdata<-expand.grid(Group=unique(data.in2$Group), A=c(min(data.in2$A), max(data.in2$A)))



    [![ggplot(data.in2, aes(x=A, y=Y, colour=Group)) + geom_point(size=1) +
    geom_line(aes(y=predict(model), group=Subject, size="Subjects"))+
    geom_line(data=newdata, aes(y=predict(model, level=0, newdata=newdata), size="Population")) +
    scale_size_manual(name="Predictions", values=c("Subjects"=0.5, "Population"=3), guide="none")][2]][2]


    I'm also trying to attach the image but I'm not sure how. https://i.stack.imgur.com/rfNwP.png










    share|improve this question














    migrated from stats.stackexchange.com Mar 28 at 12:54


    This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.





















      1












      1








      1


      0






      I'm running a lme in nlme and when I try to plot the results (using the code from one of the answered questions here), I'm getting different results than the resulting model coefficients, namely the intercept. Is this plotting the random effects intercept and not the fixed effects intercept?



      model<-lme(Y~A+ Group + A*Group, random=~1|Subject, data.in2)



       > summary(model)
      Linear mixed-effects model fit by REML
      Data: data.in2
      AIC BIC logLik
      3203.191 3227.229 -1595.596

      Random effects:
      Formula: ~1 | Subject
      (Intercept) Residual
      StdDev: 17.6086 10.03305

      Fixed effects: Y ~ A + Group + A * Group
      Value Std.Error DF t-value p-value
      (Intercept) 42.36244 7.122246 360 5.947905 0.0000
      A -1.05472 0.144155 360 -7.316565 0.0000
      Group1 -7.49777 12.920964 46 -0.580279 0.5646
      A:Group1 0.00180 0.291035 360 0.006195 0.9951
      Correlation:
      (Intr) A Group1
      A -0.902
      Group1 -0.551 0.497
      A:Group1 0.447 -0.495 -0.888

      Standardized Within-Group Residuals:
      Min Q1 Med Q3 Max
      -2.99649773 -0.50936511 -0.01409361 0.55007319 4.11784199

      Number of Observations: 410
      Number of Groups: 48


      And the graph code is:



      newdata<-expand.grid(Group=unique(data.in2$Group), A=c(min(data.in2$A), max(data.in2$A)))



      [![ggplot(data.in2, aes(x=A, y=Y, colour=Group)) + geom_point(size=1) +
      geom_line(aes(y=predict(model), group=Subject, size="Subjects"))+
      geom_line(data=newdata, aes(y=predict(model, level=0, newdata=newdata), size="Population")) +
      scale_size_manual(name="Predictions", values=c("Subjects"=0.5, "Population"=3), guide="none")][2]][2]


      I'm also trying to attach the image but I'm not sure how. https://i.stack.imgur.com/rfNwP.png










      share|improve this question














      I'm running a lme in nlme and when I try to plot the results (using the code from one of the answered questions here), I'm getting different results than the resulting model coefficients, namely the intercept. Is this plotting the random effects intercept and not the fixed effects intercept?



      model<-lme(Y~A+ Group + A*Group, random=~1|Subject, data.in2)



       > summary(model)
      Linear mixed-effects model fit by REML
      Data: data.in2
      AIC BIC logLik
      3203.191 3227.229 -1595.596

      Random effects:
      Formula: ~1 | Subject
      (Intercept) Residual
      StdDev: 17.6086 10.03305

      Fixed effects: Y ~ A + Group + A * Group
      Value Std.Error DF t-value p-value
      (Intercept) 42.36244 7.122246 360 5.947905 0.0000
      A -1.05472 0.144155 360 -7.316565 0.0000
      Group1 -7.49777 12.920964 46 -0.580279 0.5646
      A:Group1 0.00180 0.291035 360 0.006195 0.9951
      Correlation:
      (Intr) A Group1
      A -0.902
      Group1 -0.551 0.497
      A:Group1 0.447 -0.495 -0.888

      Standardized Within-Group Residuals:
      Min Q1 Med Q3 Max
      -2.99649773 -0.50936511 -0.01409361 0.55007319 4.11784199

      Number of Observations: 410
      Number of Groups: 48


      And the graph code is:



      newdata<-expand.grid(Group=unique(data.in2$Group), A=c(min(data.in2$A), max(data.in2$A)))



      [![ggplot(data.in2, aes(x=A, y=Y, colour=Group)) + geom_point(size=1) +
      geom_line(aes(y=predict(model), group=Subject, size="Subjects"))+
      geom_line(data=newdata, aes(y=predict(model, level=0, newdata=newdata), size="Population")) +
      scale_size_manual(name="Predictions", values=c("Subjects"=0.5, "Population"=3), guide="none")][2]][2]


      I'm also trying to attach the image but I'm not sure how. https://i.stack.imgur.com/rfNwP.png







      r ggplot2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 14:25









      Mircea_cel_BatranMircea_cel_Batran

      407 bronze badges




      407 bronze badges





      migrated from stats.stackexchange.com Mar 28 at 12:54


      This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.











      migrated from stats.stackexchange.com Mar 28 at 12:54


      This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.









      migrated from stats.stackexchange.com Mar 28 at 12:54


      This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.
























          1 Answer
          1






          active

          oldest

          votes


















          0
















          Your model formula does not match your output notation. The correct model formula for the output you provided is:



          model<-lme(Y ~ A + Group + A:Group, random=~1|Subject, data.in2)


          which is equivalent with:



          model<-lme(Y ~ A*Group, random=~1|Subject, data.in2)


          If you tell us more about your A and Group variables, we can comment on the model output you provided.



          Addendum:



          Not clear from your post what you mean by "getting different intercepts". In your model, the relationship between Y and A for each subject in each group is assumed to be linear (e.g., the value of Y tends to decrease as A increases); the intercept of the straight line capturing that relationship is allowed to be different across subjects within a group but the slope is presumed to be the same across subjects in that group. The slope captures the rate of change in the expected value of Y per 1-unit increase in the value of A for a given subject in a given group.



          Because your model includes an intercept between A and Group, there is a further assumption that the slopes of subjects in the first group are different than the slopes of subjects in the second group. The p-value for the interaction between A and Group is quite large, so your data don't seem to support this assumption. This is why, in your plot, you see slopes for subjects in the two groups to be more or less the same.



          The 'typical' subject in your first group (Group = 0) has an intercept given by 42.36244 and a slope given by -1.05472. Other subjects in the first group have the same slope but intercepts that vary randomly across the 'typical' intercept value of 42.36244. You can extract the deviations from this 'typical' intercept with the ranef() command. Adding these deviations to the 'typical' intercept in the first group will give you the subject-specific intercepts for the first group subjects.



          The 'typical' subject in your second group (Group = 1) has an intercept given by 42.36244 + (-7.49777) a slope given by -1.05472 + (0.00180). Other subjects in the second group have the same slope of -1.05472 + (0.00180) but intercepts that vary randomly across the 'typical' intercept value of 42.36244 + (-7.49777). You can extract the deviations from this 'typical' intercept with the ranef() command - just make sure to match each deviation with the appropriate subject in group 2. Adding these deviations to the 'typical' intercept for the second group will give you the subject-specific intercepts for the second group subjects.



          You have enough information in your summary model and the ranef() command to actually build your plot from scratch and see if it matches the plot you showed here.






          share|improve this answer






















          • 1





            You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

            – Mircea_cel_Batran
            Mar 28 at 12:12











          • Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

            – Isabella Ghement
            Mar 28 at 15:10






          • 1





            Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

            – Mircea_cel_Batran
            Mar 28 at 17:43






          • 1





            Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

            – Mircea_cel_Batran
            Mar 28 at 18:22










          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/4.0/"u003ecc by-sa 4.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%2f55398193%2fplotting-nlme-results-and-getting-different-intercepts%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0
















          Your model formula does not match your output notation. The correct model formula for the output you provided is:



          model<-lme(Y ~ A + Group + A:Group, random=~1|Subject, data.in2)


          which is equivalent with:



          model<-lme(Y ~ A*Group, random=~1|Subject, data.in2)


          If you tell us more about your A and Group variables, we can comment on the model output you provided.



          Addendum:



          Not clear from your post what you mean by "getting different intercepts". In your model, the relationship between Y and A for each subject in each group is assumed to be linear (e.g., the value of Y tends to decrease as A increases); the intercept of the straight line capturing that relationship is allowed to be different across subjects within a group but the slope is presumed to be the same across subjects in that group. The slope captures the rate of change in the expected value of Y per 1-unit increase in the value of A for a given subject in a given group.



          Because your model includes an intercept between A and Group, there is a further assumption that the slopes of subjects in the first group are different than the slopes of subjects in the second group. The p-value for the interaction between A and Group is quite large, so your data don't seem to support this assumption. This is why, in your plot, you see slopes for subjects in the two groups to be more or less the same.



          The 'typical' subject in your first group (Group = 0) has an intercept given by 42.36244 and a slope given by -1.05472. Other subjects in the first group have the same slope but intercepts that vary randomly across the 'typical' intercept value of 42.36244. You can extract the deviations from this 'typical' intercept with the ranef() command. Adding these deviations to the 'typical' intercept in the first group will give you the subject-specific intercepts for the first group subjects.



          The 'typical' subject in your second group (Group = 1) has an intercept given by 42.36244 + (-7.49777) a slope given by -1.05472 + (0.00180). Other subjects in the second group have the same slope of -1.05472 + (0.00180) but intercepts that vary randomly across the 'typical' intercept value of 42.36244 + (-7.49777). You can extract the deviations from this 'typical' intercept with the ranef() command - just make sure to match each deviation with the appropriate subject in group 2. Adding these deviations to the 'typical' intercept for the second group will give you the subject-specific intercepts for the second group subjects.



          You have enough information in your summary model and the ranef() command to actually build your plot from scratch and see if it matches the plot you showed here.






          share|improve this answer






















          • 1





            You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

            – Mircea_cel_Batran
            Mar 28 at 12:12











          • Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

            – Isabella Ghement
            Mar 28 at 15:10






          • 1





            Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

            – Mircea_cel_Batran
            Mar 28 at 17:43






          • 1





            Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

            – Mircea_cel_Batran
            Mar 28 at 18:22















          0
















          Your model formula does not match your output notation. The correct model formula for the output you provided is:



          model<-lme(Y ~ A + Group + A:Group, random=~1|Subject, data.in2)


          which is equivalent with:



          model<-lme(Y ~ A*Group, random=~1|Subject, data.in2)


          If you tell us more about your A and Group variables, we can comment on the model output you provided.



          Addendum:



          Not clear from your post what you mean by "getting different intercepts". In your model, the relationship between Y and A for each subject in each group is assumed to be linear (e.g., the value of Y tends to decrease as A increases); the intercept of the straight line capturing that relationship is allowed to be different across subjects within a group but the slope is presumed to be the same across subjects in that group. The slope captures the rate of change in the expected value of Y per 1-unit increase in the value of A for a given subject in a given group.



          Because your model includes an intercept between A and Group, there is a further assumption that the slopes of subjects in the first group are different than the slopes of subjects in the second group. The p-value for the interaction between A and Group is quite large, so your data don't seem to support this assumption. This is why, in your plot, you see slopes for subjects in the two groups to be more or less the same.



          The 'typical' subject in your first group (Group = 0) has an intercept given by 42.36244 and a slope given by -1.05472. Other subjects in the first group have the same slope but intercepts that vary randomly across the 'typical' intercept value of 42.36244. You can extract the deviations from this 'typical' intercept with the ranef() command. Adding these deviations to the 'typical' intercept in the first group will give you the subject-specific intercepts for the first group subjects.



          The 'typical' subject in your second group (Group = 1) has an intercept given by 42.36244 + (-7.49777) a slope given by -1.05472 + (0.00180). Other subjects in the second group have the same slope of -1.05472 + (0.00180) but intercepts that vary randomly across the 'typical' intercept value of 42.36244 + (-7.49777). You can extract the deviations from this 'typical' intercept with the ranef() command - just make sure to match each deviation with the appropriate subject in group 2. Adding these deviations to the 'typical' intercept for the second group will give you the subject-specific intercepts for the second group subjects.



          You have enough information in your summary model and the ranef() command to actually build your plot from scratch and see if it matches the plot you showed here.






          share|improve this answer






















          • 1





            You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

            – Mircea_cel_Batran
            Mar 28 at 12:12











          • Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

            – Isabella Ghement
            Mar 28 at 15:10






          • 1





            Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

            – Mircea_cel_Batran
            Mar 28 at 17:43






          • 1





            Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

            – Mircea_cel_Batran
            Mar 28 at 18:22













          0














          0










          0









          Your model formula does not match your output notation. The correct model formula for the output you provided is:



          model<-lme(Y ~ A + Group + A:Group, random=~1|Subject, data.in2)


          which is equivalent with:



          model<-lme(Y ~ A*Group, random=~1|Subject, data.in2)


          If you tell us more about your A and Group variables, we can comment on the model output you provided.



          Addendum:



          Not clear from your post what you mean by "getting different intercepts". In your model, the relationship between Y and A for each subject in each group is assumed to be linear (e.g., the value of Y tends to decrease as A increases); the intercept of the straight line capturing that relationship is allowed to be different across subjects within a group but the slope is presumed to be the same across subjects in that group. The slope captures the rate of change in the expected value of Y per 1-unit increase in the value of A for a given subject in a given group.



          Because your model includes an intercept between A and Group, there is a further assumption that the slopes of subjects in the first group are different than the slopes of subjects in the second group. The p-value for the interaction between A and Group is quite large, so your data don't seem to support this assumption. This is why, in your plot, you see slopes for subjects in the two groups to be more or less the same.



          The 'typical' subject in your first group (Group = 0) has an intercept given by 42.36244 and a slope given by -1.05472. Other subjects in the first group have the same slope but intercepts that vary randomly across the 'typical' intercept value of 42.36244. You can extract the deviations from this 'typical' intercept with the ranef() command. Adding these deviations to the 'typical' intercept in the first group will give you the subject-specific intercepts for the first group subjects.



          The 'typical' subject in your second group (Group = 1) has an intercept given by 42.36244 + (-7.49777) a slope given by -1.05472 + (0.00180). Other subjects in the second group have the same slope of -1.05472 + (0.00180) but intercepts that vary randomly across the 'typical' intercept value of 42.36244 + (-7.49777). You can extract the deviations from this 'typical' intercept with the ranef() command - just make sure to match each deviation with the appropriate subject in group 2. Adding these deviations to the 'typical' intercept for the second group will give you the subject-specific intercepts for the second group subjects.



          You have enough information in your summary model and the ranef() command to actually build your plot from scratch and see if it matches the plot you showed here.






          share|improve this answer















          Your model formula does not match your output notation. The correct model formula for the output you provided is:



          model<-lme(Y ~ A + Group + A:Group, random=~1|Subject, data.in2)


          which is equivalent with:



          model<-lme(Y ~ A*Group, random=~1|Subject, data.in2)


          If you tell us more about your A and Group variables, we can comment on the model output you provided.



          Addendum:



          Not clear from your post what you mean by "getting different intercepts". In your model, the relationship between Y and A for each subject in each group is assumed to be linear (e.g., the value of Y tends to decrease as A increases); the intercept of the straight line capturing that relationship is allowed to be different across subjects within a group but the slope is presumed to be the same across subjects in that group. The slope captures the rate of change in the expected value of Y per 1-unit increase in the value of A for a given subject in a given group.



          Because your model includes an intercept between A and Group, there is a further assumption that the slopes of subjects in the first group are different than the slopes of subjects in the second group. The p-value for the interaction between A and Group is quite large, so your data don't seem to support this assumption. This is why, in your plot, you see slopes for subjects in the two groups to be more or less the same.



          The 'typical' subject in your first group (Group = 0) has an intercept given by 42.36244 and a slope given by -1.05472. Other subjects in the first group have the same slope but intercepts that vary randomly across the 'typical' intercept value of 42.36244. You can extract the deviations from this 'typical' intercept with the ranef() command. Adding these deviations to the 'typical' intercept in the first group will give you the subject-specific intercepts for the first group subjects.



          The 'typical' subject in your second group (Group = 1) has an intercept given by 42.36244 + (-7.49777) a slope given by -1.05472 + (0.00180). Other subjects in the second group have the same slope of -1.05472 + (0.00180) but intercepts that vary randomly across the 'typical' intercept value of 42.36244 + (-7.49777). You can extract the deviations from this 'typical' intercept with the ranef() command - just make sure to match each deviation with the appropriate subject in group 2. Adding these deviations to the 'typical' intercept for the second group will give you the subject-specific intercepts for the second group subjects.



          You have enough information in your summary model and the ranef() command to actually build your plot from scratch and see if it matches the plot you showed here.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 28 at 15:08

























          answered Mar 27 at 16:03









          Isabella GhementIsabella Ghement

          3701 silver badge12 bronze badges




          3701 silver badge12 bronze badges










          • 1





            You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

            – Mircea_cel_Batran
            Mar 28 at 12:12











          • Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

            – Isabella Ghement
            Mar 28 at 15:10






          • 1





            Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

            – Mircea_cel_Batran
            Mar 28 at 17:43






          • 1





            Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

            – Mircea_cel_Batran
            Mar 28 at 18:22












          • 1





            You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

            – Mircea_cel_Batran
            Mar 28 at 12:12











          • Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

            – Isabella Ghement
            Mar 28 at 15:10






          • 1





            Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

            – Mircea_cel_Batran
            Mar 28 at 17:43






          • 1





            Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

            – Mircea_cel_Batran
            Mar 28 at 18:22







          1




          1





          You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

          – Mircea_cel_Batran
          Mar 28 at 12:12





          You're absolutely right, B was meant to be Group in the initial statement. A is a continuous variable and Group is a categorical variable with 2 levels.

          – Mircea_cel_Batran
          Mar 28 at 12:12













          Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

          – Isabella Ghement
          Mar 28 at 15:10





          Please see my addendum - let me know if that clarifies matters for you. By the way, are you Romanian? I am Romanian myself but established in Canada - my little brother went to the Mircea cel Batran highschool in Constanta.

          – Isabella Ghement
          Mar 28 at 15:10




          1




          1





          Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

          – Mircea_cel_Batran
          Mar 28 at 17:43





          Thank you! That was a great thorough explanation! I will try this out and see what the new plot will look like! Yes I am Romanian! Bine v-am gasit!

          – Mircea_cel_Batran
          Mar 28 at 17:43




          1




          1





          Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

          – Mircea_cel_Batran
          Mar 28 at 18:22





          Actually, as it turns out, the scales are off here. I didn't make that connection until I tried your method and naturally the average of the deviations is very close to zero, hence the population line. If I extend the x-axis out to zero, I would get the same intercept. It's always the easiest answer! Thank you anyway!

          – Mircea_cel_Batran
          Mar 28 at 18:22






          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          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%2f55398193%2fplotting-nlme-results-and-getting-different-intercepts%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현