Re: [R] Unable to Understand Results of pglm function

2019-04-23 Thread Paul Bernal
Hi Dr. Mackay,

Thank you so much for your valuable feedback.

I wonder why, when  applying the summary function over the pglm model, it
shows infinite as value for the standard errors.

Is this something we should expect? Or is there something else that needs
to be adjusted, either in the dataset(in the dataset's structure) or in the
pglm parameters.

Best regards,

Paul

El mar., 23 de abril de 2019 9:55 p. m., Duncan Mackay 
escribió:

> Hi Paul
>
> I think you may have too many IDs DATE for your model as you posted
>
> I converted your DATE into date format and named it df3
> str(df3)
> 'data.frame':   527 obs. of  11 variables:
>  $ TRANSIT : int  1 1 1 0 1 1 1 1 1 1 ...
>  $ ID  : int  1 1 2 2 3 4 5 5 6 7 ...
>  $ DATE: Factor w/ 377 levels "1-Aug-17","1-Aug-18",..: 47 75 89
> 252 3 221 62 99 224 114 ...
>  $ SHIPNAME: Factor w/ 482 levels "Aby Jeannette",..: 295 295 151 151
> 19 41 292 292 201 148 ...
>  $ Draft   : int  12 12 12 13 12 12 12 12 12 12 ...
>  $ TOTALCOST   : int  194364 219364 198260 237456 197159 198992 194337
> 219337 199198 196604 ...
>  $ BUNKER  : int  350 405 276 350 373 355 370 343 345 288 ...
>  $ CHARTERVALUE: int  14000 12825 10475 11850 13250 12100 11875 14500
> 12500 10500 ...
>  $ dt  : Date, format: "2018-03-15" "2018-08-19" "2017-07-20"
> "2017-12-19" ...
>  $ dtym: chr  "201803" "201808" "201707" "201712" ...
>  $ dty : chr  "2018" "2018" "2017" "2017" ...
>
> Here are 2 results
>
> > model1 = pglm(TRANSIT~ Draft+TOTALCOST+BUNKER+CHARTERVALUE + dty,
> +  effect=c("time"),
> +  model=c("pooling"),
> +  family=binomial('logit'),
> +  index=c("ID"),
> +  start = NULL, data=df3)
> >
> > summary(model1)
> 
> Maximum Likelihood estimation
> Newton-Raphson maximisation, 11 iterations
> Return code 2: successive function values within tolerance limit
> Log-Likelihood: -14.14988
> 6  free parameters
> Estimates:
>Estimate Std. error t value Pr(> t)
> (Intercept)   1.023e+02Inf   0   1
> Draft-5.088e+00Inf   0   1
> TOTALCOST-1.708e-04Inf   0   1
> BUNKER   -6.712e-03Inf   0   1
> CHARTERVALUE  2.524e-04Inf   0   1
> dty2018   2.215e+00Inf   0   1
> 
>
> > model1=pglm(TRANSIT~ Draft+TOTALCOST+BUNKER+CHARTERVALUE + dty,
> +  effect=c("time"),
> +  model=c("pooling"),
> +  family=binomial('logit'),
> +  index=c("ID","dty"),
> +  start = NULL, data=df3)
> Warning messages:
> 1: In pdata.frame(data, index) :
>   duplicate couples (id-time) in resulting pdata.frame
>  to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany")
> 2: In is.pbalanced.default(index[[1]], index[[2]]) :
>   duplicate couples (id-time)
>
> >
> > summary(model1)
> 
> Maximum Likelihood estimation
> Newton-Raphson maximisation, 11 iterations
> Return code 2: successive function values within tolerance limit
> Log-Likelihood: -14.14988
> 6  free parameters
> Estimates:
>Estimate Std. error t value Pr(> t)
> (Intercept)   1.023e+02Inf   0   1
> Draft-5.088e+00Inf   0   1
> TOTALCOST-1.708e-04Inf   0   1
> BUNKER   -6.712e-03Inf   0   1
> CHARTERVALUE  2.524e-04Inf   0   1
> dty2018   2.215e+00Inf   0   1
> 
>
> I have no knowledge of the pglm package and was trying it out on your data
> without going through the help properly
> NBB your DATE column has several formats which do not help
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2350
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul
> Bernal
> Sent: Wednesday, 24 April 2019 06:44
> To: yves.croiss...@univ-reunion.fr
> Cc: r-help@r-project.org
> Subject: [R] Unable to Understand Results of pglm function
>
> Dear Yves,
>
> Hope you are doing great. I have been testing the pglm function from the
> pglm package, in order to fit a logit regression to a panel dataset, and I
> do not understand the results and/or errors produced by the function, so I
> want to be able to understand whether there is a problem with the structure
> of my dataset, or I am not using the function properly or if there is
> something else going on that I am ignoring. Also, I would like to know what
> the start argument is for, or at least an example of how to use it, since I
> don´t know how to properly apply it.
>
> Here the details of what I am using and under what environment settings:
> 1-R version: 3.5.3
> 2-packages called: plm and pglm
> 3-Running on a 64-bit Operating System
> 4-Windows 8
>
> Here is the code 

Re: [R] Unable to Understand Results of pglm function

2019-04-23 Thread Duncan Mackay
Hi Paul

I think you may have too many IDs DATE for your model as you posted

I converted your DATE into date format and named it df3
str(df3)
'data.frame':   527 obs. of  11 variables:
 $ TRANSIT : int  1 1 1 0 1 1 1 1 1 1 ...
 $ ID  : int  1 1 2 2 3 4 5 5 6 7 ...
 $ DATE: Factor w/ 377 levels "1-Aug-17","1-Aug-18",..: 47 75 89 252 3 
221 62 99 224 114 ...
 $ SHIPNAME: Factor w/ 482 levels "Aby Jeannette",..: 295 295 151 151 19 41 
292 292 201 148 ...
 $ Draft   : int  12 12 12 13 12 12 12 12 12 12 ...
 $ TOTALCOST   : int  194364 219364 198260 237456 197159 198992 194337 219337 
199198 196604 ...
 $ BUNKER  : int  350 405 276 350 373 355 370 343 345 288 ...
 $ CHARTERVALUE: int  14000 12825 10475 11850 13250 12100 11875 14500 12500 
10500 ...
 $ dt  : Date, format: "2018-03-15" "2018-08-19" "2017-07-20" 
"2017-12-19" ...
 $ dtym: chr  "201803" "201808" "201707" "201712" ...
 $ dty : chr  "2018" "2018" "2017" "2017" ...

Here are 2 results 

> model1 = pglm(TRANSIT~ Draft+TOTALCOST+BUNKER+CHARTERVALUE + dty,
+  effect=c("time"), 
+  model=c("pooling"), 
+  family=binomial('logit'),
+  index=c("ID"), 
+  start = NULL, data=df3)
> 
> summary(model1)

Maximum Likelihood estimation
Newton-Raphson maximisation, 11 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -14.14988 
6  free parameters
Estimates:
   Estimate Std. error t value Pr(> t)
(Intercept)   1.023e+02Inf   0   1
Draft-5.088e+00Inf   0   1
TOTALCOST-1.708e-04Inf   0   1
BUNKER   -6.712e-03Inf   0   1
CHARTERVALUE  2.524e-04Inf   0   1
dty2018   2.215e+00Inf   0   1


> model1=pglm(TRANSIT~ Draft+TOTALCOST+BUNKER+CHARTERVALUE + dty,
+  effect=c("time"), 
+  model=c("pooling"), 
+  family=binomial('logit'),
+  index=c("ID","dty"), 
+  start = NULL, data=df3)
Warning messages:
1: In pdata.frame(data, index) :
  duplicate couples (id-time) in resulting pdata.frame
 to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany")
2: In is.pbalanced.default(index[[1]], index[[2]]) :
  duplicate couples (id-time)

> 
> summary(model1)

Maximum Likelihood estimation
Newton-Raphson maximisation, 11 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -14.14988 
6  free parameters
Estimates:
   Estimate Std. error t value Pr(> t)
(Intercept)   1.023e+02Inf   0   1
Draft-5.088e+00Inf   0   1
TOTALCOST-1.708e-04Inf   0   1
BUNKER   -6.712e-03Inf   0   1
CHARTERVALUE  2.524e-04Inf   0   1
dty2018   2.215e+00Inf   0   1


I have no knowledge of the pglm package and was trying it out on your data 
without going through the help properly
NBB your DATE column has several formats which do not help

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal
Sent: Wednesday, 24 April 2019 06:44
To: yves.croiss...@univ-reunion.fr
Cc: r-help@r-project.org
Subject: [R] Unable to Understand Results of pglm function

Dear Yves,

Hope you are doing great. I have been testing the pglm function from the
pglm package, in order to fit a logit regression to a panel dataset, and I
do not understand the results and/or errors produced by the function, so I
want to be able to understand whether there is a problem with the structure
of my dataset, or I am not using the function properly or if there is
something else going on that I am ignoring. Also, I would like to know what
the start argument is for, or at least an example of how to use it, since I
don´t know how to properly apply it.

Here the details of what I am using and under what environment settings:
1-R version: 3.5.3
2-packages called: plm and pglm
3-Running on a 64-bit Operating System
4-Windows 8

Here is the code with the different things I have tried so far:
> PGLM_Model11 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,
effect=c("twoways"), model=c("random"), family=binomial('logit'),
index=c("ID","DATE"), start = NULL, data=dataframe3)
>
> summary(PGLM_Model11)

Maximum Likelihood estimation
Newton-Raphson maximisation, 0 iterations
Return code 100: Initial value out of range.

>
> PGLM_Model12 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,

[R] Unable to Understand Results of pglm function

2019-04-23 Thread Paul Bernal
Dear Yves,

Hope you are doing great. I have been testing the pglm function from the
pglm package, in order to fit a logit regression to a panel dataset, and I
do not understand the results and/or errors produced by the function, so I
want to be able to understand whether there is a problem with the structure
of my dataset, or I am not using the function properly or if there is
something else going on that I am ignoring. Also, I would like to know what
the start argument is for, or at least an example of how to use it, since I
don´t know how to properly apply it.

Here the details of what I am using and under what environment settings:
1-R version: 3.5.3
2-packages called: plm and pglm
3-Running on a 64-bit Operating System
4-Windows 8

Here is the code with the different things I have tried so far:
> PGLM_Model11 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,
effect=c("twoways"), model=c("random"), family=binomial('logit'),
index=c("ID","DATE"), start = NULL, data=dataframe3)
>
> summary(PGLM_Model11)

Maximum Likelihood estimation
Newton-Raphson maximisation, 0 iterations
Return code 100: Initial value out of range.

>
> PGLM_Model12 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,
effect=c("twoways"), model=c("pooling"), family=binomial('logit'),
index=c("ID","DATE"), start = NULL, data=dataframe3)
>
> summary(PGLM_Model12)

Maximum Likelihood estimation
Newton-Raphson maximisation, 11 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -14.95426
5  free parameters
Estimates:
  Estimate Std. error t value Pr(> t)
(Intercept) 93.9680425Inf   0   1
dataframe3$Draft-5.3820652Inf   0   1
dataframe3$TOTALCOST-0.0001689Inf   0   1
dataframe3$BUNKER0.0072934Inf   0   1
dataframe3$CHARTERVALUE  0.0008862Inf   0   1

>
> PGLM_Model13 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,
effect=c("twoways"), model=c("within"), family=binomial('logit'),
index=c("ID","DATE"), start = NULL, data=dataframe3)
Error in maxRoutine(fn = logLik, grad = grad, hess = hess, start = start,
:
  argument "start" is missing, with no default
>
> PGLM_Model14 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,
effect=c("twoways"), model=c("between"), family=binomial('logit'),
index=c("ID","DATE"), start = NULL, data=dataframe3)
Error in maxRoutine(fn = logLik, grad = grad, hess = hess, start = start,
:
  argument "start" is missing, with no default

Below the dput of the dataset I am using for your reference:

> dput(dataframe3)
structure(list(TRANSIT = c(1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L,
0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L,
1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L,
1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L,
1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L,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 1L, 1L, 0L, 1L, 1L, 1L, 0L,
0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L,
0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L,
1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 

Re: [R] Error in pglm function when performing logit regression on Panel Data

2019-04-23 Thread Marc Schwartz via R-help


> On Apr 23, 2019, at 2:43 PM, Paul Bernal  wrote:
> 
> Dear friends,
> 
> The following error is generated when trying to fit a logistic regression
> with the pglm function:
> 
>> PGLM_Model2 <-
> pglm(dataframe2$TRANSIT~dataframe2$Draft+dataframe2$TOTALCOST+dataframe2$BUNKER+dataframe2$CHARTERVALUE,
> effect=c("twoways"), family=binomial('logit'), index=dataframe2$ID,
> data=dataframe2)
> Error in pdata.frame(data, index) :
>  'index' can be of length 3 at the most (one index variable for
> individual, time, group)
> 
> This doesn´t make sense to me because the maximum length for ID is 3 and I
> checked it twice.
> 
> A few things to keep in mind:
> 1. I am using R version 3.5.3
> 2. My worstation has Windows 8 and it is a 64-bit OS
> 
> I would like to know what I´m doing wrong and how to solve this issue (if
> possible). I provide a dput() of my dataset below:
> 
> dput(dataframe2)'



> Any guidance will be greatly appreciated,
> 
> Best regards,
> 
> Paul


Hi Paul,

I do not use pglm, but installed it.

Thanks for providing the dput() output of your data frame.

As is typical with R modeling functions, there is a reason for the 'data' 
argument, rather than specifying the 'dataframe$' prefix syntax for each DV and 
IV.

It shortens the code required to specify the formula, but perhaps more 
importantly, it defines the environment within which the function can find the 
variables to be used by the function, as specified by the various arguments.

In this case, that is critical, since, as per the examples in ?pglm, the 
'index' argument is to be specified as a character vector and not as the vector 
objects themselves. That is, use "ID" and not ID. Therefore, the function will 
search for the vector/column named "ID" within the dataframe2 object, which is 
the argument to 'data'.

Unfortunately, the help for the function does not make it clear that the value 
for 'index' should be a character vector, it simply says 'the index'. Thus one 
needs to look at the examples for some guidance.

You might want to point that out to the maintainer of the package (copied here 
now) as an improvement in the documentation.

Thus:

> pglm(TRANSIT ~ Draft + TOTALCOST + BUNKER + CHARTERVALUE, data = dataframe2, 
> effect = "twoways", family = binomial("logit"), index = "ID")
Maximum Likelihood estimation
Newton-Raphson maximisation, 0 iterations
Return code 100: Initial value out of range.


You now have other issues to deal with, which appear to be coming from the 
maxLik() function used from the package of the same name, which is a dependency 
for pglm, and I will leave those to you to resolve, probably using the 'start' 
argument to pglm().

Regards,

Marc Schwartz

__
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] Error in pglm function when performing logit regression on Panel Data

2019-04-23 Thread Paul Bernal
Dear friends,

The following error is generated when trying to fit a logistic regression
with the pglm function:

> PGLM_Model2 <-
pglm(dataframe2$TRANSIT~dataframe2$Draft+dataframe2$TOTALCOST+dataframe2$BUNKER+dataframe2$CHARTERVALUE,
effect=c("twoways"), family=binomial('logit'), index=dataframe2$ID,
data=dataframe2)
Error in pdata.frame(data, index) :
  'index' can be of length 3 at the most (one index variable for
individual, time, group)

This doesn´t make sense to me because the maximum length for ID is 3 and I
checked it twice.

A few things to keep in mind:
1. I am using R version 3.5.3
2. My worstation has Windows 8 and it is a 64-bit OS

I would like to know what I´m doing wrong and how to solve this issue (if
possible). I provide a dput() of my dataset below:

dput(dataframe2)
structure(list(TRANSIT = c(1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
1L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, 1L, 1L, 1L, 1L, 1L), ID = c(1L, 1L, 2L, 2L, 3L, 4L, 5L, 5L,
6L, 7L, 7L, 7L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 21L, 22L, 23L, 24L, 24L, 25L, 26L, 27L,
28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L,
41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 48L, 49L, 50L, 51L, 52L,
53L, 54L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L,
65L, 66L, 67L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
90L, 91L, 92L, 93L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 108L, 109L, 110L,
111L, 112L, 113L, 114L, 115L, 115L, 115L, 115L, 116L, 117L, 118L,
119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 128L,
129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L,
139L, 140L, 140L, 141L, 142L, 143L, 144L, 145L, 145L, 146L, 146L,
147L, 148L, 149L, 149L, 150L, 150L, 150L, 151L, 152L, 153L, 154L,
155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L,
166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L,
177L, 178L, 179L, 180L, 181L, 182L, 182L, 183L, 184L, 185L, 186L,
187L, 188L, 189L, 190L, 191L, 192L, 192L, 193L, 193L, 194L, 195L,
196L, 197L, 198L, 199L, 199L, 200L, 201L, 202L, 203L, 204L, 205L,
206L, 207L, 208L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L,
216L, 217L, 218L, 218L, 219L, 220L, 221L, 222L, 222L, 223L, 224L,
225L, 226L, 227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L,
236L, 237L, 238L, 239L, 240L, 241L, 241L, 241L, 242L, 243L, 244L,
245L, 246L, 247L, 247L, 248L, 248L, 249L, 249L, 250L, 251L, 252L,
253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L,
264L, 265L, 266L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 273L,
274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L, 283L, 284L,
285L, 286L, 287L, 288L, 288L, 289L, 290L, 291L, 292L, 293L, 294L,
295L, 296L, 297L, 298L, 299L, 300L, 301L, 301L, 302L, 303L, 304L,
305L, 306L, 307L, 308L, 308L, 309L, 309L, 309L, 310L, 311L, 312L,
313L, 313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 

[R] (no subject)

2019-04-23 Thread Abs Spurdle
Note that your post has no subject line.
I can't find it in my emails, which may explain why no one else has replied.

> fo<-h~a+b*log(dbh)+c*(log(dbh))^2+1.3

I'm assuming that you want to fit a model with three parameters, a, b and c.
This would be a linear model (linear in the parameters).
I'm going to ignore the +1.3 (because you don't need two intercepts),
but you can modify the following script if you want.

> I want to compute a nlm for each plot

So, three models?

How about this:
> r1 = lm (h ~ log (dbh) + I ( (log (dbh) ) ^ 2), data=ah 
> [ah$plot=="Sinca",])$coef
> r2 = lm (h ~ log (dbh) + I ( (log (dbh) ) ^ 2), data=ah 
> [ah$plot=="budeni",])$coef
> r3 = lm (h ~ log (dbh) + I ( (log (dbh) ) ^ 2), data=ah 
> [ah$plot=="Ceahlau",])$coef

> params = rbind (r1, r2, r3)
> rownames (params) = c ("Sinca", "budeni", "Ceahlau")
> colnames (params) = c ("a", "b", "c")

> params
 a b  c
Sinca-13.05110  5.657927   1.606357
budeni-2.11277  3.997636   1.104683
Ceahlau -135.57911 82.836952 -10.918932

__
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] Vectorised uniroot function

2019-04-23 Thread Shawn Way
I've had to do something similar for some of my engineering calculations.  I 
would welcome something like this.  It would make the language more amenable 
for engineering usage.

Thank you kindly!

Shawn Way, PE


-Original Message-
From: R-help  On Behalf Of Mark Clements
Sent: Tuesday, April 23, 2019 7:12 AM
To: r-help@r-project.org
Subject: [R] Vectorised uniroot function

** External Email **: This email originated from outside of the organization. 
Do not click links or open attachments unless you recognize the sender and know 
the content is safe.



A vectorised uniroot function would be useful for function inversion, e.g. for 
quantile functions and random number generation. To address this, I have 
implemented rstpm2::vuniroot that adapts the C function
R_zeroin2 for Brent's method for a vectorised objective. The function currently 
uses Rcpp, but could be re-implemented using the C API.

As an example, we can now rapidly sample from a proportional hazards mixture 
Weibull distribution:

pweibullMixturePH <- function(q, p1, RR, shape1, shape2, scale1=1, scale2=1)
1 - (p1*pweibull(q, shape1, scale1, lower.tail=FALSE) +
 (1-p1)*pweibull(q, shape2, scale2, lower.tail=FALSE))^RR rfun <- 
function(pfun) function(n, ..., lower=1e-5, upper=1e6) {
u <- runif(n)
objective <- function(q) pfun(q, ...) - u
rstpm2::vuniroot(objective, lower=rep(lower,length=n),
 upper=rep(upper,length=n))$root } rweibullMixturePH <- 
rfun(pweibullMixturePH)
set.seed(12345)
y <- rweibullMixturePH(n=1e4,p1=0.5,RR=2,shape1=1.5,shape2=0.5)

Has anyone previously developed a similar vectorised uniroot function?
Finally, would this be a useful addition to core R?

-- Mark


När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI 
kommer att behandla dina personuppgifter. Här finns information om hur KI 
behandlar personuppgifter.


Sending email to Karolinska Institutet (KI) will result in KI processing your 
personal data. You can read more about KI’s processing of personal data 
here.

__
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] Vectorised uniroot function

2019-04-23 Thread Mark Clements
A vectorised uniroot function would be useful for function inversion,
e.g. for quantile functions and random number generation. To address
this, I have implemented rstpm2::vuniroot that adapts the C function
R_zeroin2 for Brent's method for a vectorised objective. The function
currently uses Rcpp, but could be re-implemented using the C API.

As an example, we can now rapidly sample from a proportional hazards
mixture Weibull distribution:

pweibullMixturePH <- function(q, p1, RR, shape1, shape2, scale1=1, scale2=1)
1 - (p1*pweibull(q, shape1, scale1, lower.tail=FALSE) +
 (1-p1)*pweibull(q, shape2, scale2, lower.tail=FALSE))^RR
rfun <- function(pfun) function(n, ..., lower=1e-5, upper=1e6) {
u <- runif(n)
objective <- function(q) pfun(q, ...) - u
rstpm2::vuniroot(objective, lower=rep(lower,length=n),
 upper=rep(upper,length=n))$root
}
rweibullMixturePH <- rfun(pweibullMixturePH)
set.seed(12345)
y <- rweibullMixturePH(n=1e4,p1=0.5,RR=2,shape1=1.5,shape2=0.5)

Has anyone previously developed a similar vectorised uniroot function?
Finally, would this be a useful addition to core R?

-- Mark


När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI 
kommer att behandla dina personuppgifter. Här finns information om hur KI 
behandlar personuppgifter.


Sending email to Karolinska Institutet (KI) will result in KI processing your 
personal data. You can read more about KI’s processing of personal data 
here.

__
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] Multiple Lags with Dplyr

2019-04-23 Thread Gabor Grothendieck
lag.zoo supports vector-based lags on zoo objects.
A few caveats:

- dplyr's lag clobbers the base R lag (which you need to
invoke lag's methods) so if you have dplyr loaded be sure
to refer to stats::lag.

- dplyr's lag works backwards relative to the standard set
in base R so dplyr::lag(x, 1) corresponds to stat::lag(x, -1) in
base R

- zoo follows base R's standard

- you can use as.data.frame or fortify.zoo to convert a zoo
object to a data frame if you need that.  The first one
drops the time index and the second one includes it.

  library(zoo)
  stats::lag(zoo(d2$x1), 0:-2)

giving this zoo object:

   lag0 lag-1 lag-2
1 1NANA
2 2 1NA
3 3 2 1
4 4 3 2
5 5 4 3
6 6 5 4
7 7 6 5
8 8 7 6
9 9 8 7
10   10 9 8


On Tue, Apr 23, 2019 at 9:10 AM Lorenzo Isella  wrote:
>
> Dear All,
> I refer to the excellent post at
>
> https://purrple.cat/blog/2018/03/02/multiple-lags-with-tidy-evaluation/
>
> What I want to do is to create a function capable, ą la dplyr, to
> generate new columns which are a lagged version of existing columns in
> a data frame.
> For instance, you can do this manually as
>
>
> d2 <- tibble(x1 =1:10, x2=10:19,  x3=50:59)
>
>
> d3 <- d2%>%mutate(x1lag1=lag(x1, 1), x1lag2=lag(x1,2))
>
>
> but this becomes quickly tedious when you need to take several lags of
> different columns.
> One solution in the link above is the following
>
>
> lags <- function(var, n=10){
>   var <- enquo(var)
>
>   indices <- seq_len(n)
>   map( indices, ~quo(lag(!!var, !!.x)) ) %>%
> set_names(sprintf("lag_%s_%02d", quo_text(var), indices))
>
> }
>
>
> d4 <- d2 %>%
>   mutate( !!!lags(x1, 3), !!!lags(x2,3) )
>
>
> does anybody know how this could be made more general? I mean that I
> would like to take a fixed number of lags of a list of columns (x1 and
> x2, for instance), just by passing the list of columns and without
> repeating the commands for x1 and x2.
> Any suggestion is appreciated.
> Cheers
>
> Lorenzo
>
> __
> 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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
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] Multiple Lags with Dplyr

2019-04-23 Thread Lorenzo Isella

Dear All,
I refer to the excellent post at

https://purrple.cat/blog/2018/03/02/multiple-lags-with-tidy-evaluation/

What I want to do is to create a function capable, à la dplyr, to
generate new columns which are a lagged version of existing columns in
a data frame.
For instance, you can do this manually as

library(dplyr)
library(rlang)


d2 <- tibble(x1 =1:10, x2=10:19,  x3=50:59)


d3 <- d2%>%mutate(x1lag1=lag(x1, 1), x1lag2=lag(x1,2))


but this becomes quickly tedious when you need to take several lags of
different columns.
One solution in the link above is the following


lags <- function(var, n=10){
 var <- enquo(var)
 
 indices <- seq_len(n)
 map( indices, ~quo(lag(!!var, !!.x)) ) %>% 
   set_names(sprintf("lag_%s_%02d", quo_text(var), indices))
 
}



d4 <- d2 %>% 
 mutate( !!!lags(x1, 3), !!!lags(x2,3) )



does anybody know how this could be made more general? I mean that I
would like to take a fixed number of lags of a list of columns (x1 and
x2, for instance), just by passing the list of columns and without
repeating the commands for x1 and x2.
Any suggestion is appreciated.
Cheers

Lorenzo

__
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] Multiple Lags with Dplyr

2019-04-23 Thread Lorenzo Isella

Dear All,
I refer to the excellent post at

https://purrple.cat/blog/2018/03/02/multiple-lags-with-tidy-evaluation/

What I want to do is to create a function capable, à la dplyr, to
generate new columns which are a lagged version of existing columns in
a data frame.
For instance, you can do this manually as


d2 <- tibble(x1 =1:10, x2=10:19,  x3=50:59)


d3 <- d2%>%mutate(x1lag1=lag(x1, 1), x1lag2=lag(x1,2))


but this becomes quickly tedious when you need to take several lags of
different columns.
One solution in the link above is the following


lags <- function(var, n=10){
 var <- enquo(var)
 
 indices <- seq_len(n)
 map( indices, ~quo(lag(!!var, !!.x)) ) %>% 
   set_names(sprintf("lag_%s_%02d", quo_text(var), indices))
 
}



d4 <- d2 %>% 
 mutate( !!!lags(x1, 3), !!!lags(x2,3) )



does anybody know how this could be made more general? I mean that I
would like to take a fixed number of lags of a list of columns (x1 and
x2, for instance), just by passing the list of columns and without
repeating the commands for x1 and x2.
Any suggestion is appreciated.
Cheers

Lorenzo

__
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] Logistic Regression with Panel Data

2019-04-23 Thread Marc Schwartz via R-help


> On Apr 23, 2019, at 8:26 AM, Paul Bernal  wrote:
> 
> Dear friends, hope you are all doing great,
> 
> I would like to know if there is any R package that allows fitting of
> logistic regression to panel data.
> 
> I installed and loaded package plm, but from what I have read so far, plm
> only allows fitting of linear regression to panel data, not logistic.
> 
> Any help and/or guidance will be greatly appreciated,
> 
> Best regards,
> 
> Paul


Hi Paul,

You might look at the pglm package on CRAN.

Since there can be multiple methodologies that are apropos in this setting, 
such as GEE, mixed-effects, robust covariance matrix, etc., you might want to 
look at the CRAN task view that covers this domain:

  https://cran.r-project.org/web/views/Econometrics.html

Regards,

Marc Schwartz

__
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] Logistic Regression with Panel Data

2019-04-23 Thread Paul Bernal
Dear friends, hope you are all doing great,

I would like to know if there is any R package that allows fitting of
logistic regression to panel data.

I installed and loaded package plm, but from what I have read so far, plm
only allows fitting of linear regression to panel data, not logistic.

Any help and/or guidance will be greatly appreciated,

Best regards,

Paul

[[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: [R] Help with Rmarkdown HTML Logo

2019-04-23 Thread Bill Poling
I got it to work. Yay Me!

```{r, echo=FALSE}
htmltools::img(src = knitr::image_uri(file.path("C:/WHP/Revenue Development 
Products/BRA AutoDistribution/Zelis.jpg")),
   alt = 'logo',
   style = 'position:absolute; top:0; left:0; padding:10px;')
```
WHP


-Original Message-
From: Bill Poling
Sent: Monday, April 22, 2019 10:37 AM
To: r-help (r-help@r-project.org) 
Cc: Bill Poling 
Subject: Help with Rmarkdown HTML Logo

Hello.

#RStudio Version 1.1.456
sessionInfo()
#R version 3.5.3 (2019-03-11)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows >= 8 x64 
(build 9200)

I feel I have made great progress teaching myself RMarkdown using HTML 
reporting for the moment.

However, one formatting item eludes me, the Logo.

It works fine as positioned in the script below, however, it does not travel 
with the HTML when I distribute it.

I understand why, because it resides in the same file as the report.

Looking at various urls for this topic I find that this appears to do the trick:

https://stackoverflow.com/questions/43009788/insert-a-logo-in-upper-right-corner-of-r-markdown-html-document

My problem is how does my file path work in this example please?

#MY File Path:
C:\WHP\Revenue Development Products\BRA AutoDistribution\ Zelis.jpg


---
title: AUTO DISTRIBUTION ANALYSIS
author: DRAFT FOR DISCUSSION
date:
output:
  html_document:
  params:
interactive: TRUE
---

   $(document).ready(function() {
 $head = $('#header');
 $head.prepend('')
   });



h1.title {
  font-size: 38px;
  color: Purple;
  text-align: center;
}
h4.author { /* Header 4 - and the author and data headers use this too  */
font-size: 18px;
  font-family: "Times New Roman", Times, serif;
  color: Purple;
  text-align: center;



Everything above is fine, I want to enhance this report by making the logo a 
traveler so to speak.
Of course once I get this to work below I will remove the reference to it above.


```{r, echo=FALSE}
htmltools::img(src = knitr::image_uri(file.path(R.home("doc"), "html", 
"Zelis.jpg")),
   alt = 'logo',
   style = 'position:absolute; top:0; left:0; padding:10px;') ```



Thank you for your assistance.

WHP




Confidentiality Notice This message is sent from Zelis. ...{{dropped:13}}

__
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] Debugging Rmarkdown

2019-04-23 Thread Patrick Connolly
knitr::purl -- thats a great tip!  As soon as got hold of a reqular .R
script, I spotted the reason why my Fmd file wouldn't knit in a matter
of seconds.  Thank you Jeff.  Thanks also to all the other suggestions.



On Fri, 19-Apr-2019 at 02:44PM -0700, Jeff Newmiller wrote:

|> I just run each chunk in sequence starting from an fresh restart of
|> R by copying code to the R console. However you can use knitr::purl
|> to extract all of the code into a regular R script to do whatever
|> debugging you are most familiar with.


|> On April 19, 2019 2:03:00 PM PDT, Patrick Connolly 
 wrote:
|> >
|> >On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
|> >> Dear Patrick,
|> >>
|> >> This is not easy to debug without a reprex
|> >>
|> >> I would check the content of zzz and wide.i in the loop
|> >>
|> >> str(wide.i)
|> >>  zzz <- rbind(zzz, wide.i)
|> >> str(zzz)
|> >>
|> >That's just what I'm trying to achieve but the debugging doesn't work 
|> >how it does with regular R code.
|> >
|> >> Note that the Rmd always runs in a clean environment. This might 
|> >> explain the difference
|> >>
|> >The data frames xx and yy are defined in earlier code chunks. Maybe I 
|> >need to define them again.
|> >
|> >
|> >I'll look closer at it after Easter.
|> >
|> >
|> >Thanks for the suggestion.
|> >
|> >> Best regards,
|> >>
|> >> ir. Thierry Onkelinx
|> >> Statisticus / Statistician
|> >>
|> >> Vlaamse Overheid / Government of Flanders
|> >> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR
|> >NATURE 
|> >> AND FOREST
|> >> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
|> >> thierry.onkel...@inbo.be 
|> >> Havenlaan 88 bus 73, 1000 Brussel
|> >> www.inbo.be 
|> >>
|> >>
|> 
>///
|> >> To call in the statistician after the experiment is done may be no 
|> >> more than asking him to perform a post-mortem examination: he may be 
|> >> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
|> >> The plural of anecdote is not data. ~ Roger Brinner
|> >> The combination of some data and an aching desire for an answer does 
|> >> not ensure that a reasonable answer can be extracted from a given
|> >body 
|> >> of data. ~ John Tukey
|> >>
|> 
>///
|> >>
|> >> 
|> >>
|> >>
|> >> Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly 
|> >> mailto:p_conno...@slingshot.co.nz>>:
|> >>
|> >> I have a function that works in ESS, but it fails if I include it
|> >in
|> >> an .Rmd file that I tried to knit using Rstudio.  I found advice
|> >at:
|> >>
|> 
>https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
|> >>
|> >> It seems to be not referring to markdown files.  Somewhere else
|> >> suggested calling render() in the console pane.  I tried that. 
|> >The
|> >> browser() function interrupts correctly, but I can't find out
|> >what the
|> >> object zzz in the code below looks like.  Nothing prints the way
|> >it
|> >> would in a "normal" R buffer.
|> >>
|> >> code outline:  making zzz out of two dataframes xx and yy
|> >>
|> >> ##
|> >>     zzz <- NULL
|> >>     for(i in xx$Sample){
|> >>         raw.i <- 
|> >>
|> >>         etc. etc.
|> >>
|> >>         zzz <- rbind(zzz, wide.i)
|> >> }
|> >>    browser()
|> >>
|> >>     names(zzz) <- c("Cultivar", "Test", "Change")
|> >> That line fails, with a complaint about zzz being NULL.
|> >>
|> >> It appears as though the rbind doesn't do anything, but I can't
|> >see
|> >> what wide.i looks like to get an idea what could be the cause.
|> >>
|> >> Ideas what I should try are welcome.  I have no idea why the code
|> >> works in an R environment but not an Rmd one.
|> >>
|> >>
|> >> R-3.5.2,
|> >> platform       x86_64-pc-linux-gnu
|> >> arch           x86_64
|> >> os             linux-gnu
|> >> system         x86_64, linux-gnu
|> >>
|> >> Rstudio Version 1.1.383
|> >>
|> >>
|> >>
|> >> -- 
|> >>
|> >~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
|> >>
|> >>    ___    Patrick Connolly
|> >>  {~._.~}                   Great minds discuss ideas
|> >>  _( Y )_                 Average minds discuss events
|> >> (:_~*~_:)                  Small minds discuss people
|> >>  (_)-(_)                              . Eleanor Roosevelt
|> >>
|> >>
|> >~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
|> >>
|> >> __
|> >> 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
|> >> 

Re: [R] Pause script at input from terminal (interactive use)

2019-04-23 Thread Luigi Marongiu
Thank you, I'll try that!

On Tue, Apr 23, 2019 at 9:22 AM PIKAL Petr  wrote:
>
> Hi
>
> Maybe you could think about transfering **script** to **function**.
>
> In function your construction seems to be OK.
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help  On Behalf Of Luigi Marongiu
> > Sent: Thursday, April 18, 2019 4:11 PM
> > To: r-help 
> > Subject: [R] Pause script at input from terminal (interactive use)
> >
> > Dear all,
> > I am trying to write an interactive script where the user type some input 
> > from
> > the terminal. I used readline() but when I launch the file with Rscript, the
> > function is overwritten directly, there is no waiting for the user's input. 
> > For
> > instance, this example:
> >
> > VAR1 = as.numeric(readline(prompt = "Enter something -> "))
> > VAR2 = as.numeric(readline(prompt = "Enter something else -> "))
> > if(is.na(VAR1)) VAR1 = 0
> > if(is.na(VAR2)) VAR2 = "empty"
> > cat("Input was: ", VAR1, " - ", VAR2, "\n")
> >
> > is executed till the end without typing anything on terminal :
> >
> > $ Rscript test.R
> > Enter something ->
> > Enter something else ->
> > Input was:  0  -  empty
> >
> > I also tried with ',1' at the end of readline, but the effect is the same. 
> > I should
> > use the interactive() function but I am confused on its use.
> > It is possible to launch R scritps in the interactive mode in the first 
> > place? and if
> > yes, how? Or would python or julia be better choices in this case?
> > Thank you.
> > --
> > Best regards,
> > Luigi
> >
> > __
> > 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.
> Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
> partnerů PRECHEZA a.s. jsou zveřejněny na: 
> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
> processing and protection of business partner’s personal data are available 
> on website: https://www.precheza.cz/en/personal-data-protection-principles/
> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
> podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
> https://www.precheza.cz/01-dovetek/ | This email and any documents attached 
> to it may be confidential and are subject to the legally binding disclaimer: 
> https://www.precheza.cz/en/01-disclaimer/
>


-- 
Best regards,
Luigi

__
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] Pause script at input from terminal (interactive use)

2019-04-23 Thread PIKAL Petr
Hi

Maybe you could think about transfering **script** to **function**.

In function your construction seems to be OK.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Luigi Marongiu
> Sent: Thursday, April 18, 2019 4:11 PM
> To: r-help 
> Subject: [R] Pause script at input from terminal (interactive use)
>
> Dear all,
> I am trying to write an interactive script where the user type some input from
> the terminal. I used readline() but when I launch the file with Rscript, the
> function is overwritten directly, there is no waiting for the user's input. 
> For
> instance, this example:
>
> VAR1 = as.numeric(readline(prompt = "Enter something -> "))
> VAR2 = as.numeric(readline(prompt = "Enter something else -> "))
> if(is.na(VAR1)) VAR1 = 0
> if(is.na(VAR2)) VAR2 = "empty"
> cat("Input was: ", VAR1, " - ", VAR2, "\n")
>
> is executed till the end without typing anything on terminal :
>
> $ Rscript test.R
> Enter something ->
> Enter something else ->
> Input was:  0  -  empty
>
> I also tried with ',1' at the end of readline, but the effect is the same. I 
> should
> use the interactive() function but I am confused on its use.
> It is possible to launch R scritps in the interactive mode in the first 
> place? and if
> yes, how? Or would python or julia be better choices in this case?
> Thank you.
> --
> Best regards,
> Luigi
>
> __
> 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] Is it possible to calculate in r the number of days and count of b in var r from the following table:

2019-04-23 Thread PIKAL Petr
Hi

Your question is barely understandable. Maybe you wanted

?aggregate

but without further precisement it is difficult to provide definitive answer.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of ajaykumar cp
> Sent: Wednesday, April 17, 2019 4:31 PM
> To: r-help@r-project.org
> Subject: [R] Is it possible to calculate in r the number of days and count of 
> b in
> var r from the following table:
>
> Hello
>
> Is it possible to calculate in r the number of days and count of b in var r 
> from
> the following table:
>
>
> id r s t u
> 1 a 100 1 27-06-2017
> 1 a 200 0 29-06-2017
> 1 b 300 0 01-07-2017
> 2 a 500 1 12-06-2017
> 3 b 100 0 02-07-2017
> 3 a 600 1 02-07-2017
> 4 a 200 0 12-06-2017
> 4 a 300 1 15-06-2017
> 4 b 200 0 18-06-2017
> 4 a 100 0 01-07-2017
> 5 a 200 0 04-06-2017
>
> grouped by unique ID where the condition = when r = b, sum of s >= sum of s
> when t = 1?
>
> https://stackoverflow.com/q/55724900/11373077 for the discussions
>
> Thank you in advance
>
>
> --
> C P Ajaykumar
>
> [[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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] creating a data.frame from scratch

2019-04-23 Thread PIKAL Petr
Hi

Structure is usefull for exchanging information and it is result of ?dput 
function. I wonder if anybody would like to use it for **creating** data frames.

For creating data frames see functions like

?read.table,
?read.delim,
or other ?read.* functions.

Your questions are mainly adressed in R-intro which should be part of your R 
installation.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Drake Gossi
> Sent: Saturday, April 20, 2019 1:40 AM
> To: r-help@r-project.org
> Subject: [R] creating a data.frame from scratch
>
> Hello everyone,
>
> Is there any way to create a data.frame from scratch? other than, say, this?
>
> > structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =
> c("apple",
> "banana", "kiwi", "orange", "pear"), class = "factor"), Color = 
> structure(c(3L, 4L,
> 1L, 2L, 1L), .Label = c("green", "orange", "red", "yellow"
> ), class = "factor"), Shape = structure(c(3L, 1L, 2L, 3L, 3L), .Label = 
> c("oblong",
> "pear", "round"), class = "factor"), Juice = c(1, 0, 0.5, 1, 0)), class =
> "data.frame", row.names = c("1", "2", "3", "4",
> "5"))
>
>
> which yields
>
>Fruit  Color  Shape  Juice
> 1  applered  round  1.0
> 2 banana yellow oblong   0.0
> 3   pear  green   pear   0.5
> 4 orange orange  round   1.0
> 5   kiwi  green  round   0.0
>
>
> I get *that* it works. I just don't know *how* it works, and whether or not
> there is another, easier way...
>
> For example,
>
> > structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =
> c("apple", "banana", "kiwi", "orange", "pear") ...
>
>
> What on earth are these numbers? c(1L, 2L, 5L, 4L, 3L)? and why are they out
> of order?
>
> And then why put the fruits out of order? c("apple", "banana", "kiwi",
> "orange", "pear")? since that's not a descending order?
> since, in the final data.frame, it goes apple, banana, *pear*, *orange*, kiwi?
>
> So many questions!
>
> Drake
>
> [[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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] combining data.frames with is.na & match (), two questions

2019-04-23 Thread PIKAL Petr
Hi

Keep posts also to r-help, others could give you different/better solutions.

Regarding ordering, see ?order or ?sort. However this is mainly necessary only 
for plotting or exporting data.

Cheers
Petr

From: Drake Gossi 
Sent: Thursday, April 18, 2019 9:27 PM
To: PIKAL Petr 
Subject: Re: [R] combining data.frames with is.na & match (), two questions

Thanks Pikal,

Your answer was super helpful. I just learned a lot from you. The only thing I 
have to figure out now is how to rearrange the numbers, say, so that 200 is on 
top, and NA is on bottom, or so that the two 100 calories are together. 
Something like that. Perhaps I'll try an ascending/descending function.

Thank you again.

D

On Thu, Apr 18, 2019 at 1:31 AM PIKAL Petr 
mailto:petr.pi...@precheza.cz>> wrote:
Hi

I wonder why such combination is so complicated in your text book.

Having data frames fr1 and fr2

> dput(fr1)
structure(list(Fruit = structure(c(1L, 3L, 2L), .Label = c("banana",
"mango", "pear"), class = "factor"), Calories = c(100L, 100L,
200L)), class = "data.frame", row.names = c("1", "2", "3"))
> dput(fr2)
structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label = c("apple",
"banana", "kiwi", "orange", "pear"), class = "factor"), Color = structure(c(3L,
4L, 1L, 2L, 1L), .Label = c("green", "orange", "red", "yellow"
), class = "factor"), Shape = structure(c(3L, 1L, 2L, 3L, 3L), .Label = 
c("oblong",
"pear", "round"), class = "factor"), Juice = c(1, 0, 0.5, 1,
0)), class = "data.frame", row.names = c("1", "2", "3", "4",
"5"))
>

> fr1
   Fruit Calories
1 banana  100
2   pear  100
3  mango  200
>

you can use merge to combine those 2 data frames to get either all values from 
both

> merge(fr2, fr1, all=T)
   Fruit  Color  Shape Juice Calories
1  applered  round   1.0   NA
2 banana yellow oblong   0.0  100
3   kiwi  green  round   0.0   NA
4 orange orange  round   1.0   NA
5   pear  green   pear   0.5  100
6  mango  NA  200

just values from data frame with calories

> merge(fr2, fr1, all.y=T)
   Fruit  Color  Shape Juice Calories
1 banana yellow oblong   0.0  100
2   pear  green   pear   0.5  100
3  mango  NA  200

or just values from data frame with colours

> merge(fr2, fr1, all.x=T)
   Fruit  Color  Shape Juice Calories
1  applered  round   1.0   NA
2 banana yellow oblong   0.0  100
3   kiwi  green  round   0.0   NA
4 orange orange  round   1.0   NA
5   pear  green   pear   0.5  100

Cheers
Petr


> -Original Message-
> From: R-help 
> mailto:r-help-boun...@r-project.org>> On Behalf 
> Of Drake Gossi
> Sent: Thursday, April 18, 2019 1:24 AM
> To: r-help@r-project.org
> Subject: [R] combining data.frames with is.na & match (), two 
> questions
>
> Hello everyone,
>
> I'm working through this book, *Humanities Data in R* (Arnold & Tilton), and
> I'm just having trouble understanding this maneuver.
>
> In sum, I'm trying to combine data in two different data.frames.
>
> This data.frame is called fruitNutr
>
> Fruit  Calories
> 1 banana 100
> 2 pear 100
> 3 mango 200
>
> And this data.frame is called fruitData
>
> Fruit Color Shape Juice
> 1 apple red round 1
> 2 banana yellow oblong 0
> 3 pear green pear 0.5
> 4 orange orange round 1
> 5 kiwi green round 0
>
> So, as you can see, these two data.frames overlap insofar as they both have
> banana and pear. So, what happens next is the book suggests this:
>
> fruitData$calories <- NA
>
>
> As a result, I've created a new column for the fruitData data.frame:
>
> Fruit Color Shape Juice Calories
> 1 apple red round 1N/A
> 2 banana yellow oblong 0N/A
> 3 pear green pear 0.5N/A
> 4 orange orange round 1N/A
> 5 kiwi green round 0N/A
>
> Then:
>
> > index <- match (x=fruitData$Fruit, table=fruitNutr$Fruit) index
>   [1]NA   1   2  NA  NA
> > is.na(index)
>   [1]TRUE   FALSEFALSE   TRUETRUE
> > fruitData$Calories [!is.na(index)] <- 
> > fruitNutr$Calories[index[!is.na
> (index)]]
> > fruitData
>
> Fruit Color Shape Juice Calories
> 1 apple red round 1N/A
> 2 banana yellow oblong 0 100
> 3 pear green pear 0.5 100
> 4 orange orange round 1N/A
> 5 kiwi green round 0N/A
>
> I get what the first part means, that first part being this:
> fruitData$Calories [!is.na(index)]
> go into the fruitData data.frame, specifically into the calories column, and 
> only
> for what's true according to is.na(index). But I just literally 
> can't understand
> this last part.  fruitNutr$Calories[index[!is.na(index)]]
>
> Two questions.
>
>
>1. I just literally don't understand how this code works. It does work,
>of course, but I don't know what it's doing, specifically this [index[!
>is.na(index)]] part. Could someone explain it to