[R] install package av on centos 7

2019-12-09 Thread Schneider, Dominik
I tried to install the av package on centos7 server with R 3.5.3 but am 
receiving an error. I installed ffmpeg and ffmpeg-devel on centos 7 as below 
and then followed the instructions of specifying LIB_DIR and INCLUDE_DIR for 
installing av.

any help would be appreciated. Thanks


```
> install.packages('av', configure.vars = 
> c("LIB_DIR=/usr/lib64","INCLUDE_DIR=/usr/include/ffmpeg"))
Installing package into '/home/dominik/R/x86_64-pc-linux-gnu-library/3.5'
(as 'lib' is unspecified)
  % Total% Received % Xferd  Average Speed   TimeTime Time  Current
 Dload  Upload   Total   SpentLeft  Speed
  0 00 00 0 100  720k  100  720k0 0   987k  0 
--:--:-- --:--:-- --:--:--  987k
No protocol specified
* installing *source* package 'av' ...
** package 'av' successfully unpacked and MD5 sums checked
Found INCLUDE_DIR and/or LIB_DIR!
Using PKG_CFLAGS=-I/usr/include/ffmpeg
Using PKG_LIBS=-L/usr/lib64 -lavfilter
** libs
rm -f av.so formats.o info.o init.o util.o video.o
gcc -std=gnu99 -I/opt/microsoft/ropen/3.5.3/lib64/R/include -DNDEBUG 
-I/usr/include/ffmpeg   -DU_STATIC_IMPLEMENTATION  -fvisibility=hidden -fpic  
-DU_STATIC_IMPLEMENTATION -O2 -g  -c formats.c -o formats.o
gcc -std=gnu99 -I/opt/microsoft/ropen/3.5.3/lib64/R/include -DNDEBUG 
-I/usr/include/ffmpeg   -DU_STATIC_IMPLEMENTATION  -fvisibility=hidden -fpic  
-DU_STATIC_IMPLEMENTATION -O2 -g  -c info.c -o info.o
info.c: In function 'get_video_info':
info.c:33:14: error: 'AVStream' has no member named 'codecpar'
 if(stream->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
  ^
info.c:35:49: error: 'AVStream' has no member named 'codecpar'
 AVCodec *codec = avcodec_find_decoder(stream->codecpar->codec_id);
 ^
info.c:40:55: error: 'AVStream' has no member named 'codecpar'
 SET_VECTOR_ELT(streamdata, 0, Rf_ScalarReal(stream->codecpar->width));
   ^
info.c:41:55: error: 'AVStream' has no member named 'codecpar'
 SET_VECTOR_ELT(streamdata, 1, Rf_ScalarReal(stream->codecpar->height));
   ^
info.c:45:94: error: 'AVStream' has no member named 'codecpar'
 SET_VECTOR_ELT(streamdata, 5, safe_string(av_get_pix_fmt_name((enum 
AVPixelFormat) stream->codecpar->format)));

  ^
info.c: In function 'get_audio_info':
info.c:64:14: error: 'AVStream' has no member named 'codecpar'
 if(stream->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
  ^
info.c:66:49: error: 'AVStream' has no member named 'codecpar'
 AVCodec *codec = avcodec_find_decoder(stream->codecpar->codec_id);
 ^
info.c:70:55: error: 'AVStream' has no member named 'codecpar'
 SET_VECTOR_ELT(streamdata, 0, Rf_ScalarReal(stream->codecpar->channels));
   ^
info.c:71:55: error: 'AVStream' has no member named 'codecpar'
 SET_VECTOR_ELT(streamdata, 1, 
Rf_ScalarReal(stream->codecpar->sample_rate));
   ^
info.c:74:55: error: 'AVStream' has no member named 'codecpar'
 SET_VECTOR_ELT(streamdata, 4, Rf_ScalarReal(stream->codecpar->bit_rate));
   ^
info.c:77:54: error: 'AVStream' has no member named 'codecpar'
 av_get_channel_layout_string(layout, 1024, stream->codecpar->channels, 
stream->codecpar->channel_layout);
  ^
info.c:77:82: error: 'AVStream' has no member named 'codecpar'
 av_get_channel_layout_string(layout, 1024, stream->codecpar->channels, 
stream->codecpar->channel_layout);

  ^
make: *** [info.o] Error 1
ERROR: compilation failed for package 'av'
* removing '/home/dominik/R/x86_64-pc-linux-gnu-library/3.5/av'
Warning in install.packages :
  installation of package 'av' had non-zero exit status

The downloaded source packages are in
  '/tmp/RtmpMDafXK/downloaded_packages'
```

ffmpeg was installed successfully:

```
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh 
http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
Retrieving 
http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
Preparing...  # [100%]
Updating / installing...
   1:nux-dextop-release-0-5.el7.nux   # [100%]
sudo yum install ffmpeg ffmpeg-devel -y
```

Result:

```
(base) [dominik@cppc-server ffmpeg]$ ffmpeg
ffmpeg version 2.8.15 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
  

Re: [R] Having problems with the ifelse and negative numbers

2019-12-09 Thread Richard M. Heiberger
or even simpler
sqrt(abs(A))

On Mon, Dec 9, 2019 at 8:45 AM Eric Berger  wrote:
>
> Hi Bob,
> You wrote "the following error message" -
> when in fact it is a Warning and not an error message. I think your
> code does what you hoped it would do, in the sense it successfully
> calculates the sqrt(abs(negativeNumber)), where appropriate.
>
> If you want to run the code without seeing this warning message you can run
>
> ifelse( A < 0, suppressWarnings(sqrt(-A)), A )
>
> and you should be fine.
>
> HTH,
> Eric
>
> On Mon, Dec 9, 2019 at 3:18 PM Kevin Thorpe  wrote:
> >
> > The sqrt(-A) is evaluated for all A. The result returned is conditional on 
> > the first argument but the other two arguments are evaluated on the entire 
> > vector.
> >
> > Kevin
> >
> > --
> > Kevin E. Thorpe
> > Head of Biostatistics,  Applied Health Research Centre (AHRC)
> > Li Ka Shing Knowledge Institute of St. Michael's
> > Assistant Professor, Dalla Lana School of Public Health
> > University of Toronto
> > email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
> >
> >
> > On 2019-12-09, 7:58 AM, "R-help on behalf of rsherry8" 
> >  wrote:
> >
> > Please consider the following two R statements:
> >  A =  runif(20, min=-1,max=1)
> >  ifelse( A < 0, sqrt(-A), A )
> >
> > The second statement produces the following error message:
> >  rt(-A) : NaNs produced
> >
> > I understand that you cannot take the square root of a negative number
> > but I thought the condition A < 0
> > would take care of that issue. It appears not to be.
> >
> > What am I missing?
> >
> > Thanks,
> > Bob
> >
> > __
> > 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-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] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Fox, John
Dear Bert,

It's perhaps a bit pedantic to point it out, but the dispersion is estimated 
from the Pearson statistic (sum of squared residuals or weighted squared 
residuals) not from the residual deviance. You can see this in the code for 
summary.glm().

Best,
 John

  -
  John Fox, Professor Emeritus
  McMaster University
  Hamilton, Ontario, Canada
  Web: http::/socserv.mcmaster.ca/jfox

> On Dec 9, 2019, at 10:45 AM, Bert Gunter  wrote:
> 
> In addition, as John's included output shows, only 1 parameter, the
> intercept, is fit. As he also said, the sd is estimated from the residual
> deviance -- it is not a model parameter.
> 
> Suggest you spend some time with a glm tutorial/text.
> 
> Bert
> 
> On Mon, Dec 9, 2019 at 7:17 AM Marc Girondot via R-help <
> r-help@r-project.org> wrote:
> 
>> Let do a simple glm:
>> 
>>> y=rnorm(100)
>>> gnul <- glm(y ~ 1)
>>> gnul$coefficients
>> (Intercept)
>>   0.1399966
>> 
>> The logLik shows the fit of two parameters (DF=2) (intercept) and sd
>> 
>>> logLik(gnul)
>> 'log Lik.' -138.7902 (df=2)
>> 
>> But where is the sd term in the glm object?
>> 
>> If I do the same with optim, I can have its value
>> 
>>> dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"],
>> sd=x["sd"], log = TRUE))}
>>> parg <- c(mean=0, sd=1)
>>> o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
>>> o0$value/1E9
>> [1] 138.7902
>>> o0$par
>>  meansd
>> 
>> 0.1399966 0.9694405
>> 
>> But I would like have the value in the glm.
>> 
>> (and in the meantime, I don't understand why gnul$df.residual returned
>> 99... for me it should be 98=100 - number of observations) -1 (for mean)
>> - 1 (for sd); but it is statistical question... I have asked it in
>> crossvalidated [no answer still] !)
>> 
>> Thanks
>> 
>> Marc
>> 
>> __
>> 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] how to create a txt file with parsed columns

2019-12-09 Thread Ana Marija
Thanks for getting back to me, I resolved my problem with this:

library(reshape2)
c=dcast(a, rs ~ GENE)
d=merge(c,b,by="rs")
d[is.na(d)] <- 0

On Sun, Dec 8, 2019 at 11:03 PM Jim Lemon  wrote:
>
> Hi Ana,
> Is this what you want?
>
> a<-read.table(text="GENErs   BETA
> 1  ENSG0154803 rs2605134  0.0360182
> 2  ENSG0154803 rs7405677  0.0525463
> 3  ENSG0154803 rs7211573  0.0525531
> 4  ENSG0154803 rs2746026  0.0466392
> 5  ENSG0141030 rs2605134  0.0806140
> 6  ENSG0141030 rs7405677  0.0251654
> 7  ENSG0141030 rs7211573  0.0252775
> 8  ENSG0141030 rs2746026  0.0976396
> 9  ENSG0205309 rs2605134  0.0838975
> 10 ENSG0205309 rs7405677 -0.2148500
> 11 ENSG0205309 rs7211573 -0.2148170
> 12 ENSG0205309 rs2746026  0.1013920
> 13 ENSG0215030 rs2605134  0.1261050
> 14 ENSG0215030 rs7405677  0.0165236
> 15 ENSG0215030 rs7211573  0.0163509
> 16 ENSG0215030 rs2746026  0.1201180
> 17 ENSG0141026 rs2605134  0.0485897
> 18 ENSG0141026 rs7405677 -0.0929964
> 19 ENSG0141026 rs7211573 -0.0930321
> 20 ENSG0141026 rs2746026  0.0623033",
> header=TRUE,stringsAsFactors=FALSE)
> b<-read.table(text="rs   GWAS
> 1  rs2605134  0.0315177
> 2  rs7405677 -0.0816389
> 3  rs7211573 -0.0797796
> 4  rs2746026  0.0199350
> 5 rs11658521  0.0728377
> 6  rs9914107  0.0720096
> 7 rs56964223  0.0723903",
> header=TRUE,stringsAsFactors=FALSE)
> ab<-merge(a,b,by="rs")
> library(prettyR)
> abc<-stretch_df(ab,idvar="rs",to.stretch=c("GENE","BETA"))
>
> Jiim
>
> On Mon, Dec 9, 2019 at 11:10 AM Ana Marija  
> wrote:
> >
> > Hello,
> >
> > I have two data frames:
> >
> > head(a)
> >   GENErs   BETA
> > 1  ENSG0154803 rs2605134  0.0360182
> > 2  ENSG0154803 rs7405677  0.0525463
> > 3  ENSG0154803 rs7211573  0.0525531
> > 4  ENSG0154803 rs2746026  0.0466392
> > 5  ENSG0141030 rs2605134  0.0806140
> > 6  ENSG0141030 rs7405677  0.0251654
> > 7  ENSG0141030 rs7211573  0.0252775
> > 8  ENSG0141030 rs2746026  0.0976396
> > 9  ENSG0205309 rs2605134  0.0838975
> > 10 ENSG0205309 rs7405677 -0.2148500
> > 11 ENSG0205309 rs7211573 -0.2148170
> > 12 ENSG0205309 rs2746026  0.1013920
> > 13 ENSG0215030 rs2605134  0.1261050
> > 14 ENSG0215030 rs7405677  0.0165236
> > 15 ENSG0215030 rs7211573  0.0163509
> > 16 ENSG0215030 rs2746026  0.1201180
> > 17 ENSG0141026 rs2605134  0.0485897
> > 18 ENSG0141026 rs7405677 -0.0929964
> > 19 ENSG0141026 rs7211573 -0.0930321
> > 20 ENSG0141026 rs2746026  0.0623033
> >
> > head(b)
> >   rs   GWAS
> > 1  rs2605134  0.0315177
> > 2  rs7405677 -0.0816389
> > 3  rs7211573 -0.0797796
> > 4  rs2746026  0.0199350
> > 5 rs11658521  0.0728377
> > 6  rs9914107  0.0720096
> > 7 rs56964223  0.0723903
> >
> > Data frame a has:
> > > length(unique(a$GENE))
> > [1] 51
> > > dim(a)
> > [1] 287   3
> >
> > and the whole data frame b is shown
> >
> > I would like to create a txt file which would have rs match for each
> > ENSG from data frame b. If a particular ENSG does not have matching rs
> > from data frame b the value under it would be zero. So the txt file
> > would have 7 rows (for all those unique rs from data frame b) and 53
> > columns (for 51 ENSGs and one for unique rs and one for GWAS)
> >
> > So one row of that txt file would look like this.
> >
> > GENES   ENSG0154803   ENSG0141030  ENSG0205309
> > ENSG0215030ENSG0141026  GWAS
> > rs2605134   0.0360182 0.0806140 0.0838975
> > 0.1261050   0.0485897   0.0315177
> > …
> >
> > Please advise,
> > Ana
> >
> > __
> > 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] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Marc Girondot via R-help
Le 09/12/2019 à 16:45, Bert Gunter a écrit :
> In addition, as John's included output shows, only 1 parameter, the 
> intercept, is fit. As he also said, the sd is estimated from the 
> residual deviance -- it is not a model parameter.
>
> Suggest you spend some time with a glm tutorial/text.

I tried ! But I miss this point. I understand now this point. Thanks a  
lot... big progress for me.

But still I don't understand why AIC calculation uses 2 parameters if 
the SD is estimated from the residual deviance.

 > y=rnorm(100)
 > gnul <- glm(y ~ 1)
 > logLik(gnul)
'log Lik.' -136.4343 (df=2)
 > AIC(gnul)
[1] 276.8687
 > -2*logLik(gnul)+2*2
'log Lik.' 276.8687 (df=2)

This is not intuitive when to count SD as a parameter (in AIC) or not in 
df.resuidual !


>
> Bert
>
> On Mon, Dec 9, 2019 at 7:17 AM Marc Girondot via R-help 
> mailto:r-help@r-project.org>> wrote:
>
> Let do a simple glm:
>
>  > y=rnorm(100)
>  > gnul <- glm(y ~ 1)
>  > gnul$coefficients
> (Intercept)
>    0.1399966
>
> The logLik shows the fit of two parameters (DF=2) (intercept) and sd
>
>  > logLik(gnul)
> 'log Lik.' -138.7902 (df=2)
>
> But where is the sd term in the glm object?
>
> If I do the same with optim, I can have its value
>
>  > dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"],
> sd=x["sd"], log = TRUE))}
>  > parg <- c(mean=0, sd=1)
>  > o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
>  > o0$value/1E9
> [1] 138.7902
>  > o0$par
>   mean    sd
>
> 0.1399966 0.9694405
>
> But I would like have the value in the glm.
>
> (and in the meantime, I don't understand why gnul$df.residual
> returned
> 99... for me it should be 98=100 - number of observations) -1 (for
> mean)
> - 1 (for sd); but it is statistical question... I have asked it in
> crossvalidated [no answer still] !)
>
> Thanks
>
> Marc
>
> __
> 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.


Re: [R] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Bert Gunter
In addition, as John's included output shows, only 1 parameter, the
intercept, is fit. As he also said, the sd is estimated from the residual
deviance -- it is not a model parameter.

Suggest you spend some time with a glm tutorial/text.

Bert

On Mon, Dec 9, 2019 at 7:17 AM Marc Girondot via R-help <
r-help@r-project.org> wrote:

> Let do a simple glm:
>
>  > y=rnorm(100)
>  > gnul <- glm(y ~ 1)
>  > gnul$coefficients
> (Intercept)
>0.1399966
>
> The logLik shows the fit of two parameters (DF=2) (intercept) and sd
>
>  > logLik(gnul)
> 'log Lik.' -138.7902 (df=2)
>
> But where is the sd term in the glm object?
>
> If I do the same with optim, I can have its value
>
>  > dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"],
> sd=x["sd"], log = TRUE))}
>  > parg <- c(mean=0, sd=1)
>  > o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
>  > o0$value/1E9
> [1] 138.7902
>  > o0$par
>   meansd
>
> 0.1399966 0.9694405
>
> But I would like have the value in the glm.
>
> (and in the meantime, I don't understand why gnul$df.residual returned
> 99... for me it should be 98=100 - number of observations) -1 (for mean)
> - 1 (for sd); but it is statistical question... I have asked it in
> crossvalidated [no answer still] !)
>
> Thanks
>
> Marc
>
> __
> 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.


Re: [R] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Eric Berger
summary(gnul)

shows the std error of the coefficient estimate

On Mon, Dec 9, 2019 at 5:16 PM Marc Girondot via R-help
 wrote:
>
> Let do a simple glm:
>
>  > y=rnorm(100)
>  > gnul <- glm(y ~ 1)
>  > gnul$coefficients
> (Intercept)
>0.1399966
>
> The logLik shows the fit of two parameters (DF=2) (intercept) and sd
>
>  > logLik(gnul)
> 'log Lik.' -138.7902 (df=2)
>
> But where is the sd term in the glm object?
>
> If I do the same with optim, I can have its value
>
>  > dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"],
> sd=x["sd"], log = TRUE))}
>  > parg <- c(mean=0, sd=1)
>  > o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
>  > o0$value/1E9
> [1] 138.7902
>  > o0$par
>   meansd
>
> 0.1399966 0.9694405
>
> But I would like have the value in the glm.
>
> (and in the meantime, I don't understand why gnul$df.residual returned
> 99... for me it should be 98=100 - number of observations) -1 (for mean)
> - 1 (for sd); but it is statistical question... I have asked it in
> crossvalidated [no answer still] !)
>
> Thanks
>
> Marc
>
> __
> 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] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Fox, John
Dear Marc,

For your simple model, the standard deviation of y is the square-root of the 
estimated dispersion parameter:

> set.seed(123)
> y <- rnorm(100)
> gnul <- glm(y ~ 1)
> summary(gnul)

Call:
glm(formula = y ~ 1)

Deviance Residuals: 
 Min1QMedian3Q   Max  
-2.39957  -0.58426  -0.02865   0.60141   2.09693  

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.090410.091280.990.324

(Dispersion parameter for gaussian family taken to be 0.8332328)

Null deviance: 82.49  on 99  degrees of freedom
Residual deviance: 82.49  on 99  degrees of freedom
AIC: 268.54

Number of Fisher Scoring iterations: 2

> sqrt(0.8332328)
[1] 0.9128159
> mean(y)
[1] 0.09040591
> sd(y)
[1] 0.9128159

I hope this helps,
 John

  -
  John Fox, Professor Emeritus
  McMaster University
  Hamilton, Ontario, Canada
  Web: http::/socserv.mcmaster.ca/jfox

> On Dec 9, 2019, at 10:16 AM, Marc Girondot via R-help  
> wrote:
> 
> Let do a simple glm:
> 
> > y=rnorm(100)
> > gnul <- glm(y ~ 1)
> > gnul$coefficients
> (Intercept)
>   0.1399966
> 
> The logLik shows the fit of two parameters (DF=2) (intercept) and sd
> 
> > logLik(gnul)
> 'log Lik.' -138.7902 (df=2)
> 
> But where is the sd term in the glm object?
> 
> If I do the same with optim, I can have its value
> 
> > dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"], 
> > sd=x["sd"], log = TRUE))}
> > parg <- c(mean=0, sd=1)
> > o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
> > o0$value/1E9
> [1] 138.7902
> > o0$par
>  meansd
> 
> 0.1399966 0.9694405
> 
> But I would like have the value in the glm.
> 
> (and in the meantime, I don't understand why gnul$df.residual returned 99... 
> for me it should be 98=100 - number of observations) -1 (for mean) - 1 (for 
> sd); but it is statistical question... I have asked it in crossvalidated [no 
> answer still] !)
> 
> Thanks
> 
> Marc
> 
> __
> 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] A better scales::dollar() ?

2019-12-09 Thread Hadley Wickham
You can get pretty close with label_number_si():

pounds <- scales::label_number_si(prefix = "£")
pounds(10 ^ (0:7))
#> [1] "£1""£10"   "£100"  "£1K"   "£10K"  "£100K" "£1M"   "£10M"

Created on 2019-12-09 by the [reprex
package](https://reprex.tidyverse.org) (v0.3.0.9001)

Hadley

On Fri, Dec 6, 2019 at 5:51 AM POLWART, Calum (COUNTY DURHAM AND
DARLINGTON NHS FOUNDATION TRUST) via R-help 
wrote:
>
> I'm writing a quite large document in Rmarkdown which has financial data in 
> it.  I format that data using scales::dollar() currently something like this:
>
> >
> > require (scales)
> > x = 10
> > cat (dollar (x, prefix ="£", big.mark=","))
>
> £100,000
>
> But actually, I'd quite like to get £100k out in that instance so I'd do:
>
> > cat (dollar (x/10^3, prefix ="£", suffix="k" ))
>
> £100k
>
> But x could be 100 or 10,000,000.  I want some form of 'automatic' version 
> that might give me something like:
>
> >
> > require (scales)
> > y = 0:7
> > x = 1^y
> > dollar(x, prefix="£")
> [1] "£1"  "£10" "£100""£1,000"  "£10,000" 
> "£100,000""£1,000,000"  "£10,000,000"
>
> But what I want is more like:
>
> £1.00  £10.00  £100  £1k  £10k  £100k  £1m  £10m
>
> I'm sure I can write something as a little function, but before I do - is 
> there something already out there?
>
> I have a similar need to format milligrams through to kilograms.
>
>
> 
>
> This message may contain confidential information. If ...{{dropped:27}}

__
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] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Marc Girondot via R-help

Let do a simple glm:

> y=rnorm(100)
> gnul <- glm(y ~ 1)
> gnul$coefficients
(Intercept)
  0.1399966

The logLik shows the fit of two parameters (DF=2) (intercept) and sd

> logLik(gnul)
'log Lik.' -138.7902 (df=2)

But where is the sd term in the glm object?

If I do the same with optim, I can have its value

> dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"], 
sd=x["sd"], log = TRUE))}

> parg <- c(mean=0, sd=1)
> o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
> o0$value/1E9
[1] 138.7902
> o0$par
 mean    sd

0.1399966 0.9694405

But I would like have the value in the glm.

(and in the meantime, I don't understand why gnul$df.residual returned 
99... for me it should be 98=100 - number of observations) -1 (for mean) 
- 1 (for sd); but it is statistical question... I have asked it in 
crossvalidated [no answer still] !)


Thanks

Marc

__
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] Having problems with the ifelse and negative numbers

2019-12-09 Thread Eric Berger
Hi Bob,
You wrote "the following error message" -
when in fact it is a Warning and not an error message. I think your
code does what you hoped it would do, in the sense it successfully
calculates the sqrt(abs(negativeNumber)), where appropriate.

If you want to run the code without seeing this warning message you can run

ifelse( A < 0, suppressWarnings(sqrt(-A)), A )

and you should be fine.

HTH,
Eric

On Mon, Dec 9, 2019 at 3:18 PM Kevin Thorpe  wrote:
>
> The sqrt(-A) is evaluated for all A. The result returned is conditional on 
> the first argument but the other two arguments are evaluated on the entire 
> vector.
>
> Kevin
>
> --
> Kevin E. Thorpe
> Head of Biostatistics,  Applied Health Research Centre (AHRC)
> Li Ka Shing Knowledge Institute of St. Michael's
> Assistant Professor, Dalla Lana School of Public Health
> University of Toronto
> email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
>
>
> On 2019-12-09, 7:58 AM, "R-help on behalf of rsherry8" 
>  wrote:
>
> Please consider the following two R statements:
>  A =  runif(20, min=-1,max=1)
>  ifelse( A < 0, sqrt(-A), A )
>
> The second statement produces the following error message:
>  rt(-A) : NaNs produced
>
> I understand that you cannot take the square root of a negative number
> but I thought the condition A < 0
> would take care of that issue. It appears not to be.
>
> What am I missing?
>
> Thanks,
> Bob
>
> __
> 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-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] Having problems with the ifelse and negative numbers

2019-12-09 Thread Kevin Thorpe
The sqrt(-A) is evaluated for all A. The result returned is conditional on the 
first argument but the other two arguments are evaluated on the entire vector.

Kevin

-- 
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
 

On 2019-12-09, 7:58 AM, "R-help on behalf of rsherry8" 
 wrote:

Please consider the following two R statements:
 A =  runif(20, min=-1,max=1)
 ifelse( A < 0, sqrt(-A), A )

The second statement produces the following error message:
 rt(-A) : NaNs produced

I understand that you cannot take the square root of a negative number 
but I thought the condition A < 0
would take care of that issue. It appears not to be.

What am I missing?

Thanks,
Bob

__
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] Having problems with the ifelse and negative numbers

2019-12-09 Thread rsherry8

Please consider the following two R statements:
A =  runif(20, min=-1,max=1)
ifelse( A < 0, sqrt(-A), A )

The second statement produces the following error message:
rt(-A) : NaNs produced

I understand that you cannot take the square root of a negative number 
but I thought the condition A < 0

would take care of that issue. It appears not to be.

What am I missing?

Thanks,
Bob

__
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] [R-pkgs] concurve v 2.3.0 - Comparing Functions, Bootstrapping, and Exporting Tables

2019-12-09 Thread Zad Chow
Pleased to announce that the next version (2.3.0) of our package “concurve”
is out on CRAN (https://cran.r-project.org/package=concurve).

In addition to plotting confidence (consonance) curves, it can now plot two
functions next to one another to see the amount of overlap. It can also
plot likelihood and deviance functions along with consonance densities and
distributions.

And it can utilize bootstrapping (the BCa and t method) to approximate the
curves, distributions, and densities. And to top it off, it can export
tables of relevant statistics in various formats.

We welcome any feedback and bug reports (
https://github.com/zadchow/concurve/issues)

Best,

Zad R. Chow
Andrew D. Vigotsky

[[alternative HTML version deleted]]

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

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