8 Replies Latest reply: Oct 7, 2013 4:49 AM by Rochelle John RSS

    Two dimensions in Line chart, not working

    Nicolai Jørgensen

      Hi

      I'm trying to make a line chart with a plot of calculated points of time to event, e.g. failure (could be any event though).

      I works fine with one dimension (Time), but when I add another dimension, the lines look odd. Any help?

       

      I am looking for a result like below, where dimensions are 1) Time (x axis) and 2) Type (the different lines):

      ScreenHunter_01 May. 16 17.05.jpg

       

      I'm geting this:

      ScreenHunter_02 May. 16 17.16.jpg

      Please see attached simplified qvw with sample data.

       

      Any pointers appreciated.

       

      Best regards

      Nicolai

        • Two dimensions in Line chart, not working
          Fernando Suzuki

          Hi Nicolai,

           

          I think that the problem with your line chart is that it doesn't support the above() function. This function can only be used in tables (pivot or straight).

           

          Sorry but I'm not sure on how you show fix your graph. I'm not an expert yet...

           

           

          Regards,

          Fernando

            • Two dimensions in Line chart, not working
              Nicolai Jørgensen

              Hi Fernando

              Thank you. I think in fact 'above' does work with line charts and tables (not pivot though), and it works fine with only one dimension (as in the qvw attatched). Worst case, I will try out other ways of calculating to get the desired result.

               

              PS: It might seem easy to do the calculations in the loadscript with peek function (and it is), but I want all the dynamics from doing the calculations in the objects, e.g. being able to do what-ever selections in various fields. Since the results are dependent on the result from previous calculated field, this would be lost if it was calculated in the loadscript (fixed).

               

              Kind regards

              Nicolai

                • Re: Two dimensions in Line chart, not working
                  John Witherspoon

                  I'd just calculate your cumulative survival by looking at how many are alive at that time vs. the total number.  Granted, that's not exactly equivalent to your calculation, but your calculation seems wrong to me.  for intance, in Type 1, ID24 did NOT die, yet when ID20 subsequently dies, you go from a 2/7 survival rate to a 0/7 survival rate.  That makes no sense to me.  Shouldn't the death of ID20 take you to a 1/7 survival rate, as ID24 is still alive, even if she is no longer at risk?  I guess I just don't understand what you're doing.

                   

                  Of if you're saying that ID24 was removed from the population without dying at time 70, then the % should change at that point from 2/7 to 1/6 I'd think, or even all the earlier numbers should be changed to reflect 6 in the population.  But that's not hat you're doing either.

                   

                  Calculated as if the censored=1 are simply survivors, do this to your chart:

                   

                  • change your calculated dimension to just Timescale
                  • remove all expressions
                  • add this expression: count(if(Time>TimeScale or Censored=1,ID))/count(ID)
                  • stop suppressing zeros
                  • continuous axis, min=0, max=max(Time)

                   

                  If that's not exactly what you want, that's still the basic idea I'd use.  Just calculate each line separately and not by referring to all the other lines that came above it.

                   

                  It may also be worth changing your data model to not require an island dimension if you have a lot of data to process, as having a count(if()) will be slow.  Since I'm not really understanding your data, I'm not sure what sort of data model you'd want, but I don't mean precalculating anything.  I just mean having the right connections in your data model to do the work for you.

                    • Re: Two dimensions in Line chart, not working
                      Nicolai Jørgensen

                      Hi John

                      Thank you.

                      I guess the chart does need some more explanation:

                      The censored records should be included in the caldulations just like the rest until the time of censoring, but should not be included afterwards, all numbers before that remaining as they were. After a censored point, the there will be a bigger decrease per death/failure than before.

                      It is the censoring part that makes it difficult. I had started with a calculation just as you suggest, calculating points as count of those IDs have Time > TimeScale. The result is great untill the censoring accours.

                       

                      The plot (Kaplan Meier) is explained in the attached pdf (simple fly example) and is used within pharma/medico industry in medical trials. There, the calculations are done in SAS (Proc Lifetest).

                      http://en.wikipedia.org/wiki/Kaplan%E2%80%93Meier_estimator

                       

                      Nicolai

                • Re: Two dimensions in Line chart, not working
                  Nicolai Jørgensen

                  Ok. Went around the problem, by gathering the data to be calculated on, sent it out and did a partial reload with all the calculations in the load script. Works very well. Then, instead of two dimensions and two expressions, I recoded to fit all in two dimensions and one expression instead. Now the graphs look just as I want them to.

                  Thanks for input guys. Untill next time.

                   

                  /Nicolai

                  • Re: Two dimensions in Line chart, not working
                    Lee Matthews

                    Here is an example of how to create the Kaplan Meier Curve

                    http://community.qlik.com/message/401280#

                    • Re: Two dimensions in Line chart, not working
                      Rochelle John

                      Hi Nicholai,

                      Please share your expressions and dimensions.

                       

                      Rochelle