[R] R does not start from (Debian) linux command line - error with doWithOneRestart() - segmentation fault

2021-04-06 Thread Ashim Kapoor
Dear R experts,

Here is my problem :

R startup FAILS with an error message. The error message is more
meaningful when I do invoke R via sudo OR as root. I attach the
startup messages when I invoke R as :

1. as non root user
2. with sudo
3. as Root user.

The error messages ( mentioned in snippets below ) are more meaningful
to me in the above mentioned order.

When I google around for the error message, it looks like there is an
.xlsx file which has non english characters which is messing with
Java.

I do not know how to fix this. I tried :-

R --vanilla

so that it would not use any startup scripts but that also does not work.

- snip


When I try to start R from the command line :

~$ R

 *** caught segfault ***
address (nil), cause 'unknown'

Traceback:
 1: NextMethod(.Generic)
 2: Ops.numeric_version(R_version_built_under, "3.0.0")
 3: testRversion(pkgInfo, package, pkgpath)
 4: library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE, warn.conflicts = warn.conflicts, quietly =
quietly, mask.ok = mask.ok, exclude = exclude, include.only =
include.only, attach.required = attach.required)
 5: doTryCatch(return(expr), name, parentenv, handler)
 6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 7: tryCatchList(expr, classes, parentenv, handlers)
 8: tryCatch(library(package, lib.loc = lib.loc, character.only =
TRUE, logical.return = TRUE, warn.conflicts = warn.conflicts,
quietly = quietly, mask.ok = mask.ok, exclude = exclude,
include.only = include.only, attach.required = attach.required),
error = function(e) e)
 9: require(pkg, quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE)
10: .OptRequireMethods()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: Segmentation fault

- snip

When I try to start R with sudo it gives a more clear message :-

~$ sudo R

 *** caught segfault ***
address (nil), cause 'unknown'

Traceback:
 1: NextMethod(.Generic)
 2: Ops.numeric_version(R_version_built_under, "3.0.0")
 3: testRversion(pkgInfo, package, pkgpath)
 4: library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE, warn.conflicts = warn.conflicts, quietly =
quietly, mask.ok = mask.ok, exclude = exclude, include.only =
include.only, attach.required = attach.required)
 5: doTryCatch(return(expr), name, parentenv, handler)
 6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 7: tryCatchList(expr, classes, parentenv, handlers)
 8: tryCatch(library(package, lib.loc = lib.loc, character.only =
TRUE, logical.return = TRUE, warn.conflicts = warn.conflicts,
quietly = quietly, mask.ok = mask.ok, exclude = exclude,
include.only = include.only, attach.required = attach.required),
error = function(e) e)
 9: require(pkg, quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE)
10: .OptRequireMethods()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: Error in doWithOneRestart(return(` \\x82\\x0ccPV`), restart) :
  not a proper file name

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Error: not a proper file name
Error in doWithOneRestart(return(` \\x82\\x0ccPV`), restart) :
  promise already under evaluation: recursive default argument
reference or earlier problems?
Segmentation fault

- snip


Invoking R as a root user :-

$ sudo -i
root@crayshrimp ~ # R

 *** caught segfault ***
address (nil), cause 'unknown'

Traceback:
 1: NextMethod(.Generic)
 2: Ops.numeric_version(R_version_built_under, "3.0.0")
 3: testRversion(pkgInfo, package, pkgpath)
 4: library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE, warn.conflicts = warn.conflicts, quietly =
quietly, mask.ok = mask.ok, exclude = exclude, include.only =
include.only, attach.required = 

Re: [R-es] error con grid.arrange

2021-04-06 Thread Manuel Mendoza
Gracias Jorge, antes de consultaros estuve viendo varios ejemplos, tratando
de seguirlos con detalle, pero no funcionaba. Sospecho que es porque los
elementos no son simples df sino:
 [1] "data.frame" "partial".

El mar, 6 abr 2021 a las 20:52, Jorge I Velez ()
escribió:

> Manuel,
> Quizás los ejemplos en
> www.sthda.com/english/wiki/wiki.php?id_contents=7930 te ayuden.
> Saludos,
> Jorge.-
>
>
> El El mar, 6 de abr. de 2021 a la(s) 1:30 p. m., Manuel Mendoza <
> mmend...@fulbrightmail.org> escribió:
>
>> Muy buenas, trato de poner 5 ggplots juntos con  grid.arrange y me da este
>> error:
>>
>> > grid.arrange(pdpPL, pdpPs, pdpCl, pdpUr, pdpHP, nrow = 1)
>>
>> Error in `$<-.data.frame`(`*tmp*`, "wrapvp", value = list(x = 0.5, y =
>> 0.5,
>>  :
>>   replacement has 17 rows, data has 30
>>
>>
>> Algunas pistas (todo igual para los 5 PDPs):
>>
>> > class(pdpPL)
>> [1] "data.frame" "partial"
>>
>> > head(pdpPL)
>>   PrimLand   yhat
>> 1 0.00 0.12917927
>> 2 0.02 0.17702830
>> 3 0.04 0.13464397
>> 4 0.06 0.15734838
>> 5 0.08 0.11623142
>> 6 0.10 0.05936711
>>
>> > str(pdpPL)
>> Classes ‘partial’ and 'data.frame': 51 obs. of  2 variables:
>>  $ PrimLand: num  0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 ...
>>  $ yhat: num  0.129 0.177 0.135 0.157 0.116 ...
>>
>> Gracias,
>> Manuel
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
> --
> Sent from my phone. Please excuse my brevity and misspelling.
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Contrasts in coxph

2021-04-06 Thread David Winsemius



On 4/5/21 8:28 PM, Sorkin, John wrote:

I would like to define contrasts on the output of a coxph function. It appears 
that the contrast function from the contrast library does not have a method 
defined that will allow computation of contrasts on a coxph object.

How does one define and evaluate contrasts for a cox model?



I suspect that you are hoping for post-hoc pairwise contrasts. If that's 
the case, then the multcomp package's glht is generally very capable. It 
has three examples in its vignette the involve survivla models. The last 
one constructs a categorical variable for age. That's not a procedure 
that I endorse, but it may have been done for illustration of a method 
and would therefore be free of sin.



library(multcomp)  # console output follows

> if (require("survival") && require("MASS")) {
+ ### construct 4 classes of age
+ Melanoma$Cage <- factor(sapply(Melanoma$age, function(x){if( x <= 
25 ) return(1)

+ if( x > 25 & x <= 50 ) return(2)
+ if( x > 50 & x <= 75 ) return(3)
+ if( x > 75 & x <= 100) return(4) }
+ ))
+ }
> summary(Melanoma)
  time  status  sex age year    
thickness
 Min.   :  10   Min.   :1.00   Min.   :0.   Min.   : 4.00 Min.   
:1962   Min.   : 0.10
 1st Qu.:1525   1st Qu.:1.00   1st Qu.:0.   1st Qu.:42.00 1st 
Qu.:1968   1st Qu.: 0.97
 Median :2005   Median :2.00   Median :0.   Median :54.00 Median 
:1970   Median : 1.94
 Mean   :2153   Mean   :1.79   Mean   :0.3854   Mean   :52.46 Mean   
:1970   Mean   : 2.92
 3rd Qu.:3042   3rd Qu.:2.00   3rd Qu.:1.   3rd Qu.:65.00 3rd 
Qu.:1972   3rd Qu.: 3.56
 Max.   :5565   Max.   :3.00   Max.   :1.   Max.   :95.00 Max.   
:1977   Max.   :17.42

 ulcer   Cage
 Min.   :0.000   1: 14
 1st Qu.:0.000   2: 73
 Median :0.000   3:104
 Mean   :0.439   4: 14
 3rd Qu.:1.000
 Max.   :1.000
> cm <- coxph(Surv(time, status == 1) ~ Cage, data = Melanoma)
> ### specify all pair-wise comparisons among levels of "Cage"
> cm.glht <- glht(cm, mcp(Cage = "Tukey"))
> cm.glht

     General Linear Hypotheses

Multiple Comparisons of Means: Tukey Contrasts


Linear Hypotheses:
   Estimate
2 - 1 == 0  -0.2889
3 - 1 == 0   0.1910
4 - 1 == 0   1.0742
3 - 2 == 0   0.4800
4 - 2 == 0   1.3631
4 - 3 == 0   0.8832


--

David.



Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


__
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-es] error con grid.arrange

2021-04-06 Thread Manuel Mendoza
Muy buenas, trato de poner 5 ggplots juntos con  grid.arrange y me da este
error:

> grid.arrange(pdpPL, pdpPs, pdpCl, pdpUr, pdpHP, nrow = 1)

Error in `$<-.data.frame`(`*tmp*`, "wrapvp", value = list(x = 0.5, y = 0.5,
 :
  replacement has 17 rows, data has 30


Algunas pistas (todo igual para los 5 PDPs):

> class(pdpPL)
[1] "data.frame" "partial"

> head(pdpPL)
  PrimLand   yhat
1 0.00 0.12917927
2 0.02 0.17702830
3 0.04 0.13464397
4 0.06 0.15734838
5 0.08 0.11623142
6 0.10 0.05936711

> str(pdpPL)
Classes ‘partial’ and 'data.frame': 51 obs. of  2 variables:
 $ PrimLand: num  0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 ...
 $ yhat: num  0.129 0.177 0.135 0.157 0.116 ...

Gracias,
Manuel

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Contrasts in coxph

2021-04-06 Thread John Fox

Dear John,

It's not clear to me exactly what you have in mind, but 
car::linearHypothesis(), multcomp::glht(), and the emmeans package work 
with Cox models. I expect there are functions in other packages that 
will work too.


Here's an example, surely simpler than what you have in mind, but you 
can probably adapt it:


-- snip -

> library("survival")
> library("car")
Loading required package: carData
> mod.allison <- coxph(Surv(week, arrest) ~
+fin + age + race + wexp + mar + paro + prio,
+  data=Rossi)
> mod.allison
Call:
coxph(formula = Surv(week, arrest) ~ fin + age + race + wexp +
mar + paro + prio, data = Rossi)

   coef exp(coef) se(coef)  z   p
finyes -0.37942   0.68426  0.19138 -1.983 0.04742
age-0.05744   0.94418  0.02200 -2.611 0.00903
raceother  -0.31390   0.73059  0.30799 -1.019 0.30812
wexpyes-0.14980   0.86088  0.21222 -0.706 0.48029
marnot married  0.43370   1.54296  0.38187  1.136 0.25606
paroyes-0.08487   0.91863  0.19576 -0.434 0.66461
prio0.09150   1.09581  0.02865  3.194 0.00140

Likelihood ratio test=33.27  on 7 df, p=2.362e-05
n= 432, number of events= 114
>
> linearHypothesis(mod.allison, "finyes")
Linear hypothesis test

Hypothesis:
finyes = 0

Model 1: restricted model
Model 2: Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio

  Res.Df Df  Chisq Pr(>Chisq)
1426
2425  1 3.93060.04742 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> library("multcomp")
Loading required package: mvtnorm
Loading required package: TH.data
Loading required package: MASS

Attaching package: ‘TH.data’

The following object is masked from ‘package:MASS’:

geyser

> summary(glht(mod.allison, "finyes=0"))

 Simultaneous Tests for General Linear Hypotheses

Fit: coxph(formula = Surv(week, arrest) ~ fin + age + race + wexp +
mar + paro + prio, data = Rossi)

Linear Hypotheses:
Estimate Std. Error z value Pr(>|z|)
finyes == 0  -0.3794 0.1914  -1.983   0.0474 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)

>
> library(emmeans)
> pairs(emmeans(mod.allison, ~ fin))
 contrast estimateSE  df z.ratio p.value
 no - yes0.379 0.191 Inf 1.983   0.0474

-- snip -

Results are averaged over the levels of: race, wexp, mar, paro
Results are given on the log (not the response) scale.

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2021-04-05 11:28 p.m., Sorkin, John wrote:

I would like to define contrasts on the output of a coxph function. It appears 
that the contrast function from the contrast library does not have a method 
defined that will allow computation of contrasts on a coxph object.

How does one define and evaluate contrasts for a cox model?

Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


__
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] Contrasts in coxph

2021-04-06 Thread Göran Broström

Dear John,

I googled "contrasts Cox regression" and found

https://stats.stackexchange.com/questions/15603/performing-contrasts-among-treatment-levels-in-survival-analysis

where Frank Harrell reports how to do what you want with his rms 
package. At least I think so, haven't tried it myself.


Best, Göran

On 2021-04-06 05:28, Sorkin, John wrote:

I would like to define contrasts on the output of a coxph function.
It appears that the contrast function from the contrast library does
not have a method defined that will allow computation of contrasts on
a coxph object.

How does one define and evaluate contrasts for a cox model?

Thank you, John

John David Sorkin M.D., Ph.D. Professor of Medicine Chief,
Biostatistics and Informatics University of Maryland School of
Medicine Division of Gerontology and Geriatric Medicine Baltimore VA
Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD
21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone
number above prior to faxing)


__ 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] Probit model- endogeneity issue

2021-04-06 Thread John C Frain
On Wed 24 Mar 2021 at 07:54, hannelore nelissen <
hannelore.nelis...@outlook.be> wrote:

> Dear all,
> I am having some issues with using the IV strategy for an endogeneity
> problem in terms of a probit model.  In particular, I want to follow a
> two-stage procedure where I estimate a probit on the decision to peg the
> exchange rate, and then use the predicted values in the second stage
> regression. So, I need to get a probability that the country has a peg
> (estimated based on the Z variables). So, in the second stage, I have to
> include this estimated probability of the first stage (and exclude the Z
> variables that showed a significant effect). However, I do not know how to
> get this estimated probability of the first stage which I can then include
> in my second stage?
> Can somebody help me with the command I should use?
>
>
> I would really appreciate it, thanks Dear all,
>
>
> I find it a bit difficult to follow your question.  You might find

Lee (1981), Simultaneous Equation Models with discrete and censored
dependent variables, in Mansfield and McFadden (Ed’s), 346-364, MIT,
helpful in suggesting ways to proceed.

 Chapter 19 of Wooldridge :(2010), Econometric Analysis of Cross Section
and Panel Data, Princeton, may also be useful.

You might look at the r packages ivprobit and ivporbit






>
> Verzonden vanuit Mail
> voor Windows 10
>
>
> [[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.
>
-- 
John C Frain
3 Aranleigh Park
Rathfarnham
Dublin 14
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com

[[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.