Re: [R] using phia with glmmTMB

2017-09-14 Thread Jeff Newmiller
Should also make the example reproducible [1][2][3] when you do post there 
because some mismatch between the model and the data is frequently where the 
problem turns out to be, and without an example that triggers the problem it is 
very tough to figure that out. 

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html (read the 
vignette) 
-- 
Sent from my phone. Please excuse my brevity.

On September 14, 2017 3:45:38 PM PDT, Bert Gunter  
wrote:
>Dunno ...
>
>But you might do better posting this on the r-sig-mixed-models list
>where
>it both should fit better and where you are more likely to find the
>relevant expertise.
>
>Cheers,
>Bert
>
>
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>On Thu, Sep 14, 2017 at 2:26 PM, Joseph Ciarrochi
>
>wrote:
>
>> Hi folks,
>>
>> I love the Phia package andwant to use it with glmmTMB, but when i
>try to
>> use the interactionMeans command, i get the below error
>>
>> modelrepeatedmain2 <- glmmTMB(counts ~
>>  cluster*nominated*nominator*junior_senior+Ltime+
>>   (1|school)+(1|id),
>>  data=d_shortf,
>>family=nbinom1)
>>
>> interactionMeans(modelrepeatedmain2)
>>
>> Error in array(x, c(length(x), 1L), if (!is.null(names(x)))
>list(names(x),
>>  :
>>   'data' must be of a vector type, was 'NULL'
>>
>>
>> I can get this to work with GLMER of course, but I love the speed of
>> glmmTMB.
>>
>> Is there any way to get interactionMeans to work with glmmTMB?
>>
>> best
>> Joseph
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] using phia with glmmTMB

2017-09-14 Thread Bert Gunter
Dunno ...

But you might do better posting this on the r-sig-mixed-models list where
it both should fit better and where you are more likely to find the
relevant expertise.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Thu, Sep 14, 2017 at 2:26 PM, Joseph Ciarrochi 
wrote:

> Hi folks,
>
> I love the Phia package andwant to use it with glmmTMB, but when i try to
> use the interactionMeans command, i get the below error
>
> modelrepeatedmain2 <- glmmTMB(counts ~
>  cluster*nominated*nominator*junior_senior+Ltime+
>   (1|school)+(1|id),
>  data=d_shortf,
>family=nbinom1)
>
> interactionMeans(modelrepeatedmain2)
>
> Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),
>  :
>   'data' must be of a vector type, was 'NULL'
>
>
> I can get this to work with GLMER of course, but I love the speed of
> glmmTMB.
>
> Is there any way to get interactionMeans to work with glmmTMB?
>
> best
> Joseph
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] using phia with glmmTMB

2017-09-14 Thread Joseph Ciarrochi
Hi folks,

I love the Phia package andwant to use it with glmmTMB, but when i try to
use the interactionMeans command, i get the below error

modelrepeatedmain2 <- glmmTMB(counts ~
 cluster*nominated*nominator*junior_senior+Ltime+
  (1|school)+(1|id),
 data=d_shortf,
   family=nbinom1)

interactionMeans(modelrepeatedmain2)

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),
 :
  'data' must be of a vector type, was 'NULL'


I can get this to work with GLMER of course, but I love the speed of
glmmTMB.

Is there any way to get interactionMeans to work with glmmTMB?

best
Joseph

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [ESS] crayon package with ESS?

2017-09-14 Thread Kevin Wright
Update.

The crayon package in R uses ANSI color codes sent to the terminal. The
regular color codes are 30-37. For example, 31 is red, which you can see
like this:
R> red("this is red")
[1] "\033[31mthis is red\033[39m"

The pillar package is using silver (really gray, but called silver to avoid
a name clash) to print place-holding zeros that are not really of
interest.  But silver/gray is not part of the 8 ANSI base colors stored
in ansi-color-names-vector.  Instead, silver() uses code 90, which is a
part of the high-intensity colors.
R> silver("silver")
[1] "\033[90msilver\033[39m"

But the high-intensity colors are not supported by ansi-color.el, at least
by default.  Someone has created a fix for this by extending the colors.
See
https://oleksandrmanzyuk.wordpress.com/2011/11/24/better-emacs-shell-part-ii/

I have not tried this to see if it works.

Kevin Wright



On Wed, Sep 13, 2017 at 7:06 PM, Kevin Wright  wrote:

> I found a simple fix:
>
> options(crayon.enabled=TRUE)
>
> After which, the following example works:
> example(green)
>
> Now to see if I can get the colored output from the pillar package...
> https://github.com/hadley/pillar
>
> Sort of works. Negative numbers are red, but place-holder zeros are not
> being shown in gray.
>
> Kevin Wright
>
>
> On Wed, Sep 13, 2017 at 6:50 PM, Kevin Wright  wrote:
>
>>
>> Has anyone successfully used the R package "crayon" for colored text
>> inside Emacs?  The package claims to work with ESS:
>> https://cran.r-project.org/web/packages/crayon/index.html
>>
>> Digging deeper, I find this inside my iESS buffer:
>>
>> crayon::has_color() # returns FALSE
>>
>> Which seems to be caused by this code in the has_color function:
>>
>> isatty(stdout()) # returns FALSE. Why not TRUE?
>>
>> Maybe my inferior terminal settings aren't quite right... Or maybe the
>> problem is with Windows...
>>
>> --
>> Kevin Wright
>>
>
>
>
> --
> Kevin Wright
>



-- 
Kevin Wright

[[alternative HTML version deleted]]

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] Print All Warnings that Occurr in All Parallel Nodes

2017-09-14 Thread William Dunlap via R-help
> How could I check that a CSV can be opened before applying the function,
> and create an empty data.frame for those CSV.

Use tryCatch().  E.g., instead of
result <- read_csv2(file)

use

result <- tryCatch(read_csv2(file), error=function(e)
makeEmptyDataFrame(conditionMessage(e)))

where makeEmptyDataFrame(msg=NULL) is a function (which you write) that
returns a data.frame with no rows but with the proper column names and
types.  I show  it with a msg (message) argument, as you might want to
attach the error message to it as an attribute so you can see what went
wrong.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Sep 14, 2017 at 12:48 AM, TELLERIA RUIZ DE AGUIRRE, JUAN <
jtelle...@external.gamesacorp.com> wrote:

> Dear R Users,
>
> I have developed the following code for importing a series of zipped CSV
> by parallel computing.
>
> My problems are that:
>
> A) Some ZIP Files (Which contain CSVs inside) are corrupted, and cannot be
> opened.
> B) After executing parRapply I can only see the last.warning variable
> error, for knowing which CSV have failed in each node, but I cannot see all
> warnings, only 1 at a time.
>
> So:
>
> * For showing a list of all warnings in all nodes, I was thinking of using
> the following function in the code:
>
> warnings(DISPOIN_CSV_List <- parRapply(c1, DISPOIN_DIR_REL,
> parRaplly_Function))
>
> Would this work?
>
> * And also, How could I check that a CSV can be opened before applying the
> function, and create an empty data.frame for those CSV.
>
> Thank you,
> Juan
>
>
> CODE
> 
> 
> ## DISPOIN Data Import Into MariaDB
> 
> 
>
> ## 
> -
> ## Packages
> ## 
> -
>
> # update.packages("RODBC")
> # update.packages("tidyverse")
>
> ## 
> -
> ## Libraries
> ## 
> -
>
> suppressMessages(require(RODBC))
> suppressMessages(require(tidyverse))
> suppressMessages(require(parallel))
>
> ## 
> -
> ## CMD: Command for DISPOIN's Directory Acquisition
> ## 
> -
>
> # shell(cmd = 'pushd "\\srvdiscsv\data" && dir *AL*.zip /b /s >
> D:\DISPOIN_Data_Directories.csv && popd')
>
> ## 
> -
> ## RODBC
> ## 
> -
>
> ## A) MariaDB Connection String
>
> con <- odbcConnect("MariaDB_Tornado24")
>
> invisible(sqlQuery(con, "USE dispoin;"))
>
> # B) Import R Data Directories from MariaDB
>
> DISPOIN_DIR_REL <- as_tibble(sqlFetch(con, "dispoin.t_DISPOIN_DIR_REL"))
>
> odbcClose(con)
>
> # C) Import Zipped CSV data into List of Dataframes, which latter on are
> compiled as a single dataframe by
> #means of rbind
>
>   # C.1) parRapply Function Initialization:
>
>   parRaplly_Function <- function (DISPOIN_CSV_Row)
>   {
> return(read_csv2(
>   file = DISPOIN_CSV_Row,
>   col_names = c(
> "SCADA",
> "TAG",
> "ID_del_AEG",
> "Descripcion",
> "Time_ON",
> "Time_OFF",
> "Delta_Time",
> "Comentario",
> "Es_Alarma",
> "Es_Ultima",
> "Comentarios"),
>   col_types = cols(
> "SCADA" = "c",
> "TAG" = "c",
> "ID_del_AEG" = "c",
> "Descripcion" = "c",
> "Time_ON" = "c",
> "Time_OFF" = "c",
> "Delta_Time" = "c",
> "Comentario" = "c",
> "Es_Alarma" = "c",
> "Es_Ultima" = "c",
> "Comentarios" = "c"),
>   locale = default_locale(),
>   na = c("", " "),
>   quoted_na = TRUE,
>   quote = "\"",
>   comment = "",
>   trim_ws = TRUE,
>   skip = 0,
>   n_max = Inf,
>   guess_max = min(1000, n_max),
>   progress = FALSE))
>   }
>
>   # C.2) parallel Package: Environment Settings
>
>   no_cores <- detectCores()
>
>   c1 <- makeCluster(no_cores)
>
>   invisible(clusterEvalQ(c1, library(readr)))
>
>   setDefaultCluster(c1)
>
>   # C.3) parRapply Function Application:
>
>   DISPOIN_CSV_List <- parRapply(c1, DISPOIN_DIR_REL, parRaplly_Function)
>
>   suppressWarnings(stopCluster(c1))
>
> # D) List's Tibbles Compilation into a single Tibble:
>
>   DISPOIN_CSV <- do.call(rbind, DISPOIN_CSV_List)
>
> # E) Write Compiled Table into CSV:
>
>   write_csv(
> DISPOIN_CSV,
> path = file.path("D:/MySQL/R", "DISPOIN_CSV.csv"),
> na = "\\N",
> append = FALSE,
> col_names = TRUE)
>
> # F) Data Cleaning: 

Re: [R] Help understanding why glm and lrm.fit runs with my data, but lrm does not

2017-09-14 Thread Frank Harrell
Fixed 'maxiter' in the help file.  Thanks.

Please give the original source of that dataset.

That dataset is a tiny sample of GUSTO-I and not large enough to fit this
model very reliably.

A nomogram using the full dataset (not publicly available to my knowledge)
is already available in http://biostat.mc.vanderbilt.edu/tmp/bbr.pdf

Use lrm, not lrm.fit for this.  Adding maxit=20 will probably make it work
on the small dataset but still not clear on why you are using this dataset.

Frank


--
Frank E Harrell Jr  Professor  School of Medicine

Department of *Biostatistics*  *Vanderbilt University*

On Thu, Sep 14, 2017 at 10:48 AM, David Winsemius 
wrote:

>
> > On Sep 14, 2017, at 12:30 AM, Bonnett, Laura <
> l.j.bonn...@liverpool.ac.uk> wrote:
> >
> > Dear all,
> >
> > I am using the publically available GustoW dataset.  The exact version I
> am using is available here: https://na01.safelinks.
> protection.outlook.com/?url=https%3A%2F%2Fdrive.google.com%2Fopen%3Fid%
> 3D0B4oZ2TQA0PAoUm85UzBFNjZ0Ulk=02%7C01%7Cf.harrell%40vanderbilt.edu%
> 7Cadb58b13c3994f89209708d4fb8807f0%7Cba5a7f39e3be4ab3b45067fa80fa
> ecad%7C0%7C0%7C636410009046132507=UZgX3%2Ba%
> 2FU2Eeh8ybHMI6JnF0Npd2XJPXAzlmtEhDgOY%3D=0
> >
> > I would like to produce a nomogram for 5 covariates - AGE, HYP, KILLIP,
> HRT and ANT.  I have successfully fitted a logistic regression model using
> the "glm" function as shown below.
> >
> > library(rms)
> > gusto <- spss.get("GustoW.sav")
> > fit <- glm(DAY30~AGE+HYP+factor(KILLIP)+HRT+ANT,family=
> binomial(link="logit"),data=gusto,x=TRUE,y=TRUE)
> >
> > However, my review of the literature and other websites suggest I need
> to use "lrm" for the purposes of producing a nomogram.  When I run the
> command using "lrm" (see below) I get an error message saying:
> > Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
> >  Unable to fit model using "lrm.fit"
> >
> > My code is as follows:
> > gusto2 <- gusto[,c(1,3,5,8,9,10)]
> > gusto2$HYP <- factor(gusto2$HYP, labels=c("No","Yes"))
> > gusto2$KILLIP <- factor(gusto2$KILLIP, labels=c("1","2","3","4"))
> > gusto2$HRT <- factor(gusto2$HRT, labels=c("No","Yes"))
> > gusto2$ANT <- factor(gusto2$ANT, labels=c("No","Yes"))
> > var.labels=c(DAY30="30-day Mortality", AGE="Age in Years",
> KILLIP="Killip Class", HYP="Hypertension", HRT="Tachycardia", ANT="Anterior
> Infarct Location")
> > label(gusto2)=lapply(names(var.labels),function(x)
> label(gusto2[,x])=var.labels[x])
> >
> > ddist = datadist(gusto2)
> > options(datadist='ddist')
> >
> > fit1 <- lrm(DAY30~AGE+HYP+KILLIP+HRT+ANT,gusto2)
> >
> > Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
> >  Unable to fit model using "lrm.fit"
> >
> > Online solutions to this problem involve checking whether any variables
> are redundant.  However, the results for my data suggest  that none are.
> > redun(~AGE+HYP+KILLIP+HRT+ANT,gusto2)
> >
> > Redundancy Analysis
> >
> > redun(formula = ~AGE + HYP + KILLIP + HRT + ANT, data = gusto2)
> >
> > n: 2188 p: 5nk: 3
> >
> > Number of NAs:   0
> >
> > Transformation of target variables forced to be linear
> >
> > R-squared cutoff: 0.9   Type: ordinary
> >
> > R^2 with which each variable can be predicted from all other variables:
> >
> >   AGEHYP KILLIPHRTANT
> > 0.028  0.032  0.053  0.046  0.040
> >
> > No redundant variables
> >
> > I've also tried just considering "lrm.fit" and that code seems to run
> without error too:
> > lrm.fit(cbind(gusto2$AGE,gusto2$KILLIP,gusto2$HYP,
> gusto2$HRT,gusto2$ANT),gusto2$DAY30)
> >
> > Logistic Regression Model
> >
> > lrm.fit(x = cbind(gusto2$AGE, gusto2$KILLIP, gusto2$HYP, gusto2$HRT,
> > gusto2$ANT), y = gusto2$DAY30)
> >
> >   Model Likelihood DiscriminationRank
> Discrim.
> >  Ratio Test   Indexes   Indexes
> > Obs  2188LR chi2 233.59R2   0.273C
>  0.846
> >  0   2053d.f. 5g1.642Dxy
>  0.691
> >  1135Pr(> chi2) <0.0001gr   5.165gamma
>  0.696
> > max |deriv| 4e-09  gp   0.079tau-a
>  0.080
> >Brier0.048
> >
> >   Coef S.E.   Wald Z Pr(>|Z|)
> > Intercept -13.8515 0.9694 -14.29 <0.0001
> > x[1]0.0989 0.0103   9.58 <0.0001
> > x[2]0.9030 0.1510   5.98 <0.0001
> > x[3]1.3576 0.2570   5.28 <0.0001
> > x[4]0.6884 0.2034   3.38 0.0007
> > x[5]0.6327 0.2003   3.16 0.0016
> >
> > I was therefore hoping someone would explain why the "lrm" code is
> producing an error message, while "lrm.fit" and "glm" do not.  In
> particular I would welcome a solution to ensure I can produce a nomogram.
>
> Try this:
>
> lrm  # look at code, do a search on "fail"
> ?lrm.fit  # read the structure of the returned value of lrm.fit
>
> my.fit <- lrm.fit(x = 

Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Jeff Newmiller
I think you should consider whether the advantages of making an object-aware 
collections class are worth the effort... lists are the standard tool for this 
task in R, and are normally handled using the functional programming paradigm. 
Just make sure a sufficiently-complete set of methods are available for the 
objects you plan to make lists of. 
-- 
Sent from my phone. Please excuse my brevity.

On September 14, 2017 7:27:55 AM PDT, Alexander Shenkin  
wrote:
 Did you read this?
 https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf

 Maybe it could give you some insight in how to create package.
>>>
>>> That resource is ~9 years old. There are more modern treatments
>available. You
>>> can read mine at http://r-pkgs.had.co.nz.
>>>
>>> Hadley
>>>
>
>Thanks both.  I'm reading through your new book now Hadley... thanks
>for 
>that.  I'll probably take a shot at building a class to hold one tree 
>per object, and search for objects of a class (per 
>https://stackoverflow.com/questions/5158830/identify-all-objects-of-given-clas-for-further-processing)
>
>to implement collections when necessary...
>
>It does seem like there might be niche out there for a resource for 
>folks deciding how to structure their package given what they're trying
>
>to provide; i.e. should they construct a collection of functions, or 
>class defs, or...  Could well exist already, and I may just have missed
>
>it...
>
>Thanks,
>Allie
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help understanding why glm and lrm.fit runs with my data, but lrm does not

2017-09-14 Thread David Winsemius

> On Sep 14, 2017, at 12:30 AM, Bonnett, Laura  
> wrote:
> 
> Dear all,
> 
> I am using the publically available GustoW dataset.  The exact version I am 
> using is available here: 
> https://drive.google.com/open?id=0B4oZ2TQA0PAoUm85UzBFNjZ0Ulk
> 
> I would like to produce a nomogram for 5 covariates - AGE, HYP, KILLIP, HRT 
> and ANT.  I have successfully fitted a logistic regression model using the 
> "glm" function as shown below.
> 
> library(rms)
> gusto <- spss.get("GustoW.sav")
> fit <- 
> glm(DAY30~AGE+HYP+factor(KILLIP)+HRT+ANT,family=binomial(link="logit"),data=gusto,x=TRUE,y=TRUE)
> 
> However, my review of the literature and other websites suggest I need to use 
> "lrm" for the purposes of producing a nomogram.  When I run the command using 
> "lrm" (see below) I get an error message saying:
> Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
>  Unable to fit model using "lrm.fit"
> 
> My code is as follows:
> gusto2 <- gusto[,c(1,3,5,8,9,10)]
> gusto2$HYP <- factor(gusto2$HYP, labels=c("No","Yes"))
> gusto2$KILLIP <- factor(gusto2$KILLIP, labels=c("1","2","3","4"))
> gusto2$HRT <- factor(gusto2$HRT, labels=c("No","Yes"))
> gusto2$ANT <- factor(gusto2$ANT, labels=c("No","Yes"))
> var.labels=c(DAY30="30-day Mortality", AGE="Age in Years", KILLIP="Killip 
> Class", HYP="Hypertension", HRT="Tachycardia", ANT="Anterior Infarct 
> Location")
> label(gusto2)=lapply(names(var.labels),function(x) 
> label(gusto2[,x])=var.labels[x])
> 
> ddist = datadist(gusto2)
> options(datadist='ddist')
> 
> fit1 <- lrm(DAY30~AGE+HYP+KILLIP+HRT+ANT,gusto2)
> 
> Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
>  Unable to fit model using "lrm.fit"
> 
> Online solutions to this problem involve checking whether any variables are 
> redundant.  However, the results for my data suggest  that none are.
> redun(~AGE+HYP+KILLIP+HRT+ANT,gusto2)
> 
> Redundancy Analysis
> 
> redun(formula = ~AGE + HYP + KILLIP + HRT + ANT, data = gusto2)
> 
> n: 2188 p: 5nk: 3
> 
> Number of NAs:   0
> 
> Transformation of target variables forced to be linear
> 
> R-squared cutoff: 0.9   Type: ordinary
> 
> R^2 with which each variable can be predicted from all other variables:
> 
>   AGEHYP KILLIPHRTANT
> 0.028  0.032  0.053  0.046  0.040
> 
> No redundant variables
> 
> I've also tried just considering "lrm.fit" and that code seems to run without 
> error too:
> lrm.fit(cbind(gusto2$AGE,gusto2$KILLIP,gusto2$HYP,gusto2$HRT,gusto2$ANT),gusto2$DAY30)
> 
> Logistic Regression Model
> 
> lrm.fit(x = cbind(gusto2$AGE, gusto2$KILLIP, gusto2$HYP, gusto2$HRT,
> gusto2$ANT), y = gusto2$DAY30)
> 
>   Model Likelihood DiscriminationRank Discrim.
>  Ratio Test   Indexes   Indexes
> Obs  2188LR chi2 233.59R2   0.273C   0.846
>  0   2053d.f. 5g1.642Dxy 0.691
>  1135Pr(> chi2) <0.0001gr   5.165gamma   0.696
> max |deriv| 4e-09  gp   0.079tau-a   0.080
>Brier0.048
> 
>   Coef S.E.   Wald Z Pr(>|Z|)
> Intercept -13.8515 0.9694 -14.29 <0.0001
> x[1]0.0989 0.0103   9.58 <0.0001
> x[2]0.9030 0.1510   5.98 <0.0001
> x[3]1.3576 0.2570   5.28 <0.0001
> x[4]0.6884 0.2034   3.38 0.0007
> x[5]0.6327 0.2003   3.16 0.0016
> 
> I was therefore hoping someone would explain why the "lrm" code is producing 
> an error message, while "lrm.fit" and "glm" do not.  In particular I would 
> welcome a solution to ensure I can produce a nomogram.

Try this:

lrm  # look at code, do a search on "fail"
?lrm.fit  # read the structure of the returned value of lrm.fit

my.fit <- lrm.fit(x = cbind(gusto2$AGE, gusto2$KILLIP, gusto2$HYP, gusto2$HRT,
gusto2$ANT), y = gusto2$DAY30)

print(my.fit$fail)  # the error message you got from the lrm call means 
convergence failed

Documentation bug: The documentation of the cause of the 'fail'- value 
incorrectly gives the name of this parameter as 'maxiter' in the  Value section.

-- 
David.



> 
> Kind regards,
> Laura
> 
> Dr Laura Bonnett
> NIHR Post-Doctoral Fellow
> 
> Department of Biostatistics,
> Waterhouse Building, Block F,
> 1-5 Brownlow Street,
> University of Liverpool,
> Liverpool,
> L69 3GL
> 
> 0151 795 9686
> l.j.bonn...@liverpool.ac.uk
> 
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's 

Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Alexander Shenkin

Did you read this?
https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf

Maybe it could give you some insight in how to create package.


That resource is ~9 years old. There are more modern treatments available. You
can read mine at http://r-pkgs.had.co.nz.

Hadley



Thanks both.  I'm reading through your new book now Hadley... thanks for 
that.  I'll probably take a shot at building a class to hold one tree 
per object, and search for objects of a class (per 
https://stackoverflow.com/questions/5158830/identify-all-objects-of-given-clas-for-further-processing) 
to implement collections when necessary...


It does seem like there might be niche out there for a resource for 
folks deciding how to structure their package given what they're trying 
to provide; i.e. should they construct a collection of functions, or 
class defs, or...  Could well exist already, and I may just have missed 
it...


Thanks,
Allie

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [ESS] crayon package with ESS?

2017-09-14 Thread François Michonneau
Hi Kevin,

  Use the GitHub version of the crayon package. It contains a patch to
have the latest versions of Emacs compatible that hasn't been released
on CRAN yet.

  Cheers,
  -- François

On Wed, Sep 13, 2017 at 8:06 PM, Kevin Wright  wrote:
> I found a simple fix:
>
> options(crayon.enabled=TRUE)
>
> After which, the following example works:
> example(green)
>
> Now to see if I can get the colored output from the pillar package...
> https://github.com/hadley/pillar
>
> Sort of works. Negative numbers are red, but place-holder zeros are not
> being shown in gray.
>
> Kevin Wright
>
>
> On Wed, Sep 13, 2017 at 6:50 PM, Kevin Wright  wrote:
>
>>
>> Has anyone successfully used the R package "crayon" for colored text
>> inside Emacs?  The package claims to work with ESS:
>> https://cran.r-project.org/web/packages/crayon/index.html
>>
>> Digging deeper, I find this inside my iESS buffer:
>>
>> crayon::has_color() # returns FALSE
>>
>> Which seems to be caused by this code in the has_color function:
>>
>> isatty(stdout()) # returns FALSE. Why not TRUE?
>>
>> Maybe my inferior terminal settings aren't quite right... Or maybe the
>> problem is with Windows...
>>
>> --
>> Kevin Wright
>>
>
>
>
> --
> Kevin Wright
>
> [[alternative HTML version deleted]]
>
> __
> ESS-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help

Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread PIKAL Petr
Hi Hadley

Yes, I found it too quite easily by Google.

Cheers
Petr

> -Original Message-
> From: Hadley Wickham [mailto:h.wick...@gmail.com]
> Sent: Thursday, September 14, 2017 3:33 PM
> To: PIKAL Petr 
> Cc: Alexander Shenkin ; r-help 
> Subject: Re: [R] To implement OO or not in R package, and if so, how to
> structure it?
>
> > Did you read this?
> > https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf
> >
> > Maybe it could give you some insight in how to create package.
>
> That resource is ~9 years old. There are more modern treatments available. You
> can read mine at http://r-pkgs.had.co.nz.
>
> Hadley
>
>
> --
> http://hadley.nz


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Hadley Wickham
> Did you read this?
> https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf
>
> Maybe it could give you some insight in how to create package.

That resource is ~9 years old. There are more modern treatments
available. You can read mine at http://r-pkgs.had.co.nz.

Hadley


-- 
http://hadley.nz

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Hadley Wickham
I just finished the first draft of the chapters on OO programming for
the 2nd edition of "Advanced R": https://adv-r.hadley.nz - you might
find them helpful.

Hadley

On Thu, Sep 14, 2017 at 7:58 AM, Alexander Shenkin  wrote:
> Hello all,
>
> I am trying to decide how to structure an R package.  Specifically, do I use
> OO classes, or just provide functions?  If the former, how should I
> structure the objects in relation to the type of data the package is
> intended to manage?
>
> I have searched for, but haven't found, resources that guide one in the
> *decision* about whether to implement OO frameworks or not in one's R
> package.  I suspect I should, but the utility of the package would be aided
> by *collections* of objects.  R, however, doesn't seem to implement
> collections.
>
> Background: I am writing an R package that will provide a framework for
> analyzing structural models of trees (as in trees made of wood, not
> statistical trees).  These models are generated from laser scanning
> instruments and model fitting algorithms, and hence may have aspects that
> are data-heavy.  Furthermore, coputing metrics based on these structures can
> be computationally heavy.  Finally, as a result, each tree has a number of
> metrics associated with it (which may be expensive to calculate), along with
> the underlying data of that tree.  It will be important as well to perform
> calculations across many of these trees, as one would do in a dataframe.
>
> This last point is important: if one organizes data across potentially
> thousands of objects, how easy or hard is it to massage properties of those
> objects into a dataframe for analysis?
>
> Thank you in advance for thoughts and pointers.
>
> Allie
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
http://hadley.nz

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread PIKAL Petr
Hi

I do not consider myself as an expert in field of R package programming but if 
your data are rectangular, why not use data.frames.

OTOH if they are structured in free form (something like lm result) you could 
use lists.

Did you read this?
https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf

Maybe it could give you some insight in how to create package.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Alexander
> Shenkin
> Sent: Thursday, September 14, 2017 2:59 PM
> To: r-help 
> Subject: [R] To implement OO or not in R package, and if so, how to structure
> it?
>
> Hello all,
>
> I am trying to decide how to structure an R package.  Specifically, do I use 
> OO
> classes, or just provide functions?  If the former, how should I structure the
> objects in relation to the type of data the package is intended to manage?
>
> I have searched for, but haven't found, resources that guide one in the
> *decision* about whether to implement OO frameworks or not in one's R
> package.  I suspect I should, but the utility of the package would be aided by
> *collections* of objects.  R, however, doesn't seem to implement collections.
>
> Background: I am writing an R package that will provide a framework for
> analyzing structural models of trees (as in trees made of wood, not 
> statistical
> trees).  These models are generated from laser scanning instruments and model
> fitting algorithms, and hence may have aspects that are data-heavy.
> Furthermore, coputing metrics based on these structures can be
> computationally heavy.  Finally, as a result, each tree has a number of 
> metrics
> associated with it (which may be expensive to calculate), along with the
> underlying data of that tree.  It will be important as well to perform
> calculations across many of these trees, as one would do in a dataframe.
>
> This last point is important: if one organizes data across potentially 
> thousands
> of objects, how easy or hard is it to massage properties of those objects 
> into a
> dataframe for analysis?
>
> Thank you in advance for thoughts and pointers.
>
> Allie
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express 

[R] To implement OO or not in R package, and if so, how to structure it?

2017-09-14 Thread Alexander Shenkin

Hello all,

I am trying to decide how to structure an R package.  Specifically, do I 
use OO classes, or just provide functions?  If the former, how should I 
structure the objects in relation to the type of data the package is 
intended to manage?


I have searched for, but haven't found, resources that guide one in the 
*decision* about whether to implement OO frameworks or not in one's R 
package.  I suspect I should, but the utility of the package would be 
aided by *collections* of objects.  R, however, doesn't seem to 
implement collections.


Background: I am writing an R package that will provide a framework for 
analyzing structural models of trees (as in trees made of wood, not 
statistical trees).  These models are generated from laser scanning 
instruments and model fitting algorithms, and hence may have aspects 
that are data-heavy.  Furthermore, coputing metrics based on these 
structures can be computationally heavy.  Finally, as a result, each 
tree has a number of metrics associated with it (which may be expensive 
to calculate), along with the underlying data of that tree.  It will be 
important as well to perform calculations across many of these trees, as 
one would do in a dataframe.


This last point is important: if one organizes data across potentially 
thousands of objects, how easy or hard is it to massage properties of 
those objects into a dataframe for analysis?


Thank you in advance for thoughts and pointers.

Allie

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help understanding why glm and lrm.fit runs with my data, but lrm does not

2017-09-14 Thread Jan van der Laan


With lrm.fit you are fitting a completely different model. One of the 
things lrm does, is preparing the input for lrm.fit which in this case 
means that dummy variables are generated for categorical variables such 
as 'KILLIP'.


The error message means that model did not converge after the maximum 
number of iterations. One possible solution is to try to increase the 
maximum number of iterations, e.g.:


fit1 <- lrm(DAY30~AGE+HYP+KILLIP+HRT+ANT, data = gusto2, maxit = 100)

HTH,

Jan



On 14-09-17 09:30, Bonnett, Laura wrote:

Dear all,

I am using the publically available GustoW dataset.  The exact version I am 
using is available here: 
https://drive.google.com/open?id=0B4oZ2TQA0PAoUm85UzBFNjZ0Ulk

I would like to produce a nomogram for 5 covariates - AGE, HYP, KILLIP, HRT and ANT.  I 
have successfully fitted a logistic regression model using the "glm" function 
as shown below.

library(rms)
gusto <- spss.get("GustoW.sav")
fit <- 
glm(DAY30~AGE+HYP+factor(KILLIP)+HRT+ANT,family=binomial(link="logit"),data=gusto,x=TRUE,y=TRUE)

However, my review of the literature and other websites suggest I need to use "lrm" for 
the purposes of producing a nomogram.  When I run the command using "lrm" (see below) I 
get an error message saying:
Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
   Unable to fit model using "lrm.fit"

My code is as follows:
gusto2 <- gusto[,c(1,3,5,8,9,10)]
gusto2$HYP <- factor(gusto2$HYP, labels=c("No","Yes"))
gusto2$KILLIP <- factor(gusto2$KILLIP, labels=c("1","2","3","4"))
gusto2$HRT <- factor(gusto2$HRT, labels=c("No","Yes"))
gusto2$ANT <- factor(gusto2$ANT, labels=c("No","Yes"))
var.labels=c(DAY30="30-day Mortality", AGE="Age in Years", KILLIP="Killip Class", 
HYP="Hypertension", HRT="Tachycardia", ANT="Anterior Infarct Location")
label(gusto2)=lapply(names(var.labels),function(x) 
label(gusto2[,x])=var.labels[x])

ddist = datadist(gusto2)
options(datadist='ddist')

fit1 <- lrm(DAY30~AGE+HYP+KILLIP+HRT+ANT,gusto2)

Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
   Unable to fit model using "lrm.fit"

Online solutions to this problem involve checking whether any variables are 
redundant.  However, the results for my data suggest  that none are.
redun(~AGE+HYP+KILLIP+HRT+ANT,gusto2)

Redundancy Analysis

redun(formula = ~AGE + HYP + KILLIP + HRT + ANT, data = gusto2)

n: 2188 p: 5nk: 3

Number of NAs:   0

Transformation of target variables forced to be linear

R-squared cutoff: 0.9   Type: ordinary

R^2 with which each variable can be predicted from all other variables:

AGEHYP KILLIPHRTANT
  0.028  0.032  0.053  0.046  0.040

No redundant variables

I've also tried just considering "lrm.fit" and that code seems to run without 
error too:
lrm.fit(cbind(gusto2$AGE,gusto2$KILLIP,gusto2$HYP,gusto2$HRT,gusto2$ANT),gusto2$DAY30)

Logistic Regression Model

  lrm.fit(x = cbind(gusto2$AGE, gusto2$KILLIP, gusto2$HYP, gusto2$HRT,
  gusto2$ANT), y = gusto2$DAY30)

Model Likelihood DiscriminationRank Discrim.
   Ratio Test   Indexes   Indexes
  Obs  2188LR chi2 233.59R2   0.273C   0.846
   0   2053d.f. 5g1.642Dxy 0.691
   1135Pr(> chi2) <0.0001gr   5.165gamma   0.696
  max |deriv| 4e-09  gp   0.079tau-a   0.080
 Brier0.048

Coef S.E.   Wald Z Pr(>|Z|)
  Intercept -13.8515 0.9694 -14.29 <0.0001
  x[1]0.0989 0.0103   9.58 <0.0001
  x[2]0.9030 0.1510   5.98 <0.0001
  x[3]1.3576 0.2570   5.28 <0.0001
  x[4]0.6884 0.2034   3.38 0.0007
  x[5]0.6327 0.2003   3.16 0.0016

I was therefore hoping someone would explain why the "lrm" code is producing an error message, 
while "lrm.fit" and "glm" do not.  In particular I would welcome a solution to ensure I 
can produce a nomogram.

Kind regards,
Laura

Dr Laura Bonnett
NIHR Post-Doctoral Fellow

Department of Biostatistics,
Waterhouse Building, Block F,
1-5 Brownlow Street,
University of Liverpool,
Liverpool,
L69 3GL

0151 795 9686
l.j.bonn...@liverpool.ac.uk



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Print All Warnings that Occurr in All Parallel Nodes

2017-09-14 Thread TELLERIA RUIZ DE AGUIRRE, JUAN
Dear R Users,

I have developed the following code for importing a series of zipped CSV by 
parallel computing.

My problems are that:

A) Some ZIP Files (Which contain CSVs inside) are corrupted, and cannot be 
opened.
B) After executing parRapply I can only see the last.warning variable error, 
for knowing which CSV have failed in each node, but I cannot see all warnings, 
only 1 at a time.

So:

* For showing a list of all warnings in all nodes, I was thinking of using the 
following function in the code:

warnings(DISPOIN_CSV_List <- parRapply(c1, DISPOIN_DIR_REL, 
parRaplly_Function))

Would this work?

* And also, How could I check that a CSV can be opened before applying the 
function, and create an empty data.frame for those CSV.

Thank you,
Juan


CODE

## DISPOIN Data Import Into MariaDB


## -
## Packages
## -

# update.packages("RODBC")
# update.packages("tidyverse")

## -
## Libraries
## -

suppressMessages(require(RODBC))
suppressMessages(require(tidyverse))
suppressMessages(require(parallel))

## -
## CMD: Command for DISPOIN's Directory Acquisition
## -

# shell(cmd = 'pushd "\\srvdiscsv\data" && dir *AL*.zip /b /s > 
D:\DISPOIN_Data_Directories.csv && popd')

## -
## RODBC
## -

## A) MariaDB Connection String

con <- odbcConnect("MariaDB_Tornado24")

invisible(sqlQuery(con, "USE dispoin;"))

# B) Import R Data Directories from MariaDB

DISPOIN_DIR_REL <- as_tibble(sqlFetch(con, "dispoin.t_DISPOIN_DIR_REL"))

odbcClose(con)

# C) Import Zipped CSV data into List of Dataframes, which latter on are 
compiled as a single dataframe by
#means of rbind

  # C.1) parRapply Function Initialization:

  parRaplly_Function <- function (DISPOIN_CSV_Row)
  {
return(read_csv2(
  file = DISPOIN_CSV_Row,
  col_names = c(
"SCADA",
"TAG",
"ID_del_AEG",
"Descripcion",
"Time_ON",
"Time_OFF",
"Delta_Time",
"Comentario",
"Es_Alarma",
"Es_Ultima",
"Comentarios"),
  col_types = cols(
"SCADA" = "c",
"TAG" = "c",
"ID_del_AEG" = "c",
"Descripcion" = "c",
"Time_ON" = "c",
"Time_OFF" = "c",
"Delta_Time" = "c",
"Comentario" = "c",
"Es_Alarma" = "c",
"Es_Ultima" = "c",
"Comentarios" = "c"),
  locale = default_locale(),
  na = c("", " "),
  quoted_na = TRUE,
  quote = "\"",
  comment = "",
  trim_ws = TRUE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  progress = FALSE))
  }

  # C.2) parallel Package: Environment Settings

  no_cores <- detectCores()

  c1 <- makeCluster(no_cores)

  invisible(clusterEvalQ(c1, library(readr)))

  setDefaultCluster(c1)

  # C.3) parRapply Function Application:

  DISPOIN_CSV_List <- parRapply(c1, DISPOIN_DIR_REL, parRaplly_Function)

  suppressWarnings(stopCluster(c1))

# D) List's Tibbles Compilation into a single Tibble:

  DISPOIN_CSV <- do.call(rbind, DISPOIN_CSV_List)

# E) Write Compiled Table into CSV:

  write_csv(
DISPOIN_CSV,
path = file.path("D:/MySQL/R", "DISPOIN_CSV.csv"),
na = "\\N",
append = FALSE,
col_names = TRUE)

# F) Data Cleaning: Environment Variable Removal

  rm(list=ls())

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help understanding why glm and lrm.fit runs with my data, but lrm does not

2017-09-14 Thread Bonnett, Laura
Dear all,

I am using the publically available GustoW dataset.  The exact version I am 
using is available here: 
https://drive.google.com/open?id=0B4oZ2TQA0PAoUm85UzBFNjZ0Ulk

I would like to produce a nomogram for 5 covariates - AGE, HYP, KILLIP, HRT and 
ANT.  I have successfully fitted a logistic regression model using the "glm" 
function as shown below.

library(rms)
gusto <- spss.get("GustoW.sav")
fit <- 
glm(DAY30~AGE+HYP+factor(KILLIP)+HRT+ANT,family=binomial(link="logit"),data=gusto,x=TRUE,y=TRUE)

However, my review of the literature and other websites suggest I need to use 
"lrm" for the purposes of producing a nomogram.  When I run the command using 
"lrm" (see below) I get an error message saying:
Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
  Unable to fit model using "lrm.fit"

My code is as follows:
gusto2 <- gusto[,c(1,3,5,8,9,10)]
gusto2$HYP <- factor(gusto2$HYP, labels=c("No","Yes"))
gusto2$KILLIP <- factor(gusto2$KILLIP, labels=c("1","2","3","4"))
gusto2$HRT <- factor(gusto2$HRT, labels=c("No","Yes"))
gusto2$ANT <- factor(gusto2$ANT, labels=c("No","Yes"))
var.labels=c(DAY30="30-day Mortality", AGE="Age in Years", KILLIP="Killip 
Class", HYP="Hypertension", HRT="Tachycardia", ANT="Anterior Infarct Location")
label(gusto2)=lapply(names(var.labels),function(x) 
label(gusto2[,x])=var.labels[x])

ddist = datadist(gusto2)
options(datadist='ddist')

fit1 <- lrm(DAY30~AGE+HYP+KILLIP+HRT+ANT,gusto2)

Error in lrm(DAY30 ~ AGE + HYP + KILLIP + HRT + ANT, gusto2) :
  Unable to fit model using "lrm.fit"

Online solutions to this problem involve checking whether any variables are 
redundant.  However, the results for my data suggest  that none are.
redun(~AGE+HYP+KILLIP+HRT+ANT,gusto2)

Redundancy Analysis

redun(formula = ~AGE + HYP + KILLIP + HRT + ANT, data = gusto2)

n: 2188 p: 5nk: 3

Number of NAs:   0

Transformation of target variables forced to be linear

R-squared cutoff: 0.9   Type: ordinary

R^2 with which each variable can be predicted from all other variables:

   AGEHYP KILLIPHRTANT
 0.028  0.032  0.053  0.046  0.040

No redundant variables

I've also tried just considering "lrm.fit" and that code seems to run without 
error too:
lrm.fit(cbind(gusto2$AGE,gusto2$KILLIP,gusto2$HYP,gusto2$HRT,gusto2$ANT),gusto2$DAY30)

Logistic Regression Model

 lrm.fit(x = cbind(gusto2$AGE, gusto2$KILLIP, gusto2$HYP, gusto2$HRT,
 gusto2$ANT), y = gusto2$DAY30)

   Model Likelihood DiscriminationRank Discrim.
  Ratio Test   Indexes   Indexes
 Obs  2188LR chi2 233.59R2   0.273C   0.846
  0   2053d.f. 5g1.642Dxy 0.691
  1135Pr(> chi2) <0.0001gr   5.165gamma   0.696
 max |deriv| 4e-09  gp   0.079tau-a   0.080
Brier0.048

   Coef S.E.   Wald Z Pr(>|Z|)
 Intercept -13.8515 0.9694 -14.29 <0.0001
 x[1]0.0989 0.0103   9.58 <0.0001
 x[2]0.9030 0.1510   5.98 <0.0001
 x[3]1.3576 0.2570   5.28 <0.0001
 x[4]0.6884 0.2034   3.38 0.0007
 x[5]0.6327 0.2003   3.16 0.0016

I was therefore hoping someone would explain why the "lrm" code is producing an 
error message, while "lrm.fit" and "glm" do not.  In particular I would welcome 
a solution to ensure I can produce a nomogram.

Kind regards,
Laura

Dr Laura Bonnett
NIHR Post-Doctoral Fellow

Department of Biostatistics,
Waterhouse Building, Block F,
1-5 Brownlow Street,
University of Liverpool,
Liverpool,
L69 3GL

0151 795 9686
l.j.bonn...@liverpool.ac.uk



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.