Re: [R] bootstrap confidence intervals

2021-11-05 Thread David Winsemius



On 11/5/21 1:16 PM, varin sacha via R-help wrote:

Dear R-experts,

Here is a toy example. How can I get the bootstrap confidence intervals working 
?

Many thanks for your help


library(DescTools)
library(boot)
  
A=c(488,437,500,449,364)

dat<-data.frame(A)
med<-function(d,i) {
temp<-d[i,]

# shouldn't this be

HodgesLehmann(temp)  # ???

# makes no sense to extract a bootstrap sample and then return a value 
calculated on the full dataset


HodgesLehmann(A)
}
boot.out<-boot(data=dat,statistic=med,R=100)


I would have imagined that one could simply extract the quantiles of the 
HodgesLehmann at the appropriate tail probabilities:



quantile(boot.out$t, c(0.025, 0.975))
    2.5%    97.5%
400.5000 488.0001


It doesn't seem reasonable to have bootstrap CI's that are much tighter 
than the estimates on the original data:



> HodgesLehmann(boot.out$t, conf.level=0.95)
   est lwr.ci upr.ci
449.75 444.25 453.25    # seems to be cheating
> HodgesLehmann(dat$A, conf.level=0.95)
   est lwr.ci upr.ci
   449    364    500    # Much closer to the quantiles above


--

David.


HodgesLehmann(boot.out$t)

boot.ci(boot.out,type="all")


__
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] Error in loadNamespace(i, c(lib.loc, .libPaths())

2021-11-05 Thread Jeff Newmiller
You are using github packages. Post your question on the corresponding packege 
Issues page on GitHub. Such questions are not related to the topic of the R 
language (read the Posting Guide, which also indicates that this plain text 
mailing list will strip formatting from your emails, so do send plain text in 
the future).

On November 5, 2021 3:07:56 PM PDT, Bogdan Tanasa  wrote:
>Dear all,
>
> i am using Monocle3 in order to study disease development by single-cell
>technologies :
>
>https://cole-trapnell-lab.github.io/monocle3/
>
>When I am installing additional packages like "spData" from
>
>https://nowosad.github.io/spData/, I am getting the message :
>
>Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
>  here is no package called ‘spData’
>
>How shall I correct it ?
>
>The installation is in a R/4.0.3 that runs on a SLURM cluster by the system
>administrator.
>
>Occasionally, additional packages in R are installed in my home folder :
>/home/tanasa/
>
>Thank you !
>
>   [[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] extracting a R object from an R image

2021-11-05 Thread Jeff Newmiller
IMO you are being a bit too literal. It is absolutely possible to load the file 
into a dedicated environment and use the $ or [[]] extraction operator to 
access a specific object in that environment.

?load
?new.env

Or, you can attach the file, copy to a new variable, and detach. (see examples 
in ?load)


On November 5, 2021 3:26:49 PM PDT, Bert Gunter  wrote:
>You can't. You can only save and load whole .RData files. You can, of
>course, save and load separate R objects in separate files. But note
>in ?save.image:
>
>"For saving single R objects, saveRDS() is mostly preferable to
>save(), notably because of the functional nature of readRDS(), as
>opposed to load(). "
>
>You may wish to search on "data serialization" (e.g. on Wikipedia) or
>similar to better understand the underlying ideas.
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Fri, Nov 5, 2021 at 3:01 PM Bogdan Tanasa  wrote:
>>
>> Dear all,
>>
>> I saved my work in a Rimage that contains multiple objects ;
>>
>> the objects were generated with Monocle3 :
>>
>> https://cole-trapnell-lab.github.io/monocle3/docs/starting/
>>
>> one object is called CDS.
>>
>> How shall I extract this object CDS (that has a complex structure) from the
>> R image ?
>>
>> thank you,
>>
>> Bogdan
>>
>> [[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] extracting a R object from an R image

2021-11-05 Thread Bert Gunter
You can't. You can only save and load whole .RData files. You can, of
course, save and load separate R objects in separate files. But note
in ?save.image:

"For saving single R objects, saveRDS() is mostly preferable to
save(), notably because of the functional nature of readRDS(), as
opposed to load(). "

You may wish to search on "data serialization" (e.g. on Wikipedia) or
similar to better understand the underlying ideas.

Bert Gunter

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

Bert Gunter

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


On Fri, Nov 5, 2021 at 3:01 PM Bogdan Tanasa  wrote:
>
> Dear all,
>
> I saved my work in a Rimage that contains multiple objects ;
>
> the objects were generated with Monocle3 :
>
> https://cole-trapnell-lab.github.io/monocle3/docs/starting/
>
> one object is called CDS.
>
> How shall I extract this object CDS (that has a complex structure) from the
> R image ?
>
> thank you,
>
> Bogdan
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Error in loadNamespace(i, c(lib.loc, .libPaths())

2021-11-05 Thread Bogdan Tanasa
Dear all,

 i am using Monocle3 in order to study disease development by single-cell
technologies :

https://cole-trapnell-lab.github.io/monocle3/

When I am installing additional packages like "spData" from

https://nowosad.github.io/spData/, I am getting the message :

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
  here is no package called ‘spData’

How shall I correct it ?

The installation is in a R/4.0.3 that runs on a SLURM cluster by the system
administrator.

Occasionally, additional packages in R are installed in my home folder :
/home/tanasa/

Thank you !

[[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] extracting a R object from an R image

2021-11-05 Thread Bogdan Tanasa
Dear all,

I saved my work in a Rimage that contains multiple objects ;

the objects were generated with Monocle3 :

https://cole-trapnell-lab.github.io/monocle3/docs/starting/

one object is called CDS.

How shall I extract this object CDS (that has a complex structure) from the
R image ?

thank you,

Bogdan

[[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] bootstrap confidence intervals

2021-11-05 Thread varin sacha via R-help
Dear R-experts,

Here is a toy example. How can I get the bootstrap confidence intervals working 
?

Many thanks for your help


library(DescTools)
library(boot)
 
A=c(488,437,500,449,364)
dat<-data.frame(A)
med<-function(d,i) { 
temp<-d[i,]
HodgesLehmann(A)
}
boot.out<-boot(data=dat,statistic=med,R=100)
HodgesLehmann(boot.out$t)

boot.ci(boot.out,type="all")


__
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] Which version of R install for mac

2021-11-05 Thread Marc Schwartz via R-help

Hi,

Not sure where you have been looking, but on CRAN:

https://cran.r-project.org/index.html

there is a box at the top of the main page to Download R for macOS, 
which brings you to:


https://cran.r-project.org/bin/macosx/

The first version there, 4.1.2, which is the pkg binary for macOS 10.13 
and higher for Intel CPUs is the one that you want.


Note that there is also a macOS specific FAQ here:

https://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and finally, a macOS specific help list here:

https://stat.ethz.ch/mailman/listinfo/r-sig-mac

You will also likely want to install XQuartz, which is available here:

https://www.xquartz.org

Regards,

Marc Schwartz


Mark Don Young wrote on 11/5/21 10:59 AM:

I am having trouble finding a version of R install compatible with my mac.
I have an older Macbook pro 2016 with the latest version of Big Slur 11.6.
Intel core i5 2.9 Ghz-Dual-Core.
Is there a version of R compatible with my computer?
Thanks
Mark


__
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] Which version of R install for mac

2021-11-05 Thread Mark Don Young
I am having trouble finding a version of R install compatible with my mac.
I have an older Macbook pro 2016 with the latest version of Big Slur 11.6.
Intel core i5 2.9 Ghz-Dual-Core.
Is there a version of R compatible with my computer?
Thanks
Mark

[[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] Date

2021-11-05 Thread Val
Thank you All.
The issue was not reading different file. I just mistyped the column
name, instead of typing My_date I typed mydate in the email.  The
problem is solved by using this
dat=read.csv("myfile.csv",stringsAsFactors=FALS)
suggested by Jim.

On Thu, Nov 4, 2021 at 7:58 PM Jeff Newmiller  wrote:
>
> Then you are looking at a different file... check your filenames. You have 
> imported the column as character, and R has not yet recognized that it is 
> supposed to be a date, so it can only show what it found.
>
> You will almost certainly find your error if you make a reproducible example.
>
> On November 4, 2021 5:30:22 PM PDT, Val  wrote:
> >Jeff,
> >
> >The date from y data file looks like as follow in the Linux environment,
> >My_date
> >2019-09-16
> >2021-02-21
> >2021-02-22
> >2017-10-11
> >2017-10-10
> >2018-11-11
> >2017-10-27
> >2017-10-30
> >2019-05-20
> >
> >On Thu, Nov 4, 2021 at 5:00 PM Jeff Newmiller  
> >wrote:
> >>
> >> You are claiming behavior that is not something R does, but is something 
> >> Excel does constantly.
> >>
> >> Compare what your data file looks like using a text editor with what R has 
> >> imported. Absolutely do not use a spreadsheet program to do this.
> >>
> >> On November 4, 2021 2:43:25 PM PDT, Val  wrote:
> >> >IHi All, l,
> >> >
> >> >I am  reading a csv file  and one of the columns is named as  "mydate"
> >> > with this form, 2019-09-16.
> >> >
> >> >I am reading this file as
> >> >
> >> >dat=read.csv("myfile.csv")
> >> > the structure of the data looks like as follow
> >> >
> >> >str(dat)
> >> >mydate : chr  "09/16/2019" "02/21/2021" "02/22/2021" "10/11/2017" ...
> >> >
> >> >Please note the format  has  changed from -mm-dd  to mm/dd/
> >> >When I tried to change this   as a Date using
> >> >
> >> >as.Date(as.Date(mydate, format="%m/%d/%Y" )
> >> >I am getting this error message
> >> >Error in charToDate(x) :
> >> >  characte string is not in a standard unambiguous format
> >> >
> >> >My question is,
> >> >1. how can I read the file as it is (i.e., without changing the date 
> >> >format) ?
> >> >2. why does R change the date format?
> >> >
> >> >Thank you,
> >> >
> >> >__
> >> >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.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
>
> --
> Sent from my phone. Please excuse my brevity.

__
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] How to select single table with ODB package

2021-11-05 Thread Luigi Marongiu
Hello,
I am connecting R to a libreoffice-generated database (.odb) using the
ODB package.
I would like to link a dataframe to a specific table, but I cannot
manage to extract a given table:
```
> db =  odb.open(".../LOdatabase.odb", jarFile = NULL)
> odb.tables(db)
$demographic
field.name field.type data.type name  comment
1  IDINTEGER   numeric   ID Unique identifier (auto)
2Study_IDINTEGER   numeric Study_IDlink to STUDY
[...]
> sqlQuery = "FROM TABLE demographic SELECT ALL"
> odb.read(db, sqlQuery, stringsAsFactors = FALSE, check.names = FALSE,
+ encode = TRUE, autoLogical = TRUE)
Error: Error while executing SQL query  : "Unable to retrieve JDBC result set
  JDBC ERROR: Unexpected token: FROM in statement [FROM]
  Statement: FROM TABLE demographic SELECT ALL"
> sqlQuery = "SELECT * FROM demographic"
> odb.read(db, sqlQuery, stringsAsFactors = FALSE, check.names = FALSE,
+ encode = TRUE, autoLogical = TRUE)
Error: Error while executing SQL query  : "Unable to retrieve JDBC result set
  JDBC ERROR: Table not found in statement [SELECT * FROM demographic]
  Statement: SELECT * FROM demographic"
> sqlQuery = "SELECT * FROM db$demographic"
> odb.read(db, sqlQuery, stringsAsFactors = FALSE, check.names = FALSE,
+ encode = TRUE, autoLogical = TRUE)
Error: Error while executing SQL query  : "Unable to retrieve JDBC result set
  JDBC ERROR: Table not found in statement [SELECT * FROM db$demographic]
  Statement: SELECT * FROM db$demographic"
```
What is the correct syntax?
Thank you

__
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] heatmap ploting

2021-11-05 Thread Jim Lemon
Hi Steve,
That plot looks to me as though a value-to-color transformation is
performed on the logarithm of gene expression. The scale bar can be
roughly reproduced like this:

library(plotrix)
plot(0,xlim=c(0,3))
gradient.rect(0,-0.1,3,0.1,
 col=color.scale(seq(0,3,0.1),
 c(0.7,1,1,1,0.7,0.2),
 c(0.7,1,0,0,0,0),
 c(1,0,0,0.1,0.7,0.2)))
text(0:3,rep(0.2,3),c(0,10,100,1000))

The horizontal lengths of the stacked bars of the plot can then be
adjusted to the number of subjects in a given bin of log gene
expressions. A tricky plot, but it can be done in R.

Jim

On Fri, Nov 5, 2021 at 6:08 PM Stephen HonKit Wong  wrote:
>
> Dear Community,
>
> I have an example heatmap plot in this link
> 
> which was generated by java I believe, I want to make a similar plot in R.
> Any clues on how to do it? Thanks.
>
> The column is a gene, and the rows are different cancer types with
> different numbers of patients. The heatmap value represents the expression
> value, such as FPKM, which can range from 0 to over several hundreds.
>
>
> Much thanks!
>
> Steve
>
> [[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] Please help me debugg

2021-11-05 Thread Ivan Krylov
On Fri, 5 Nov 2021 12:29:21 +0530
Shrinivas Dharma  wrote:

> I am trying to run the following double loop which  I have written
> but it is not running.

Thanks for providing the code, but it's much easier to help you if you
provide the data, too. Use dput(head(...)) to make it easy for us to
copy-paste the data.

> Unable to get my head around the mistake. Please try to spot the bug
> and help

> > for(i in 1:122){  
> + for(j in 1:68){
> + if(V(FriendGraph)$name[i]==names[j]){
> + gender_vector[i]<-sex[j]
> + break;}
> + else{gender_vector[i]<-NA}
> + } }

> Error in `[.data.frame`(sex, j) : undefined columns selected

sex[j] extracts the `j`th column out of the `sex` data frame. Does
`sex` contain 68 columns? If you want the `j`th row, use sex[j,].

Also, it may help to use merge() and have the R language do some of the
work for you, if you organise your `names` and `sex` into a single
data.frame to merge V(FriendGraph) with.

Additionally, you might save some of the execution time if you move the
V(FriendGraph) calculation out of the loop.

>   [[alternative HTML version deleted]]

P.S. Your post came across mostly fine, but please compose your mail in
plain text, not HTML. We only see the plain text version, and in many
cases, the mailers horribly mangle the post when they automatically
generate it from the HTML message.

-- 
Best regards,
Ivan

__
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] Please help me debugg

2021-11-05 Thread Shrinivas Dharma
I am trying to run the following double loop which  I have written but it
is not running.
Unable to get my head around the mistake. Please try to spot the bug and
help

> for(i in 1:122){
+ for(j in 1:68){
+ if(V(FriendGraph)$name[i]==names[j]){
+ gender_vector[i]<-sex[j]
+ break;}
+ else{gender_vector[i]<-NA}
+ } }

*Error in `[.data.frame`(sex, j) : undefined columns selectedCalled from:
`[.data.frame`(sex, j)*
Browse[1]>

-- 
Warm Regards,
*Shrinivas Dharmadhikari*

Metric Consultancy Ltd.
91, Florida Estate,
Keshavanagar, Mundhwa
Pune-411036.

M: +91 98 230 09850
E : dha...@metricuk.com
www.metricglobal.com

*P* Please consider the environment and do not print this email unless
absolutely necessary.

[[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] heatmap ploting

2021-11-05 Thread Stephen HonKit Wong
Dear Community,

I have an example heatmap plot in this link

which was generated by java I believe, I want to make a similar plot in R.
Any clues on how to do it? Thanks.

The column is a gene, and the rows are different cancer types with
different numbers of patients. The heatmap value represents the expression
value, such as FPKM, which can range from 0 to over several hundreds.


Much thanks!

Steve

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