tag:blogger.com,1999:blog-1275149608391671670.comments2014-04-20T15:08:38.080-04:00SAS and RKen Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comBlogger460125tag:blogger.com,1999:blog-1275149608391671670.post-18266195273730112612014-04-20T15:08:38.080-04:002014-04-20T15:08:38.080-04:00Thanks for the post. It is really helpful. I perfo...Thanks for the post. It is really helpful. I performed survival analysis and KM curve cross each other suggesting that PH assumption is not met but my schenfeld test is not significant. So, could you please tell me what can be the reason that Schoenfeld test is not significant even though KM curves are crossing?Vishal Balihttp://www.blogger.com/profile/10778331267390532406noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-40922083198270089922014-04-17T10:45:05.890-04:002014-04-17T10:45:05.890-04:00Nice, Andrej, thanks.
For those not familiar, in ...Nice, Andrej, thanks.<br /><br />For those not familiar, in R outer() generates the outer product of two vectors, by default. This is equivalent to the %o% operator:<br />> 1:2 %o% 1:2<br /> [,1] [,2]<br />[1,] 1 2<br />[2,] 2 4<br />> outer(1:2,1:2)<br /> [,1] [,2]<br />[1,] 1 2<br />[2,] 2 4<br />As Andrej demonstrates, you can supply a function on the vector inputs as an optional argument to outer().<br /><br />(To get the inner product of two vectors, use the %*% operator:<br />> 1:2 %*% 1:2<br /> [,1]<br />[1,] 5 <br />.)Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-12763121428631505372014-04-15T08:36:14.824-04:002014-04-15T08:36:14.824-04:00Nice post! Also a classical example for which to a...Nice post! Also a classical example for which to apply 'outer':<br /><br />outer(1:5, 1:5, function(x, y) 1/(x + y - 1))<br /><br />Cheers, <br />Andrejanspiessnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-50510274766370371962014-04-14T13:18:31.974-04:002014-04-14T13:18:31.974-04:00Not in the function that's provided with the l...Not in the function that's provided with the lawstat package, as far as I know. There may well be implementations in other packages, and it's likely that generating the test from scratch would not be too difficult, especially if you begin with the code included in the lawstat package.Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-48977470401937319542014-04-14T11:53:18.686-04:002014-04-14T11:53:18.686-04:00Yes, I did miss your point, Rick. I don't use...Yes, I did miss your point, Rick. I don't use IML, so I don't try to understand the IML parts of your posts. Apologies-- I know your focus is IML, but I find great value in the additional content.<br /><br />The row() and col() functions in R return the row number or column number of each item in a matrix. Thus for the matrix <br />> matrix(1:4, nrow=2)<br /> [,1] [,2]<br />[1,] 1 3<br />[2,] 2 4<br /><br />we find<br />> row(matrix(1:4, nrow=2))<br /> [,1] [,2]<br />[1,] 1 1<br />[2,] 2 2<br /><br />This does suggest more elegant and readable one-line solutions than the sapply() version I supplied above.Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-54379569201075877272014-04-14T09:48:11.820-04:002014-04-14T09:48:11.820-04:00I think you overlooked the point of my last exampl...I think you overlooked the point of my last example. Both SAS and R support the row() and col() functions, so you can construct the Hilbert matrix using nearly identical statements. The SAS/IML statements are:<br /><br />H = j(5,5, .); /* 5x5 matrix of missing */<br />H = 1 / (row(H) + col(H) - 1);<br /><br />The R statements are similar:<br /><br />H = matrix(NA, 5,5) # 5x5 matrix of missing<br />H = 1 / (row(H) + col(H) - 1)<br />Rick Wicklinhttp://www.blogger.com/profile/13919716786757842151noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-79324797215321458552014-03-14T10:12:11.937-04:002014-03-14T10:12:11.937-04:00Has anybody tried that sas macro with a dataset th...Has anybody tried that sas macro with a dataset that has time-dependent covariates? (i.e. phreg has a start and a stop time)John Lucashttp://www.blogger.com/profile/02943346227726453300noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-38666528398389787152014-03-14T00:47:43.389-04:002014-03-14T00:47:43.389-04:00I note you force SAS to use type=abs, rather than ...I note you force SAS to use type=abs, rather than the default type=square (of the residuals). Is there any way to use the squared residuals in the R Levene test?nacnudushttp://www.blogger.com/profile/17853234588720421664noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-44485201826778292032014-02-18T09:16:43.176-05:002014-02-18T09:16:43.176-05:00Another alternative in SAS is to use PROC PLAN, wh...Another alternative in SAS is to use PROC PLAN, which also supports more complicated designs. For this example:<br /><br />proc plan seed=&seed;<br /> factors Block=%sysfunc(ceil(&N/&blocksize)) ordered<br /> Arm =&blocksize;<br /> output out=Blocks;<br />run;<br />data Blocks; set Blocks;<br /> Item = mod(_N_-1,&blocksize)+1;<br /> Arm = mod(Arm,2)+1;<br />run;<br /><br /><br />The PROC PLAN doc has <a href="http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_plan_gettingstarted02.htm" rel="nofollow">a related example</a>. PROC PLAN is used extensively by researchers in clinical trials, and there are dozens of SAS Global Forum papers that describe its use in Big Pharma.Rick Wicklinhttp://www.blogger.com/profile/13919716786757842151noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-62717745535422210052014-02-10T10:04:06.132-05:002014-02-10T10:04:06.132-05:00Thanks, Rick-- Your approach is much cleaner.
As ...Thanks, Rick-- Your approach is much cleaner.<br /><br />As a rule, I prefer general tools, like ODS output data sets, over idiosyncratic ones, like the various output options available in some procedures. Knowing how to use ODS data sets means that you can always(?) gain access to displayed output. But it's often the case that idiosyncratic tools are quicker or less painful to use.Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-63082404702337421162014-02-07T20:52:02.996-05:002014-02-07T20:52:02.996-05:00Ken, Welcome back to blogging. I understand your c...Ken, Welcome back to blogging. I understand your comment about elegance in R vs SAS, which is why I encourage you to read my <a href="http://blogs.sas.com/content/iml" rel="nofollow">statistical programming blog</a> which features SAS/IML programs. As you know, the SAS/IML language is a matrix language with syntax similar to R. As you infer, having a high-level language enables you to write compact code.<br /><br />Elegance is not only depends on the tools that one uses but also on the correct options that software provides. In the case of your SAS example, your code is unnecessarily complicated because you use ODS OUTPUT instead of the OUTPUT statement in PROC FREQ. If you use the OUTPUT statement, you do not need to use PROC TRANSPOSE, nor do you need the complications of testing for EOF in the DATA step. The code looks something like this (hope the comment box doesn't eat my code!):<br /><br /><br />proc freq data = rej noprint;<br />by i;<br />tables event /binomial(level='1');<br />weight w;<br />output out=rej3 binomial;<br />run;<br /><br />data rej4;<br />set rej3;<br />prob = pdf('BINOMIAL',...);<br />prob_include = ...;<br />run;<br /><br /><br />Again, welcome back. I look forward to reading future columns.Rick Wicklinhttp://www.blogger.com/profile/13919716786757842151noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-71711550447762445732014-02-05T13:08:40.654-05:002014-02-05T13:08:40.654-05:00Just to reiterate: Frank Harrell's rms package...Just to reiterate: Frank Harrell's rms package (Regression Modeling Strategies) is a wonderful resource for contrasts and many other real-world analyses.Nick Hortonhttp://www.blogger.com/profile/00242216324355342047noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-58374469437710487652014-02-05T12:09:46.570-05:002014-02-05T12:09:46.570-05:00thanks for this helpful notes.
Harrell's rm...thanks for this helpful notes. <br /><br />Harrell's rms package has some nice capabilities for writing contrasts.<br /><br />In SAS I would recommend looking at the LSMestimate statement for comparisons, particularly for complex contrasts involving interactions. It can be considerably easier to write a contrast in lsmean space that parameter space.Jeffhttp://www.blogger.com/profile/12894304971865920290noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-31722766939216253172014-02-02T11:41:14.466-05:002014-02-02T11:41:14.466-05:00You can find here(http://stackoverflow.com/questio...You can find here(http://stackoverflow.com/questions/14245361/population-pyramid-density-plot-in-r/14249027#14249027) some other example s using R. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-76602293974318508292014-02-01T08:37:07.420-05:002014-02-01T08:37:07.420-05:00Lately I have been studying mapping using SAS, JMP...Lately I have been studying mapping using SAS, JMP, and Tableau. The latter is the easiest, but SAS is fine as well, if one has time to do much trial & error. I am studying your R example and I like it, but the big question I have now is doing county level maps. Do you know any good reference work using R for county level maps? Also overlays - a quick example might be overlaying disease prevalence with a population density, with perhaps bubbles of medical facilities?Richard Thorntonhttp://www.blogger.com/profile/15202210755848307854noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-30218521343966147402013-12-06T03:01:11.760-05:002013-12-06T03:01:11.760-05:00Great, much easier to understand. thanks!
Great, much easier to understand. thanks!<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-68386635456412442892013-10-28T12:59:25.077-04:002013-10-28T12:59:25.077-04:00What about:
> s1 <- survfit( coxph( Surv( ti...What about:<br />> s1 <- survfit( coxph( Surv( times,events) ~ 1), type = "aalen")<br /><br />> s1$surv <- (-log(s1$surv))<br />> s1$upper<- (-log(s1$upper))<br />> s1$lower <- (-log(s1$lower))<br />> s1$std.err<- (-log(s1$std.err))<br /><br />> plot(s1,firsty=0)<br /><br /><br />frisettehttp://www.blogger.com/profile/05796501490775973313noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-32206433435392629372013-10-08T10:01:14.784-04:002013-10-08T10:01:14.784-04:00I have a few questions about adding complication t...I have a few questions about adding complication to a baseline model:<br /><br />1) Adding covariates: <br />a. I do not see G2 anymore in the output. The only fit stat I get it Log-likelihoo. Any way to get all the fit stats?<br /><br />b. When running a model with covariates (even with the OUTPAR option) one can obtain a different solution compared to the baseline model without covariates. It seems that in this case arguing about the effects of covariates cannot be done with reference to classes identified in a baseline model, but the meaning of classes should be discussed from the model with covariate, right?<br /><br />c. Other programs (e.g Latent Gold) allow to use covariates as ‘inactive’ so that they do not affect the solution, but they are only used to describe class membership probabilities. Is this possible in PROC LCA? And how can one judge absolute model fir when df is high (btw, what is the threshold after which we can say that G2 doesn’t follow a chi-square distribution?)<br /><br />2) Multi-group LCA<br />a. I thought that adding a variable to define multiple-groups ,imposing measurement invariance, would be mathematically equivalent to adding that variable as covariate. However, from my empirical tries, I obtain different results. <br /><br />b. when running a model with multiple groups and imposing measurement invariance, class membership probabilities are given for each group separately. Is it possible to get in the output the class membership probabilities for the whole sample?Annahttp://www.blogger.com/profile/15632357407229577825noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-44360152780890533712013-09-22T16:48:28.774-04:002013-09-22T16:48:28.774-04:00Kudos to Giles Crane for pointing out that R can a...Kudos to Giles Crane for pointing out that R can also compute quantiles, and confidence limits, of survival curves.<br />The quantile function has a method for survfit objects of the survival package:<br /><br />quantile( survfit( fit), c(0.25, 0.50, 0.75) )<br /><br />NickNick Hortonhttp://www.blogger.com/profile/00242216324355342047noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-623558719511165192013-09-18T14:24:23.986-04:002013-09-18T14:24:23.986-04:00The thing about that interaction is that (IIUC) it...The thing about that interaction is that (IIUC) it needs to be calculated at every censoring time and every failure time in the data set. The SAS code calculates the interactions within the PHREG procedure to do this. If you just calculate a static one-time variable, you'll get a different and wrong answer.<br /><br />I'm 100% sure it's possible to do this analysis in R-- it's just that for the purposes of assessing proportionality, the approach we show here is easier to implement.Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-70327008606247589422013-09-18T09:31:30.795-04:002013-09-18T09:31:30.795-04:00I don't think that "In R the time-varying...I don't think that "In R the time-varying covariate approach is harder to implement". I believe you just add an interaction term with time, just as you did in SAS.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-47383846005778383612013-09-14T05:00:49.331-04:002013-09-14T05:00:49.331-04:00Is there also a possibility to test the proportion...Is there also a possibility to test the proportionality assumption for a discrete-time hazard model? stat4444http://www.blogger.com/profile/09305393095243604112noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-57860494630483652652013-09-11T11:26:03.160-04:002013-09-11T11:26:03.160-04:00Glad you found this clear and helpful, Breanna.
I...Glad you found this clear and helpful, Breanna.<br /><br />I haven't yet tried to run Shiny on one of these, unfortunately. We'll have to run a follow-up to demonstrate that.<br /><br />(BTW, your R lines look odd to me. Did you mean to do a setwd() and save the files from the demo Shiny?) Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-6232832005522678882013-09-10T23:21:08.347-04:002013-09-10T23:21:08.347-04:00I was able to run R on AWS using your directions. ...I was able to run R on AWS using your directions. Your directions were very clear and helpful!! I have been having issues starting up and using R-Shiny from R on AWS. When I try to get started I get this error:<br /><br />> ~/shinyapp<br />Error: unexpected '/' in "~/"<br />> |-- ui.R<br />Error: unexpected '|' in "|"<br />> |-- server.R<br />Error: unexpected '|' in "|"<br /><br />Do you have any suggestions to help? <br />Thank you for creating an easy way to use R on AWS!!<br />BreannaBreanna Gronnerhttp://www.blogger.com/profile/06509231275481929750noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-40973167454845221582013-08-29T10:38:57.795-04:002013-08-29T10:38:57.795-04:00Thanks for explanation!
It is possible to estimat...Thanks for explanation!<br /><br />It is possible to estimate separate regression models for each stratum?<br />to improve the precision of estimates? Anyone have some references?Anonymousnoreply@blogger.com