Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Seasonality graphics

    Hi,

    i need help!

    I'm testing seasonality in trend research about a rare disease. I found statistical significance over eight year of analysis (96 time points) by applying a generalized linear model.
    Then i calculate monthly mean and performed a graph (cycleplot, with a graphical clear seasonality).. I'd like to obtain a line connecting my monthly means.. but i can't found the right command.

    My GLM command: (glm trend i.month c.year cos_1 sin_1 time, family (poisson) link(log) eform)
    My Cycleplot command: (cycleplot mean month year, xla(1/12) sy(i) myla(J F M A M J J A S O N D)

    mean correspond to the combined trend mean over each month

    i attached what i obtained and what i'd like to obtain

    Can someone help me?

    Attached Files

  • #2
    cycleplot is from the Stata Journal.

    Is

    Code:
    line mean month, sort
    what you want?

    Comment


    • #3
      Maybe on predicted data, and in a way to make it continuous.. as posted in second image!

      Comment


      • #4
        Sorry, but I am lost here. If you can post a graph, you must know how to make that graph. Fine, but I don't understand what you're missing.

        Comment


        • #5
          That's not my graph! I took it from the web, and i'd like to do something like that.. but i don't know how!

          Comment


          • #6
            The first one is mine, and i have no idea how to transform it into the second one!

            Comment


            • #7
              cycleplot can produce the second graph.

              Comment


              • #8
                I was confused too; sorry about that. I am not clear enough about your data to advise. For example, nothing in your glm call makes it obvious to me why hemisphere predictions differ by a factor of almost 10.

                Comment


                • #9
                  Make it simple: how can i produce the second graph (northern southern etc.etc.) with cycleplot? Which options can add the continous line?

                  Beginning with this command: (cycleplot mean month year, xla(1/12) sy(i) myla(J F M A M J J A S O N D)
                  Last edited by Emanuele Spina; 08 May 2019, 10:13.

                  Comment


                  • #10
                    It's your first graph that could come out of cycleplot, or so I guess.

                    Comment


                    • #11
                      Please make an effort to present a data example using the dataex command in the future. You can produce the second graph using twoway. Here is some technique.

                      Code:
                      *CREATING DATA EXAMPLE FOR ILLUSTRATION
                      clear
                      set obs 10
                      local months "jan feb mar apr may"
                      set seed 2019
                      foreach month of local months{
                      gen `month'= runiformint(15, 40)
                      }
                      
                      *PRESERVE INITIAL DATASET
                      preserve
                      *COLLAPSE TO GET MEANS BY MONTH
                      collapse (mean) jan- may
                      *DUPLICATE MONTHLY MEANS TWICE AND CREATE OBSERVATION #
                      expand 3
                      gen t=_n
                      
                      *RESHAPE TO LONG LAYOUT
                      rename (jan-may) month#, addnumber(1)
                      reshape long month, i(t)
                      label var month "Mean whatever"
                      *SORT AND ORDER
                      sort _j
                      gen order=_n
                      *GRAPH USING TWOWAY
                      
                      tw(line month order if _j==1)(line month order if _j==2)(line month order if _j==3) ///
                      (line month order if _j==4) (line month order if _j==5, leg(off) xtitle("") ///
                      xlabel(2 "Jan" 5 "Feb" 8 "Mar" 11 "Apr" 14 "May") scheme(s1mono))

                      Result:
                      Click image for larger version

Name:	Graph.png
Views:	1
Size:	14.3 KB
ID:	1497482

                      Comment


                      • #12
                        Ok, this graph is what i obtain with cycleplot (see my first graph).

                        Now i'm searching a command for a connection line (see the second graph i posted, that's NOT mine but an example i found in literature).

                        Can you help me?

                        Comment


                        • #13
                          I guess the confusion is that what you are referring to "first" and "second" graph is inverted. You are making the one that looks like Stata, but want to do something similar to the graph that is subdivided into the Northern and Southern Hemispheres, correct?

                          Try looking if some sort of line graph with smoothing (lowess) doesn't help you:

                          Code:
                          clear
                          input long month float y
                           5 45
                           4 49
                           8 50
                           1 47
                           9 52
                           7 51
                           6 46
                           2 47
                          12 50
                          11 51
                          10 48
                           3 42
                          end
                          label values month mon
                          label def mon 1 "apr", modify
                          label def mon 2 "aug", modify
                          label def mon 3 "dec", modify
                          label def mon 4 "feb", modify
                          label def mon 5 "jan", modify
                          label def mon 6 "jul", modify
                          label def mon 7 "jun", modify
                          label def mon 8 "mar", modify
                          label def mon 9 "may", modify
                          label def mon 10 "nov", modify
                          label def mon 11 "oct", modify
                          label def mon 12 "sep", modify
                          
                          
                          
                          twoway (lowess y month, bwidth(0.5)) (scatter y month)

                          Comment


                          • #14
                            Ok. By correcting your input


                            clear
                            input long month float y
                            5 53
                            4 51
                            8 47
                            1 45
                            9 50
                            7 46
                            6 50
                            2 49
                            12 42
                            11 48
                            10 51
                            3 50
                            end
                            label values month mon
                            label def mon 4 "apr", modify
                            label def mon 8 "aug", modify
                            label def mon 1 "dec", modify
                            label def mon 2 "feb", modify
                            label def mon 4 "jan", modify
                            label def mon 7 "jul", modify
                            label def mon 6 "jun", modify
                            label def mon 3 "mar", modify
                            label def mon 5 "may", modify
                            label def mon 11 "nov", modify
                            label def mon 10 "oct", modify
                            label def mon 9 "sep", modify



                            twoway (lowess y month, bwidth(0.5)) (scatter y month)

                            i obtained this graph, that is much more than previously seen on my pc.

                            Now, the graph to what i'm inspiring (northern and southern, as you have correctly decoded: D) has a more "harmonic" line. I think that the researchers have shown the predicted line according to their model. There's a way to do it?
                            Attached Files

                            Comment


                            • #15
                              Hi Emanuele,

                              The question for me is what is it that you are trying to show. If you are trying to create just a figure that looks pretty, with a line that seems more "harmonic", you can play around with settings in the graph twoway graphic user interface. Some alternatives are to change the bandwidth or to specify mean on the command (see below). To obtain further info on what that does, please refer to the help file.

                              Code:
                              twoway (lowess y month, mean bwidth(0.6)) (scatter y month)
                              help twoway_lowess
                              If what you want is to plot what the prediction of your model is (a good way to compare how your model is performing when comparing to your data), you can try using the predict command after your model - help predict, and then plot the prediction of your model as a line in your graph (instead of the lowess smoothing). See a mock model below with the prediction plotted against data.

                              Code:
                              clear
                              input long month float y
                               1 45
                               2 49
                               3 50
                               4 51
                               5 53
                               6 50
                               7 46
                               8 47
                               9 50
                              10 51
                              11 48
                              12 42
                              end
                              label values month mon
                              label def mon 1 "jan", modify
                              label def mon 2 "feb", modify
                              label def mon 3 "mar", modify
                              label def mon 4 "apr", modify
                              label def mon 5 "may", modify
                              label def mon 6 "jun", modify
                              label def mon 7 "jul", modify
                              label def mon 8 "aug", modify
                              label def mon 9 "sep", modify
                              label def mon 10 "oct", modify
                              label def mon 11 "nov", modify
                              label def mon 12 "dec", modify
                              
                              gen y2 = y*y
                              poisson y y2
                              predict y2hat
                              twoway (line y2hat month) (scatter y month)

                              Comment

                              Working...
                              X