tag:blogger.com,1999:blog-1275149608391671670.comments2014-07-23T12:59:08.031-04:00SAS and RKen Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comBlogger477125tag:blogger.com,1999:blog-1275149608391671670.post-85382979238263534132014-07-22T18:38:31.169-04:002014-07-22T18:38:31.169-04:00This comment has been removed by the author.Lamar Hunt IIIhttp://www.blogger.com/profile/04003664235960435714noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-7905569402908233862014-07-22T18:38:17.526-04:002014-07-22T18:38:17.526-04:00Amazon has changed the format again to: "Amaz...Amazon has changed the format again to: "Amazon Best Sellers Rank".<br /><br />However, I tried to run the SAS program and it was not reading the line with the rank info onto the same line as the one that contains "Amazon Best Sellers Rank". So I just changed the relevant string to "in Books" in the code and it works.Lamar Hunt IIIhttp://www.blogger.com/profile/04003664235960435714noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-82611073326077818242014-07-13T14:07:12.546-04:002014-07-13T14:07:12.546-04:00Does anyone know how to create a heaviside functio...Does anyone know how to create a heaviside function in SAS when the predictor variable has 3 categories?Vishal Balihttp://www.blogger.com/profile/10778331267390532406noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-70807355129906186442014-07-08T02:26:24.097-04:002014-07-08T02:26:24.097-04:00You could get similar results using a conversion t...You could get similar results using a conversion to Fisher Z and then back again. I.e.:<br /><br />#"mat" being a r x c matrix/table<br />chicalc <- chisq.test(mat)$statistic<br /><br /># calculate Cramer's v - <br />K <- min(nrow(mat),ncol(mat))<br />crv <- sqrt(chicalc / sum(mat)*(K-1))<br /><br /># convert the Cramer's V to a Fisher's Z<br />fz <- 0.5 * log((1 + crv)/(1 - crv))<br /><br /># calculate 95% conf.int around Fisher Z<br />conf.level <- 0.05<br />se <- 1/sqrt(sum(mat)-3) * qnorm(1-(conf.level/2))<br />cifz <- fz + c(-se,se)<br /><br /># convert it back to conf.int around Cramer's V<br />cicrv <- (exp(2 * cifz) - 1)/(1 + exp(2 * cifz))thelatemailhttp://www.blogger.com/profile/13449819504543410744noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-75238955699178952402014-07-04T16:06:19.873-04:002014-07-04T16:06:19.873-04:00Hi, Matt--
Thanks for that praise, and I hope th...Hi, Matt-- <br /><br />Thanks for that praise, and I hope that the book is helpful to you. Looking back on this post, it's hard to believe it's only 3 and half years since RStudio appeared, given how much it's become a part of my process and how much more it now does.<br /><br />I'm not aware of simple ways to run SAS from RStudio. It would be possible, though clunky, to use RStudio as a text editor for .sas, .log and .lst files, and to write R functions to submit SAS batch jobs in the OS. I think that would be a bit sad in light of the increased use of graphics in recent versions of SAS, though.<br /><br />With (a lot) more work, you could probably do a similar thing, but leveraging the RStudio interface and making SAS HTML output go to a file that RSudio could/would display in a quadrant.<br /><br />Another option would be to work with the proc_r SAS macro described here http://sas-and-r.blogspot.com/2012/01/sas-macro-simplifies-sas-and-r.html. That would mean using the SAS IDE and basically using R only in batch, though. And many people have had trouble with proc_r. I have not used it in some time, myself.<br /><br />If you find or make a nice solution, please tell us about it!Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-46328954457726299792014-07-03T18:19:54.507-04:002014-07-03T18:19:54.507-04:00Great post (and looks like great book, too!...just...Great post (and looks like great book, too!...just grabbed a copy from CRC Press site). I love RStudio for all the same reasons. I found your post googling for info on whether I could run SAS code from RStudio. I'm tired of moving between SAS, Stata, and R IDEs, and I'm wondering if there's a way to do all from one. Either one of the program's IDEs (Rstudio would be my pref), or through a separate IDE. I'm not really a programmer (researcher who programs), so I don't know all the IDEs out there. I'm trying to setup a makeshift IDE with TextPad or NotePad++ (already have a workflow for my files that works well, so don't need versioning, etc.). <br /><br />Any pointers would be very welcome. Thaks!Matt Janshttp://www.blogger.com/profile/11096204786869681199noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-35073944768065010092014-06-26T11:36:27.454-04:002014-06-26T11:36:27.454-04:00In the SAS example, you might want to use the CLPA...In the SAS example, you might want to use the CLPARM=wald option on the model statement. That produces a table that shows that the CI for the c and x parameters include zero, but the CIs for the Intercept and interaction terms do not.Rick Wicklinhttp://www.blogger.com/profile/13919716786757842151noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-11107066336482034012014-06-25T11:46:47.777-04:002014-06-25T11:46:47.777-04:00Possibly. Please contact me privately via e-mail....Possibly. Please contact me privately via e-mail.Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-59907280684746914802014-06-24T11:12:32.836-04:002014-06-24T11:12:32.836-04:00My primary reason for wanting to do post hoc power...My primary reason for wanting to do post hoc power was to retain the relationships between the variables we have. I'm having trouble simulating variables and accounting for the relationships between them. I have one categorical variable and one continuous one, and I'm interested in looking at the interaction between them. Any suggestions? Anissa Mikehttp://www.blogger.com/profile/03292349145333273789noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-28780269786967999792014-06-19T11:44:44.235-04:002014-06-19T11:44:44.235-04:00Post-hoc power assessment is fairly controversial ...Post-hoc power assessment is fairly controversial and is frowned upon by many statisticians. But it's not hard to adapt our code to simulate your setting and then to assess power to detect an interaction. I'll write up a new blog post to address this shortly, and thanks for the questionKen Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-36344703774147871612014-06-18T10:18:19.146-04:002014-06-18T10:18:19.146-04:00I'm interested in doing a post-hoc power test ...I'm interested in doing a post-hoc power test for a logistic regression, but I also have an interaction between continuous and categorical variables. Any suggestions on how to incorporate this into your code? Sorry, I realize this is several years after the original post, just hoping to get some advice as I've only been able to find information on assessing power for an interaction OR for a logistic regression, but not both. Thanks!Anissa Mikehttp://www.blogger.com/profile/03292349145333273789noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-32981699569335054012014-04-27T15:44:52.518-04:002014-04-27T15:44:52.518-04:00Thanks Ken for your reply! I am looking at antidep...Thanks Ken for your reply! I am looking at antidepressant use and risk of dementia in a propensity score matched sample. There are 732 patients in each group (Parox and other).<br /><br />The percentage of censoring is 92.3% (677/732) in Parox group and 92.4% (676/732) in other group. This is a propensity score matched sample. I only controlled for osteoporosis in the adjusted analysis as it was significant even after matching. I only tested for Schoenfeld residuals using supermum test using 1000 replications(p=0.0650). I checked for KM curves using log rank test (p=0.635). <br /><br />I also feel that it is a sample size issue as 55/732 had dementia in the Parox group and 56/732 got dementia in the other group in the matched sample.<br />Vishal Balihttp://www.blogger.com/profile/10778331267390532406noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-26354451655311510572014-04-27T15:35:34.644-04:002014-04-27T15:35:34.644-04:00This comment has been removed by the author.Vishal Balihttp://www.blogger.com/profile/10778331267390532406noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-10081380853954579252014-04-25T22:59:59.147-04:002014-04-25T22:59:59.147-04:00Often we have multiple columns that require imputa...Often we have multiple columns that require imputation. In this case, it's helpful to define a function na2mean() using the syntax you have in the post and then do somethng like this:<br /><br />mydata[vars_to_impute]<-apply(mydata[vars_to_impute],2,na2mean)Jamesnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-37369235439610383672014-04-25T08:03:08.702-04:002014-04-25T08:03:08.702-04:00It's easier than if you had to roll your own c...It's easier than if you had to roll your own code!<br /><br />My interpretation is that we observed a Cramer's V of 0.098 (very weak association). We're 95% confidence that the true V is captured by the interval 0.013 to 0.187. Nick Hortonhttp://www.blogger.com/profile/00242216324355342047noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-58643190224232682532014-04-25T07:42:37.221-04:002014-04-25T07:42:37.221-04:00you call that easy? and where is the interpretatio...you call that easy? and where is the interpretation?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-81265429348882242502014-04-23T10:28:39.783-04:002014-04-23T10:28:39.783-04:00Without seeing the data, my guess would be a lack ...Without seeing the data, my guess would be a lack of power. If the sample size (or number of events) is small, I'd be pretty concerned about the proportionality assumption.Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag: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.com