Re: [R] igraph_vertex

2024-02-24 Thread David Winsemius



On 2/24/24 12:10, Kimmo Elo wrote:

Hi,

first of all, your example was not reproducible! But once I added
"library(igraph)" and "library(scico)" plus generally replaced
"aes_collapsed" by "edge_list", I started to work :-)



After copying your lead in that replacement the error I got was:


network <- graph_from_data_frame(edge_list, directed= FALSE, + vertices 
= details) #Error: object 'details' not found Same conclusion, though. 
Incomplete presentation of code. -- David.




Anyway, the error is produced by this line:

+ edge.width= network,

It seems to me that you have forgotten to name a variable here (you now
use the whole network object as variable, which most probably won't
work).

Just as a kind advice for the future: if you encounter errors like
this, it is always a good idea to debug the problematic code by
commenting it out line by line. So you will - most probably - find our
those sections resulting in errors.

HTH,

Kimmo

la, 2024-02-24 kello 12:09 +0100, SIBYLLE STÖCKLI via R-help kirjoitti:

Dear R-community

  


It would be nice to get some input how to find a solution for the
following
error in igraph and vertex setting.

  


Thank you very much

Sibylle

  


par(bg="black")
network %>% plot(

+ vertex.color=clrs[V(.)$community],

+ vertex.size=V(.)$hub_score*1,

+ vertex.frame.color=V(.)$color,

+ vertex.label.color="white",

+ vertex.label.cex=0.5,

+ vertex.label.family="Helvetica",

+ vertex.label.font=1,

+ edge.curved=0.5,

+ edge.width= network,

+ layout=layout_with_mds(.))

Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) :

   Index gr��er als maximales 6

  

  


Reproducible example:

  


edge_list<-read.csv("edges_table_Test.csv")

  


#create network and add some necessary attributes (vertices) for the
plot

network <- graph_from_data_frame(aes_collapsed, directed= FALSE,

  vertices = details)

  

  


temp<-cluster_optimal(network)

temp<-cbind(membership=temp$membership, Names=temp$name)

aes_collapsed <- aes_collapsed %>%

   merge(temp, by="Names")

  

  


network <- network %>%

   set_edge_attr(name = "type", value = factor(aes_collapsed$Names,

  ordered =
is.ordered(V(network)$name))) %>%

   set_edge_attr(name = "membership", value =
aes_collapsed$membership) %>%

   set_edge_attr(name = "color",

   value = c(viridis::viridis(5))

   [match(E(.)$type, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name = "trans_v_net", value = c(transitivity(.,
type =
"local"))) %>%

   set_vertex_attr(name = "hub_score", value = c(hub_score(.)$vector))
%>%

   set_vertex_attr(name = "color",

   value = c(viridis::viridis((5)))

   [match(V(.)$name, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name= "community",
value=cluster_optimal(.)$membership)

  


clrs<-scico(3, palette = "batlow")

  


par(bg="black")

network %>% plot(

  vertex.color=clrs[V(.)$community],

  vertex.size=V(.)$hub_score*5,

  vertex.frame.color=V(.)$color,

  vertex.label.color="white",

  vertex.label.cex=0.5,

  vertex.label.family="Helvetica",

  vertex.label.font=1,

  edge.curved=0.5,

  edge.width= network,

  layout=layout_with_mds(.))

  

  


edges_table_Test.csv

  



Names

target

weight


B.B

A.A

4


C.C

A.A

5


D.D

A.A

5


E.E

A.A

5


F.F

A.A

1


C.C

B.B

5


E.E

B.B

1


F.F

B.B

2


A.A

C.C

5


B.B

C.C

1


D.D

C.C

5


E.E

C.C

5


F.F

C.C

3


A.A

D.D

5


B.B

D.D

1


C.C

D.D

5


E.E

D.D

5


F.F

D.D

4


A.A

E.E

5


B.B

E.E

1


C.C

E.E

4


D.D

E.E

5


F.F

E.E

5


A.A

F.F

5


B.B

F.F

1


C.C

F.F

2


D.D

F.F

3


E.E

F.F

4


F.F

F.F

5

  



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

2024-02-24 Thread David Winsemius
The reason html is specifically advised against as a format is that it 
does things like mangling data such as is happening in your example. You 
should repost using settings on you mail client for plain-text. Your 
code should start by loading necessary packages. You should also not 
post screen output versions of code since that will insert lots of 
superfluous "+"'s. Some but not all API will be able to strip those 
characters.



--

David.

On 2/24/24 03:09, SIBYLLE STÖCKLI via R-help wrote:

Dear R-community

  


It would be nice to get some input how to find a solution for the following
error in igraph and vertex setting.

  


Thank you very much

Sibylle


par(bg="black")
network %>% plot(

+ vertex.color=clrs[V(.)$community],

+ vertex.size=V(.)$hub_score*1,

+ vertex.frame.color=V(.)$color,

+ vertex.label.color="white",

+ vertex.label.cex=0.5,

+ vertex.label.family="Helvetica",

+ vertex.label.font=1,

+ edge.curved=0.5,

+ edge.width= network,

+ layout=layout_with_mds(.))

Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) :

   Index gr��er als maximales 6

  

  


Reproducible example:

  


edge_list<-read.csv("edges_table_Test.csv")

  


#create network and add some necessary attributes (vertices) for the plot

network <- graph_from_data_frame(aes_collapsed, directed= FALSE,

  vertices = details)

  

  


temp<-cluster_optimal(network)

temp<-cbind(membership=temp$membership, Names=temp$name)

aes_collapsed <- aes_collapsed %>%

   merge(temp, by="Names")

  

  


network <- network %>%

   set_edge_attr(name = "type", value = factor(aes_collapsed$Names,

  ordered =
is.ordered(V(network)$name))) %>%

   set_edge_attr(name = "membership", value = aes_collapsed$membership) %>%

   set_edge_attr(name = "color",

   value = c(viridis::viridis(5))

   [match(E(.)$type, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name = "trans_v_net", value = c(transitivity(., type =
"local"))) %>%

   set_vertex_attr(name = "hub_score", value = c(hub_score(.)$vector)) %>%

   set_vertex_attr(name = "color",

   value = c(viridis::viridis((5)))

   [match(V(.)$name, c(factor(V(.)$name)))]) %>%

   set_vertex_attr(name= "community", value=cluster_optimal(.)$membership)

  


clrs<-scico(3, palette = "batlow")

  


par(bg="black")

network %>% plot(

  vertex.color=clrs[V(.)$community],

  vertex.size=V(.)$hub_score*5,

  vertex.frame.color=V(.)$color,

  vertex.label.color="white",

  vertex.label.cex=0.5,

  vertex.label.family="Helvetica",

  vertex.label.font=1,

  edge.curved=0.5,

  edge.width= network,

  layout=layout_with_mds(.))

  

  


edges_table_Test.csv

  



Names

target

weight


B.B

A.A

4


C.C

A.A

5


D.D

A.A

5


E.E

A.A

5


F.F

A.A

1


C.C

B.B

5


E.E

B.B

1


F.F

B.B

2


A.A

C.C

5


B.B

C.C

1


D.D

C.C

5


E.E

C.C

5


F.F

C.C

3


A.A

D.D

5


B.B

D.D

1


C.C

D.D

5


E.E

D.D

5


F.F

D.D

4


A.A

E.E

5


B.B

E.E

1


C.C

E.E

4


D.D

E.E

5


F.F

E.E

5


A.A

F.F

5


B.B

F.F

1


C.C

F.F

2


D.D

F.F

3


E.E

F.F

4


F.F

F.F

5

  



[[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] Rtools and things dependent on it

2024-02-23 Thread David Winsemius


Sent from my iPhone

> On Feb 23, 2024, at 18:19, Sorkin, John  wrote:
> 
> David,
> 
> I greatly appreciate the explanation you gave regarding R tools providing 
> tools available in Linux distros, but not found in Windows. (I am using a 
> windows system). Does this mean that Linux users don't need to use R tools 
> when they want to compile R code. 

Yes. That’s been true for me anyway. On a Mac I need to make sure I have the 
proper C and Fortran compilers and the proper environment variables , which are 
always provided by Saint  Simon Urbanek at the att.research site. 

— 
David. 
> 
> Additionally, thank you for the information about what I should read. I will 
> look at the material again, and hopefully things the material you suggest I 
> read will be more understandable.
> 
> John
> 
> P.S. This email should be in txt format, not html. I sent if from my desktop 
> windows machine which provides more options than does my iPhone.
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine, University of Maryland School of Medicine;
> Associate Director for Biostatistics and Informatics, Baltimore VA Medical 
> Center Geriatrics Research, Education, and Clinical Center;
> PI Biostatistics and Informatics Core, University of Maryland School of 
> Medicine Claude D. Pepper Older Americans Independence Center;
> Senior Statistician University of Maryland Center for Vascular Research;
> 
> Division of Gerontology and Paliative Care,
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> Cell phone 443-418-5382
> 
> 
> 
> 
> 
> From: David Winsemius 
> Sent: Friday, February 23, 2024 8:14 PM
> To: Sorkin, John
> Cc: avi.e.gr...@gmail.com; r-help@r-project.org
> Subject: Re: [R] Rtools and things dependent on it
> 
> 
> On 2/23/24 16:28, Sorkin, John wrote:
> David,
> My apologies regarding the format of my email. I am replying using my iPhone, 
> and I can’t find a way to switch from what I suspect is html to txt format.
> The link you sent told me that R tools allows compilation of code.
> 
> 
> It's specifically designed to provide the code tools missing in Windows that 
> would other wise have been provided by a typical Linux distro. More 
> expansively, it allows compilation of code written in C and/or Fortran using 
> the version that was used to build the matching R version and allows it to be 
> called by the routines written in R that bind a package together.
> 
> This is good to know, but beyond this important fact, the rest of the 
> material was close to unintelligible.
> 
> The phrase "the rest of the material" is not specific enough to offer more 
> explanation. You should quote material that is beyond your understanding. You 
> should only be reading the sections named: "Installing Rtools43" and 
> "Building packages from source using Rtools43". I doubt that material further 
> on would be relevant.
> 
> --
> 
> David
> 
> I doubt this is the fault of the author, it is probably because I lack some 
> basic knowledge. Can you suggest some more basic material I can read. Please 
> note. I am not computer naive, I am simply missing basic knowledge of the 
> material discussed in the web page.
> Thank you,
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to 
> faxing)
> 
> On Feb 23, 2024, at 7:01 PM, David Winsemius 
> <mailto:dwinsem...@comcast.net> wrote:
> 
> 
> On 2/23/24 14:34, avi.e.gr...@gmail.com<mailto:avi.e.gr...@gmail.com> wrote:
> This may be a dumb question and the answer may make me feel dumber.
> 
> I have had trouble for years with R packages wanting Rtools on my machine
> and not being able to use it. Many packages are fine as binaries are
> available. I have loaded Rtools and probably need to change my PATH or
> something.
> 
> 
> I suppose making sure that whatever directory holds your Rtools code is
> on your path would be a good idea. I wondered if there's an environment
> variable that could be set, but reading the page on using Rtools did not
> mention one until I got down to the section on building R from source
> which is surely NOT what you want to do.. You should read the
> information on installation and building packages from source.
> https://cran.r-project.org/bin/windows/base/howto-R-devel.html<https://c

Re: [R] Rtools and things dependent on it

2024-02-23 Thread David Winsemius


On 2/23/24 16:28, Sorkin, John wrote:
> David,
> My apologies regarding the format of my email. I am replying using my 
> iPhone, and I can’t find a way to switch from what I suspect is html 
> to txt format.
> The link you sent told me that R tools allows compilation of code.


It's specifically designed to provide the code tools missing in Windows 
that would other wise have been provided by a typical Linux distro. More 
expansively, it allows compilation of code written in C and/or Fortran 
using the version that was used to build the matching R version and 
allows it to be called by the routines written in R that bind a package 
together.

> This is good to know, but beyond this important fact, the rest of the 
> material was close to unintelligible.

The phrase "the rest of the material" is not specific enough to offer 
more explanation. You should quote material that is beyond your 
understanding. You should only be reading the sections named:"Installing 
Rtools43" and "Building packages from source using Rtools43". I doubt 
that material further on would be relevant.

-- 

David

> I doubt this is the fault of the author, it is probably because I lack 
> some basic knowledge. Can you suggest some more basic material I can 
> read. Please note. I am not computer naive, I am simply missing basic 
> knowledge of the material discussed in the web page.
> Thank you,
> John
>> John David Sorkin M.D., Ph.D.
>> Professor of Medicine
>> Chief, Biostatistics and Informatics
>> University of Maryland School of Medicine Division of Gerontology and 
>> Geriatric Medicine
>> Baltimore VA Medical Center
>> 10 North Greene Street 
>> GRECC  (BT/18/GR)
>> Baltimore, MD 21201-1524 
>> (Phone) 410-605-711 9
>> (Fax)410-605-7913  (Please call phone number above 
>> prior to faxing)
>
>> On Feb 23, 2024, at 7:01 PM, David Winsemius  
>> wrote:
>>
>> 
>> On 2/23/24 14:34, avi.e.gr...@gmail.com wrote:
>>> This may be a dumb question and the answer may make me feel dumber.
>>>
>>> I have had trouble for years with R packages wanting Rtools on my 
>>> machine
>>> and not being able to use it. Many packages are fine as binaries are
>>> available. I have loaded Rtools and probably need to change my PATH or
>>> something.
>>
>>
>> I suppose making sure that whatever directory holds your Rtools code is
>> on your path would be a good idea. I wondered if there's an environment
>> variable that could be set, but reading the page on using Rtools did not
>> mention one until I got down to the section on building R from source
>> which is surely NOT what you want to do.. You should read the
>> information on installation and building packages from source.
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran.r-project.org%2Fbin%2Fwindows%2Fbase%2Fhowto-R-devel.html=05%7C02%7CJSorkin%40som.umaryland.edu%7C7000449b5bd74e1d6cbb08dc34cbcba8%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638443297110517980%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=%2B1tC1ROo11Bj1dPg7Ho9lDcVfL31Y3mCYUYqwDcyKs4%3D=0
>>  
>> which
>> includes this sentence:
>>
>> "It is recommended to use the defaults and install into|c:/rtools43|.
>> When done that way, Rtools43 may be used in the same R session which
>> installed it or which was started before Rtools43 was installed."
>>
>>>
>>> But I recently suggested to someone that they might want to use the 
>>> tabyl()
>>> function in the janitor package that I find helpful. I get a warning 
>>> when I
>>> install it about Rtools but it works fine. When they install it, it 
>>> fails. I
>>> assumed they would get it from CRAN the same way I did as we are 
>>> both using
>>> Windows and from within RSTUDIO.
>>>
>>> In the past, I have run into other packages I could not use and just 
>>> moved
>>> on but it seems like time to see if this global problem has a 
>>> work-around.
>>>
>>> And, in particular, I have the latest versions of both R and RSTUDIO 
>>> which
>>> can be a problem when other things are not as up-to-date.
>>>
>>> Or, maybe some people with R packages could be convinced to make 
>>> binaries
>>> available in the first place?
>>
>> Binaries are automatically produced by CRAN but perhaps you are trying
>> to install from some other source? It would help if you could be
>> specific about several missing pieces of information: Operating syst

Re: [R] Rtools and things dependent on it

2024-02-23 Thread David Winsemius



On 2/23/24 15:39, Sorkin, John wrote:

Avi ,
Your question is not dumb. Let me ask a more fundamental question. What is R 
tools, what does it do, and how is it used. From time to time, I receive a 
message when I down load a package saying I need R tools. When I receive the 
message, I don’t know what I should do, other than down load R tools.


https://cran.r-project.org/bin/windows/base/howto-R-devel.html


And do configure your client to send only plain-text.


--

David.


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

On Feb 23, 2024, at 5:34 PM, avi.e.gr...@gmail.com wrote:

This may be a dumb question and the answer may make me feel dumber.


__
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] Rtools and things dependent on it

2024-02-23 Thread David Winsemius


On 2/23/24 14:34, avi.e.gr...@gmail.com wrote:
> This may be a dumb question and the answer may make me feel dumber.
>   
> I have had trouble for years with R packages wanting Rtools on my machine
> and not being able to use it. Many packages are fine as binaries are
> available. I have loaded Rtools and probably need to change my PATH or
> something.


I suppose making sure that whatever directory holds your Rtools code is 
on your path would be a good idea. I wondered if there's an environment 
variable that could be set, but reading the page on using Rtools did not 
mention one until I got down to the section on building R from source 
which is surely NOT what you want to do.. You should read the 
information on installation and building packages from source. 
https://cran.r-project.org/bin/windows/base/howto-R-devel.html which 
includes this sentence:

"It is recommended to use the defaults and install into|c:/rtools43|. 
When done that way, Rtools43 may be used in the same R session which 
installed it or which was started before Rtools43 was installed."

>   
> But I recently suggested to someone that they might want to use the tabyl()
> function in the janitor package that I find helpful. I get a warning when I
> install it about Rtools but it works fine. When they install it, it fails. I
> assumed they would get it from CRAN the same way I did as we are both using
> Windows and from within RSTUDIO.
>   
> In the past, I have run into other packages I could not use and just moved
> on but it seems like time to see if this global problem has a work-around.
>   
> And, in particular, I have the latest versions of both R and RSTUDIO which
> can be a problem when other things are not as up-to-date.
>   
> Or, maybe some people with R packages could be convinced to make binaries
> available in the first place?

Binaries are automatically produced by CRAN but perhaps you are trying 
to install from some other source? It would help if you could be 
specific about several missing pieces of information: Operating system, 
R version, Rtools version, current location of Rtools, names of packages 
and where they were obtained.


Regards and good luck;

David (a.k.a IRTFM)

> Avi
>
>   [[alternative HTML version deleted]]
Rhelp is a plain text mailing list. You should configure your email 
client to send only plain-text and NOT html.
[[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] Convert character date time to R date-time variable.

2023-12-08 Thread David Winsemius



On 12/7/23 08:21, Sorkin, John wrote:

Colleagues,

I have a matrix of character data that represents date and time. The format of 
each element of the matrix is
"2020-09-17_00:00:00"
How can I convert the elements into a valid R date-time constant?


You will not be able to store these datetime values in an R matrix, at 
least as class POSIXct. You could with class POSIXlt, but I've not seen 
it used before but it does appear possible since matrices can contain 
lists.


R matrices do no provide the capability to assign attributes, so only 
atomic types and lists can be elements. If you wanted to maintain the 
same structure, your first step might be to coerce to a data.frame and 
then proceed, or to first construct a vector and then use as the first 
argument to `matrix`.



Best;

David



Thank you,
John



John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;

Associate Director for Biostatistics and Informatics, Baltimore VA Medical 
Center Geriatrics Research, Education, and Clinical Center;

PI Biostatistics and Informatics Core, University of Maryland School of 
Medicine Claude D. Pepper Older Americans Independence Center;

Senior Statistician University of Maryland Center for Vascular Research;

Division of Gerontology and Paliative Care,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382



__
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 can I remove my packages from rdrr.io?

2023-11-01 Thread David Winsemius



> On Nov 1, 2023, at 6:06 AM, Kim Emilia  wrote:
> 
> Hello all,
> 
> I would like to take down my packages posted/created on the website rdrr.io.
> [https://rdrr.io/] Is there any way to take down packages from the website?
> It would be appreciated if you suggested/offered a way to remove the
> package from the website.
> 

The website you are concerned about is not maintained by the R-project. A but 
of link-following suggested to me that the person you need to be addressing 
this to has a "personal" webpage at:  https://ianhowson.com/

There will be many other sites that hold most or all of the extensive list of 
CRAN packages, although it is certainly true that rrio.io has become a favorite 
of Google. 

-- 
David
> 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-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] running crossvalidation many times MSE for Lasso regression

2023-11-01 Thread David Winsemius



> On Oct 22, 2023, at 4:01 PM, Bert Gunter  wrote:
> 
> No error message shown Please include the error message so that it is
> not necessary to rerun your code. This might enable someone to see the
> problem without running the code (e.g. downloading packages, etc.)
> 
> -- Bert
> 
> On Sun, Oct 22, 2023 at 1:36 PM varin sacha via R-help
>  wrote:
>> 
>> Dear R-experts,
>> 
>> Here below my R code with an error message. Can somebody help me to fix this 
>> error?
>> Really appreciate your help.
>> 
>> Best,
>> 
>> 
>> # MSE CROSSVALIDATION Lasso regression
>> 
>> library(glmnet)
>> 
>> 
>> x1=c(34,35,12,13,15,37,65,45,47,67,87,45,46,39,87,98,67,51,10,30,65,34,57,68,98,86,45,65,34,78,98,123,202,231,154,21,34,26,56,78,99,83,46,58,91)
>> x2=c(1,3,2,4,5,6,7,3,8,9,10,11,12,1,3,4,2,3,4,5,4,6,8,7,9,4,3,6,7,9,8,4,7,6,1,3,2,5,6,8,7,1,1,2,9)
>> y=c(2,6,5,4,6,7,8,10,11,2,3,1,3,5,4,6,5,3.4,5.6,-2.4,-5.4,5,3,6,5,-3,-5,3,2,-1,-8,5,8,6,9,4,5,-3,-7,-9,-9,8,7,1,2)
>> T=data.frame(y,x1,x2)
>> 
>> z=matrix(c(x1,x2), ncol=2)
>> cv_model=glmnet(z,y,alpha=1)
>> best_lambda=cv_model$lambda.min
>> best_lambda
>> 
>> 
>> # Create a list to store the results
>> lst<-list()
>> 
>> # This statement does the repetitions (looping)
>> for(i in 1 :1000) {
>> 
>> n=45
>> 
>> p=0.667
>> 
>> sam=sample(1 :n,floor(p*n),replace=FALSE)
>> 
>> Training =T [sam,]
>> Testing = T [-sam,]
>> 
>> test1=matrix(c(Testing$x1,Testing$x2),ncol=2)
>> 
>> predictLasso=predict(cv_model, newx=test1)
>> 
>> 
>> ypred=predict(predictLasso,newdata=test1)

The error I got was:

Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "c('matrix', 
'array', 'double', 'numeric')"


I'm not sure why the name of the object was cv_model since it was not created 
as a cross-validation result.

The loops called predict() twice and it was the second call that produced the 
error since the predictLasso object was not a glmnet classed object.

If the OP had left out the second use of predict and then subtracted 
predictLasso from the y vector a result would have appeared

y=T[-sam,]$y
MSE = mean((y-predictLasso)^2)
...
> mean(unlist(lst))
[1] 23.39621

Whether this is meaningful is hard to tell. It also makes the fundamental error 
of overwriting the original data object `y` with another intermediate result.

-- 
David
>> y=T[-sam,]$y
>> 
>> MSE = mean((y-ypred)^2)
>> MSE
>> lst[i]<-MSE
>> }
>> mean(unlist(lst))
>> ##
>> 
>> 
>> 
>> 
>> __
>> 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] RQuantLib installation problem

2023-09-24 Thread David Winsemius



On 9/24/23 08:23, Ivan Krylov wrote:

On Sun, 24 Sep 2023 02:19:20 +
Naresh Gurbuxani  wrote:


install.packages("RQuantLib", repos = "https://cran.r-project.org;)

Installing package into ‘/usr/local/lib/R/4.1/site-library’
(as ‘lib’ is unspecified)
trying URL
'https://cran.r-project.org/src/contrib/RQuantLib_0.4.17.tar.gz'



Ivan is undoubtedly more knowledgeable on these matters than I, but I 
noticed that you are trying to install the current version of RQuantLib 
into a library that appears associated with a significantly older 
version of R than is current the current version. (And I second the 
advice that this is a question properly addressed to the R_SIG-mac 
mailing list but only with a much better description of version of your 
setup and how R was installed. You might want to install RQuantLib for a 
time frame that matched R 4.1.x. The archive is here:


https://cran.r-project.org/src/contrib/00Archive/RQuantLib/

You may also want to set the compile flags so that R can find your 
version of gfortran. That can be done within install.packages but most 
experts would prefer that you do it from a system terminal session with 
$ R CMD INSTALL. You can find details at the r help page `


?INSTALL -- David

  

dyld[29996]: Library not loaded:
/usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
Referenced from: <383F3774-06DE-3792-AA2C-C9D6B37A2D89>
/usr/local/Cellar/r/4.1.2/lib/R/lib/libR.dylib

So you're installing source packages into a Homebrew-built R, and they
fail to load after being compiled?

If you don't get an answer here, try r-sig-...@r-project.org or
.



__
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] predict function type class vs. prob

2023-09-23 Thread David Winsemius
That's embarrassing. Apologies for the garbles HTML posting. I'll see if 
this is more readable:


On 9/23/23 05:30, Rui Barradas wrote:

Às 11:12 de 22/09/2023, Milbert, Sabine (LGL) escreveu:

Dear R Help Team,

My research group and I use R scripts for our multivariate data 
screening routines. During routine use, we encountered some 
inconsistencies within the predict() function of the R Stats Package. 





On 9/23/23 05:30, Rui Barradas wrote:
> Às 11:12 de 22/09/2023, Milbert, Sabine (LGL) escreveu:
>> Dear R Help Team,
>>
>> My research group and I use R scripts for our multivariate data 
screening routines. During routine use, we encountered some 
inconsistencies within the predict() function of the R Stats Package.


In addition to Rui's correction to this misstatement, the caret package 
is really a meta package that attempts to implement an umbrella 
framework for a vast array of tools from a wide variety of sources. It 
is an immense effort but not really a part of the core R project. The 
correct place to file issues is found in the DESCRIPTION file:



URL: https://github.com/topepo/caret/
BugReports: https://github.com/topepo/caret/issues

 If you use `str` on an object constructed with caret, you discover 
that the `predict` function is actually not in the main workspace but 
rather embedded in the fit-object itself. I think this is a rather 
general statement regarding the caret universe, and so I expect that 
your fit -objects can be examined for the code that predict.train will 
use with this approach. Your description of your analysis methods was 
rather incompletely specified, and I will put an appendix of "svm" 
methods that might be specified after my demonstration using code. (Note 
that I do not see a caret "weights" hyper-parameter for the "svmLinear" 
method which is actually using code from pkg:kernlab.)



library(caret)
svmFit <- train(Species ~ ., data = iris, method = "svmLinear",
 trControl = trainControl(method = "cv"))

 class(svmFit)
#[1] "train" "train.formula"
str(predict(svmFit))
 Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
str(svmFit)
#---screen output-
List of 24
 $ method  : chr "svmLinear"
 $ modelInfo   :List of 13
  ..$ label : chr "Support Vector Machines with Linear Kernel"
  ..$ library   : chr "kernlab"
  ..$ type  : chr [1:2] "Regression" "Classification"
  ..$ parameters:'data.frame':    1 obs. of  3 variables:
  .. ..$ parameter: chr "C"
  .. ..$ class    : chr "numeric"
  .. ..$ label    : chr "Cost"
  ..$ grid  :function (x, y, len = NULL, search = "grid")
  ..$ loop  : NULL
  ..$ fit   :function (x, y, wts, param, lev, last, classProbs, ...)
  ..$ predict   :function (modelFit, newdata, submodels = NULL)
  ..$ prob  :function (modelFit, newdata, submodels = NULL)
  ..$ predictors:function (x, ...)
  ..$ tags  : chr [1:5] "Kernel Method" "Support Vector Machines" 
"Linear Regression" "Linear Classifier" ...

  ..$ levels    :function (x)
  ..$ sort  :function (x)
 $ modelType   : chr "Classification"
#   large amount of screen output omitted--

# note that the class of svmFit$modelInfo$predict is 'function'
# and its code at least to this particular svm method of which there are 
about 10!



svmFit$modelInfo$predict

# screen output --
function (modelFit, newdata, submodels = NULL)
{
    svmPred <- function(obj, x) {
    hasPM <- !is.null(unlist(obj@prob.model))
    if (hasPM) {
    pred <- kernlab::lev(obj)[apply(kernlab::predict(obj,
    x, type = "probabilities"), 1, which.max)]
    }
    else pred <- kernlab::predict(obj, x)
    pred
    }
    out <- try(svmPred(modelFit, newdata), silent = TRUE)
    if (is.character(kernlab::lev(modelFit))) {
    if (class(out)[1] == "try-error") {
    warning("kernlab class prediction calculations failed; 
returning NAs")

    out <- rep("", nrow(newdata))
    out[seq(along = out)] <- NA
    }
    }
    else {
    if (class(out)[1] == "try-error") {
    warning("kernlab prediction calculations failed; returning 
NAs")

    out <- rep(NA, nrow(newdata))
    }
    }
    if (is.matrix(out))
    out <- out[, 1]
    out
}


--
David


>> Through internal research, we were unable to find the reason for 
this and have decided to contact your help team with the following issue:

>>
>> The predict() function is used once to predict the class membership 
of a new sample (type = "class") on a trained linear SVM model for 
distinguishing two classes (using the caret package). It is then used to 
also examine the probability of class membership (type = "prob"). Both 
are then presented in an R shiny output. Within the routine, we noticed 
two samples (out of 100+) where the class prediction and probability 
prediction did not match. The prediction probabilities of one class 
(52%) did not match the class membership 

Re: [R] predict function type class vs. prob

2023-09-23 Thread David Winsemius


On 9/23/23 05:30, Rui Barradas wrote:
> Às 11:12 de 22/09/2023, Milbert, Sabine (LGL) escreveu:
>> Dear R Help Team,
>>
>> My research group and I use R scripts for our multivariate data 
>> screening routines. During routine use, we encountered some 
>> inconsistencies within the predict() function of the R Stats Package.

In addition to Rui's correction to this misstatement, the caret package 
is really a meta package that attempts to implement an umbrella 
framework for a vast array of tools from a wide variety of sources. It 
is an immense effort but not really a part of the core R project. The 
correct place to file issues is found in the DESCRIPTION file:


URL: https://github.com/topepo/caret/ BugReports: 
https://github.com/topepo/caret/issues

  If you use `str` on an object constructed with caret, you discover 
that the `predict` function is actually not in the main workspace but 
rather embedded in the fit-object itself. I think this is a rather 
general statement regarding the caret universe, and so I expect that 
your fit -objects can be examined for the code that predict.train will 
use with this approach. Your description of your analysis methods was 
rather incompletely specified, and I will put an appendix of "svm" 
methods that might be specified after my demonstration using code. (Note 
that I do not see a caret "weights" hyper-parameter for the "svmLinear" 
method which is actually using code from pkg:kernlab.)


library(caret) svmFit <- train(Species ~ ., data = iris, method = 
"svmLinear", trControl = trainControl(method = "cv")) class(svmFit) #[1] 
"train" "train.formula" str(predict(svmFit)) Factor w/ 3 levels 
"setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... str(svmFit) #---screen 
output- List of 24 $ method : chr "svmLinear" $ modelInfo 
:List of 13 ..$ label : chr "Support Vector Machines with Linear Kernel" 
..$ library : chr "kernlab" ..$ type : chr [1:2] "Regression" 
"Classification" ..$ parameters:'data.frame': 1 obs. of 3 variables: .. 
..$ parameter: chr "C" .. ..$ class : chr "numeric" .. ..$ label : chr 
"Cost" ..$ grid :function (x, y, len = NULL, search = "grid") ..$ loop : 
NULL ..$ fit :function (x, y, wts, param, lev, last, classProbs, ...) 
..$ predict :function (modelFit, newdata, submodels = NULL) ..$ prob 
:function (modelFit, newdata, submodels = NULL) ..$ predictors:function 
(x, ...) ..$ tags : chr [1:5] "Kernel Method" "Support Vector Machines" 
"Linear Regression" "Linear Classifier" ... ..$ levels :function (x) ..$ 
sort :function (x) $ modelType : chr "Classification" #  large 
amount of screen output omitted-- # note that the class of 
svmFit$modelInfo$predict is 'function' # and its code at least to this 
particular svm method of which there are about 10!
svmFit$modelInfo$predict # screen output -- function (modelFit, 
newdata, submodels = NULL) { svmPred <- function(obj, x) { hasPM <- 
!is.null(unlist(obj@prob.model)) if (hasPM) { pred <- 
kernlab::lev(obj)[apply(kernlab::predict(obj, x, type = 
"probabilities"), 1, which.max)] } else pred <- kernlab::predict(obj, x) 
pred } out <- try(svmPred(modelFit, newdata), silent = TRUE) if 
(is.character(kernlab::lev(modelFit))) { if (class(out)[1] == 
"try-error") { warning("kernlab class prediction calculations failed; 
returning NAs") out <- rep("", nrow(newdata)) out[seq(along = out)] <- 
NA } } else { if (class(out)[1] == "try-error") { warning("kernlab 
prediction calculations failed; returning NAs") out <- rep(NA, 
nrow(newdata)) } } if (is.matrix(out)) out <- out[, 1] out }  -- David


>> Through internal research, we were unable to find the reason for this 
>> and have decided to contact your help team with the following issue:
>>
>> The predict() function is used once to predict the class membership 
>> of a new sample (type = "class") on a trained linear SVM model for 
>> distinguishing two classes (using the caret package). It is then used 
>> to also examine the probability of class membership (type = "prob"). 
>> Both are then presented in an R shiny output. Within the routine, we 
>> noticed two samples (out of 100+) where the class prediction and 
>> probability prediction did not match. The prediction probabilities of 
>> one class (52%) did not match the class membership within the predict 
>> function. We use the same seed and the discrepancy is reproducible in 
>> this sample. The same problem did not occur in other trained models 
>> (lda, random forest, radial SVM...).

*Support Vector Machines with Boundrange String Kernel*(|method = 
'svmBoundrangeString'|)

For classification and regression using packagekernlabwith tuning 
parameters:

  *

length (|length|, numeric)

  *

Cost (|C|, numeric)

*Support Vector Machines with Class Weights*(|method = 'svmRadialWeights'|)

For classification using packagekernlabwith tuning parameters:

  *

Sigma (|sigma|, numeric)

  *

Cost (|C|, numeric)

  *

Weight (|Weight|, numeric)

*Support 

Re: [R] how to change the y-axis to logarithmic in a barplot ggplot

2023-07-16 Thread David Winsemius



On 7/16/23 14:51, Maria Lathouri via R-help wrote:

Dear all,


I am having the following dataset
fc<-
ID    values    databases
Al    0.15    phreeqc
Al    0.6    carbfix
Al    0.47    actual
Ca    7.2    phreeqc
Ca    7.2    carbfix
Ca    0.3    actual
Na    14.4    phreeqc
Na    84    carbfix
Na    106    actual
Cl    22    phreeqc
Cl    21.9    carbfix
Cl    72.1    actual
Fe    0.05    phreeqc
Fe    0.43    carbfix
Fe    1.25    actual
Mg    0.35    phreeqc
Mg    0.17    carbfix
Mg    0.08    actual
SO4    0    phreeqc
SO4    0    carbfix
SO4    416    actual


As you can see, the values range from 0 to 400. I want it to plot it in bars; 
when I am plotting it as you can imagine the values near zero don't show at 
all. So I am trying to make the y axis logarithmic. I have created the 
following code but it doesn't work. I get the bars with zero above and the 
others on top.


ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +



None of those aes() names are in your data object. They should be one of

ID    values    databases



geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))


What are you intending with `

aes(y=log(mean)

`

+ theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = 
element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title = 
element_blank())
+ scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette = "Dark2")


--

David.



I would very much appreciate your help. I am stuck.


Kind regards,
Maria

__
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] InformationValue package

2023-05-26 Thread David Winsemius
If it was in CRAN you will find it in the Archives. 

Sent from my iPhone

> On May 26, 2023, at 1:37 PM, Jeff Reichman  wrote:
> 
> R Help
> 
> 
> 
> 
> 
> There use to be a package called "InformationValue" which was used to
> calculate the optimal probability cutoff for a ROC plot.  That package was
> archived some time ago and I was wondering if there is another function (in
> another package) that would perform the calculation.  I can always recall
> the archived package too.
> 
> 
> 
> Jeff
> 
> 
>[[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] Split String in regex while Keeping Delimiter

2023-04-12 Thread David Winsemius
I thought replacing the spaces following instances of +++,++,+,- with "\n" and 
then reading with scan should succeed. Like Ivan Krylov I was fairly sure that 
you meant the minus sign to be "-" rather than "–", but perhaps your were using 
MS Word as an editor which is inconsistent with effective use of R. If so, 
learn to use a proper programming editor, and in any case learn to post to 
rhelp in plain text.

-- 
David

scan(text=gsub("([-+]){1}\\s", "\\1\n", dat), what="", sep="\n")



> On Apr 12, 2023, at 2:29 AM, Emily Bakker  wrote:
> 
> Hello List,
>  
> I have a dataset consisting of strings that I want to split while saving the 
> delimiter.
>  
> Some example data:
> “leucocyten + gramnegatieve staven +++ grampositieve staven ++”
> “leucocyten – grampositieve coccen +”
>  
> I want to split the strings such that I get the following result:
> c(“leucocyten +”,  “gramnegatieve staven +++”,  “grampositieve staven ++”)
> c(“leucocyten –“, “grampositieve coccen +”)
>  
> I have tried strsplit with a regular expression with a positive lookahead, 
> but I am not able to achieve the results that I want.
>  
> I have tried:
> as.list(strsplit(x, split = “(?=[\\+-]{1,3}\\s)+, perl=TRUE)
>  
> Which results in:
> c(“leucocyten “, “+”,  “gramnegatieve staven “, “+”, “+”, “+”,  
> “grampositieve staven ++”)
> c(“leucocyten “, “–“, “grampositieve coccen +”)
>  
>  
> Is there a function or regular expression that will make this possible?
>  
> Kind regards,
> Emily 
>  
> __
> 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] simultaneous confidence intervals for multinomial proportions: sample size

2023-04-09 Thread David Winsemius



> On Apr 9, 2023, at 5:46 AM, palad...@trustindata.de wrote:
> 
> Hello!
> I want to calculate simultaneous confidence intervals for a nominal variable 
> with three categories: "yes", "no", "partially" and I expect that far more 
> than 5 samples fall into each category.
> I have read that Glaz & Sison's method is only appropriate for variables with 
> 7 or more categories. Therefore, the Goodman method seems like a good idea.
> I have found the R function "MultinomCI" {DescTools} to calculate these CIs.
> However, I have not found a way to calculate in advance the required sample 
> size for the Goodman method at a fixed confidence level and length of the 
> intervall.



Seems very unlikely that you can achieve both of those goals simultaneously. I 
would expect the CI width t vary with the size of the sample in each category 
in any case. So I'm wondering if your failure at searching derives from the 
impossibility of your goal. Why would you desire such a result?


-- 
David.
> I would be very grateful for any suggestion.
> 
> 
> Many thanks in advance!
> 
> Claudia
> 
> 
>   [[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] "prob" package alternative

2023-04-06 Thread David Winsemius


On 4/6/23 02:15, Martin Maechler wrote:
>> peter murage
>>  on Tue, 4 Apr 2023 06:24:56 + writes:
>  > Which package in R replaced package prob?
>
> Well, if you google that you should quickly be lead to
> (something I even think makes sense to memorize as "rule"
>package= ) :
>
>https://CRAN.R-project.org/package=prob
>
> which now says that the package was archived as it depended on
> another package that was archived.
>
> Both are still there -- in the CRAN archive --
> but to install them may be a bit of work

I suspect Martin is referring to the need to have an OS-specific 
toolchain for compiling packages. In this case however the DESCRIPTION 
files says:


NeedsCompilation: no


So it is probably a simple matter to install. Err not quite 
correctOr it would have been if there hadn't been several dependencies, 
some of which required compilation. Here's what finally worked on a 
machine that has a working toolchain.

install.packages("fBasics")

install.packages("http://cran.nexr.com/src/contrib/fOptions_3042.86.tar.gz;, 
repo=NULL)

install.packages("http://cran.nexr.com/src/contrib/fAsianOptions_3042.82.tar.gz;,
 
repo=NULL)

install.packages("https://cran.r-project.org/src/contrib/Archive/prob/prob_1.0-1.tar.gz;,
 
repo=NULL)


I think I could have changed my repo to cran.nexr.com and they might 
have even had binaries. I'll check. Yep, they do have source and 
binaries. So that might be the easiest. You could try just this:


install.packages("fAsianOptions", repo="http://cran.nexr.com/;, 
dependencies=TRUE)


-- 

David.

> particularly if you are
> on Windows (as it suggeested you are via a Microsoft "add" at
> the end of your R-help post ..).
> One way I'd use is Winbuilder
> (which will require you to set yourself as formal "Maintainer" of
>   the package before submission).
>
> An alternative may be to use Rhub ..
> or then learn to do it yourself, by installing the "Rtools" (for Windows):
> --->https://cran.r-project.org/bin/windows/Rtools/
>   
> With best regards,
> Martin
>
> __
> 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 guidehttp://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] R does not run under latest RStudio

2023-04-06 Thread David Winsemius



On 4/6/23 03:49, Steven Yen wrote:

The RStudio list generally does not respond to free version users. I was hoping 
someone one this (R) list would be kind enough to help me.



I don't think that is true. It is perhaps true that you cannot get 
personalized help from employed staff, but you can certainly submit to 
the Q forum.



--

David



Steven from iPhone


On Apr 6, 2023, at 6:22 PM, Uwe Ligges  wrote:

No, but you need to ask on an RStudio mailing list.
This one is about R.

Best,
Uwe Ligges





On 06.04.2023 11:28, Steven T. Yen wrote:
I updated to latest RStudio (RStudio-2023.03.0-386.exe) but
R would not run. Error message:
Error Starting R
The R session failed to start.
RSTUDIO VERSION
RStudio 2023.03.0+386 "Cherry Blossom " (3c53477a, 2023-03-09) for Windows
[No error available]
I also tried RStudio 2022.12.0+353 --- same problem.
I then tried another older version of RStudio (not sure version
as I changed file name by accident) and R ran.
Any clues? Please help. Thanks.
__
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] Problems with foreign

2023-03-30 Thread David Winsemius



On 3/30/23 10:36, José Oscar Delgado Bautista wrote:

  Good day
My name is José Oscar, I'm from Mexico and I have some questions about
foreign in your write.foreig( ) function. We know that this function
generates the inputs to be able to run them or execute them in another
program like SPSS, SAS or Stata. In these cases, when creating an example
file, a matrix and using the function to execute the .sps file directly
from SPSS, I don't care or work based on the SPSS environment. With Stata
the problem does not arise, but this same problem also arises with SAS, in
that sense or question, how could I solve this? Do you have any guides or
tutorials on the correct use of the function?


I don't really understand the question. Not sure what the problem you 
are seeing when you attempt to get SAS-style output. I went to the help 
page for `write.foreign`:


?write.foreign

...  and the Arguments section clearly shows that although "SPSS" is the 
default value, that any of the other recognized values for the format of 
the output would be accepted.


Perhaps you are so inexperienced with R that you don't even know how to 
access the help system?



This is the code:
x<- matrix(data = sample(1:100,
  100),
nrow = 10, ncol = 10)

x2<- as.data.frame(x)

write.foreign(x2, "x2_spss.txt", "x2_spss.sps", package = "SPSS")


When I changed the "package" argument to "SAS", ...  I get SAS code:

* Written by R;
*  write.foreign(esoph, datafile, codefile, package = "SAS") ;

PROC FORMAT;
value agegp
 1 = "25-34"
 2 = "35-44"
 3 = "45-54"
 4 = "55-64"
 5 = "65-74"
 6 = "75+"
;

value alcgp
 1 = "0-39g/day"
 2 = "40-79"
 3 = "80-119"
 4 = "120+"
;

value tobgp
 1 = "0-9g/day"
 2 = "10-19"
 3 = "20-29"
 4 = "30+"
;

DATA  rdata ;
INFILE  "/tmp/RtmpFcHZ9L/file6a7222461f1c"
 DSD
 LRECL= 15 ;
INPUT
 agegp
 alcgp
 tobgp
 ncases
 ncontrols
;
FORMAT agegp agegp. ;
FORMAT alcgp alcgp. ;
FORMAT tobgp tobgp. ;
RUN;

--

David.



[[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] Failing to install the rgl package

2023-01-26 Thread David Winsemius



On 1/26/23 11:04, Tunga Kantarcı wrote:

Hi,

I try to execute the seven lines of code below to plot a graph. But I
am failing as the messages below show. Where am I going wrong?


install.packages("rgl")
library(rgl)
y_hat = X%*%B_hat
open3d(windowRect = c(100,100,900,900),family = "serif")
color = rainbow(length(y_hat))[rank(y_hat)]
plot3d(educ,exper,wage,col = color,type = "s",size = 0.5,xlim =
c(0,20),ylim = c(0,60),zlim = c(-10,70),box = FALSE,axes = TRUE)
planes3d(B_hat[2],B_hat[3],-1,B_hat[1],alpha = 0.5,col = "azure")


  -

install.packages("rgl")

trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/rgl_1.0.1.tgz'
Content type 'application/x-gzip' length 9425401 bytes (9.0 MB)
==
downloaded 9.0 MB

The downloaded binary packages are in
/var/folders/fx/_msf5ycn14g59c3vlc4pc7b8gn/T//RtmpfaezHX/downloaded_packages

library(rgl)

Registered S3 methods overwritten by 'rgl':
   method   from
   knit_print.rglId
   knit_print.rglOpen3d
   sew.rglRecordedplot
Error in dyn.load(dynlib <- getDynlib(dir)) :
   unable to load shared object
'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so':
   
dlopen(/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so,
0x0006): Library not loaded: /opt/X11/lib/libGLU.1.dylib
   Referenced from: <82C7D9AE-E1B2-39EA-A909-163B033CF7B1>



So It appears that X11, a.k.a. XQuartz on a Mac, is failing to load. You 
probably need to reinstall XQuartz with a current version that matches 
your version of R. You are also getting a message saying Java sdk cannot 
be found.



You also appear to be attempting to load the version for R 4.1 while the 
current version of R is 4.2. The R "ecosystem" needs consistency in 
versions of R, XQuartz, Java, and R packages. You will probably get 
better success if you first upgrade R, then reinstall XQuartz,  then 
reinstall or update Java, and finally update all your installed packages 
including rgl and then give it another go.


Finally, this is Rhelp. There is a SIG for R-Mac users. This question 
would have been more on-topic for  that help mailing list.


--

David


/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so
   Reason: tried: '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libGLU.1.dylib' (no
such file), '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/Library/Frameworks/R.framework/Resources/lib/libGLU.1.dylib' (no
such file), '/Users/tunga/lib/libGLU.1.dylib' (no such file),
'/usr/local/lib/libGLU.1.dylib' (no such file),
'/usr/lib/libGLU.1.dylib' (no such file, not in dyld cache),
'/lib/libGLU.1.dylib' (no such file),
'/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libGLU.1.dylib'
(no such file), '/var/folders/fx/_msf5ycn
In addition: Warning message:
package ‘rgl’ was built under R version 4.1.2
Error: package or namespace load failed for ‘rgl’:
  .onLoad failed in loadNamespace() for 'rgl', details:
   call: rgl.init(initValue, onlyNULL)
   error: OpenGL is not available in this build
In addition: Warning messages:
1: Loading rgl's DLL failed.
This build of rgl depends on XQuartz, which failed to load.
  See the discussion in https://stackoverflow.com/a/66127391/2554330
2: Trying without OpenGL...

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

2022-12-18 Thread David Winsemius
I cannot tell whether it would happen to me for two reasons: I don't use 
Windows anymore and R's current version is 4.2.1.



You can determine whether it is the core packages that are throwing the 
error (rather unlikely) or perhaps something you have in your 
(invisible) .Rdata file. You should probably update your installation of 
R and throw away the .Rdata file that I suspect has gotten corrupted or 
is loading a flaky package. If you don't want to update R, then you 
should at the very least try to run R from a command line with



>  R --vanilla

At least that's I what I remember from my Windows daze. You should also 
review the Win-R-FAQ which I think has similar advice.



--

David

On 12/18/22 16:20, Jeff Newmiller wrote:

Doesn't happen to me.

On December 16, 2022 12:44:17 AM PST, "Mathurin, Gottfried via R-help" 
 wrote:

Hello,
I currently face the issue of Windows 10 throwing a code 3221226505
whenever I try to use R-4.1.3.
Is this issue known and could you possibly share a fix?

Thank you in advance,

*Gottfried*



__
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] What is new in R especially about Tidyverse.

2022-11-29 Thread David Winsemius
The OP should familiarize him/her-self with the `news()` function. It 
would allow reading what the authors of packages including those of the 
base packages have to say about material changes.



#First, type:

?news

#Then perhaps:

news(package="R") news(package="tidyverse") -- David.

On 11/27/22 06:26, Ebert,Timothy Aaron wrote:

I suggest starting with a browser (I used Google), and search for "Tidyverse". 
Some pages there should help. I would check out the github link. Before going too far I 
would also check out the Wikipedia page, and the references cited therein. Using key 
words from these resources and using citations in these resources should get you much 
closer to your goal.
I had thought that github kept track of versions. I am not super familiar with 
github. While I could not find the version histories, I might not have general access to 
that information or I simply did not know where to look. There is a possibility that the 
detailed version histories might be information overload and you will have to sift 
through many small tweaks to find important developments. You might need to clearly 
define what constitutes an "important update" or the audience that found the 
update important.

Tim

-Original Message-
From: R-help  On Behalf Of Eric Berger
Sent: Sunday, November 27, 2022 3:50 AM
To: Abdullah DOĞRUL 
Cc: r-help@r-project.org
Subject: Re: [R] What is new in R especially about Tidyverse.

[External Email]

Hi Abdullah,
The Tidyverse is a set of R packages that are designed to work well together 
for handling a variety of common tasks in data science. Many of these packages 
are written by Hadley Wickham, chief scientist at RStudio.com.

https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHadley_Wickhamdata=05%7C01%7Ctebert%40ufl.edu%7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638051358176015383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=yWWonY9jWhq9NE9I7BQ7eEQ%2B8u39hjxktaQvtXTkQoY%3Dreserved=0

RStudio.com is a commercial company which provides both free and non-free 
products for data science. Many R users use the free IDE RStudio provided by 
them. The company recently changed its name from RStudio.com to Posit, as it 
wants to emphasize that its tools are not restricted to R (e.g.
Python is supported, Quarto for documents, etc)

I suggest you look at the resources available at https::/posit.co as a start.

Besides the tidyverse packages, you might want to investigate how different 
groups have used the tidyverse philosophy (and packages) to provide groups of 
packages for handling specific sub-disciplines in data science. For example, 
Rob Hyndman's group has created the tidyverts (the 'ts' refers to time series) 
which extends the tidyverse packages and also contributed additional packages. 
The tidyverts facilitates time series forecasting.

Good luck,
Eric



On Sun, Nov 27, 2022 at 10:16 AM Abdullah DOĞRUL 
wrote:


To whom it may concern,

Currently I'm doing my MSc in Turkey. My department is Industrial
Engineering. I'm going to do my thesis about Tidyverse in R. I'm
looking for articles which contain what is new, what changed and what
is Tidyverse's contributions?

I need a help about how to find those articles. I have found some of
articles. But, probably they'll not help much.

Thank you for your help.
Best regards.

Abdullah DOĞRUL

 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat
.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl
.edu%7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e
1b84%7C0%7C0%7C638051358176015383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
sdata=cPJFkNJfLjyipJXzJSsgP6tsZbuxoZSDSKicG4jrBqg%3Dreserved
=0
PLEASE do read the posting guide
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r
-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%
7Ca473eece3c93493f8b7d08dad0546547%7C0d4da0f84a314d76ace60a62331e1b84%
7C0%7C0%7C638051358176015383%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM
DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
sdata=GJRLQ9rc9R71FWpzrc0RA1z87sNvh6jhBIVKlws1HeE%3Dreserved=0
and provide commented, minimal, self-contained, reproducible code.


 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

[R] unmet dependency for r-base-core ... was Re: ubuntu 22

2022-11-14 Thread David Winsemius


On 11/14/22 15:22, Ragia . wrote:
>dear group ,
> cant install r base into ubuntu 22.
> the msg is
> The following packages have unmet dependencies:
>   r-base-core : Depends: libicu70 (>= 70.1-1~) but it is not installable


Have you tried looking up the package that would contain libicu70?  I 
had no problem locating a copy of libicu70_70.1-2_amd64.deb 

 
with search terms: "libicu70 ubuntu 22".


> Recommends: r-recommended but it is not going to be installed
> Recommends: r-doc-html but it is not going to be installed
> E: Unable to correct problems, you have held broken packages.
> thanks in advance
>
>   [[alternative HTML version deleted]]


Do note that Rhelp is a plain text mailing list. And further note that 
the proper mailing list (also plain text) would have been R-SIG-debian.


-- 

David.

>
> __
> 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 guidehttp://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] Logistic regression for large data

2022-11-11 Thread David Winsemius
That’s not a large data set. Something else besides memory limits is going on. 
You should post output of summary(Base). 

— 
David
Sent from my iPhone

> On Nov 11, 2022, at 11:29 PM, George Brida  wrote:
> 
> Dear R users,
> 
> I have a database  called Base.csv   (attached to this email) which
> contains 13 columns and 8257 rows and whose the first 8 columns are dummy
> variables which take 1 or 0. The problem is when I wrote the following
> instructions to do a logistic regression , R runs for hours and hours
> without giving an output:
> 
> Base=read.csv("C:\\Users\\HP\\Desktop\\New\\Base.csv",header=FALSE,sep=";")
> fit_1=glm(Base[,2]~Base[,1]+Base[,10]+Base[,11]+Base[,12]+Base[,13],family=binomial(link="logit"))
> 
> Apparently, there is not enough memory to have the requested output. Is
> there any other function for logistic regression that handle large data and
> return output in reasonable time.
> 
> Many thanks
> 
> Kind regards
> 
> George
> __
> 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] Plotting a triangular prism

2022-11-10 Thread David Winsemius
One might think that after all these years you would have understood that “it’s 
not working” is an excessively imprecise description of, well, anything. 

Also html is deprecated severely on Rhelp. 

— 
David. 

Sent from my iPhone

> On Nov 10, 2022, at 5:46 PM, Erin Hodgess  wrote:
> 
> Hello!
> 
> I’m trying to draw a triangular prism.  I have used rgl, plot3d, and it’s
> still not working as I would like.
> 
> Has anyone done this, please?
> 
> Thanks for any help.
> 
> Sincerely,
> Erin
> -- 
> Erin Hodgess, PhD
> mailto: erinm.hodg...@gmail.com
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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 this *always* the intended R^2 value for no intercept in lm?

2022-11-06 Thread David Winsemius
To Thierry; When you omit an intercept you require that the line in 
multivariate space that represents the ‘predictions’ go through the (0,0,0,…) 
I.e. the origin. It’s a fairly restrictive requirement. There IS an intercept, 
even though it’s not explicitly seen in the model. If it’s not required by 
theory in your domain of investigation, you are advised to avoid such a 
practice.

— 
David. 

Sent from my iPhone

> On Nov 5, 2022, at 12:41 PM, Bert Gunter  wrote:
> 
> FAQ 7.41
> and
> https://stackoverflow.com/questions/57415793/r-squared-in-lm-for-ero-intercept-model
> 
> (among numerous others that could no doubt be found with a bit of
> searching).
> 
> In short, the "null models" against which you are comparing the fitted
> model are different with and without an intercept.
> 
> --Bert
> 
> 
> 
>> On Sat, Nov 5, 2022 at 11:52 AM Thierry Zell  wrote:
>> 
>> I am puzzled by the computation of R^2 with intercept omitted that is
>> already illustrated by the following example taken from help("lm")
>> 
>> ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
>> ## Page 9: Plant Weight Data.
>> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
>> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
>> group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
>> weight <- c(ctl, trt)
>> lm.D9 <- lm(weight ~ group)
>> lm.D90 <- lm(weight ~ group - 1) # omitting intercept
>> 
>> The calculations for the R^2 for both models  are consistent with the
>> help("summary.lm") description:
>> "y* is the mean of y[i] if there is an intercept and zero otherwise."
>> Which causes a dramatic difference in the resulting R^2 values.
>> 
>> r2.D9 <- summary(lm.D9)$r.squared
>> r2.D90 <- summary(lm.D90)$r.squared
>> 
>> all.equal(r2.D9, 0.0730775989903856) #TRUE
>> all.equal(r2.D90, 0.981783272435264) #TRUE
>> 
>> This is counter-intuitive to say the least since the two models have
>> identical predictions and both models could be described more
>> accurately as two intercepts rather than zero. I see three
>> possibilities:
>> 
>> 1. This is the intended result, in which case no fix is required, but
>> I’d be curious to understand the argument better.
>> 2. This is an unfortunate outcome but not worth fixing as the user can
>> easily compute the correct R^2. In this case, I'd suggest that this
>> unintuitive behavior should be explicitly called out in the
>> documentation.
>> 3. This is a bug worth fixing.
>> 
>> I look forward to hearing the community’s opinion on this.
>> Thanks in advance!
>> 
>> __
>> 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] Associate a .R file with the RGui

2022-11-05 Thread David Winsemius



On 11/5/22 09:58, Amarjit Chandhial via R-help wrote:

Hi Jeff,


Please see my original question.


You were told that RGui is not an editor.

Are you implying that your initial message contained an implicit request 
for instructions on how to get R code in an .R file to be opened 
automagically when double-clicked or to have "open in " 
appear when right-clicked? (I didn't see that clearly expressed.)


If you want something else to happen with a file that has a .R extension 
when double-clicked or right-clicked in a GUI file manager, then you 
need to configure your OS to do whatever else it is that you expect. 
This is not really an R question. It's an OS question. There are many 
editors that can also bring up R consoles when the right  key combo is 
pressed. They do require some study for their specific actions, but this 
is not really the place to get guidance on the fine details.


--

David.




Thanks,
Amarjiit




On 5 Nov 2022, at 15:03, Jeff Newmiller  wrote:

RGui is not an editor. It is a console (aka REPL, 
https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop).

When using RGui, it is up to you to edit your R file in an external editor like Notepad++ 
and copy paste code snippets or use source("yourfile.R") as desired.


On November 5, 2022 6:47:54 AM PDT, Amarjit Chandhial via R-help 
 wrote:



Hi Andrew/Petr,


Thanks for the replies.

In R Console if I run:

R.home("bin")

I get the following

"C:/PROGRA~1/R/R-42~1.2/bin/x64"

which is where

Rgui.exe is (within the x64 folder there are 13 files in total: 8 . exe
and 5 .dll).


In file Explorer if I right-click on a .R file -> Open With -> R for
Windows GUI Front-End

RGui (64-bit) opens but the .R file does not appear in the editor.


Amarjit


-- Original Message --
From: "Andrew Simmons" 
To: "Amarjit Chandhial" 
Cc: "R-help Mailing List" 
Sent: Friday, 4 Nov, 2022 At 09:08
Subject: Re: [R] Associate a .R file with the RGui

In an R session, run this:

writeLines(normalizePath(R.home("bin")))


Right click your .R file > Open with > Choose another app > Check the
box "Always use this app to open .R files" > Look for another app on
this PC
Paste the directory found above, then select "Rgui.exe"


On Fri, Nov 4, 2022, 04:49 Amarjit Chandhial via R-help
mailto:r-help@r-project.org> > wrote:

Hi,


My OS is Windows 11 Pro 64-Bit, I have R 4.2.2 and RStudio installed.

If I double-click on a .R file in File Explorer the OS gives me the
option of opening the .R in RStudio, or Look for an app in the
Microsoft
Store, or More Apps. Similarly with a right-click.

I would like to associate a .R file with the RGui, not RStudio, thus
when I double-click on a .R file in File Explorer the .R file opens in
the R Editor in RGui.

On my PC R 4.2.2 is located in "C:/Program Files/R/R-4.2.2/etc"

Please can someone provide step-by-step instructions on how to
associate?


thanks,
Amarjit

 [[alternative HTML version deleted]]

__
R-help@r-project.org   mailing list -- To
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help

PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




[[alternative HTML version deleted]]

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

--
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-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] Reading Text files from UK Met Office into R again...

2022-10-12 Thread David Winsemius
First one needs to remove the extraneous line-ends that you created by using an 
editor that inserts those line-ends (or perhaps it was your mail-client that 
added them because you failed to post in plain-text. I removed those files "by 
hand" and then created a text "file".

txt <- "2015-01-01 00:00, 03002, WMO, SYNOP, 1, 12, 1011, 4, 7, 200, 18, 82, , 
, 8, , , , , 100, 450, 1005.4, 5, , 102, 4, , 129, , , , , , , , 8.7, 7.5, 
8.1,1003.6, , , , , , , 1, 1, 1, , , 1, , , , , 1, 1, 1, 1, 1, 1, , 1, , 1, 1, 
, , , , , , , , , 1, , , , , 2014-12-31 23:53, 0, , , , , , , , , , , , K, , , 
, , 91.7, A, , , ,
2015-01-01 00:00, 03005, WMO, SYNOP, 1, 9, 1011, 4, 1, 210, 26, 62, 8, 6, ,8, 
8, , , 8, 30, 700, 1006, 1, 8, 54, 7, 6, 105, , , , , , , , 8.6, 7.3, 8, 996.1, 
, 01, , , , , 1, 1, 1, 1, 1, 1, 1, , , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, , , , , , , , 1, , , , , 2014-12-31 23:55, 0, , , , , , , , , , , , K, , , , 
, 91.7, A, , , 0, 1
2015-01-01 00:00, 03006, WMO, SYNOP, 1, 10, 1011, 4, 6, 210, 23, , , , , , , , 
, , , , , , , , , , , , , , , , , , , , , , , , , , , 1, 1, , , , , , , , , , , 
, , , , , , , , , , , , , , , , , , , , , , , 2014-12-31 23:53, 0, , , , , , , 
, , , , , , , , , , , A, , , ,
2015-01-01 00:00, 03010, WMO, SYNOP, 1, 17, 1011, 4, 6, 230, 21, , , , , , , , 
, , , 1006.1, , , , , , , , , , , , , , 9.4, 6.2, 7.9, , , , , , , , 1, 1, , , 
, , , , , , , , 1, 1, 1, 1, , , , , , , , , , , , , , , , , , , ,"

# Then use `count.fields`
count.fields(file=textConnection(txt))
[1] 104 106 105  81

# So i'm guessing you arbitrarily snipped in the middl of own of the text lines

dat <- read.table(text=txt, sep=",", fill=TRUE, row.names=NULL, head=FALSE)
 str(dat)
'data.frame':   4 obs. of  105 variables:
 $ V1  : chr  "2015-01-01 00:00" "2015-01-01 00:00" "2015-01-01 00:00" 
"2015-01-01 00:00"
 $ V2  : int  3002 3005 3006 3010
 $ V3  : chr  " WMO" " WMO" " WMO" " WMO"
 $ V4  : chr  " SYNOP" " SYNOP" " SYNOP" " SYNOP"
 $ V5  : int  1 1 1 1
 $ V6  : int  12 9 10 17
 $ V7  : int  1011 1011 1011 1011
 $ V8  : int  4 4 4 4
 $ V9  : int  7 1 6 6
 $ V10 : int  200 210 210 230
 $ V11 : int  18 26 23 21
 $ V12 : int  82 62 NA NA
 $ V13 : int  NA 8 NA NA
 $ V14 : int  NA 6 NA NA
 $ V15 : int  8 NA NA NA
 $ V16 : int  NA 8 NA NA
 $ V17 : int  NA 8 NA NA
 $ V18 : logi  NA NA NA NA
 $ V19 : logi  NA NA NA NA
 $ V20 : int  100 8 NA NA
 #snipped about 80 lines ...
 $ V99 : num  91.7 NA NA NA
  [list output truncated]


ALWAYS use a programming editor and always post in plain-text.

-- David.

> On Oct 9, 2022, at 4:50 PM, Ivan Krylov  wrote:
> 
> On Sun, 9 Oct 2022 12:01:27 +0100
> Nick Wray  wrote:
> 
>> Error in read.table("midas_wxhrly_201501-201512.txt", fill = T) :
>>  duplicate 'row.names' are not allowed
> 
> Since you don't pass the `header` argument, I think that the automatic
> header detection is here at play. This is what ?read.table has to say
> about row names:
> 
>>> If there is a header and the first row contains one fewer field than
>>> the number of columns, the first column in the input is used for the
>>> row names.  Otherwise if ‘row.names’ is missing, the rows are
>>> numbered.
> 
> Perhaps the "one fewer field in the header than the number of columns"
> condition is true for files after 2010? I'm too lazy to sign up for a
> CEDA account and I'm not sure I'd be given access to hourly datasets
> anyway.
> 
> If this is the reason for the failure (first column used as rownames()
> and turns out to be non-unique), there's an easy way to fix that:
> 
>>> Using ‘row.names = NULL’ forces row numbering.
> 
> I don't see a header in your example. If there's actually no header
> containing column names, passing `header = FALSE` will both prevent the
> error and avoid eating the first line of the file.
> 
> -- 
> 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-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 steam graph

2022-10-02 Thread David Winsemius
I think you are being dishonest. That code does not appear on hrbrmstr's 
vignette at least in a form that I recognize.


When I run your code from the first posting with all the instances of 
`com_num` replaced by `com_name` and removing the `pointer` entry in dat 
which throws an error when trying to define dat, I get


Error in `group_by()`: ! Must group by variables found in `.data`. ✖ 
Column `com_name` is not found. So I "rewind the process to the point 
where the error is reported and find


dat %>%+ select(year, month, company, share, com_name) %>% + 
tidyr::gather(company, share, -year) # A tibble: 148 × 3 year company 
share1 2018 month 12 2 2019 month 1 3 2019 month 2 4 
2019 month 3 5 2019 month 4 6 2019 month 5 7 2019 month 6 8 2019 month 7 
9 2017 month 1 10 2017 month 2 # … with 138 more rows # ℹ Use `print(n = 
...)` to see more rows So the "gathering" process seems to have removed 
the `com_name` column. Can exit R without saving your workspace and then 
construct a series of R commands that will create a reproducible 
example? -- David.


On 10/2/22 10:03, Tariq Khasiri wrote:
Actually in my main data the column name is com_num ( where 
mistakenly I pasted the sample data here under the com_name ). So, 
when I run the command successfully this is the error shows up -


    ▆
  1. ├─... %>% sg_legend(show = TRUE, label = "Share: ")
  2. ├─streamgraph::sg_legend(., show = TRUE, label = "Share: ")
  3. ├─streamgraph::sg_fill_brewer(., "PuOr")
  4. ├─streamgraph::sg_axis_x(., 0.8)
  5. ├─streamgraph::streamgraph(., "com_num", "n", "year")
  6. │ └─base::data.frame(data)
  7. ├─dplyr::ungroup(.)
  8. ├─dplyr::tally(., wt = share)
  9. ├─dplyr::group_by(., year, com_num)
 10. └─dplyr:::group_by.data.frame(., year, com_num)
 11.   └─dplyr::group_by_prepare(.data, ..., .add = .add, caller_env = 
caller_env())

 12.     └─rlang::abort(bullets, call = error_call)

Any suggestions on how I can fix it ??

On Sun, 2 Oct 2022 at 09:12, David Winsemius  
wrote:


I don’t see a column with the name ‘com_num’, so the error message
makes complete sense.

—
David

Sent from my iPhone

> On Oct 2, 2022, at 5:06 AM, Tariq Khasiri
 wrote:
>
> Hi, i'm trying to create a steamgraph with the following data
by creating a
> unit indicator by combing the year and month. But, I'm getting
error as :
>
> Error in `group_by()`:
> ! Must group by variables found in `.data`.
> ✖ Column `com_num` is not found.
> Run `rlang::last_error()` to see where the error occurred.
>
> ### Packages needed for the code
> devtools::install_github("hrbrmstr/streamgraph")
>
> library(tidyverse)
> library(ggplot2)
> library(dplyr)
> library(steamgraph)
>
> ### Code ( The following code can be found on creator's account
> https://hrbrmstr.github.io/streamgraph/ )
>
> dat %>%
> select(year, month, company, share, com_num) %>%
>  tidyr::gather(company, share, -year) %>%
>  group_by(year, com_num) %>%
>  tally(wt=share) %>%
>  ungroup %>%
>  streamgraph("com_num", "n", "year") %>%
>  sg_axis_x(0.8) %>%
>  sg_fill_brewer("PuOr") %>%
>  sg_legend(show=TRUE, label="Share: ")
>
>
> ### data is like the following
>
> dput(dat)
> structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019,
> 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017,
> 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
> 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12,
> 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company =
c("ABC",
> "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH"
> ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55,
> 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53,
> 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1,
> 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,

Re: [R] Help with steam graph

2022-10-02 Thread David Winsemius
I don’t see a column with the name ‘com_num’, so the error message makes 
complete sense. 

— 
David

Sent from my iPhone

> On Oct 2, 2022, at 5:06 AM, Tariq Khasiri  wrote:
> 
> Hi, i'm trying to create a steamgraph with the following data by creating a
> unit indicator by combing the year and month. But, I'm getting error as :
> 
> Error in `group_by()`:
> ! Must group by variables found in `.data`.
> ✖ Column `com_num` is not found.
> Run `rlang::last_error()` to see where the error occurred.
> 
> ### Packages needed for the code
> devtools::install_github("hrbrmstr/streamgraph")
> 
> library(tidyverse)
> library(ggplot2)
> library(dplyr)
> library(steamgraph)
> 
> ### Code ( The following code can be found on creator's account
> https://hrbrmstr.github.io/streamgraph/  )
> 
> dat %>%
> select(year, month, company, share, com_num) %>%
>  tidyr::gather(company, share, -year) %>%
>  group_by(year, com_num) %>%
>  tally(wt=share) %>%
>  ungroup %>%
>  streamgraph("com_num", "n", "year") %>%
>  sg_axis_x(0.8) %>%
>  sg_fill_brewer("PuOr") %>%
>  sg_legend(show=TRUE, label="Share: ")
> 
> 
> ### data is like the following
> 
> dput(dat)
> structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019,
> 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017,
> 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
> 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019), month = c(12,
> 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5), company = c("ABC",
> "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH",
> "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH", "FGH"
> ), share = c(20, 16.5, 15, 15.5, 15.5, 16, 17, 16.5, 61, 55,
> 53, 53, 54, 53, 58, 54, 50, 47, 55, 50, 52, 51, 51.5, 52, 53,
> 54, 55, 53, 54, 50, 42, 48, 41, 40, 39, 36.5, 35), com_name = c(1,
> 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), row.names = c(NA,
> -37L), spec = structure(list(cols = list(year = structure(list(), class =
> c("collector_double",
> "collector")), month = structure(list(), class = c("collector_double",
> "collector")), company = structure(list(), class = c("collector_character",
> "collector")), share = structure(list(), class = c("collector_double",
> "collector")), com_name = structure(list(), class = c("collector_double",
> "collector"))), default = structure(list(), class = c("collector_guess",
> "collector")), delim = ","), class = "col_spec"), problems =  0x7fd732028680>, class = c("spec_tbl_df",
> "tbl_df", "tbl", "data.frame"))
> 
>[[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] Interpreting fa.diagram from package psych

2022-09-11 Thread David Winsemius



On 9/11/22 07:17, Ebert,Timothy Aaron wrote:

It is a bad graphic as the legend that should explain the color coding is 
missing. The next option is to copy the data and code and see if you can 
reproduce the figure. You can then play with the code and read a bit about the 
procedures to figure out what is going on. It should not be too hard. My guess 
is that there is some additional variable with three states that is being used. 
If this were the iris data set I would guess it was the three species: setosa, 
versicolor, and virginica.


Pretty sure that guess is incorrect.

I'm not sure there should be a legend. The colors just indicate group 
membership derived from a mathematical process that has attempted to 
separate case into distinct groups that maximize the correlations within 
individual groupings. And therefore maximizes the distance separating 
the groups. The number of groups is specified in the function call. You 
should go to the earlier results and see if you can construct the 
groupings to maximize internal correlations. Psychometricians do this 
when they don't really have a theoretical basis for doing classification 
and are asking the data do it for them. If they are doing this on a 
questionnaire dataset, they often go back to the specific 
questions/answer pairings within groupings and try to assign meaning to 
them.  They then build post-hoc explanations and often do further 
studies to see if they can replicate the results and achieve some sort 
of stable synthetic construct.  It's a rather theory-free strategy and 
so trying to assign labels automatically would be difficult.


--

David


Tim

-Original Message-
From: R-help  On Behalf Of Luigi Marongiu
Sent: Sunday, September 11, 2022 3:02 AM
To: David Winsemius 
Cc: r-help 
Subject: Re: [R] Interpreting fa.diagram from package psych

[External Email]

Sorry, the file was automatically downloaded and opened with the browser 
instead of pointing to the webpage.
Here is a better link:
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran.r-project.org%2Fweb%2Fpackages%2FpsychTools%2Fvignettes%2Ffactor.pdfdata=05%7C01%7Ctebert%40ufl.edu%7C9d0e49ff1aab4d5db2d308da93c3ac01%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637984765998607455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=2OxukCvxcx9xFJQiAInt2ulqC23qiBjQRPU128O%2Bjn8%3Dreserved=0
The figure is on page 22.
The question is: The dots have different colors; how do I know what they 
represent?
Is there a way to show an auto-legend?
Thank you

On Sat, Sep 10, 2022 at 11:33 PM David Winsemius  wrote:


On 9/10/22 14:08, Luigi Marongiu wrote:

Hello,
I have plotted data from exploratory factor analysis, and I got a
graph similar to FIGURE 11 (PAGE 36) of this link
file:///home/gigiux/Downloads/An_overview_of_the_psych_package.pdf

This appears to be a link you a file on your personal device rather
than an attachment.

How do I interpret the figure? In particular, how do I know what the
colors represent?
Thank you


--
Best regards,
Luigi

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7C9d0e49ff1aab4d5db2d308da93c3ac01%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637984765998607455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=KfsnfNKp3klZMJcvvuPD4gqI6fffn95FkpaPm8KyEnA%3Dreserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%7C9d0e49ff1aab4d5db2d308da93c3ac01%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637984765998607455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=7CZst6A76lzHADI4iRNJ%2FVI2%2FMOGLCAVnTL8aRLNjVA%3Dreserved=0
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] confidence intervals

2022-09-08 Thread David Winsemius
The first article had no code and did not describe a formula that I could find 
which matched your code. The second article is behind a paywall. 

— 
David. 

Sent from my iPhone

> On Sep 3, 2022, at 3:39 PM, Bogdan Tanasa  wrote:
> 
> 
> Dear Aaron, David, and everyone,
> 
> Thank you again for your comments on my question related to the confidence 
> intervals. I am sorry for the late reply. 
> 
> The definition of the 95 confidence intervals where our discussion originates 
> from has been proposed by the authors of these two articles (I am including 
> the links to the articles just to show that the formula has been published in 
> a methods article a while ago; the articles are in the field of biology 
> though, where not too many of you are part of, I guess). These authors have 
> written the scripts and they have made those available on github. I have 
> asked a while ago the authors why they have chosen this formula, however, I 
> have not received any reply. In any case, at this moment I will use the 
> mathematical formulas described in the articles :
> 
> https://www.cell.com/molecular-cell/fulltext/S1097-2765(15)00304-4
> 
> https://www.nature.com/articles/s41596-019-0218-7
> 
> Wishing everyone a good weekend, 
> 
> Bogdan
> 
> 
> 
>> On Sun, Aug 28, 2022 at 6:53 PM Ebert,Timothy Aaron  wrote:
>> I have a general dislike of "analysis emergencies." I would like to see a 
>> data emergency wherein someone must cram 3 years of data collection into 18 
>> months so that they have time to work out the correct analysis. I am sure 
>> others would suggest working out how analyze the data before starting the 
>> experiment.
>> 
>> Our business office gives this advice to faculty members: An emergency on 
>> your part is not an emergency on our part. 
>> 
>> How about starting by answering the questions posted by the people you are 
>> hoping will help. Focus on David's middle paragraph. However, if you can 
>> re-code everything to work, then it would seem that you already know the 
>> answer and it might be simpler/faster to write the correct code.
>> 
>> You might spend some time looking for a scientific paper that uses that 
>> equation for the confidence interval and thereby get some context to explain 
>> why the equation is correct.
>> 
>> Tim
>> 
>> -Original Message-
>> From: R-help  On Behalf Of Bogdan Tanasa
>> Sent: Sunday, August 28, 2022 8:55 PM
>> To: David Winsemius 
>> Cc: r-help 
>> Subject: Re: [R] confidence intervals
>> 
>> [External Email]
>> 
>> Hi David,
>> 
>> Thank you for your comments, and feed-back message. I am very happy to learn 
>> from the experience of the people on R mailing list, and without any doubt, 
>> I am very thankful to you and to everyone for sharing their knowledge. I do 
>> apologize for any confusion that I have created unwillingly with my previous 
>> email.
>> 
>> About my previous email related to the confidence intervals: indeed I have 
>> posted the question with a detailed description on stackoverflow, and the 
>> link is listed below.
>> 
>> I have to admit that I have been in rush willing to have the suggestions of 
>> R-help members by Monday (if that would have been possible), as I have to 
>> make a decision at the beginning of this week on whether I need to re-code 
>> the shell script in R. I have a deadline on Wed. The script itself is less 
>> important per se, I have included it just to point our the origin of my 
>> question.
>> 
>> I do certainly respect the principles of online R-help community, and I 
>> would very much appreciate if I could have your advice on the following :
>> shall a "R code related emergency" arise, would it be acceptable to post the 
>> question on stackoverflow with the corresponding data tables and detailed 
>> code, and to refer the posting on R-help mailing list ?
>> 
>> If it is acceptable at least for a single email, and if you do not mind, I 
>> could mention the link to stackoverflow, inviting our members to read it, 
>> shall they be comfortable with this topic.
>> 
>> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F73507697%2Fconfidence-intervals-of-a-biological-assay%3Fnoredirect%3D1%23comment129816241_73507697data=05%7C01%7Ctebert%40ufl.edu%7C0ba5d535471b46c05ec508da89592c20%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637973313343894313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Cs

Re: [R] About spDataLarge Package

2022-08-29 Thread David Winsemius



On 8/29/22 09:30, Paul Bernal wrote:

Dear friends,

I have just installed R version 4.2.1 for Windows on my machine, and was
trying to install package spDataLarge, but the console threw the following
error message:

Warning in install.packages :
   package 'spDataLarge' is not available for this version of R

A version of this package for your version of R might be available
elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

I used the following command to try to install it:

install.packages("spDataLarge", repos = "https://nowosad.github.io/drat/;,
type = "source")



I'm on a Linux box and I get no difficulty using:

install.packages("spDataLarge",repos  =  "https://nowosad.github.io/drat/",type  =  
"source")

That was the third of three options on its webpage at:

https://github.com/Nowosad/spDataLarge


There is an "issue" from Roger Bivand regarding the need for 
type="source: https://github.com/Nowosad/spDataLarge/issues/24


It would seem that `type="source"` might be superfluous since the 
package does not require compilation. At any rate there are two other 
options at that page and you might want to investigate them.



--

David.


I tried with earlier versions of R (4.2.0 and 4.0.3) but I keep getting the
same error. I was searching to see if I could obtain information regarding
the R version or versions that support this package, but haven't found
anything thus far.

Any suggestions on how to successfully install this package?

Something odd is that I was able to install package spData, but not
spDataLarge (in R version 4.2.1)

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.


__
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] confidence intervals

2022-08-27 Thread David Winsemius
You cross-posted this to StackOverflow and did not say so.  ... and you 
posted in HTML Bad dog squared. I cast one of the close votes on SO, but 
here I can only say ... READ the Posting Guide.


You also give no citation other than someone's Github files with minimal 
comments in that material. You should indicate whether this code has any 
solid support. Why do you think this code is something to depend upon?


After all, you been posting questions on R-help for several months. 
Don't you think you should make a good faith effort to understand the 
principles underlying this resource?



--

David.

On 8/26/22 17:55, Bogdan Tanasa wrote:

Dear all,

Although I know that it is not a statistics mailing list, given my work on
ICeChIP

https://github.com/shah-rohan/icechip/blob/master/Scripts/computeHMDandError

I would appreciate to have the answer to a question :

given two variables a and b (a and b can have 1000 paired-values) and a
calibration number "cal",

why the 95 confidence interval has been calculated as such for each value
a(i) and b(i) :

100 / cal * sqrt (( a/ (b^2) + (a^2) / (b ^3)) * 1.96

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.


Re: [R] Predicted values from glm() when linear predictor is NA.

2022-07-27 Thread David Winsemius



On 7/27/22 17:26, Rolf Turner wrote:

I have a data frame with a numeric ("TrtTime") and a categorical
("Lifestage") predictor.

Level "L1" of Lifestage occurs only with a single value of TrtTime,
explicitly 12, whence it is not possible to estimate a TrtTime "slope"
when Lifestage is "L1".

Indeed, when I fitted the model

 fit <- glm(cbind(Dead,Alive) ~ TrtTime*Lifestage, family=binomial,
data=demoDat)

I got:


as.matrix(coef(fit))
   [,1]
(Intercept)-0.91718302
TrtTime 0.88846195
LifestageEgg + L1 -45.36420974
LifestageL114.27570572
LifestageL1 + L2   -0.30332697
LifestageL3-3.58672631
TrtTime:LifestageEgg + L1   8.10482459
TrtTime:LifestageL1 NA
TrtTime:LifestageL1 + L20.05662651
TrtTime:LifestageL3 1.66743472

That is, TrtTime:LifestageL1 is NA, as expected.

I would have thought that fitted or predicted values corresponding to
Lifestage = "L1" would thereby be NA, but this is not the case:


predict(fit)[demoDat$Lifestage=="L1"]
   26   65  131
24.02007 24.02007 24.02007

fitted(fit)[demoDat$Lifestage=="L1"]
  26  65 131
   1   1   1

That is, the predicted values on the scale of the linear predictor are
large and positive, rather than being NA.

What this amounts to, it seems to me, is saying that if the linear
predictor in a Binomial glm is NA, then "success" is a certainty.
This strikes me as being a dubious proposition.  My gut feeling is that
misleading results could be produced.


The NA is most likely caused by aliasing, so some other combination of 
factors a perfect surrogate for every case with that level of the 
interaction. The `predict.glm` function always requires a complete set 
of values to construct a case. Whether apparent incremental linear 
prediction of that interaction term is large or small will depend on the 
degree of independent contribution of the surrogate levels of other 
variables..



David.



Can anyone explain to me a rationale for this behaviour pattern?
Is there some justification for it that I am not currently seeing?
Any other comments?  (Please omit comments to the effect of "You are as
thick as two short planks!". :-) )

I have attached the example data set in a file "demoDat.txt", should
anyone want to experiment with it.  The file was created using dput() so
you should access it (if you wish to do so) via something like

 demoDat <- dget("demoDat.txt")

Thanks for any enlightenment.

cheers,

Rolf Turner


__
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] Does the function "c" have a character limit?

2022-07-13 Thread David Winsemius


On 7/12/22 23:26, David Winsemius wrote:

I think the restriction is not specific to `c` but rather is a limitation on 
the length of expressions. My foggy memory is that the limit is in the 450-500 
character vicinity. Pretty sure it’s been discussed here in the past.



One way to get around this limitation is to create a .r file and source 
the material. I just tested with your code and it succeeded.



--

David.



—
David.

Sent from my iPhone


On Jul 12, 2022, at 11:13 PM, core_contingency  wrote:

To Whom it May Concern,

I am creating a vector with the base R function "c", with many arguments as 
shown below:

  $ R
  > MES = c("A2M", "ABRACL", "ACADVL", "ACAP2", "ACTA2", "ACTN1", "ADAM19", "ADAM9", "ADAMTS5", "ADGRE5", "ADGRG6", "AEBP1", "AJUBA", "ALDH1A3", "AMMECR1", "ANTXR1", "ANXA1", "ANXA2", "ANXA5", "ANXA6", "APOE", "APP", "ARHGAP1", "ARHGEF40", "ARL1", "ARL4A", "ARMCX2", "ARPC1B", "ASPH", "ATP10D", "ATP1B1", "ATP2B1", "ATP2B4", "ATP6V0E1", "ATP8B2", "ATXN1", "B2M", "BAG3", "BGN", "BMP5", "BNC2", "BOC", "BTN3A2", "C1orf198", "C1orf54", "C4orf32", "C6orf120", "CALD1", "CALU", "CAPN2", "CAPN6", "CBFB", "CBLB", "CCDC80", "CD164", "CD44", "CD59", "CD63", "CDH11", "CETN2", "CFH", "CFI", "CILP", "CKAP4", "CLIC4", "CMTM3", "CMTM6", "CNN3", "COL11A1", "COL12A1", "COL1A1", "COL27A1", "COL3A1", "COL4A1", "COL4A2", "COL5A1", "COL5A2", "COL6A1", "COL6A2", "COL6A3", "COPA", "CPED1", "CPS1", "CRABP2", "CREB3L2", "CREG1", "CRELD2", "CRISPLD1", "CRTAP", "CSRP1", "CTDSP2", "CTNNA1", "CTSB", "CTSC", "CTSO", "CXCL12", "CYBRD1", "CYFIP1", "CYP26A1", "CYR61", "DCAF6", "DDOST", "DDR2", "DESI2", "DKK3", "DLC1", "DLX1", "DLX2", "DMD", "DNAJC1", "DNAJC10", "DNAJC3", "DNM3OS", "DPY19L1", "DSE", "DUSP14", "DUSP5", "DUSP6", "EDEM1", "EDNRA", "EFEMP2", "EGFR", "EGR1", "EGR3", "EHD2", "ELAVL1", "ELF1", "ELK3", "ELK4", "EMILIN1", "EMP1", "ENAH", "EPHA3", "EPS8", "ERBIN", "ERLIN1", "ERRFI1", "ETS1", "EVA1A", "EXT1", "EXTL2", "F2R", "F2RL2", "FAM102B", "FAM114A1", "FAM120A", "FAM129A", "FAM3C", "FAM43A", "FAM46A", "FAT1", "FBN1", "FBN2", "FGFR1", "FIBIN", "FILIP1L", "FKBP14", "FLNA", "FLRT2", "FMOD", "FN1", "FNDC3B", "FSTL1", "FUCA2", "FZD1", "FZD2", "FZD7", "GABRR1", "GALNT10", "GAS1", "GAS2", "GDF15", "GJA1", "GNAI1", "GNG12", "GNS", "GORAB", "GPC6", "GPR137B", "GPX8", "GRN", "GSN", "HES1", "HEXB", "HIBADH", "HIPK3", "HIST1H2AC", "HIST1H2BK", "HLA-A", "HLA-B", "HLA-C", "HLA-F", "HLX", "HNMT", "HOMER1", "HS3ST3A1", "HSP90B1", "HSPA5", "HSPB1", "HTRA1", "HYOU1", "ID1", "ID3", "IFI16", "IFITM2", "IFITM3", "IGF2R", "IGFBP5", "IGFBP6", "IL13RA1", "IL6ST", "INSIG1", "IQGAP2", "ITGA10", "ITGA4", "ITGAV", "ITGB1", "ITM2B", "ITM2C", "ITPR1", "ITPRIPL2", "JAK1", "JAM3", "KANK2", "KCNK2", "KCT

Re: [R] Does the function "c" have a character limit?

2022-07-13 Thread David Winsemius
I think the restriction is not specific to `c` but rather is a limitation on 
the length of expressions. My foggy memory is that the limit is in the 450-500 
character vicinity. Pretty sure it’s been discussed here in the past. 

— 
David. 

Sent from my iPhone

> On Jul 12, 2022, at 11:13 PM, core_contingency  wrote:
> 
> To Whom it May Concern,
> 
> I am creating a vector with the base R function "c", with many arguments as 
> shown below:
> 
>  $ R
>  > MES = c("A2M", "ABRACL", "ACADVL", "ACAP2", "ACTA2", "ACTN1", 
> "ADAM19", "ADAM9", "ADAMTS5", "ADGRE5", "ADGRG6", "AEBP1", "AJUBA", 
> "ALDH1A3", "AMMECR1", "ANTXR1", "ANXA1", "ANXA2", "ANXA5", "ANXA6", "APOE", 
> "APP", "ARHGAP1", "ARHGEF40", "ARL1", "ARL4A", "ARMCX2", "ARPC1B", "ASPH", 
> "ATP10D", "ATP1B1", "ATP2B1", "ATP2B4", "ATP6V0E1", "ATP8B2", "ATXN1", "B2M", 
> "BAG3", "BGN", "BMP5", "BNC2", "BOC", "BTN3A2", "C1orf198", "C1orf54", 
> "C4orf32", "C6orf120", "CALD1", "CALU", "CAPN2", "CAPN6", "CBFB", "CBLB", 
> "CCDC80", "CD164", "CD44", "CD59", "CD63", "CDH11", "CETN2", "CFH", "CFI", 
> "CILP", "CKAP4", "CLIC4", "CMTM3", "CMTM6", "CNN3", "COL11A1", "COL12A1", 
> "COL1A1", "COL27A1", "COL3A1", "COL4A1", "COL4A2", "COL5A1", "COL5A2", 
> "COL6A1", "COL6A2", "COL6A3", "COPA", "CPED1", "CPS1", "CRABP2", "CREB3L2", 
> "CREG1", "CRELD2", "CRISPLD1", "CRTAP", "CSRP1", "CTDSP2", "CTNNA1", "CTSB", 
> "CTSC", "CTSO", "CXCL12", "CYBRD1", "CYFIP1", "CYP26A1", "CYR61", "DCAF6", 
> "DDOST", "DDR2", "DESI2", "DKK3", "DLC1", "DLX1", "DLX2", "DMD", "DNAJC1", 
> "DNAJC10", "DNAJC3", "DNM3OS", "DPY19L1", "DSE", "DUSP14", "DUSP5", "DUSP6", 
> "EDEM1", "EDNRA", "EFEMP2", "EGFR", "EGR1", "EGR3", "EHD2", "ELAVL1", "ELF1", 
> "ELK3", "ELK4", "EMILIN1", "EMP1", "ENAH", "EPHA3", "EPS8", "ERBIN", 
> "ERLIN1", "ERRFI1", "ETS1", "EVA1A", "EXT1", "EXTL2", "F2R", "F2RL2", 
> "FAM102B", "FAM114A1", "FAM120A", "FAM129A", "FAM3C", "FAM43A", "FAM46A", 
> "FAT1", "FBN1", "FBN2", "FGFR1", "FIBIN", "FILIP1L", "FKBP14", "FLNA", 
> "FLRT2", "FMOD", "FN1", "FNDC3B", "FSTL1", "FUCA2", "FZD1", "FZD2", "FZD7", 
> "GABRR1", "GALNT10", "GAS1", "GAS2", "GDF15", "GJA1", "GNAI1", "GNG12", 
> "GNS", "GORAB", "GPC6", "GPR137B", "GPX8", "GRN", "GSN", "HES1", "HEXB", 
> "HIBADH", "HIPK3", "HIST1H2AC", "HIST1H2BK", "HLA-A", "HLA-B", "HLA-C", 
> "HLA-F", "HLX", "HNMT", "HOMER1", "HS3ST3A1", "HSP90B1", "HSPA5", "HSPB1", 
> "HTRA1", "HYOU1", "ID1", "ID3", "IFI16", "IFITM2", "IFITM3", "IGF2R", 
> "IGFBP5", "IGFBP6", "IL13RA1", "IL6ST", "INSIG1", "IQGAP2", "ITGA10", 
> "ITGA4", "ITGAV", "ITGB1", "ITM2B", "ITM2C", "ITPR1", "ITPRIPL2", "JAK1", 
> "JAM3", "KANK2", "KCNK2", "KCTD12", "KDELC2", "KDELR2", "KDELR3", "KDM5B", 
> "KIAA1462", "KIF13A", "KIRREL", "KLF10", "KLF4", "KLF6", "L3HYPDH", "LAMB1", 
> "LAMC1", "LAMP1", "LAPTM4A", "LASP1", "LATS2", "LEPROT", "LGALS1", "LHFP", 
> "LHX8", "LIFR", "LIPA", "LITAF", "LIX1L", "LMAN1", "LMNA", "LOXL2", "LPP", 
> "LRP10", "LRRC17", "LRRC8C", "LTBP1", "LUZP1", "MAGT1", "MAML2", "MAN2A1", 
> "MANF", "MBD2", "MBNL1", "MBTPS1", "MEOX1", "MEOX2", "MEST", "MGAT2", "MGP", 
> "MGST1", "MICAL2", "MMP2", "MOB1A", "MRC2", "MXRA5", "MYADM", "MYDGF", 
> "MYL12A", "MYL12B", "MYLIP", "NANS", "NBR1", "NEK7", "NES", "NFIA", "NFIC", 
> "NID1", "NID2", "NOTCH2", "NOTCH2NL", "NPC2", "NPTN", "NQO1", "NR3C1", 
> "NRP1", "OGFRL1", "OLFML2A", "OLFML2B", "OLFML3", "OSTC", "P4HA1", "PALLD", 
> "PAPSS2", "PCDH18", "PCOLCE2", "PCSK5", "PDE3A", "PDE7B", "PDGFC", "PDIA3", 
> "PDIA4", "PDIA6", "PDLIM1", "PEA15", "PEAK1", "PHLDA3", "PHLDB2", "PHTF2", 
> "PIAS3", "PLAGL1", "PLEKHA2", "PLEKHH2", "PLK2", "PLOD2", "PLOD3", "PLPP1", 
> "PLS3", "PLSCR1", "PLSCR4", "PLXDC2", "POLR2L", "PON2", "POSTN", "PPIB", 
> "PPIC", "PPT1", "PRCP", "PRDM6", "PRDX4", "PRDX6", "PROM1", "PRRX1", "PTBP1", 
> "PTGER4", "PTGFRN", "PTN", "PTPN14", "PTPRG", "PTPRK", "PTRF", "PXDC1", 
> "PXDN", "PYGL", "QKI", "QSOX1", "RAB13", "RAB29", "RAB31", "RAP1A", "RAP1B", 
> "RBMS1", "RCN1", "RECK", "REST", "RGL1", "RGS10", "RGS3", "RHOC", "RHOJ", 
> "RIN2", "RIT1", "RNFT1", "RNH1", "ROBO1", "ROR1", "RRBP1", "S1PR3", "SASH1", 
> "SCPEP1", "SCRG1", "SDC2", "SDC4", "SDCBP", "SDF4", "SEC14L1", "SEL1L3", 
> "SEMA3C", "SEMA3F", "SEPT10", "SERPINE2", "SERPINH1", "SFT2D1", "SFT2D2", 
> "SGK1", "SH3BGRL", "SHC1", "SHROOM3", "SIX1", "SIX4", "SKIL", "SLC16A4", 
> "SLC30A1", "SLC30A7", "SLC35F5", "SLC38A2", "SLC38A6", "SLC39A14", "SMAD3", 
> "SNAI2", "SNAP23", "SOSTDC1", "SOX9", "SPARC", "SPARCL1", "SPATA20", "SPCS3", 
> "SPRED1", "SPRY1", "SPRY4", "SPRY4-IT1", "SQSTM1", "SRPX", "SSBP4", "SSR1", 
> "SSR3", "STAT1", "STAT3", "STEAP1", "STK38L", "SUCLG2", "SURF4", "SVIL", 
> "SYDE1", "SYNJ2", "SYPL1", "TCF7L2", "TFE3", "TFPI", "TGFB1I1", "TGFBR2", 
> "THBS1", "TIMP1", "TJP1")
>  +
> 
> For some reason, the R console does not display a ">" symbol, indicating that 
> it has completed the function, but displays a "+" symbol instead, which 
> indicates that the function is still waiting for more input. However, I 
> believe that my 

Re: [R] printing with bothe print and cat...

2022-07-09 Thread David Winsemius
If spaces needed. In first sequences then 

paste( 1:5, collapse=“ “)

Sent from my iPhone

> On Jul 9, 2022, at 9:59 AM, David Winsemius  wrote:
> 
> Skip the for loops:
> 
> cat(paste( seq(1:5), ““, 1:5) )
> 
> — 
> David
> 
> Sent from my iPhone
> 
>> On Jul 9, 2022, at 9:47 AM, akshay kulkarni  wrote:
>> 
>> Dear members,
>>I have the following code:
>> 
>> testprint <- function() {
>> 
>> for(i in 1:5) {for(j in 1:5)
>> {cat(j)}
>>   print(i)}
>> }
>> 
>> And the output is:
>> 
>>> testprint()
>> 12345[1] 1
>> 12345[1] 2
>> 12345[1] 3
>> 12345[1] 4
>> 12345[1] 5
>> 
>> Any idea on how to remove the [1] from the output, and give spaces in the 
>> cat output? The desired output is:
>> 
>> 1 2 3 4 5  1
>> 1 2 3 4 5  2
>> 1 2 3 4 5  3
>> 1 2 3 4 5  4
>> 1 2 3 4 5  5
>> Many thanks in advance.
>> 
>> THanking you,
>> Yours  sincreely,
>> AKSHAY M KULKARNI
>> 
>>   [[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] printing with bothe print and cat...

2022-07-09 Thread David Winsemius
Skip the for loops:

cat(paste( seq(1:5), ““, 1:5) )

— 
David

Sent from my iPhone

> On Jul 9, 2022, at 9:47 AM, akshay kulkarni  wrote:
> 
> Dear members,
> I have the following code:
> 
> testprint <- function() {
> 
>  for(i in 1:5) {for(j in 1:5)
>  {cat(j)}
>print(i)}
> }
> 
> And the output is:
> 
>> testprint()
> 12345[1] 1
> 12345[1] 2
> 12345[1] 3
> 12345[1] 4
> 12345[1] 5
> 
> Any idea on how to remove the [1] from the output, and give spaces in the cat 
> output? The desired output is:
> 
> 1 2 3 4 5  1
> 1 2 3 4 5  2
> 1 2 3 4 5  3
> 1 2 3 4 5  4
> 1 2 3 4 5  5
> Many thanks in advance.
> 
> THanking you,
> Yours  sincreely,
> AKSHAY M KULKARNI
> 
>[[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] if zlib version >= 1.2.5... no

2022-05-30 Thread David Winsemius
Pasting a prior posted thread on the R-Mac list:

Ah, well, I see now that libR.dylib was not built or linked in
tools.so simply because I had not configured with --enable-R-shlib
... 'make' succeeds but only when I build R as a shared library.

The dlopen error isn't seen in the nightly builds, which also use
--enable-R-shlib. It would be good to know if others are able to
reproduce the error when configuring in the _default_ way, i.e.,
without --enable-R-shlib.

Mikael

> On 2022-02-10 4:30 pm, Mikael Jagan wrote:
>> On 2022-02-10 1:42 pm, Mikael Jagan wrote:
>> It seems my first message to mailing list, which had all of the attachments,
>> was caught in the spam filter. In case it helps, I've dumped the config.site,
>> config.log, and build.out on GitHub:
>> 
>> https://github.com/jaganmn/attachments/tree/6a7257014792f5e8cf7bb0bcd3bb27c7fabf7577/r-sig-mac/2022-02-10
>>  
>> 
>>> On 2022-02-10 1:11 pm, Prof Brian Ripley wrote:
 On 10/02/2022 17:28, Mikael Jagan wrote:
 Oops - forgot to mention: I am trying to build R-devel, currently at 
 r81706.
 
 Mikael
 
> On 2022-02-10 12:13 pm, Mikael Jagan wrote:
> Hello,
> 
> I am running Big Sur on an M1 Mac and trying to build R from sources.
> Some system details:
> 
> R> sessionInfo()
>  > Platform: aarch64-apple-darwin20 (64-bit)
>  > Running under: macOS Big Sur 11.6.3
> 
> $ clang --version
>  > Apple clang version 13.0.0 (clang-1300.0.29.30)
>  > Target: arm64-apple-darwin20.6.0
> 
> $ /opt/R/arm64/gfortran/bin/gfortran --version
>  > GNU Fortran (GCC) 11.0.0 20201219 (experimental)
> 
> It has been a few months since I last built R on this machine.
> At the time, I was building with LLVM clang rather than Apple clang
> to obtain OpenMP support. I was recently nudged about the OpenMP
> runtime library made available here:
> 
> https://mac.r-project.org/openmp/
> 
> which would allow me to build "normally" with Apple clang.
> I am trying now to make the switch.
> 
> I have installed all of the binaries hosted here
> 
> https://mac.r-project.org/bin/darwin20/arm64/
> 
> rather than those hosted here
> 
> https://mac.r-project.org/libs-arm64/
> 
> which I had previously installed. (Though: the first URL is missing
> binaries for gfortran, pandoc, tcl, tk, and tkTable. I obtained
> these from the second URL. _Both_ URLs are missing a zlib binary,
> so I reluctantly obtained zlib from Homebrew.)
>>> 
>>> zlib is part of the OS.  For pkg-config you need the zlib stub available 
>>> from https://mac.r-project.org/libs-4/.  That *is* in the R-admin manual.  
>>> Also, that tcl, tk, and tkTable can be installed as part of an R binary 
>>> installation.
>> 
>> Thanks - I wasn't sure whether that zlib stub was suitable for my system.
>> 
>>> 
>>> For pandoc I use the official Intel builds under emulation without any 
>>> problems (including checking all of CRAN).  But you don't need pandoc to 
>>> build R.
>>> 
>>> I understand that the transition to https://mac.r-project.org/bin is work 
>>> in progress, but its newer versions of libs are preferred.
>>> 
> 
> Anyway, I'm running into trouble now... I have attached my
> config.site, config.log, and build.out (from 'make >&') ...
> config.log seems completely normal, but in build.out I see
> many linker warnings of the form
> 
>  > ld: warning: could not create compact unwind for _dchdc_: registers 72 
> and 73 not saved contiguously in frame
>  > ld: warning: could not create compact unwind for _dpoco_: registers 72 
> and 73 not saved contiguously in frame
>  > ld: warning: object file (/opt/R/arm64/lib/libreadline.a(history.o)) 
> was built for newer macOS version (20.0) than being linked (11.0)
>  > ld: warning: object file 
> (/opt/R/arm64/lib/liblzma.a(liblzma_la-alone_decoder.o)) was built for 
> newer macOS version (20.0) than being linked (11.0)
>>> 
>>> Hmm, that's about a binary liblzma.  I'd download again (maybe try both 
>>> sites), and if it is still wrong, build from the sources.
>> If you search build.out, you'll find that this warning is issued
>> for _every_ binary obtained from
>> 
>> https://mac.r-project.org/bin/darwin20/arm64/
>> 
>> I'll try the old site again.
> Reverting to the old binaries resolves all of the version mismatch warnings,
> so perhaps there is just a glitch in the way the new binaries were built.
>> 
> And the build eventually fails for a seemingly unrelated
> reason:
> 
>  > clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names 
> -undefined dynamic_lookup -single_module -multiply_defined suppress 
> -falign-functions=64 -g -O2 -Wall -pedantic 
> -Wno-implicit-function-declaration -flto=thin -fPIC -Wl,-mllvm,-threads=4 
> -L/opt/homebrew/opt/zlib/lib -L/opt/R/arm64/lib -L/usr/local/lib -lomp -o 

Re: [R] Suggestions as to how to proceed would be appreciated...............

2022-05-22 Thread David Winsemius
There are several CRAN Task Views. Some of them should intersect with your 
question. I don’t think your description of the problem suggest that 
multivariate correlation is the best approach.  Some sort of optimization or 
numerical simulation would seem to be more fruitful.

— 
David 
Sent from my iPhone

> On May 22, 2022, at 12:01 PM, Bernard Comcast  
> wrote:
> 
> Its simply a query to know what tools/packages R has for correlating single 
> values with multivalued vectors. If that is outside the scope of the PG then 
> so be it.
> 
> Bernard
> 
> Sent from my iPhone so please excuse the spelling!"
> 
>> On May 22, 2022, at 1:52 PM, Bert Gunter  wrote:
>> 
>> 
>> Please read the posting guide(PG) inked below. Your query sounds more like a 
>> project that requires a paid consultant; if so, this is way beyond the scope 
>> of this list as described in the PG. So don't be too surprised if you don't 
>> get a useful response, which this isn't either of course.
>> 
>> 
>> 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 Sun, May 22, 2022 at 10:40 AM Bernard McGarvey 
  wrote:
>>> I work in aspects of Cold Chain transportation in the pharmaceutical 
>>> industry. These shippers are used to transport temperature sensitive 
>>> products by surrounding the product load box with insulating materials of 
>>> various sorts. The product temperature has lower and upper allowed limits 
>>> so that when the product temperature hits one of these limits, the shipper 
>>> fails and this failure time is teh shipper duration. If the shipper is 
>>> exposed to very low or very high ambient temperatures during a shipment 
>>> then we expect the duration of the shipper to be low.
>>> 
>>> The particular problem I am currently undertaking is to create a fast way 
>>> to predict the duration of a shipping container when it is exposed to a 
>>> given ambient temperature.
>>> 
>>> Currently we have the ability to predict such durations using a calibrated 
>>> 3D model (typically a finite element or finite volume transient 
>>> representation of the heat transfer equations). These models can predict 
>>> the temperature of the pharmaceutical product within the shipper over time 
>>> as it is exposed to an external ambient temperature profile. .
>>> 
>>> The problem with the 3D model is that it takes significant CPU time and the 
>>> software is specialized. What I would like to do is to be able to enter the 
>>> ambient profile into a spreadsheet and then be able to predict the expected 
>>> duration of the shipper using a simple calculation that can be implemented 
>>> in the spreadsheet environment. The idea I had was as follows:
>>> 
>>> 1. Create a selection of ambient temperature profiles covering a wide range 
>>> of ambient behavior. Ensure the profiles are long enough so that the 
>>> shipper is sure to fail at some time during the ambient profile.
>>> 
>>> 2. Use the 3D model to predict the shipper duration for the selection of 
>>> ambient temperature profiles in (1). Each ambient temperature will have its 
>>> own duration.
>>> 
>>> 3. Since only the ambient temperatures up to the duration time are 
>>> relevant, truncate each ambient profile for times greater than the duration.
>>> 
>>> 4. Step (3) means that the ambient temperature profiles will have different 
>>> lengths corresponding to the different durations.
>>> 
>>> 5. Use the truncated ambient profiles and their corresponding durations to 
>>> build some type of empirical model relating the duration to the 
>>> corresponding ambient profile.
>>> 
>>> Some other notes:
>>> 
>>> a. We know from our understanding of how the shippers are constructed and 
>>> the laws of heat transfer that some sections of the ambient profile will 
>>> have more of an impact on determining the duration that other sections.
>>> b. Just correlating the duration with the average temperature of the 
>>> profile can predict the duration for that profile to within 10-15%. We are 
>>> looking for the ability to get within 2% of the shipper duration predicted 
>>> by the 3D model.
>>> 
>>> What I am looking for is suggestions as to how to approach step (5) with 
>>> tools/packages available in R.
>>> 
>>> Thanks in advance
>>> 
>>> Bernard McGarvey, Ph.D.
>>> 
>>> Technical Advisor
>>> Parenteral Supply Chain LLC
>>> 
>>> bernard.first.princip...@gmail.com mailto:bernard.first.princip...@gmail.com
>>> 
>>> (317) 627-4025
>>> 
>>> 
>>> 
>>>[[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] installing an R package

2022-04-28 Thread David Winsemius
Pretty sure the right way to install that package is with the Bioc installer. 

Sent from my iPhone

> On Apr 28, 2022, at 3:35 PM, Bogdan Tanasa  wrote:
> 
> HI everyone,
> 
> I must transfer a package from one platform (AWS) where I was able to
> install the package
> 
> to another platform (local PC), where I am not able to install the package.
> 
> The package is called : BSgenome.Hsapiens.UCSC.hg38
> 
> Is there a way to transfer the files from BSgenome.Hsapiens.UCSC.hg38
> folder (below) from AWS to local PC and get it to run ? Thanks !
> 
> 4.0KDESCRIPTION
> 4.0KINDEX
> 28K Meta
> 4.0KNAMESPACE
> 20K R
> 784Mextdata
> 24K help
> 12K html
> 
>[[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] What is the intended behavior, when subsetting using brackets [ ], when the subset criterion has NA's?

2022-04-06 Thread David Winsemius



On 4/6/22 16:17, Ebert,Timothy Aaron wrote:

Based on the OP's submission I pasted the following into R and tried to run it.

Here is what I think was posted (comments removed):

my_data <- 1:5
my_data
my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria
equals TRUE my_data[my_subset_criteria == T]
my_subset_criteria == T)

Assuming that this is the right code I tried to run it.
The third line " my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria" 
returns an error.



As it should. You put two commands on the same line with no correct 
separator:Either of these should succeed:


my_subset_criteria <- c( F, F, T, NA, NA)
my_subset_criteria

# OR
 
my_subset_criteria <- c( F, F, T, NA, NA) ; my_subset_criteria


(The original poster had the correct syntax.)

--
David




Error: unexpected symbol in " my_subset_criteria <- c( F, F, T, NA, NA) 
my_subset_criteria"

Regards,
Tim

-Original Message-
From: Jeff Newmiller 
Sent: Wednesday, April 6, 2022 5:22 PM
To: r-help@r-project.org; Ebert,Timothy Aaron ; Kelly Thompson 
; r-help@r-project.org
Subject: Re: [R] What is the intended behavior, when subsetting using brackets 
[ ], when the subset criterion has NA's?

[External Email]

Mmmm, ESP on the blink.

WHAT error? from which line of code?

BTW see The R Inferno, section 8.2.32

On April 6, 2022 1:52:47 PM PDT, "Ebert,Timothy Aaron"  wrote:

I get an error with this:
my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria


Tim

-Original Message-
From: R-help  On Behalf Of Kelly Thompson
Sent: Wednesday, April 6, 2022 4:13 PM
To: r-help@r-project.org
Subject: [R] What is the intended behavior, when subsetting using brackets [ ], 
when the subset criterion has NA's?

[External Email]

I noticed that I get different results when subsetting using subset, compared to 
subsetting using  "brackets" when the subset criteria have NA's.

Here's an example

#START OF EXAMPLE
my_data <- 1:5
my_data

my_subset_criteria <- c( F, F, T, NA, NA) my_subset_criteria

#subsetting using subset returns the data where my_subset_criteria
equals TRUE my_data[my_subset_criteria == T]

#subsetting using brackets returns the data where my_subset_criteria
equals TRUE, and also NA where my_subset_criteria is NA subset(my_data,
my_subset_criteria == T)

#END OF EXAMPLE

This behavior is also mentioned here
https://urldefense.proofpoint.com/v2/url?u=https-3A__statisticaloddsand
ends.wordpress.com_2018_10_07_subsetting-2Din-2Dthe-2Dpresence-2Dof-2Dn
as_=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=NoPFkG
0n9RFRaacmiiQ9Hp1cGniz9ED5YGN11-Jh6rD_zkTTE8e5egsKqzQDMSEW=5lgkxT5A_M
SfElILNk1ZM3RGpcBWpMBu713av1DH1mk=

Q. Is this the intended behavior when subsetting with brackets?

Thank you!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailm
an_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRz
sn7AkP-g=NoPFkG0n9RFRaacmiiQ9Hp1cGniz9ED5YGN11-Jh6rD_zkTTE8e5egsKqzQD
MSEW=g9IzSC3WrXPLYjys_RdYSmgUoFFjsbwRJZZodqtDRa0=
PLEASE do read the posting guide
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org
_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsR
zsn7AkP-g=NoPFkG0n9RFRaacmiiQ9Hp1cGniz9ED5YGN11-Jh6rD_zkTTE8e5egsKqzQ
DMSEW=uy6rCSNVehGynLn3ZCpLp_r2gHhoGcya4dbRe-tqQRc=
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailm
an_listinfo_r-2Dhelp=DwIFaQ=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRz
sn7AkP-g=QLbQb6DaELgtR0Qo6aQx51ea30OmGIC0oqVB_naWxmKYlQyw_N81MiAKj_5Z
9TXC=G7rw7ZKvhE_HMF4z5cA5Gsr0C018E51Ov9ye3Ui2GX0=
PLEASE do read the posting guide
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org
_posting-2Dguide.html=DwIFaQ=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsR
zsn7AkP-g=QLbQb6DaELgtR0Qo6aQx51ea30OmGIC0oqVB_naWxmKYlQyw_N81MiAKj_5
Z9TXC=PKD9VZ1n0p_NfoQ2OvbmPEVr14lVwLZx09mOIWPRZmk=
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.


__
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] ggplot2

2022-04-04 Thread David Winsemius



On 4/4/22 04:39, Ebert,Timothy Aaron wrote:

install.packages("ggplot2")



Depending on your OS, there might be a better chance of success with


install.packages("ggplot2", dependencies=TRUE)

The Linux install process doesn't need this but the binary install on MacOS or 
Windows may need this to prevent the sort of error message that was offered.

--
David


library(ggplot2)

An alternative
install.packages("tidyverse")
library(tidyverse)

The first only installs ggplot2. The alternative installs a bunch of other 
stuff as well.

Tim

-Original Message-
From: R-help  On Behalf Of Richard Vickery
Sent: Sunday, April 3, 2022 12:49 PM
To: R-help@r-project.org
Subject: [R] ggplot2

[External Email]

Hi there,

I am finally getting to some material I had problems with in university, where I was 
introduced to R - one of those that because of time constraints, I had challenges 
figuring out, particularly because I decided long ago on using Fedora Linux. The book, 
"Understanding Statistics Using R" by Andy Field et. al., says to install 
ggplot2 into R and the version of R that the dnf command installs will neigher install 
this package nor 'scales'. The result I get is below, and I attempted installing the 
packages via the tar command, and that neither worked, and I attempted
library("ggplot2") and R said the package was unavailable. What can I do to 
move forward?

Thanks,

Richard

 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=7xEzNpsPEMvdQLIcBNo-VFJErGQIZfwF2ueg-0lesWT4DSOwIMyZ5deX1XUeO2R2=QTw5eQQCMPK5qxhL7YKJYRMJWwmPSDI4bR9Px8VJrvA=
PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=7xEzNpsPEMvdQLIcBNo-VFJErGQIZfwF2ueg-0lesWT4DSOwIMyZ5deX1XUeO2R2=0kmwSZfq16L-GtPuQa5mSO8VGqauae08iBxm57dPnKI=
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] Question About lm()

2022-02-09 Thread David Winsemius
The models are NOT equivalent. Why would you’ll think they were?

— 
David

Sent from my iPhone

> On Feb 9, 2022, at 11:10 PM, Bromaghin, Jeffrey F via R-help 
>  wrote:
> 
> Hello,
> 
> I was constructing a simple linear model with one categorical (3-levels) and 
> one quantitative predictor variable for a colleague. I estimated model 
> parameters with and without an intercept, sometimes called reference cell 
> coding and cell means coding.
> 
> Model 1: yResp ~ -1 + xCat + xCont
> Model 2: yResp ~ xCat + xCont
> 
> These models are equivalent and the estimated coefficients come out fine, but 
> the R-squared and F statistics returned by summary() differ markedly. I spent 
> some time looking at the code for both lm() and summary.lm() but did not find 
> the source of the difference. aov() and anova() results also differ, so I 
> suspect the issue involves how the sums of squares are being computed. I've 
> also spent some time trying to search online for information on this, without 
> success. I haven't used lm() for quite a while, but my memory is that these 
> differences didn't occur in the distant past when I was teaching.
> 
> Thanks in advance for any insights you might have,
> Jeff
> 
> Jeffrey F. Bromaghin
> Research Statistician
> USGS Alaska Science Center
> 907-786-7086
> Jeffrey Bromaghin, Ph.D. | U.S. Geological Survey 
> (usgs.gov)
> Ecosystems Analytics | U.S. Geological Survey 
> (usgs.gov)
> 
> 
>[[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] Speed up studentized confidence intervals ?

2021-12-29 Thread David Winsemius



On 12/29/21 11:08 AM, varin sacha via R-help wrote:

Dear David,
Dear Rui,

Many thanks for your response. It perfectly works for the mean. Now I have a 
problem with my R code for the median. Because I always get 1 (100%) coverage 
probability that is more than very strange. Indeed, considering that an 
interval whose lower limit is the smallest value in the sample and whose upper 
limit is the largest value has 1/32 + 1/32 = 1/16 probability of non-coverage, 
implying that the confidence of such an interval is 15/16 rather than 1 (100%), 
I suspect that the confidence interval I use for the median is not correctly 
defined for n=5 observations, and likely contains all observations in the 
sample ? What is wrong with my R code ?



Seems to me that doing  a bootstrap within a `replicate` call is not 
needed. (Use one or the other as a mechanism for replication.


Here's what I would consider to be a "bootstrap" operation for 
estimating a 95% CI on the Gamma distributed population you created:


Used a sample size of 1 rather than 10


> quantile( replicate( 1000, {median(sample(s,5))}) , .5+c(-0.475,0.475))
 2.5% 97.5%
0.1343071 0.6848352

This is using boot::boot to calculate medians of samples of size 5

> med <- function( data, indices) {
+ d <- data[indices[1:5]] # allows boot to select sample
+ return( median(d))
+ }
> res <- boot(data=s, med, 1000)

> str(res)
List of 11
 $ t0   : num 0.275
 $ t    : num [1:1000, 1] 0.501 0.152 0.222 0.11 0.444 ...
 $ R    : num 1000
 $ data : num [1:1] 0.7304 0.4062 0.1901 0.0275 0.2748 ...
 $ seed : int [1:626] 10403 431 -118115842 -603122380 -2026881868 
758139796 1148648893 -1161368223 1814605964 -1456558535 ...

 $ statistic:function (data, indices)
  ..- attr(*, "srcref")= 'srcref' int [1:8] 1 8 4 1 8 1 1 4
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' 


 $ sim  : chr "ordinary"
 $ call : language boot(data = s, statistic = med, R = 1000)
 $ stype    : chr "i"
 $ strata   : num [1:1] 1 1 1 1 1 1 1 1 1 1 ...
 $ weights  : num [1:1] 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 
1e-04 1e-04 1e-04 ...

 - attr(*, "class")= chr "boot"
 - attr(*, "boot_type")= chr "boot"

> quantile( res$t , .5+c(-0.475,0.475))
 2.5% 97.5%
0.1283309 0.6821874






library(boot)

s=rgamma(n=10,shape=2,rate=5)
median(s)

N <- 100
out <- replicate(N, {
a<- sample(s,size=5)
median(a)

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

   boot.out <- boot(data = dat, statistic = med, R = 1)
   boot.ci(boot.out, type = "bca")$bca[, 4:5]
})

#coverage probability
median(out[1, ] < median(s) & median(s) < out[2, ])





Le jeudi 23 décembre 2021, 14:10:36 UTC+1, Rui Barradas  
a écrit :





Hello,

The code is running very slowly because you are recreating the function
in the replicate() loop and because you are creating a data.frame also
in the loop.

And because in the bootstrap statistic function med() you are computing
the variance of yet another loop. This is probably statistically wrong
but like David says, without a problem description it's hard to say.

Also, why compute variances if they are never used?

Here is complete code executing in much less than 2:00 hours. Note that
it passes the vector a directly to med(), not a df with just one column.


library(boot)

set.seed(2021)
s <- sample(178:798, 10, replace = TRUE)
mean(s)

med <- function(d, i) {
   temp <- d[i]
   f <- mean(temp)
   g <- var(temp)
   c(Mean = f, Var = g)
}

N <- 1000
out <- replicate(N, {
   a <- sample(s, size = 5)
   boot.out <- boot(data = a, statistic = med, R = 1)
   boot.ci(boot.out, type = "stud")$stud[, 4:5]
})
mean(out[1, ] < mean(s) & mean(s) < out[2, ])
#[1] 0.952



Hope this helps,

Rui Barradas

Às 11:45 de 19/12/21, varin sacha via R-help escreveu:

Dear R-experts,

Here below my R code working but really really slowly ! I need 2 hours with my 
computer to finally get an answer ! Is there a way to improve my R code to 
speed it up ? At least to win 1 hour ;=)

Many thanks


library(boot)

s<- sample(178:798, 10, replace=TRUE)
mean(s)

N <- 1000
out <- replicate(N, {
a<- sample(s,size=5)
mean(a)
dat<-data.frame(a)

med<-function(d,i) {
temp<-d[i,]
f<-mean(temp)
g<-var(replicate(50,mean(sample(temp,replace=T
return(c(f,g))

}

     boot.out <- boot(data = dat, statistic = med, R = 1)
     boot.ci(boot.out, type = "stud")$stud[, 4:5]
})
mean(out[1,] < mean(s) & mean(s) < out[2,])


__
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 

Re: [R] Error Awareness

2021-12-26 Thread David Winsemius



On 12/23/21 3:11 AM, Stephen H. Dawson, DSL via R-help wrote:

Hi,


I am thinking about awareness of errors when an R script runs.

My concern is I have an error-free script. I run it for months on end 
without problems. Then, something changes somewhere causing an error. 
My wonderment is how R will tell me I had an error in the script, but 
the rest of the script ran without impairment.


QUESTIONS
What are some of the more helpful options available to an R developer 
to capture errors in a script run?


What are some of the best processes to implement these more helpful 
options?


See this insight from Spencer Graves from Feb 2011 on Rhelp:

https://stat.ethz.ch/pipermail/r-help/2011-February/268512.html





Thanks,


__
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] Speed up studentized confidence intervals ?

2021-12-22 Thread David Winsemius
I’m wondering if this is an X-Y problem. (A request to do X when the real 
problem should be doing Y. ) You haven’t explained the goals in natural or 
mathematical language which is leaving me to wonder why you are doing either 
sampling or replication (much less doing both within each iteration in the the 
function given to boot. )

— 
David

Sent from my iPhone

> On Dec 19, 2021, at 3:50 AM, varin sacha via R-help  
> wrote:
> 
> Dear R-experts,
> 
> Here below my R code working but really really slowly ! I need 2 hours with 
> my computer to finally get an answer ! Is there a way to improve my R code to 
> speed it up ? At least to win 1 hour ;=)
> 
> Many thanks
> 
> 
> library(boot)
> 
> s<- sample(178:798, 10, replace=TRUE)
> mean(s)
> 
> N <- 1000
> out <- replicate(N, {
> a<- sample(s,size=5)
> mean(a)
> dat<-data.frame(a)
> 
> med<-function(d,i) {
> temp<-d[i,]
> f<-mean(temp)
> g<-var(replicate(50,mean(sample(temp,replace=T
> return(c(f,g))
> 
> }
> 
>   boot.out <- boot(data = dat, statistic = med, R = 1)
>   boot.ci(boot.out, type = "stud")$stud[, 4:5]
> })
> mean(out[1,] < mean(s) & mean(s) < out[2,]) 
> 
> 
> __
> 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] problem: try to passing macro value into submit block

2021-12-21 Thread David Winsemius



On 12/21/21 6:00 PM, Kai Yang via R-help wrote:

Hi team,I'm trying to pass macro variable into R script in Proc iml. I want to do change 
variable in color= and export the result with different file name.If I don't use macro, 
the code work well. But when I try to use macro below, I got error message: "Submit 
block cannot be directly placed in a macro. Instead, place the submit block into a file 
first and then use %include to include the file within a macro definition.". After 
reading the message, I still not sure how to fix the problem in the code. Anyone can help 
me?
Thank you,Kai
%macro pplot(a);proc iml;
submit / R;
library(ggplot2)library(tidyverse)
mpg %>%  filter(hwy <35) %>%   ggplot(aes(x = displ, y = hwy, color = )) +   
geom_point()ggsave("c:/temp/")
endsubmit;
quit;%mend;%pplot(drv);%pplot(cyl);

[[alternative HTML version deleted]]



Two problems I see. 1) you posted to R-help using html whereas the 
mailing list is a plain text venue, and 2) I reasonably sure that's a 
SAS error message and we don't consult on SAS problems.


If you strip out the stuff involving "" and add back in the elided 
line-breaks the R code runs without error.


--

David.



__
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] Degree symbol as axis label superscript [RESOLVED]

2021-11-30 Thread David Winsemius



On 11/30/21 1:22 PM, Rich Shepard wrote:

On Tue, 30 Nov 2021, David Winsemius wrote:


Really? What was wrong with this?
plot(1, 1, xlab=expression(32^degree) )  # the example given on 
?plotmath


David,

Absolutely nothing. When there's no specific degree value in the label
because the axis represents a range of values there's no digit preceeding
the ^ symbol.

The axis label is 'Temperature (oC)' with the degree symbol preceeding a
character, not following a specific digit.



There's nothing special about following a digit. You can have it follow 
anything. Since you were going to need to quote the parentheses anywa, 
then have it superscripted above the level of the paren:



plot(1,1, ylab = expression(Temperature~"("^degree*C*")")   )

--

David.



Rich

__
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] Degree symbol as axis label superscript [RESOLVED]

2021-11-30 Thread David Winsemius



On 11/30/21 12:29 PM, Rich Shepard wrote:

On Tue, 30 Nov 2021, Rich Shepard wrote:


Thanks, Andrew. I will.


plotmath didn't have the solution; 



Really? What was wrong with this?


plot(1, 1, xlab=expression(32^degree) )  # the example given on ?plotmath


--

David.




the use of the LaTeX ^ for a superscript
had a character or number preceeding it. Using 'degree' prints that 
string

on the axis.

What does work is using the unicode for the degree symbol as prefix to
either C or F. In my case:
ylab('Water Temperature (\u00B0C)')
does the job.

I found this solution with the DDG search string, 'degree symbol in R 
plot

axis label'. This stackexchange thread has the answer:
 



Regards,

Rich

__
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: unexpected symbol in "read.csv(12agosto.csv after installing Monterey

2021-11-08 Thread David Winsemius
There is a dedicated mailing list for Mac specific questions. You should 
subscribe before posting further but your first posting will still get 
moderated so don't send second postings because you think it's taking 
too long:


r-sig-...@r-project.org

And I'm a Mac user but do not understand what code was used. And I don't 
think the complete error message was included on the subject line. You 
should paste the complete code that was used and indicate whether it 
occurs with every file or only one particular file or file name. And do 
include the complete error message in the body of the email.


(I'm wondering if there could be an issue with encoding of a file name 
since you are using a US locale but the MacOS may be set for a Mexican 
locale.)


--

David

On 11/8/21 5:59 PM, cue...@cicese.mx wrote:

\n<>\n\n \n<> \n<>\n\n\n\n
--please do not edit the information below--

R Version:
platform = aarch64-apple-darwin20
arch = aarch64
os = darwin20
system = aarch64, darwin20
status =
major = 4
minor = 1.2
year = 2021
month = 11
day = 01
svn rev = 81115
language = R
version.string = R version 4.1.2 (2021-11-01)
nickname = Bird Hippie

GUI:
R-GUI 1.77 (8007)

Locale:
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

Search Path:
.GlobalEnv, tools:RGUI, package:stats, package:graphics, package:grDevices, 
package:utils, package:datasets, package:methods,
Autoloads, package:base


--
Horacio, de la Cueva, PhD
CICESE
Biología Experimental y Aplicada
Carretera Ensenada Tijiuana No. 3918
Zona Playitas,
Ensenada BC
22760
México

US Mailing Address:
P.O. Box, 430222
San Ysidro, CA 92143

cue...@cicese.mx
cohevolut...@gmail.com
cohevolut...@icloud.com
https://horaciodelacueva.blogspot.mx/
cel +52 646 171 5485

ORCID
-0002-5280-6458

Web of Science ResearcherID
ABA-4045-2020.


[[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] 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] How to install package meta on Linux Ubuntu 21?,

2021-09-29 Thread David Winsemius



On 9/29/21 8:04 PM, Jeff Newmiller wrote:

This is called hijacking a thread. Bad etiquette.

You need to pay attention to column types and NA values. Only do regular 
expression manipulations on character data, and NA is never something you can 
do string operations on.


To Giuseppa;

When you see the characters  without any surrounding quotes they are 
not really character values, but rather how the print function displays 
a missing value for a factor column. You cannot "eliminate it". In a 
very real sense it has already been "eliminated".


Read up on missing value handling at:


?NA... although that aspect is not mentioned at the help page (although 
it should be. Look at this console session fragment:



> factor(NA)
[1]   # factor missing values get the extra angle brackets.
Levels:
> NA
[1] NA
> char <- c("a", "NA", NA)
> char
[1] "a"  "NA" NA    # note that a character value of "NA" has quotes but 
a real missing value has none.


--

David.



On September 29, 2021 7:24:41 PM PDT, giuseppacef...@gmail.com wrote:

Hello,

I wonder if you can help me with this.  I am trying to eliminate unnecessary characters 
from the columns of a data frame.  For example this one, "df <- mutate_all(df,
 funs(str_replace_all(., "\\[|\\]", "")))" eliminates the [ and 
] that sometimes surround a number. Ex; [24.5] [54.6]

When I use the same command to eliminate the string "" it does not work. The only 
difference I have noticed is that the cell in the column containing the [ ] characters contains all the numbers 
in one row, but the cell in the column containing the "" characters contains several rows.

For example: variable_name
1 
2 
3  ...
I wonder if I have to collapse all the rows in a single row and eliminate one 
row.

Thank you,

Giuseppa Cefalu

-Original Message-
From: R-help  On Behalf Of Rui Barradas
Sent: Wednesday, September 29, 2021 3:13 PM
To: Kevin Thorpe ; Luigi Marongiu 

Cc: R Help Mailing List 
Subject: Re: [R] How to install package meta on Linux Ubuntu 21?

Hello,

The recommended way is to install r-base-dev, you probably only have r-base.

sudo apt-get update
sudo apt-get install r-base-dev


Hope this helps,

Rui Barradas

Às 17:53 de 29/09/21, Kevin Thorpe escreveu:

It looks to me like you do not have the development packages installed in 
Ubuntu. These should be easy to obtain with a suitable apt-get command, but 
since I am not a primary Ubuntu user, I do not know the package names.



On Sep 29, 2021, at 9:46 AM, Luigi Marongiu  wrote:

Hello
I have R version 4.1.1 (2021-08-10) -- "Kick Things", on an Ubuntu 21
machine. I am trying to install the package meta but I get the
following error:
```
...
ERROR: dependency ‘RcppEigen’ is not available for package ‘lme4’
* removing ‘/home/gigiux/R/x86_64-pc-linux-gnu-library/4.1/lme4’
Warning in install.packages :
   installation of package ‘lme4’ had non-zero exit status
ERROR: dependency ‘lme4’ is not available for package ‘meta’
```
I tried to install RcppEigen but:
```
...
/usr/bin/ld: cannot find -llapack
/usr/bin/ld: cannot find -lblas
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:10: RcppEigen.so] Error 1
ERROR: compilation failed for package ‘RcppEigen’
* removing ‘/home/gigiux/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen’
Warning in install.packages :
   installation of package ‘RcppEigen’ had non-zero exit status ```
and lme4 requires RcppEigen.
I launched
`$ sudo apt-get install r-cran-rcppeigen` installation successful but
I got the same error in installing RcppEigen.
What could be the error?
--
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.

__
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] Improvement: function cut

2021-09-18 Thread David Winsemius



On 9/18/21 5:28 AM, Leonard Mada via R-help wrote:

Hello Andrew,


I add this info as a completion (so other users can get a better
understanding):

If we want to perform a survival analysis, than the interval should be
closed to the right, but we should include also the first time point (as
per Intention-to-Treat):

[0, 4](4, 8](8, 12](12, 16]

[0, 4](4, 8](8, 12](12, 16](16, 20]


So the series is extendible to the right without any errors!

But the 1st interval (which is the same in both series) is different
from the other intervals: [0, 4].


I feel that this should have been the default behaviour for cut().


To Leonard;

If you do not like the behavior of `cut`, then you should "roll your 
own". It's very unlikely that R Core will modify a base cunction like 
cut. You might want to look at Hmisc::cut2. Frank Harrell didn't like 
that default behavior and thought he could make a better cut, so he just 
put it in his package. I did like his version better and often used it 
when I was actively programming. I suspect there is also a tidyverse 
cut-like function, but I'm not terribly familiar with that fork of R. 
(It's really not the same language IMHO.)


But it's a waste of time and energy to try propose modifications of core 
R functions unless *you* can show that it is stable across 20,000 
packages and will not offend long-time users. The likelihood  of that 
happening for your proposal is vanishing small in my estimation. You 
shouldn't ask R Core to do that for you. They are busy fixing real bugs.



If you want to persist despite my negativity, then you should make a 
complete proposal by submitting a proper diff file that incorporates 
your tested efforts to the Rdevel mailing list.



--

David



Note:

I was induced to think about a different situation in my previous
message, as you constructed open intervals on the right, and also
extended to the right. But survival analysis should be as described in
this mail and should probably be the default.


Sincerely,


Leonard


On 9/18/2021 1:29 AM, Andrew Simmons wrote:

I disagree, I don't really think it's too long or ugly, but if you
think it is, you could abbreviate it as 'i'.


x <- 0:20
breaks1 <- seq.int (0, 16, 4)
breaks2 <- seq.int (0, 20, 4)
data.frame(
     cut(x, breaks1, right = FALSE, i = TRUE),
     cut(x, breaks2, right = FALSE, i = TRUE),
     check.names = FALSE
)


I hope this helps.

On Fri, Sep 17, 2021 at 6:26 PM Leonard Mada mailto:leo.m...@syonic.eu>> wrote:

 Hello Andrew,


 But "cut" generates factors. In most cases with real data one
 expects to have also the ends of the interval: the argument
 "include.lowest" is both ugly and too long.

 [The test-code on the ftable thread contains this error! I have
 run through this error a couple of times.]


 The only real situation that I can imagine to be problematic:

 - if the interval goes to +Inf (or -Inf): I do not know if there
 would be any effects when including +Inf (or -Inf).


 Leonard


 On 9/18/2021 1:14 AM, Andrew Simmons wrote:

 While it is not explicitly mentioned anywhere in the
 documentation for .bincode, I suspect 'include.lowest = FALSE' is
 the default to keep the definitions of the bins consistent. For
 example:


 x <- 0:20
 breaks1 <- seq.int (0, 16, 4)
 breaks2 <- seq.int (0, 20, 4)
 cbind(
     .bincode(x, breaks1, right = FALSE, include.lowest = TRUE),
     .bincode(x, breaks2, right = FALSE, include.lowest = TRUE)
 )


 by having 'include.lowest = TRUE' with different ends, you can
 get inconsistent behaviour. While this probably wouldn't be an
 issue with 'real' data, this would seem like something you'd want
 to avoid by default. The definitions of the bins are


 [0, 4)
 [4, 8)
 [8, 12)
 [12, 16]


 and


 [0, 4)
 [4, 8)
 [8, 12)
 [12, 16)
 [16, 20]


 so you can see where the inconsistent behaviour comes from. You
 might be able to get R-core to add argument 'warn', but probably
 not to change the default of 'include.lowest'. I hope this helps


 On Fri, Sep 17, 2021 at 6:01 PM Leonard Mada mailto:leo.m...@syonic.eu>> wrote:

 Thank you Andrew.


 Is there any reason not to make: include.lowest = TRUE the
 default?


 Regarding the NA:

 The user still has to suspect that some values were not
 included and run that test.


 Leonard


 On 9/18/2021 12:53 AM, Andrew Simmons wrote:

 Regarding your first point, argument 'include.lowest'
 already handles this specific case, see ?.bincode

 Your second point, maybe it could be helpful, but since both
 'cut.default' and '.bincode' return NA if a value isn't
 within a bin, you could make something like this on your own.
 Might be worth pitching to R-bugs on the 

Re: [R] R: Many package imports have issues related to 'pillar'

2021-09-08 Thread David Winsemius



On 9/8/21 3:13 AM, Sigurjón Þorsteinsson wrote:

Hi

I am looking for a solution to this problem

library(geepack)

Error: package or namespace load failed for ‘geepack’:
  .onLoad failed in loadNamespace() for 'pillar', details:
   call: readRDS(nsInfoFilePath)
   error: unknown input format

More information:
https://stackoverflow.com/questions/69073165/r-many-package-imports-have-issues-related-to-pillar



If you search on SO you find that the error typically lies in failing to 
properly update R package libraries when you upgrade to a new 
installation of R. So it may not have anything to to do with the pillar 
package specifically.  My understanding (not an expert understanding) is 
that this arises because the serialization protocol of rds files may 
differ from version to version.



https://stackoverflow.com/questions/6473831/readrdsfile-in-r

You might first follow the usual path of removing any .Rdata and 
.Rhistory files


Then an R console command to try might be:


update.packages(checkBuilt=TRUE, ask=FALSE) # may take a long time


--

David.



Thanks for helping
Sigurjon

__
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] [External] Package for "design graphs"

2021-08-18 Thread David Winsemius
The only person who got the image was Richard. The rest of us got the 
posting from the list server which stripped you image. If it had been a 
pdf or png I think it might have survived the digital journey rather 
than being blown to bits.


On 8/18/21 7:29 AM, mad...@gmail.com wrote:

I have attached a photo from our book

E. Hansen "Introduktion til matematisk statistik"

the numbers represent the labels of one factor while the letters
represent the labels of anothr factor.

.. Mads


On Tue, 2021-08-17 at 22:42 +, Richard M. Heiberger wrote:

can you post an example of the graph?

From: R-help  on behalf of
mad...@gmail.com 
Sent: Tuesday, August 17, 2021 16:02
To: r-help@r-project.org
Subject: [External] [R] Package for "design graphs"
  
Hi,


in our course littrature a "design graph" of two factors R and S with
associated maps s : I -> S and f : I -> S where I is some finite
index
set, is a graph with factor labeles as vertices and lines f(i) to
s(i)
for all observations i in I. Is there a package on CRAN that can draw
graphs like this automatically?

I haven't been able to find anyting by searching.

Regards, Mads

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Crmh%40temple.edu%7C00a59081bd66463e433d08d961b9e105%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637648273248735184%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=dNwMcJa6okIxlK97dprkVkCk4g5mn6hYsBr1Hez7m%2F8%3Dreserved=0
PLEASE do read the posting guide
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7Crmh%40temple.edu%7C00a59081bd66463e433d08d961b9e105%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637648273248745142%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=YZlqRVki%2FaQMdaGQgddyLLmAH3bCsnhPTuhlnrSb1PE%3Dreserved=0
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] substitute column data frame based on name stored in variable in r

2021-08-09 Thread David Winsemius



On 8/9/21 12:22 PM, Luigi Marongiu wrote:

Thank you! it worked fine! The only pitfall is that `NA` became
``. This is essentially the same thing anyway...



It's not "essentially the same thing". It IS the same thing. The print 
function displays those '<>' characters flanking NA's when the class is 
factor. Type this at your console:



factor(NA)


--

David



On Mon, Aug 9, 2021 at 5:18 PM Ivan Krylov  wrote:

Thanks for providing a reproducible example!

On Mon, 9 Aug 2021 15:33:53 +0200
Luigi Marongiu  wrote:


df[df[['vect[2]']] == 2, 'vect[2]'] <- "No"

Please don't quote R expressions that you want to evaluate. 'vect[2]'
is just a string, like 'hello world' or 'I want to create a new column
named "vect[2]" instead of accessing the second one'.


Error in `[<-.data.frame`(`*tmp*`, df[[vect[2]]] == 2, vect[2], value
= "No") : missing values are not allowed in subscripted assignments
of data frames

Since df[[2]] containts NAs, comparisons with it also contain NAs. While
it's possible to subset data.frames with NAs (the rows corresponding to
the NAs are returned filled with NAs of corresponding types),
assignment to undefined rows is not allowed. A simple way to remove the
NAs and only leave the cases where df[[vect[2]]] == 2 is TRUE would be
to use which(). Compare:

df[df[[vect[2]]] == 2,]
df[which(df[[vect[2]]] == 2),]

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


Re: [R] Issue regarding specifying pdBlocked matrix for random effects vcov in nlme package

2021-08-08 Thread David Winsemius
Dear Dr. David;

Re; List rejection

I'm unable to explain why this posting was refused. It does have 4 image 
files attached. That is more than I typically see on Rhelp. I'm only a 
volunteer moderator, and not one of the owners of the list. I speculate 
that if you were to repost to rhelp (and NOT to R-Core where this 
message does not belong) and you were to substitute copied text from 
your console for all except the first image, it might go through (at 
least to the moderation queue where it could be reviewed by human eyes 
and wetware. (I suspect the number of images and links caused an 
automatic spam rejection.)

I also wonder if your modified re-submission should instead be directed 
to the R-SIG-mixed-models list since that appears to be the question 
topic. Some of the experts there are not regular contributor of viewers 
of Rhelp which is focused on the maechanics of the R language itself.

-- 

David Winsemius

Volunteer moderator.

On 8/2/21 1:43 PM, Benjamin Davis wrote:
>
> Hello,
>
> ��� I have come across an issue regarding specifying the 
> vcov of the random effects while using the /medrc/ package, which I 
> believe is very likely to originate from the /nlme/ package. I have 
> posted the question to StackOverflow if it is easier to read there:
>
> https://stackoverflow.com/questions/68626894/specifying-the-variance-covariance-matrix-for-random-effects-for-medrc-or-nlme
>  
> <https://urldefense.com/v3/__https://stackoverflow.com/questions/68626894/specifying-the-variance-covariance-matrix-for-random-effects-for-medrc-or-nlme__;!!HGYKHdhaPg!Ghq6dEJafKNBdT7h64jc9_H5JJWEnEQ891_QRsUZClnGXCeYntzRiXDmmq2XMTQ$>.
>
> I am using a 3-parameter log-logistic non-linear function
>
> and am including a species indicator variable based on whether my data 
> originates from humans (H) or rats (R). I am looking to specify a 
> blocked variance-covariance matrix for the random effects where 
> covariances are estimated for the off-diagonals of function parameters 
> within the same species, but not between species.
>
> I have attempted to estimate this vcov using the �medrm� function from 
> the /medrc/ package. While the notation is slightly different from the 
> �nlme� function, the estimation is performed in the same manner. I 
> have attempted to specify the random effect vcov using the 
> �'pdBlocked' function.
>
> M3b <- medrm(inhibition ~ concentration, curveid=b + d + e ~ species,� 
> data=OP,
>
> �random= 
> list(subject=pdBlocked(list(b~species, d~species, e~species))),
>
> �fct=LL.3(), control=c(drmc(method="CG"), 
> nlmeControl(msMaxIter = 150)))
>
> However, this results in almost the opposite of what I intended, 
> providing covariances within parameter type but across species (which 
> is non-sensical given that no subject can be both a human and a rat).
>
> Do you have any recommendations on how to fix this, ideally using one 
> of the existing pd-matrix functions?
>
> Thanks in advance for your reply.
>
> *Benjamin Davis, Ph.D.*
> Senior Scientist
> *Exponent*
> Direct +1-202-772-4942
> Email dav...@exponent.com <mailto:dav...@exponent.com>
>
> *Benjamin Davis, Ph.D.*
> Senior Scientist
> *Exponent*
> Direct +1-202-772-4942
> Email dav...@exponent.com <mailto:dav...@exponent.com>
>

[[alternative HTML version deleted]]

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


Re: [R] Help with package EasyPubmed

2021-08-04 Thread David Winsemius



> On Aug 3, 2021, at 11:20 AM, bharat rawlley via R-help  
> wrote:
> 
> Hello, 
> When I try to run the following code using the package Easypubmed, I get a 
> null result - 
>> batch_pubmed_download(query_7)
> NULL
> #query_7 <- "Cardiology AND randomizedcontrolledtrial[Filter] AND 2011[PDAT]"
> However, the exact same search string yields 668 results on Pubmed. 

Did you try with: 
'Cardiology AND "randomized controlled trial"[Filter] AND 2011[PDAT]'

DAVID.

> 
> 
> I am unable to figure out why this is happening. If I use the search string 
> "Cardiology AND 2011[PDAT]" then it works just fine. 
> Any help would be greatly appreciated
> 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-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 matrix from a list without a for loop

2021-07-09 Thread David Winsemius



On 7/9/21 10:40 AM, Laurent Rhelp wrote:

Dear R-Help-list,

  I have a list init_l containing 16 dataframes and I want to create a 
matrix 4 x 4 from this list with a dataframe in every cell of the 
matrix. I succeeded to do that but my loop is very uggly (cf. below). 
Could somebody help me to write nice R code to do this loop ?


Thank you very much

Laurent


##
## mock data, 16 dataframes in a list
##
init_l <- lapply( seq(1,16) , function(x) {
  data.frame( V1 = rnorm(3),
  V2 = rnorm(3),
  V3 = rnorm(3)
    )
})

##
## lists matrix creation with n = 4 columns and n = 4 rows
##
n <- 4




Just assign a dimension attribute and you will have your two dimensional 
structure



> dim(init_l) <- c(n,n)
> init_l[ 2,2]
[[1]]
  V1 V2 V3
1 -1.4103259  1.9214184 -0.1590919
2  0.1899490  0.3842191  2.4502078
3 -0.4282764 -0.9992190  1.5384344

> is.matrix(init_l)
[1] TRUE

--

David


## an example of row to create the matrix with lists in the cells
one_row <- rbind( rep( list(rep(list(1),3)) , n) )
mymat <- do.call( "rbind" , rep( list(one_row) , n) )

##
## The UGGLY loop I would like to improve:
##

## populate the matrix
k <- 1
for( i in 1:n){
  for( j in 1:n){
    mymat[i,j][[1]] <- list( init_l[[ k ]] )
    k <- k+1
  }
}

colnames(mymat) <- c("X1", "X2", "X3", "X3")
rownames(mymat) <- c("X1", "X2", "X3", "X4")


mymat

# X1 X2 X3 X3
# X1 List,1 List,1 List,1 List,1
# X2 List,1 List,1 List,1 List,1
# X3 List,1 List,1 List,1 List,1
# X4 List,1 List,1 List,1 List,1


#
# verification, it works
#
mymat[2,2]
init_l[[6]]

##
init_l[[6]]

library(tidyverse)
mymat.t <- as.tibble(mymat)
mymat.t
unnest(mymat.t[2,2],cols="X2")[[1]][[1]]

mymat.df <- as.data.frame(mymat)
mymat.df[2,2][[1]][[1]]


thx





__
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] Some difficulties to use the apply command on an array

2021-07-05 Thread David Winsemius



> On Jul 5, 2021, at 7:56 AM, Laurent Rhelp  wrote:
> 
> Dear R-Help,
> 
> I have an array x made up of three matrices of 5 rows and 3 columns of 
> complex numbers (the complex numbers are not the problem)
> 
> ## my array
> x <- structure(c(5.6196790161893828+0i, 5.7565523942393364+0i, 
> 8.5242834298729342+0i,
>   10.304766710160479+0i, 11.412967010108229+0i, 
> -2.6952197604866495-5.7324226520260237e-18i,
>   -3.8053698833683476-1.5535793240880411i, 
> -4.440850591952894-0.21277190153473785i,
>   -4.9049897326853316+0.22487294128201613i, 
> -4.6982778900868931-0.35986943359186585i,
>   -6.7722948827866034-1.8252881225149525e-16i, 
> -5.6864255243941733-0.82149125972147463i,
>   -2.5321753317962115-3.4309121438578525i, 
> 0.85377696343414344-4.3720244641138883i,
>   6.3363344379954638-2.23654533694011i, 
> -2.6952197604866495+5.7324226520260237e-18i,
>   -3.8053698833683476+1.5535793240880411i, 
> -4.440850591952894+0.21277190153473785i,
>   -4.9049897326853316-0.22487294128201613i, 
> -4.6982778900868931+0.35986943359186585i,
>   3.1683154084671417+0i, 5.397392162921844+0i, 
> 8.3085887222115922+0i,
>   11.150391891976289+0i, 13.173434845070231+0i, 
> 3.7978840709983359+5.0735539531499429e-17i,
>   3.0599215005995717-2.3669737981128267i, 
> 0.5951827523696811-3.2116907301709845i,
>   -1.7735244105472532-3.8366652813316566i, 
> -5.0558348297797169-2.6645747173403049i,
>   -6.7722948827866034+1.8252881225149525e-16i, 
> -5.6864255243941733+0.82149125972147463i,
>   -2.5321753317962115+3.4309121438578525i, 
> 0.85377696343414344+4.3720244641138883i,
>   6.3363344379954638+2.23654533694011i, 
> 3.7978840709983359-5.0735539531499429e-17i,
>   3.0599215005995717+2.3669737981128267i, 
> 0.5951827523696811+3.2116907301709845i,
>   -1.7735244105472532+3.8366652813316566i, 
> -5.0558348297797169+2.6645747173403049i,
>   8.5581082281979697+0i, 8.6908832216086331+0i, 
> 12.394094469562258+0i,
>   16.106350896659897+0i, 19.569513600539693+0i), .Dim = c(5L, 3L,
> 3L))
> 
> str(x)
> #  cplx [1:5, 1:3, 1:3] 5.62+0i 5.76+0i 8.52+0i ...
> 
> The dimensions (i,j,k) of my array are 5, 3, 3. For every value of i, I am 
> interested in the squared matrices made up of the j columns for all the k 
> indice. For a given value i I have to keep the row i for every k. For example 
> if i=1, I am interested by the matrix x[1,,]
> ##
> x[1,,]
> 
> ##  [,1] [,2] [,3]
> ## [1,]  5.619679+0i -2.695220+0i -6.772295+0i
> ## [2,] -2.695220-0i  3.168315+0i  3.797884-0i
> ## [3,] -6.772295-0i  3.797884+0i  8.558108+0i
> 
> Now, for every value of i, I want to calculate the SVD decomposition and get 
> the diagonal matrix created by the singular values. When I set the i value it 
> works:
> diag( svd(x[1,,])$d )
> 
> # [,1] [,2]  [,3]
> # [1,] 15.73833 0.00 0.000
> # [2,]  0.0 1.502771 0.000
> # [3,]  0.0 0.00 0.1049992
> 
> 
> But when I try to do a loop on the i value it doesn't work:
> 
> apply(x, c(2,3), FUN = function(x) diag( svd(x)$d ))
> 

Use a different indexing strategy:

res <- apply(x, 1, FUN = function(x) diag( svd(x)$d ))

The result is flattened but each of the columns in that `res`-object are the 
entries in a 3x3 matrix. Reform it by:

> dim(res) <- c(3,3,5)
> res
, , 1

 [,1] [,2]  [,3]
[1,] 15.73833 0.00 0.000
[2,]  0.0 1.502771 0.000
[3,]  0.0 0.00 0.1049992

, , 2

[,1] [,2] [,3]
[1,] 16.0011 0.00 0.00
[2,]  0. 3.357086 0.00
[3,]  0. 0.00 0.486643

, , 3

 [,1] [,2][,3]
[1,] 16.05269  0.0 0.0
[2,]  0.0 11.49007 0.0
[3,]  0.0  0.0 1.68421

, , 4

 [,1] [,2] [,3]
[1,] 19.58508  0.0 0.00
[2,]  0.0 14.83712 0.00
[3,]  0.0  0.0 3.139307

, , 5

 [,1] [,2] [,3]
[1,] 26.75931  0.0 0.00
[2,]  0.0 11.81372 0.00
[3,]  0.0  0.0 5.582891


-- 
David

> 
> # [,1][,2][,3]
> # [1,] Numeric,361 Numeric,81  Numeric,144
> # [2,] Numeric,81  Numeric,400 Numeric,81
> # [3,] Numeric,144 Numeric,81  Numeric,900
> 
> I do not understand how to do the apply on an array in order to get my 
> diagonals matrices. I think that I miss something about the understanding of 
> the array object.
> 
> Thank you for your help
> 
> Laurent
> 
> 
> 
> 
> -- 
> L'absence de virus dans ce courrier électronique a été vérifiée par le 
> logiciel antivirus Avast.
> https://www.avast.com/antivirus
> 
> __
> 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, 

Re: [R] Plotting the ASCII character set.

2021-07-03 Thread David Winsemius



Sent from my iPhone

> On Jul 3, 2021, at 7:00 PM, Rolf Turner  wrote:
> 
> 
>> On Sat, 3 Jul 2021 09:40:28 +0200
>> Ivan Krylov  wrote:
>> 
>> Hello Rolf Turner,
>> 
>> On Sat, 3 Jul 2021 14:02:59 +1200
>> Rolf Turner  wrote:
>> 
>>> Can anyone suggest how I might get my plot_ascii() function working
>>> again?  Basically, it seems to me, the question is:  how do I
>>> persuade R to read in "\260" as "\ub0" rather than "\xb0"?
>> 
>> Part of the problem is that the "\xb0" byte is not in ASCII, which
>> covers only the lower half of possible 8-bit bytes. I guess that the
>> strings containing bytes with highest bit set used to be interpreted
>> as Latin-1 on your machine, but now get interpreted as UTF-8, which
>> changes their meaning (in UTF-8, the highest bit being set indicates
>> that there will be more bytes to follow, making the string invalid if
>> there is none).
>> 
>> The good news is, since it's Latin-1, which is natively supported by
>> R, there are even multiple options:
>> 
>> 1. Mark the string as Latin-1 by setting Encoding(a) <- 'latin1' and
>> let R do the re-encoding if and when Pango asks it for a UTF-8-encoded
>> string.
>> 
>> 2. Decode Latin-1 into the locale encoding by using iconv(a, 'latin1',
>> '') (or set the third parameter to 'UTF-8', which would give almost
>> the same result on a machine with a UTF-8 locale). The result is,
>> again, a string where Encoding(a) matches the truth. Explicitly
>> setting UTF-8 may be preferable on Windows machines running pre-UCRT
>> builds of R where the locale encoding may not contain all Latin-1
>> characters, but that's not a problem for you, as far as I know.
>> 
>> For any encoding other than Latin-1 or UTF-8, option (2) is still
>> valid.
>> 
>> I have verified that your example works on my GNU/Linux system with a
>> UTF-8 locale if I use either option.
> 
> Thanks Ivan. That solves most of the problem, but there are still
> glitches. I get a plot OK, but a substantial number of the characters
> are displayed as a wee rectangle containing a 2 x 2 array of digits
> such as
> 
>>  0 0
>>  8 0
> 
> Also note that there is a bit of difference between the results of using
> Encoding() and the results of using iconv(). E.g. if I do
> 
> a <- "\x80"
> b <- iconv(a,"latin1","UTF-8")
> Encoding(a) <- "latin1"
> 
> then when I type "a" I get the Euro symbol "€", but when I type "b"
> I get the string "\u0080".
> 
> But that doesn't really matter.  More problematic is the fact that if I
> do either
> 
>plot(0,0,type="n",xlim=c(0,1),ylim=c(0,1),ann=FALSE,axes=FALSE)
>text(0.5,0.5,labels=a,cex=6)
> or
> 
>plot(0,0,type="n",xlim=c(0,1),ylim=c(0,1),ann=FALSE,axes=FALSE)
>text(0.5,0.5,labels=b,cex=6)
> 
> then I get wee rectangle with 0 0 8 0 arranged in a 2 x 2 array inside.
> (Setting cex=6 makes it easier for my ageing eyes to see what the
> mAxdigits are.)
> 
> E Is hethere any way that I can get the Euro symbol to display correctly in
> such a graphic?
> 
Pick a font that is supported on your OS that has the desired glyph. 
Also look at the examples in:

?points

— 
David 
> Thanks.
> 
> cheers,
> 
> Rolf
> 
> -- 
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
> 
> __
> 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] Special characters in cell names

2021-06-23 Thread David Winsemius
On my keyboard the key is share with the tilde symbol and is up on the left 
hand corner. 

Sent from my iPhone

> On Jun 23, 2021, at 2:45 PM, David Winsemius  wrote:
> 
> Backticks. NOT apostrophes. 
> 
> — David
> 
> Sent from my iPhone
> 
>> On Jun 23, 2021, at 2:40 PM, Mahmood Naderan  wrote:
>> 
>> Hi Bert,
>> I don't know what does "check.names" do here, but my commands look like
>> 
>> 
>>> mydata <- read.csv('r.3080..csv', header=T,row.names=1)
>> 
>>> head(mydata)
>> W  AX/Y
>> P1   M  1.469734 0.004144405
>> P2M 20.584841 0.008010306
>> P3 M 53.519800 0.166034888
>> P4  M 42.308700 0.051545443
>> P5   M 99.236384 0.893037857
>> P6M 94.279504 0.856837525
>> 
>> So when I use
>> 
>> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
>> 
>> 
>> The output is not correct. I don't see values (scale) on the y-axis.
>> Anyway, I fixed that with a label.
>> 
>> Regards,
>> Mahmood
>> 
>> 
>> 
>> 
>>>> On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter  
>>>> wrote:
>>> 
>>> I found your specification quite vague. What did you mean by a "data file"
>>> -- a data frame in R? -- a file in the file system?
>>> 
>>> I may be completely wrong here, but another possibility is that you read
>>> your data into an R data.frame via, e.g. read.table() or read.csv(), but
>>> failed to specify the check.names = FALSE, argument. This would cause a
>>> column named "x/y" in your original table to be given the name "x.y" in R,
>>> as "x/y" is not a syntactically valid name. See ?make.names for details.
>>> 
>>> As others have already said, enclosing non-syntactically valid names in
>>> back ticks usually works (maybe always works??). So for example:
>>> 
>>> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
>>> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
>>> z  ## yields:
>>> a/b y
>>> 1   1 1
>>> 2   2 2
>>> 3   3 3
>>> 4   4 4
>>> 5   5 5
>>> 
>>> Of course, ignore if this is all irrelevant.
>>> 
>>> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
>>> wrote:
>>> 
>>>> Unfortunately, using 'X/Y' doesn't work either.
>>>> Instead I used labels like below
>>>> 
>>>> P + scale_y_continuous(name="X/Y")
>>>> 
>>>> Thanks for the suggestions.
>>>> 
>>>> Regards,
>>>> Mahmood
>>>> 
>>>> 
>>>> 
>>>> 
>>>> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
>>>> wrote:
>>>> 
>>>>> If no one comes up with a better suggestion:
>>>>> a. Change the column name to "Y" so that you get the plot you want
>>>>> b. Use axis labels and legend text to show the text that you want. (The
>>>>> user never has to know that you changed the column name )
>>>>> 
>>>>> HTH,
>>>>> Eric
>>>>> 
>>>>> On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
>>>>> wrote:
>>>>> 
>>>>>> Hi
>>>>>> I have a column in my data file which is "X/Y". With '/' I want to
>>>>>> emphasize that values are the ratio of X over Y.
>>>>>> Problem is that in the following command for a violin plot, I am not
>>>> able
>>>>>> to specify that '/' even with double quotes.
>>>>>> 
>>>>>> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>>>>>> 
>>>>>> However, if I change that column to "Y" and use
>>>>>> 
>>>>>> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>>>>>> 
>>>>>> Then the plot will be correctly shown.
>>>>>> Any ideas for that?
>>>>>> 
>>>>>> Regards,
>>>>>> Mahmood
>

Re: [R] Special characters in cell names

2021-06-23 Thread David Winsemius
Backticks. NOT apostrophes. 

— David

Sent from my iPhone

> On Jun 23, 2021, at 2:40 PM, Mahmood Naderan  wrote:
> 
> Hi Bert,
> I don't know what does "check.names" do here, but my commands look like
> 
> 
>> mydata <- read.csv('r.3080..csv', header=T,row.names=1)
> 
>> head(mydata)
>  W  AX/Y
> P1   M  1.469734 0.004144405
> P2M 20.584841 0.008010306
> P3 M 53.519800 0.166034888
> P4  M 42.308700 0.051545443
> P5   M 99.236384 0.893037857
> P6M 94.279504 0.856837525
> 
> So when I use
> 
> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
> 
> 
> The output is not correct. I don't see values (scale) on the y-axis.
> Anyway, I fixed that with a label.
> 
> Regards,
> Mahmood
> 
> 
> 
> 
>> On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter  wrote:
>> 
>> I found your specification quite vague. What did you mean by a "data file"
>> -- a data frame in R? -- a file in the file system?
>> 
>> I may be completely wrong here, but another possibility is that you read
>> your data into an R data.frame via, e.g. read.table() or read.csv(), but
>> failed to specify the check.names = FALSE, argument. This would cause a
>> column named "x/y" in your original table to be given the name "x.y" in R,
>> as "x/y" is not a syntactically valid name. See ?make.names for details.
>> 
>> As others have already said, enclosing non-syntactically valid names in
>> back ticks usually works (maybe always works??). So for example:
>> 
>> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
>> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
>> z  ## yields:
>>  a/b y
>> 1   1 1
>> 2   2 2
>> 3   3 3
>> 4   4 4
>> 5   5 5
>> 
>> Of course, ignore if this is all irrelevant.
>> 
>> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
>> wrote:
>> 
>>> Unfortunately, using 'X/Y' doesn't work either.
>>> Instead I used labels like below
>>> 
>>> P + scale_y_continuous(name="X/Y")
>>> 
>>> Thanks for the suggestions.
>>> 
>>> Regards,
>>> Mahmood
>>> 
>>> 
>>> 
>>> 
>>> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
>>> wrote:
>>> 
 If no one comes up with a better suggestion:
 a. Change the column name to "Y" so that you get the plot you want
 b. Use axis labels and legend text to show the text that you want. (The
 user never has to know that you changed the column name )
 
 HTH,
 Eric
 
 On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
 wrote:
 
> Hi
> I have a column in my data file which is "X/Y". With '/' I want to
> emphasize that values are the ratio of X over Y.
> Problem is that in the following command for a violin plot, I am not
>>> able
> to specify that '/' even with double quotes.
> 
> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
> 
> However, if I change that column to "Y" and use
> 
> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
> 
> Then the plot will be correctly shown.
> Any ideas for that?
> 
> Regards,
> Mahmood
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
 
>>> 
>>>[[alternative HTML version deleted]]
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>> 
> 
>[[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] Data is not properly written in csv file

2021-06-21 Thread David Winsemius
This was an exact duplicate of a posting to StackOverflow where it has a 
response. You are asked in the Posting Guide not to crosspost.



--

David.

On 6/20/21 8:03 AM, Sri Priya wrote:

location <- '
http://keic.mica-apps.net/wwwisis/ET_Annual_Reports/Religare_Enterprises_Ltd/RELIGARE-2017-2018.pdf
'

# Extract the table
out <- extract_tables(location)


__
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] RINLA

2021-06-09 Thread David Winsemius



On 6/9/21 8:48 PM, peri He wrote:

Dear Friends,

I am running a simple code for rinla.  The INLA package is installed 
successfully on Rstudio.



Techinically, the package is installed in an R library. You are using 
Rstudio as your IDE, but it does not run packages.



But when I run inla (y~x,..) function, I get the following error: could not find 
function "inla"
Did anybody have the same problem before?

I would appreciate it if any information is shared.

Regards,

install.packages("INLA", repos = "https://inla.r-inla-download.org/R/stable;, 
dep = TRUE)



Despite setting dep=TRUE is still got a warning:

"Warning in install.packages :
  dependencies ‘Ecdat’, ‘mpoly’, ‘symmoments’ are not available"


library(INLA)
N = 100  #500, 5000, 25000, 10
x = rnorm(N, mean=6, sd=2)
y = rnorm(N, mean=x,sd=1)
data = list(x=x, y=y, N=N)
# The likelihood family is �gaussian�
model<- inla(y ~ x, family = c("gaussian"), data = data, 
control.predictor=list(link=1))
Summary <- (model)


Despite the warning, INLA installed and loaded without complaint and the 
code ran without error.


I later ran:

install.packages(c('Ecdat', 'mpoly', 'symmoments'))    # no problems 
here either.


So I'm unable to recreate your error.

sessionInfo()

#---

R version 4.0.4 (2021-02-15)   #I'm admittedly not up-to-date, If 
you are,  then provide details


I did check to see if there are any later versions of pkg:INLA and could 
not find any


Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C LC_TIME=en_US.UTF-8    
LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8 
LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C 
LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C


attached base packages:
[1] parallel  stats graphics  grDevices utils datasets methods   
base


other attached packages:
[1] INLA_21.02.23   sp_1.4-5    foreach_1.5.1 
Matrix_1.3-2    RBGL_1.66.0 graph_1.68.0

[7] BiocGenerics_0.36.0

loaded via a namespace (and not attached):
 [1] lattice_0.20-41 codetools_0.2-18    grid_4.0.4 
MatrixModels_0.5-0  stats4_4.0.4    splines_4.0.4
 [7] iterators_1.0.13    tools_4.0.4 yaml_2.2.1 
compiler_4.0.4  BiocManager_1.30.12





[[alternative HTML version deleted]]



Rhelp is a plain-text mailing list. HTML is not welcome.

--

David.

__
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] Need help to fix the max date filter problem in the date input

2021-06-09 Thread David Winsemius



On 6/9/21 5:06 AM, Biplab Nayak wrote:

Hi Greg,

Please find the objective of the code(bold) and code mentioned below. I was
trying to do to achieve the below objective but somehow it's not working.



The phrase "somehow not working" is not a useful description of an outcome.



1.Order assessment based on the latest due date so select input
automatically shows the order of assessment name.

2.Filter based on the one name or multiple names in the  select input



library(tidyverse)

#library(stringr)# attached with tidyverse

#library(readr)

library(shiny)

library(dplyr)



I'm pretty sure the tidyverse super-package includes most of the others 
with the exception of pkg:shiny (which does not appear to be needed anyway.)


Here's what my version of tidyverse loads:

Imports: broom (>= 0.5.2), cli (>= 1.1.0), crayon (>= 1.3.4), dbplyr (>= 
1.4.2), dplyr (>= 0.8.3), forcats (>= 0.4.0),
 ggplot2 (>= 3.2.1), haven (>= 2.2.0), hms (>= 0.5.2), httr 
(>= 1.4.1), jsonlite (>= 1.6), lubridate (>=
 1.7.4), magrittr (>= 1.5), modelr (>= 0.1.5), pillar (>= 
1.4.2), purrr (>= 0.3.3), readr (>= 1.3.1), readxl
 (>= 1.3.1), reprex (>= 0.3.0), rlang (>= 0.4.1), 
rstudioapi (>= 0.10), rvest (>= 0.3.5), stringr (>=

 1.4.0), tibble (>= 2.1.3), tidyr (>= 1.0.0), xml2 (>= 1.2.2)


ttclasses <- read_csv("~/tmp/ttclasses.csv")

We do not have your data.


#Filter data

ttclasses <-ttclasses %>%

filter(str_detect(assessment, "Assignment"))

  ttclasses <-ttclasses %>%  filter(str_detect(name, "Name"))
Without a result that summarizes the changes in the data composition at 
each step, we cannot make any guesses as to your problem

##Remove NA values.

ttclasses <-ttclasses %>% drop_na("score")



*## Sort  assessment based on max due_date*

  ttclasses  <- ttclasses [order( - due_date, assessment ),]



#Convert to factor

ttclasses$assessment <- factor(ttclasses$assessment)



# please see the formats in help("strptime")

ttclasses$due_date <-  as.Date(ttclasses$due_date, format = "%m/%d/%y")
Yes, do see ?strptime. That format assumes dates are in MM/DD/YY format, 
i.e slashes as separators and 2 digit years. Getting the date format 
wrong is a common way to create NA values. It is better not to overlay 
such efforts on top of the original column name. That way you can still 
make changes without redoing the entire data steps.


ttclasses$name <- factor(ttclasses$name)

Thanks & Regards
Biplab Nayak






On Wed, Jun 9, 2021 at 12:15 AM Greg Minshall  wrote:


Biplab,

i'm not sure how to help you here, but this list pretty much runs on
plain ASCII (or, these days, utf-8) e-mail.  for the most part, without
attachments.  so, simply-formatted text, including code, with some
mechanism in the code to initialize any data structures (data frames,
matrices, etc.) needed for the example.

some of this is described in the posting guide

https://www.r-project.org/posting-guide.html


formatting your e-mail in this way will likely increase your odds of a
helpful reply.

cheers, Greg


[[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] Help for Use of R software

2021-06-06 Thread David Winsemius
I get the sense that you need further background on statistical testing 
issues and suggest this resource:



https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3510268/


--

David Winsemius, MD, MPH

On 6/6/21 10:06 AM, Lee Simon wrote:

Dear Sir/Madam,

May I seek for your kind help for the use of R software for conducting
two-proportional z-test which is test for non-inferiority? What function
will the R software provide for doing such test with 95%CI and P-value
calculated. Thank you very much!

With kindest regards,
Simon

[[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] Help for Use of R software

2021-06-06 Thread David Winsemius
A google-search of the term brings up as its first hit a link to a page 
on the rdocumentation.org website that indicates that theTrialSize 
package(version1.4) 
 has a 
function named "TwoSampleProportion.NIS".


If you executed these commands in an R console:

install.packages("TrialSize")
packageDescription("TrialSize")
library(TrialSize)
?TwoSampleProportion.NIS

 you would probably see a help page that has almost the same content 
as the page at rdocumentation.org


(A "two sample z-test", at least as I understand such a label, is not 
necessarily a test for non-inferiority. That page doesn't actually 
describe the results of a calculation using the 
"TwoSampleProportion.NIS" function but if you go to the code you find 
it's not doing a test of any sort but rather doing an oversimplified 
sample size calculation.)


You appear to not understand that R is a system of packages that are 
optionally installed and loaded into the core programming environment. I 
would advise that you do some self-learning about how to use R (or) that 
you contract with a person who can provide the skills need to both 
educate you about the statistical issues in trial design and run your 
analyses for you.


You should also read the fine Posting Guide:

http://www.R-project.org/posting-guide.html

--

David.

On 6/6/21 1:29 AM, Lee Simon wrote:

Dear Sir/Madam,

May I seek for your kind help for the use of R software for conducting
two-proportional z-test which is test for non-inferiority? I have found one
saying using function (TwoSampleProportion.NIS(alpha, beta, p1, p2, k,
delta, margin) but the software said there is not such function. Thank you
very much for your kind help.

With kindest regards,
Simon

[[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] Help in modifying code to extract data from url

2021-05-22 Thread David Winsemius
Several authors hav addressed this problem with names that resemble 
"rbindfill". In my machine I find four instances:


??rbindfill

Help pages:
ffbase::ffdfrbind.fill        rbind for ffdf where missing columns are 
added if not available in one of the ffdf objects
plyr::rbind.fill        Combine data.frames by row, filling in missing 
columns.
plyr::rbind.fill.matrix        Bind matrices by row, and fill missing 
columns with NA.

rockchalk::rbindFill        Stack together data frames


--

David.

On 5/20/21 2:19 AM, Jim Lemon wrote:

Hi Bhaskar,
If you are using read.table or similar, see the "fill=" argument.

Jim

On Thu, May 20, 2021 at 9:54 AM Bhaskar Mitra  wrote:

Hello Everyone,

I am trying to extract data from a url. The codes work well when the
data structure is as follows:

X Y
1 2
1 5
1 6
1 7
3 4

However, the code fails when the data structure has no number
under the 2nd column (shown below).I get the following error:

"Error in data.frame(..., check.names = FALSE) :
   arguments imply differing number of rows: 242, 241"


X Y
1 2
1
1
1 7
3 4

Can anyone please help me in how I can modify the codes ( shown below) to
adjust for the above mentioned condition
in the data structure.

library(rjson)

url <- "abcd.com"
json_data <- fromJSON(file= url)
d3 <- lapply(json_data[[2]], function(x) c(x["data"]))
d3 <- do.call(rbind, d3)
X_Dataframe = as.data.frame(unlist(d3[[1]]))
b <- do.call("cbind", split(X_Dataframe, rep(c(1, 2), length.out =
nrow(X_Dataframe


regards,
bhaskar

 [[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-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] COXPH: How should weights be entered in coxph, as the log of the weight or as the weight on its original scale?

2021-05-19 Thread David Winsemius
Perhaps this package could be considered

https://cran.r-project.org/web/packages/hrIPW/hrIPW.pdf

That packages author also has a 2016 article in Statistics in Medicine on the 
properties of estimates from such analyses that might be useful. 

— 
David Winsemius, MD, MPH

Sent from my iPhone

> On May 19, 2021, at 8:01 PM, Sorkin, John  wrote:
> 
> When running a propensity score weighted analysis using coxph(), are the 
> weights entered as the log of the weights, or as the weights on the original 
> scale, i.e. coxph(Surv(time,status)~group,weights=weights   ,data=mydata) 
> or
>  coxph(Surv(time,status)~group,weights=log(weights),data=mydata)
> 
> I am creating weights using logistic regression as described below.
> 
> # Lalonde data from the MatchIt package is used in the pseudo code below
> install.packages("MatchIt")
> library("MatchIt")
> 
> #
> # Calculate propensity scores using logistic regression.#
> #
> ps <- glm(treat ~ age + educ +nodegree +re74+ 
> re75,data=lalonde,family=binomial())
> summary(ps)
> #PS on the scale of the dependent variable
> # Add the propensity scores to the dataset
> lalonde$psvalue <- predict(ps,type="response")
> #
> # END Calculate propensity scores using logistic regression.#
> #
> 
> #
> # Convert propensity scores to weights#
> #
> # Different weights for cases (1) and controls
> lalonde$weight.ATE <- ifelse(lalonde$treat == 1, 
> 1/lalonde$psvalue,1/(1-lalonde$psvalue))
> summary(lalonde$weight.ATE)
> #
> # END Convert propensity scores to weights#
> #
> 
> ##
> # Examples of two possible way  to enter weights in the coxph model. #
> ##
> fit1 <- coxph(Surv(time,status)~group,weights=lalonde$weight,data=lalonde)
> or
> fit2 <- 
> coxph(Surv(time,status)~group,weights=log(lalonde$weight),data=lalonde)
> ##
> # Examples of two possible way  to enter weights in the coxph model. #
> ##
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


Re: [R] series of densities

2021-05-17 Thread David Winsemius



On 5/17/21 7:44 AM, Troels Ring wrote:

Dear friends
I'm trying to plot in silico derived values of 3 types of 
buffer-capacities  over pH values and want densities of the three 
types together at each pH with the pH values on the abscissa.


I have generated some data

set.seed(2345)
pHs <- c(7.2,7.4,7.6)
pH <- rep(pHs,each=30)
BC <- rep(rep(c(20,10,10),each=10),3)+rnorm(90,0,5)
type <- rep(rep(c("TOT","NC","CA"),each=10),3)

ddd <- data.frame(pH,BC,type)

GG <- ggplot()
for (i in 1:3) {
  dd <- ddd[ddd$pH==pHs[i],]
  GG <- GG + geom_density(data=dd,aes(x=BC,fill=type),alpha=0.1)
}
GG

but here I only get all pH values  plotted together whereas I want 3 
series in the vertical direction at the three pH values.


I wonder how this could be done?


Here are two different displays of the data. I haven't figured out what 
was intended by the request for " 3 series in the vertical direction at 
the three pH values".


library(ggplot2)

#violin plots are density-like

ggplot( data=ddd, aes(x=pH, y=BC,group=interaction(type,pH), 
col=type))+geom_violin()


#boxplots are summary methods

ggplot( data=ddd, aes(x=pH, y=BC,group=interaction(type,pH), 
col=type))+geom_boxplot()





All best wishes

Troels Ring, MD
Aalborg, Denmark

PS: Windows 10,

R version 4.0.5 (2021-03-31

__
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] series of densities

2021-05-17 Thread David Winsemius



On 5/17/21 7:44 AM, Troels Ring wrote:

Dear friends
I'm trying to plot in silico derived values of 3 types of 
buffer-capacities  over pH values and want densities of the three 
types together at each pH with the pH values on the abscissa.


I have generated some data

set.seed(2345)
pHs <- c(7.2,7.4,7.6)
pH <- rep(pHs,each=30)
BC <- rep(rep(c(20,10,10),each=10),3)+rnorm(90,0,5)
type <- rep(rep(c("TOT","NC","CA"),each=10),3)

ddd <- data.frame(pH,BC,type)

GG <- ggplot()
for (i in 1:3) {
  dd <- ddd[ddd$pH==pHs[i],]
  GG <- GG + geom_density(data=dd,aes(x=BC,fill=type),alpha=0.1)
}
GG

but here I only get all pH values  plotted together whereas I want 3 
series in the vertical direction at the three pH values.



Are you perhaps hoping for means of grouped values connected by lines?


Of perhaps a bee-swarm type plot? there are quite a few overlapping points.


-- --

David.



I wonder how this could be done?

All best wishes

Troels Ring, MD
Aalborg, Denmark

PS: Windows 10,

R version 4.0.5 (2021-03-31

__
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] grep

2021-05-08 Thread David Winsemius



On 5/8/21 10:00 AM, Steven Yen wrote:
Below, the first command simply creates a list of 16 names (labels) 
which can be ignore.


In the 2nd and 3rd commands, I am able to identify names containing 
"black".


In line 4, I am trying to identify names containing "black" or 
"conserv" but obviously it does not work. Can someone help? Thanks.


> names<-names(tp.nohs$estimate)[c(1:8,58:65)]; names
 [1] "x1.one"  "x1.black"    "x1.othrrace" "x1.moddkna" 
"x1.conserv"  "x1.nstrprty"
 [7] "x1.strrep"   "x1.sevngprt" "x2.one"  "x2.black" 
"x2.othrrace" "x2.moddkna"

[13] "x2.conserv"  "x2.nstrprty" "x2.strrep"   "x2.sevngprt"
> grep("black",names,value=TRUE)
[1] "x1.black" "x2.black"
> grep("black",names,value=FALSE)
[1]  2 10
> grep(c("black","conserv"),names,value=TRUE)
[1] "x1.black" "x2.black"
Warning message:
In grep(c("black", "conserv"), names, value = TRUE) :
  argument 'pattern' has length > 1 and only the first element will be 
used



Try using the logical OR operator (vertical bar, AKA "pipe")

grep(c("black|conserv"), names, value=TRUE)

--

David.



__
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] calculating area of ellipse

2021-05-06 Thread David Winsemius



On 5/6/21 6:29 PM, Jim Lemon wrote:

Hi James,
If the result contains the major (a) and minor (b) axes of the
ellipse, it's easy:

area<-pi*a*b



ITYM semi-major and semi-minor axes.


--

David



try using str() on the result you get.

Jim

On Fri, May 7, 2021 at 3:51 AM james meyer  wrote:

In doing meta-analysis of diagnostic accuracy I produce ellipses of confidence
and prediction intervals in two dimensions.  How can I calculate the area of
the ellipse in ggplot2 or base R?

thank you
James Meyer

__
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] Question about using R sample datasets

2021-05-02 Thread David Winsemius
Again, the terms of the license govern the legalities. I don’t think you would 
need any further efforts at licensing your commentary. Screenshots or text 
copies would both be just copies and the appropriate citations would probably 
be all that were needed. I do not think your commentary or explanatory work 
would need to be considered FOSS or a copyleft license. There are many 
instances of commercial, copyrighted books that contain portions of R source 
code. Several businesses exist that sell accessories or packages that depend on 
but are not part of core R. Some of them seem to me to be skirting the line of 
legality but I don’t think there have been any cases brought before judicial 
authorities. So your plans seems completely safe and well inside accepted and 
legal boundaries to my understanding. 

David 

Sent from my iPhone

> On May 2, 2021, at 2:39 AM, Maja Analytics  
> wrote:
> 
> 
> Thanks for the advice.
> 
> What about R code? Is that free to share? I would use my own dataset or made 
> up dataset, so I am only now interested what about R code, can I screenshot 
> it and then explain what is on the photo?
> 
> Maja
> 
> ned, 2. svi 2021. u 01:17 David Winsemius  napisao je:
>> Any answer you get here will will have all the authority of "some guy on the 
>> Internet", but my reading of the licenses is that as long as you give proper 
>> credit that you can use any material in teaching or commercial purposes AND 
>> derivative works are likewise copy-able on an open source (FOSS) basis. You 
>> should read the LinkedIn TOS and make sure that posting there is not subject 
>> to some sort of publisher's copyright. That might be a violation fo the 
>> licensing for material copied from CRAN sources. Acknowledgment alone might 
>> not be an acceptable use. You may need to seek appropriate legal counsel or 
>> get opinions from the creators of the licensing language, since there are a 
>> variety of license.
>> 
>> David Winsemius, MD, (IANAL)
>> 
>> 
>> > On May 1, 2021, at 12:17 PM, Maja Analytics 
>> >  wrote:
>> > 
>> > Hello!
>> > 
>> > I would like to make tutorials for non-data scientists in R on Medium and
>> > as LinkedIn articles. Could you tell me if I can use R sample datasets (I
>> > would note the acknowledgements on the end) for that?
>> > 
>> > Thanks in advance, kind regards,
>> > Maja
>> > 
>> >   [[alternative HTML version deleted]]
>> > 
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide 
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> 

[[alternative HTML version deleted]]

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


Re: [R] Question about using R sample datasets

2021-05-01 Thread David Winsemius
Any answer you get here will will have all the authority of "some guy on the 
Internet", but my reading of the licenses is that as long as you give proper 
credit that you can use any material in teaching or commercial purposes AND 
derivative works are likewise copy-able on an open source (FOSS) basis. You 
should read the LinkedIn TOS and make sure that posting there is not subject to 
some sort of publisher's copyright. That might be a violation fo the licensing 
for material copied from CRAN sources. Acknowledgment alone might not be an 
acceptable use. You may need to seek appropriate legal counsel or get opinions 
from the creators of the licensing language, since there are a variety of 
license.

David Winsemius, MD, (IANAL)


> On May 1, 2021, at 12:17 PM, Maja Analytics  
> wrote:
> 
> Hello!
> 
> I would like to make tutorials for non-data scientists in R on Medium and
> as LinkedIn articles. Could you tell me if I can use R sample datasets (I
> would note the acknowledgements on the end) for that?
> 
> Thanks in advance, kind regards,
> Maja
> 
>   [[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] evil attributes

2021-04-11 Thread David Winsemius



On 4/11/21 11:46 AM, Viechtbauer, Wolfgang (SP) wrote:

The is.vector() thing has also bitten me in the behind on a few occasions. When 
I want to check if something is a vector, allow for it to possibly have some 
additional attributes (besides names) that would make is.vector() evaluate to 
FALSE, but evaluate to FALSE for lists (since is.vector(list(a=1, b=2)) is TRUE 
-- which also wasn't what I had initially expected before reading the 
documentation), I use:

.is.vector <- function(x)
is.atomic(x) && !is.matrix(x) && !is.null(x)

This might also work:

.is.vector <- function(x)
is(x, "vector") && !is.list(x)


That will allow expression vectors to return TRUE, but they are not 
atomic so they would be excluded by your current version.


--

David.



I am sure there are all kinds of edge (and probably also not so edge) cases 
where these also fail to work properly. Kinda curious if there are better 
approaches out there.



You might want to exclude expression vectors as well.




Best,
Wolfgang


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Therneau, Terry
M., Ph.D. via R-help
Sent: Saturday, 10 April, 2021 16:12
To: R-help
Subject: Re: [R] evil attributes

I wrote: "I confess to being puzzled WHY the R core has decided on this
definition..."
After just a little more thought let me answer my own question.

a. The as.vector() function is designed to strip off everything extraneous and
leave just
the core.   (I have a mental image of Jack Webb saying "Just the facts
ma'am").   I myself
use it freqently in the test suite for survival, in cases where I'm checking the
corrent
numeric result and don't care about any attached names.

  b. is.vector(x) essentially answers the question "does x look like a result of
as.vector?"

Nevertheless I understand Roger's confusion.

--
Terry M Therneau, PhD
Department of Quantitative Health Sciences
Mayo Clinic
thern...@mayo.edu

"TERR-ree THUR-noh"

__
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] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread David Winsemius



On 4/9/21 5:21 AM, Wolfgang Grond wrote:

Greg,

here I get the error message:

Error my_function(val) :

cannot find function my_function.


I'm guessing that you are following someone else's blog and have failed 
one of two things:


- understand that what was meant by the author was that you were assumed 
to have a function in mind to use for a programming strategy being 
illustrated


- or you were copying and pasting only part of a blog and failed to 
paste in the code from above where there was earlier code defining 
`my_function`




Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall :

Wolfgang,


result <- assign(paste("subnet_",  val, sep = "")

result <- my_function(val)

i don't understand why you are twice assigning to =result=.  also, the
first assignment doesn't seem well formatted (t's missing a value?).

did you mean something like

: assign(paste("subnet_",  val, sep = ""), my_function(val))

(which i would think should work)?

cheers, Greg

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


-
Numberland - Dr. Wolfgang Grond
Diplomphysiker, TQM-Assessor (EFQM)
Six Sigma Green Belt
Ingenieurbüro / Engineering Consultancy
Lohfeld 20, DE-95326 Kulmbach, Germany
Phone: +49 9221 6919131
Fax: +49 9221 6919156
Mail: gr...@numberland.com
URL: http://www.numberland.com
[[alternative HTML version deleted]]

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


__
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] Unable to extract gene list from chromosome

2021-04-08 Thread David Winsemius


On 4/8/21 3:42 PM, pooja sinha wrote:
> Hi David,
>
> Sorry I forgot to attach the file. Now it's attached.


Now when I go back and check the values of the setup variables after 
seeing an error on the last call,

Error in .processResults(postRes, mart = mart, sep = sep, fullXmlQuery = 
fullXmlQuery,  :
   Query ERROR: caught BioMart::Exception::Database: Error during query 
execution: You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use 
near 'AND (main.seq_region_end_1020 >= '15108600' OR 
main.seq_region_end_1020 >= '9115' at line 1

I now notice:


AT_AC_Gene$chr

#NULL

Changing that to AT_AC_Gene$Chromosome_number gets at least a startup 
message from the server:

Batch submitting query 
[==>---] 
5% eta:  1m

Error in .processResults(postRes, mart = mart, sep = sep, fullXmlQuery = 
fullXmlQuery,  :
   Query ERROR: caught BioMart::Exception::Database: Error during query 
execution: You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use 
near 'AND (main.seq_region_end_1020 >= '15108600' OR 
main.seq_region_end_1020 >= '9115' at line 1

But then I get the same error before about SQL syntax error.


Then I ran it with only complete cases and now get no error but again 
see no hits:

str(final_1)
'data.frame':    0 obs. of  6 variables:
  $ external_gene_name: logi
  $ ensembl_gene_id   : logi
  $ start_position    : logi
  $ end_position  : logi
  $ rgd_symbol    : logi
  $ chromosome_name   : logi


I also see a lot of NA's in that dataset and when I just send the first 
10 rows of the request, I get no error (but also no matches.)


So you clearly are not giving us all the data or all the code, but I'm 
finally wondering if you just don't have an data that matches teh 
external datasets in your chosen "biomart". Can you offer a smaller 
dataset that you know with certainty should produce a match?


Alternatively, you might want to post this instead at the BioConductor 
mailing list. They are the people who have a better chance of spotting 
obvious errors. I've found two likely code-related errors but I'm not a 
computational biostatistician.

David

>
>
> Thanks,
> Puja
>
> On Thu, Apr 8, 2021 at 6:01 PM David Winsemius  <mailto:dwinsem...@comcast.net>> wrote:
>
>
> On 4/8/21 2:30 PM, pooja sinha wrote:
> > Hi All,
> >
> > I am trying to extract gene list from chromosome number and
> position, for
> > that I am using biomaRt in R but I am getting error messages as
> shown
> > below. Also below is the code I am using for extraction.
> >
> > library("biomaRt")
> > listMarts()
> > ensembl <- useMart("ensembl")
> > datasets <- listDatasets(ensembl)
> > ensembl = useDataset("rnorvegicus_gene_ensembl",mart=ensembl)
> > AT_AC_Gene <-
> read.csv("AT-AC-methylkit_biomart-4-7-21.csv",header=T)
>
>
> #--- a this point I get
>
> Error in file(file, "rt") : cannot open the connection
> In addition: Warning message:
> In file(file, "rt") :
>    cannot open file 'AT-AC-methylkit_biomart-4-7-21.csv': No such
> file
> or directory
>
> > attributes <-
> >
> 
> c("external_gene_name","ensembl_gene_id","start_position","end_position","rgd_symbol","chromosome_name")
> > filters <- c("chromosome_name","start","end")
> > values <- list(AT_AC_Gene$chr,AT_AC_Gene$start,AT_AC_Gene$end)
> > final_1 <- getBM(attributes=attributes, filters=filters,
> values=values,
> > mart=ensembl)
> >
> > The code runs well without any error but the final1 output has 0
> > observations of 6 variables. Why?
> >
> > Can anyone help me with this?
>
>
> You are more likely to get a useful response on the BioC mailing
> list.
> It appears you have a dependenciy of a csv file that you have not
> told
> us about.
>
>
> -- 
>
> David
>
> >
> >
> > Thanks,
> >
> > Puja
> >
> >       [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org <mailto: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] Unable to extract gene list from chromosome

2021-04-08 Thread David Winsemius



On 4/8/21 2:30 PM, pooja sinha wrote:

Hi All,

I am trying to extract gene list from chromosome number and position, for
that I am using biomaRt in R but I am getting error messages as shown
below. Also below is the code I am using for extraction.

library("biomaRt")
listMarts()
ensembl <- useMart("ensembl")
datasets <- listDatasets(ensembl)
ensembl = useDataset("rnorvegicus_gene_ensembl",mart=ensembl)
AT_AC_Gene <- read.csv("AT-AC-methylkit_biomart-4-7-21.csv",header=T)



#--- a this point I get

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'AT-AC-methylkit_biomart-4-7-21.csv': No such file 
or directory



attributes <-
c("external_gene_name","ensembl_gene_id","start_position","end_position","rgd_symbol","chromosome_name")
filters <- c("chromosome_name","start","end")
values <- list(AT_AC_Gene$chr,AT_AC_Gene$start,AT_AC_Gene$end)
final_1 <- getBM(attributes=attributes, filters=filters, values=values,
mart=ensembl)

The code runs well without any error but the final1 output has 0
observations of 6 variables. Why?

Can anyone help me with this?



You are more likely to get a useful response on the BioC mailing list. 
It appears you have a dependenciy of a csv file that you have not told 
us about.



--

David




Thanks,

Puja

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

2021-04-06 Thread David Winsemius



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

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

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



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



library(multcomp)  # console output follows

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

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

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

     General Linear Hypotheses

Multiple Comparisons of Means: Tukey Contrasts


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


--

David.



Thank you,
John

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


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


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


Re: [R] using MAP and PURR to compute characteristic roots

2021-03-31 Thread David Winsemius



On 3/31/21 5:10 PM, Veerappa Chetty wrote:

I have to compute characteristic roots for 100s of U.S.counties.  I got
help using " lapply". I prefer using MAP and PURR if that is possible. I am
using them to compute linear regressions.
Here is my test problem and the output. I would appreciate any help.
Thanks
V.K.Chetty

test.dat<- tibble(ID=c(1,2),a=c(1,1),b=c(1,1),c=c(2,2),d=c(4,3))
test.out<-test.dat %>% nest(-ID) %>% mutate(fit = purrr::map(data,~
function(x) eigen(data.matrix(x)), data=.))



I think you will find that there is a bias on R-help toward using "base" 
R functions where it seems "natural". The venue where "tidyverse" 
solutions are typically returned is StackOverflow.)


It wasn't stated  clearly what you wanted from this. The `eigen` 
function returns a list object so the apply function neatly handles row 
based operations:



> apply( test.dat[-1], 1, function(x){eigen(matrix(x,2))})
[[1]]
eigen() decomposition
$values
[1] 4.5615528 0.4384472

$vectors
   [,1]   [,2]
[1,] -0.4896337 -0.9627697
[2,] -0.8719282  0.2703230


[[2]]
eigen() decomposition
$values
[1] 3.7320508 0.2679492

$vectors
   [,1]   [,2]
[1,] -0.5906905 -0.9390708
[2,] -0.8068982  0.3437238


If you instead wanted only the eigenvalues you might have chosen to 
extract them at the time of the `eigen` call:



 apply( test.dat[-1], 1, function(x){eigen(matrix(x,2))$values})
  [,1]  [,2]
[1,] 4.5615528 3.7320508
[2,] 0.4384472 0.2679492

Do note that the values are returned column-wise.

(I see that you noted in an earlier (duplicate) rhelp posting that you 
were expecting "younger" respondents. Since I'm in my eighth decade, I 
probably don't qualify.)



--

David Winsemius, MD




I get this output:

test.out$fit

[[1]]
function(x) eigen(data.matrix(x))


[[2]]
function(x) eigen(data.matrix(x))


[[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] Thank you 4 Davide

2021-03-22 Thread David Winsemius



On 3/22/21 8:24 AM, francesca brun via R-help wrote:

Hello,
The problem was that version 4.0.4 did not support the package so I tried with 
several old versions until 3.6.2 installs both climtrend and Rcmdr with its 
graphical interface !! solved and thanks again Davide !!Francesca



I'm glad you got success.

However, for anyone viewing this I must note that the proper name of the 
package is 'climtrends'. I'm not sure that you  ever spelled it 
correctly in your two postings to rhelp. R users will get little system 
help for poorly spelled package names. There is some hinting that occurs 
when using Rstudio, but that will only occur for packages that are 
already installed on one's system.



--

David.


(from Italy)


[[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] Help Package 'CLIMTRENDS' from Archive

2021-03-22 Thread David Winsemius



> On Mar 22, 2021, at 4:54 AM, francesca brun via R-help  
> wrote:
> 
> Hello,
> I need to run the 'climtrend' library

It's a package, not a library. Libraries are directory locations and typically 
hold multiple packages.

> which is no longer available, I downloaded and installed it from the archive 
> on my pc but it doesn't work, it says "I can't find the function ..." what 
> should I do? I absolutely need to use it, in addition to installing it, what 
> should I do to use it?
> thank you in advance for your kindness,

If earlier you got a message telling you of successful installation, then the 
most likely error is failure to execute code that loads the packages contents 
into your R workspace. 

library(climtrends) # needs to be done before you will see functions from it in 
you console session.

Of course, it's always possible you misspelled the function name. I see that 
the package uses a lot of camelCase names and R does NOT allow errors in 
spelling (such as your spelling of the package names as CLIMTRENDS. )

On a mac running R 3.6 I got no error installing from source. It did not 
require compiler tools.

-- 
David.

> Francesca
> __
> 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] about a p-value < 2.2e-16

2021-03-19 Thread David Winsemius



Sent from my iPhone

> On Mar 18, 2021, at 10:26 PM, Bogdan Tanasa  wrote:
> 
> Dear Spencer, thank you very much for your prompt email and help. When
> using :
> 
>> wilcox.test(rnorm(100), rnorm(100, 2), exact=TRUE)
> W = 698, p-value < 2.2e-16
> 
>> wilcox.test(rnorm(100), rnorm(100, 2), exact=FALSE)
> W = 1443, p-value < 2.2e-16
> 
> and in both cases p-value < 2.2e-16. By "exact" p-value, i have meant the
> "precise" p-value ;
> 
> If I may ask please, could we write p-value = 0 ?
> 
> i have noted a similar conversation on stackexchange, although the answer
> is not very clear (to me).

The reason it wasn’t and couldn’t be “clear” was that the underlying scientific 
question and the statistical methods were not precisely described. 

The same lack of background information still persists in this discussion. 

— 
David
> 
> https://stats.stackexchange.com/questions/78839/how-should-tiny-p-values-be-reported-and-why-does-r-put-a-minimum-on-2-22e-1
> 
> thanks again,
> 
> bogdan
> 
>> On Thu, Mar 18, 2021 at 10:05 PM Spencer Graves <
>> spencer.gra...@effectivedefense.org> wrote:
>>  I would push back on that from two perspectives:
>>1.  I would study exactly what the journal said very
>> carefully.  If they mandated "wilcox.test", that function has an
>> argument called "exact".  If that's what they are asking, then using
>> that argument gives the exact p-value, e.g.:
>>> wilcox.test(rnorm(100), rnorm(100, 2), exact=TRUE)
>>Wilcoxon rank sum exact test
>> data:  rnorm(100) and rnorm(100, 2)
>> W = 691, p-value < 2.2e-16
>>2.  If that's NOT what they are asking, then I'm not
>> convinced what they are asking makes sense:  There is is no such thing
>> as an "exact p value" except to the extent that certain assumptions
>> hold, and all models are wrong (but some are useful), as George Box
>> famously said years ago.[1]  Truth only exists in mathematics, and
>> that's because it's a fiction to start with ;-)
>>  Hope this helps.
>>  Spencer Graves
>> [1]
>> https://en.wikipedia.org/wiki/All_models_are_wrong
 On 2021-3-18 11:12 PM, Bogdan Tanasa wrote:
 <
>> https://meta.stackexchange.com/questions/362285/about-a-p-value-2-2e-16>
>>> Dear all,
>>> i would appreciate having your advice on the following please :
>>> in R, the wilcox.test() provides "a p-value < 2.2e-16", when we compare
>>> sets of 1000 genes expression (in the genomics field).
>>> however, the journal asks us to provide the exact p value ...
>>> would it be legitimate to write : "p-value = 0" ? thanks a lot,
>>> -- 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.
> 
>   [[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] hist from a list

2021-03-08 Thread David Winsemius


On 8/3/20 11:48 AM, Pedro páramo wrote:

Hi Rasmus, Josh and Rui,

First of all many thanks in advance about your help.

The first thig is sometimes you say " you are posting in HTML and that
makes the
post unreadable as this is a plain text list" how can I put the code in the
correct way, not html (attaching in txt?)


Set your gmail client to deliver in plain text.

Attached is a png file that is a screen shot of a Chrome mediated effort 
at composing a message and clicking the three-stacked-dots icon at the 
lower right corner. (Learn to use your chosen software tools by reading 
manuals or searching.)



--

David.



The second about the code:

I have used this:

bwc <- cbind(bwfinal2,bwfinal)
colnames(bwc)=c("Accion","reval")
df <- matrix(unlist(bwc), nrow=nrow(bwc), byrow=F)
colnames(bwchist)=c("Accion","reval")
bwchist <-as.data.frame(bwc[order(df[,2]), ])

bwchist is the ordered cum stock returns in the year but because is a list
it is not possible to plot and histogram with x (names of stocks) and the x
axist the value of cum stocks (reval)

when I put dput(bwchist) the console says:

dput(bwchist)
structure(list(Accion = list("REE", "Enagas", "Grifols", "Ferrovial",
 "Acerinox", "Naturgy", "Inditex", "Bankia", "ENCE", "Aena",
 "Bankinter", "Mapfre", "CaixaBank", "CIE", "Colonial", "Almirall",
 "Indra", "ArcelorMittal", "ACS", "Telefonica", "Amadeus",
 "BBVA", "Merlin", "Santander", "Repsol", "Melia", "Sabadell",
 "IAG", "Acciona", "Endesa", "MasMovil", "Iberdrola", "SGamesa",
 "Viscofan", "Cellnex"), reval = list(-0.0200827282700085,
 -0.0590294115600855, -0.214126598790964, -0.220773677809979,
 -0.229653300324357, -0.257944379583984, -0.283942789063822,
 -0.285159347392533, -0.303814713896458, -0.30734460425763,
 -0.309408155539818, -0.319912221435868, -0.322790949659181,
 -0.344047579452905, -0.347919538415482, -0.356898907103825,
 -0.374263261296661, -0.40147247119078, -0.405150043834815,
 -0.406022775042175, -0.413786100987797, -0.440679109311707,
 -0.442603156492871, -0.491634140733524, -0.499254932434042,
 -0.6, -0.709737357505148, -0.724461258850966, 0.0220528711420083,
 0.0462767672643172, 0.115044247787611, 0.238734548714937,
 0.274578114644054, 0.343422896082666, 0.387826126094928)), class =
"data.frame", row.names = c(NA,
-35L))

I try to make an hist or barplot but because it is a list no way to obtain
the plot.

Many thanks again for your help.

I have printed two manuals to improve my level, but if you can help me, I
would be very very gratefull.



El vie., 31 jul. 2020 a las 18:28, Rasmus Liland ()
escribió:


On 2020-07-31 10:07 -0500, Joshua Ulrich wrote:
| On Fri, Jul 31, 2020 at 9:55 AM Rui Barradas wrote:
| | Às 15:44 de 31/07/2020, Michael Dewey escreveu:
| | | Dear Pedro
| | |
| | | Some comments in-line
| | |
| | | On 30/07/2020 21:16, Pedro páramo wrote:
| | | | Hi all,
| | | |
| | | | I attach my code, the think is I
| | | | want to make a bar plot the last
| | | | variable called "bwchist" so the
| | | | X axis are "Accion" and the y
| | | | axis are "reval" values.
| | | |
| | | | I have prove class(bwchist) and
| | | | says dataframe but its still a
| | | | list because it says me I have
| | | | prove to unlist, but it doesnt
| | | | work
| | | |
| | | | hist(bwchist)
| | | | Error in hist.default(bwchist) : 'x' must be numeric
| | |
| | | So bwchist is not a numeric
| | | variable as hist needs. Aboce you
| | | said it is a data frame but data
| | | frames are not numeric.
| | |
| | | For future reference your example
| | | is way too long for anyone to go
| | | through and try to help you. Try
| | | next time to reduce it to the
| | | absolute minimum by removing
| | | sections while you still get the
| | | error.  It is also easier to get
| | | help if you can remove unnecessary
| | | packages.
| | |
| | | It is also unreadable because you
| | | are posting in HTML and that makes
| | | the post unreadable as this is a
| | | plain text list.
| |
| | Hello,
| |
| | I second Michael's opinion. When the
| | post's code is very long, there is a
| | tendency to have less answers.
| |
| | Please post the output of
| |
| | dput(head(bwchist, 30))
| |
| | It's much shorter code and it
| | recreates the data so we will be
| | able to see what's wrong and try to
| | find a solution.
|
| Hi Pedro,
|
| Another 'best practice' and polite
| thing to do is link to other places
| you may have cross-posted.  That will
| give people the opportunity to see if
| your questions has been answered in
| another forum.
|
| I saw your post on R-SIG-Finance
| (https://stat.ethz.ch/pipermail/r-sig-finance/2020q3/014979.html),
| and started to work on a solution.
|
| I don't know how to do this in
| tidyquant, but here's how you can do
| it with quantmod:
|
| # all tickers
| tk <- c("ANA.MC", "ACS.MC", "AENA.MC", "AMS.MC", "MTS.MC", "BBVA.MC", "
SAB.MC",
|   "SAN.MC", "BKT.MC", "CABK.MC", "CLNX.MC", "ENG.MC", "ENC.MC", 

Re: [R] quantile from quantile table calculation without original data

2021-03-06 Thread David Winsemius



On 3/6/21 1:02 AM, Abby Spurdle wrote:

I came up with a solution.
But not necessarily the best solution.

I used a spline to approximate the quantile function.
Then use that to generate a large sample.
(I don't see any need for the sample to be random, as such).
Then compute the sample mean and sd, on a log scale.
Finally, plug everything into the plnorm function:

p <- seq (0.01, 0.99,, 1e6)
Fht <- splinefun (temp$percent, temp$size)
x <- log (Fht (p) )
psolution <- plnorm (0.1, mean (x), sd (x), FALSE)
psolution

The value of the solution is very close to one.
Which is not a surprise.

Here's a plot of everything:

u <- seq (0.01, 1.65,, 200)
v <- plnorm (u, mean (x), sd (x), FALSE)
plot (u, v, type="l", ylim = c (0, 1) )
points (temp$size, temp$percent, pch=16)
points (0.1, psolution, pch=16, col="blue")


Here's another approach, which uses minimization of the squared error to 
get the parameters for a lognormal distribution.


temp <- structure(list(size = c(1.6, 0.9466, 0.8062, 0.6477, 0.5069,
0.3781, 0.3047, 0.2681, 0.1907), percent = c(0.01, 0.05, 0.1,
0.25, 0.5, 0.75, 0.9, 0.95, 0.99)), .Names = c("size", "percent"
), row.names = c(NA, -9L), class = "data.frame")

obj <- function(x) {sum( qlnorm(1-temp$percent, x[[1]], 
x[[2]])-temp$size )^2}


# Note the inversion of the poorly named and flipped "percent" column,

optim( list(a=-0.65, b=0.42), obj)

#

$par
 a  b
-0.7020649  0.4678656

$value
[1] 3.110316e-12

$counts
function gradient
  51   NA

$convergence
[1] 0

$message
NULL


I'm not sure how principled this might be. There's no consideration in 
this approach for expected sampling error at the right tail where the 
magnitudes of the observed values will create much larger contributions 
to the sum of squares.


--

David.




On Sat, Mar 6, 2021 at 8:09 PM Abby Spurdle  wrote:

I'm sorry.
I misread your example, this morning.
(I didn't read the code after the line that calls plot).

After looking at this problem again, interpolation doesn't apply, and
extrapolation would be a last resort.
If you can assume your data comes from a particular type of
distribution, such as a lognormal distribution, then a better approach
would be to find the most likely parameters.

i.e.
This falls within the broader scope of maximum likelihood.
(Except that you're dealing with a table of quantile-probability
pairs, rather than raw observational data).

I suspect that there's a relatively easy way of finding the parameters.

I'll think about it...
But someone else may come back with an answer first...


On Sat, Mar 6, 2021 at 8:17 AM Abby Spurdle  wrote:

I note three problems with your data:
(1) The name "percent" is misleading, perhaps you want "probability"?
(2) There are straight (or near-straight) regions, each of which, is
equally (or near-equally) spaced, which is not what I would expect in
problems involving "quantiles".
(3) Your plot (approximating the distribution function) is
back-the-front (as per what is customary).


On Fri, Mar 5, 2021 at 10:14 PM PIKAL Petr  wrote:

Dear all

I have table of quantiles, probably from lognormal distribution

  dput(temp)
temp <- structure(list(size = c(1.6, 0.9466, 0.8062, 0.6477, 0.5069,
0.3781, 0.3047, 0.2681, 0.1907), percent = c(0.01, 0.05, 0.1,
0.25, 0.5, 0.75, 0.9, 0.95, 0.99)), .Names = c("size", "percent"
), row.names = c(NA, -9L), class = "data.frame")

and I need to calculate quantile for size 0.1

plot(temp$size, temp$percent, pch=19, xlim=c(0,2))
ss <- approxfun(temp$size, temp$percent)
points((0:100)/50, ss((0:100)/50))
abline(v=.1)

If I had original data it would be quite easy with ecdf/quantile function but 
without it I am lost what function I could use for such task.

Please, give me some hint where to look.


Best regards

Petr
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/


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

Re: [R] quantile from quantile table calculation without original data

2021-03-05 Thread David Winsemius



On 3/5/21 1:14 AM, PIKAL Petr wrote:

Dear all

I have table of quantiles, probably from lognormal distribution

  dput(temp)
temp <- structure(list(size = c(1.6, 0.9466, 0.8062, 0.6477, 0.5069,
0.3781, 0.3047, 0.2681, 0.1907), percent = c(0.01, 0.05, 0.1,
0.25, 0.5, 0.75, 0.9, 0.95, 0.99)), .Names = c("size", "percent"
), row.names = c(NA, -9L), class = "data.frame")

and I need to calculate quantile for size 0.1

plot(temp$size, temp$percent, pch=19, xlim=c(0,2))
ss <- approxfun(temp$size, temp$percent)
points((0:100)/50, ss((0:100)/50))
abline(v=.1)

If I had original data it would be quite easy with ecdf/quantile function but 
without it I am lost what function I could use for such task.


The quantiles are in reverse order so tryoing to match the data to 
quantiles from candidate parameters requires subtracting them from unity:


> temp$size
[1] 1.6000 0.9466 0.8062 0.6477 0.5069 0.3781 0.3047 0.2681 0.1907
> qlnorm(1-temp$percent, -.5)
[1] 6.21116124 3.14198142 2.18485959 1.19063854 0.60653066 0.30897659 
0.16837670 0.11708517 0.05922877

> qlnorm(1-temp$percent, -.9)
[1] 4.16346589 2.10613313 1.46455518 0.79810888 0.40656966 0.20711321 
0.11286628 0.07848454 0.03970223

> qlnorm(1-temp$percent, -2)
[1] 1.38589740 0.70107082 0.48750807 0.26566737 0.13533528 0.06894200 
0.03756992 0.02612523 0.01321572

> qlnorm(1-temp$percent, -1.6)
[1] 2.06751597 1.04587476 0.72727658 0.39632914 0.20189652 0.10284937 
0.05604773 0.03897427 0.01971554

> qlnorm(1-temp$percent, -1.6, .5)
[1] 0.64608380 0.45951983 0.38319004 0.28287360 0.20189652 0.14410042 
0.10637595 0.08870608 0.06309120

> qlnorm(1-temp$percent, -1, .5)
[1] 1.1772414 0.8372997 0.6982178 0.5154293 0.3678794 0.2625681 
0.1938296 0.1616330 0.1149597

> qlnorm(1-temp$percent, -1, .4)
[1] 0.9328967 0.7103066 0.6142340 0.4818106 0.3678794 0.2808889 
0.2203318 0.1905308 0.1450700

> qlnorm(1-temp$percent, -0.5, .4)
[1] 1.5380866 1.1710976 1.0127006 0.7943715 0.6065307 0.4631076 
0.3632657 0.3141322 0.2391799

> qlnorm(1-temp$percent, -0.55, .4)
[1] 1.4630732 1.1139825 0.9633106 0.7556295 0.5769498 0.4405216 
0.3455491 0.2988118 0.2275150

> qlnorm(1-temp$percent, -0.55, .35)
[1] 1.3024170 1.0260318 0.9035201 0.7305712 0.5769498 0.4556313 
0.3684158 0.3244257 0.2555795

> qlnorm(1-temp$percent, -0.55, .45)
[1] 1.6435467 1.2094723 1.0270578 0.7815473 0.5769498 0.4259129 
0.3241016 0.2752201 0.2025322

> qlnorm(1-temp$percent, -0.53, .45)
[1] 1.6767486 1.2339052 1.0478057 0.7973356 0.5886050 0.4345169 
0.3306489 0.2807799 0.2066236

> qlnorm(1-temp$percent, -0.57, .45)
[1] 1.6110023 1.1855231 1.0067207 0.7660716 0.5655254 0.4174793 
0.3176840 0.2697704 0.1985218


Seems like it might be an acceptable fit. modulo the underlying data 
gathering situation which really should be considered.


You can fiddle with that result. My statistical hat (not of PhD level 
certification) says that the middle quantiles in this sequence probably 
have the lowest sampling error for a lognormal, but I'm rather unsure 
about that. A counter-argument might be that since there is a hard lower 
bound of 0 for the 0-th quantile that you should be more worried about 
matching the 0.1907 value to the 0.01 order statistic, since 99% of the 
data is know to be above it. Seems like efforts at matching the 0.50 
quantile to 0.5069 for the logmean parameter and matching the 0.01 
quantile 0.1907 for estimation of  the variance estimate might be 
preferred to worrying too much about the 1.6 value which would be in the 
right tail (and far away from your region of extrapolation.)



Further trial and error:


> qlnorm(1-temp$percent, -0.58, .47)
[1] 1.6709353 1.2129813 1.0225804 0.7687497 0.5598984 0.4077870 
0.3065638 0.2584427 0.1876112

> qlnorm(1-temp$percent, -0.65, .47)
[1] 1.5579697 1.1309763 0.9534476 0.7167775 0.5220458 0.3802181 
0.2858382 0.2409704 0.1749275

> qlnorm(1-temp$percent, -0.65, .5)
[1] 1.6705851 1.1881849 0.9908182 0.7314290 0.5220458 0.3726018 
0.2750573 0.2293682 0.1631355

> qlnorm(1-temp$percent, -0.65, .4)
[1] 1.3238434 1.0079731 0.8716395 0.6837218 0.5220458 0.3986004 
0.3126657 0.2703761 0.2058641

> qlnorm(1-temp$percent, -0.68, .4)
[1] 1.2847179 0.9781830 0.8458786 0.6635148 0.5066170 0.3868200 
0.3034251 0.2623852 0.1997799

> qlnorm(1-temp$percent, -0.65, .39)
[1] 1.2934016 0.9915290 0.8605402 0.6791257 0.5220458 0.4012980 
0.3166985 0.2748601 0.2107093

>
> qlnorm(1-temp$percent, -0.65, .42)
[1] 1.3868932 1.0416839 0.8942693 0.6930076 0.5220458 0.3932595 
0.3047536 0.2616262 0.1965053

> qlnorm(1-temp$percent, -0.68, .42)
[1] 1.3459043 1.0108975 0.8678396 0.6725261 0.5066170 0.3816369 
0.2957468 0.2538940 0.1906976



(I did make an effort at searching for quantile matching as a method for 
distribution fitting, but came up empty.)



--

David.



Please, give me some hint where to look.


Best regards

Petr

>[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and 

Re: [R] Out from an R package

2021-02-25 Thread David Winsemius



On 2/25/21 7:24 AM, Göran Djurfeldt wrote:

Help! I am going crazy for a very simple reason. I can’t access the output from 
for instance the lme4 package in R. I have been able to import an SPSS file 
into an R data frame. I have downloaded and installed the Lme4 package and I 
think I have also learnt how to produce a mixed model with lmer:

Output <- lmer(G10ln ~ v191_ms + (1 | couno), data = 'G10R')

How shall I define the output from lmer? What kind of object is it? How do I 
define it?


I'm not sure what you mean by "How do I define" the output from a 
function. The function does the "definition", but you can correctly 
refer to the output of most regression functions as "a list". The best 
way to get the specific result from a function is to go to its help page 
and look at the Details and Values sections.



--

David.



Goran

[[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] Plotting world maps with locations.

2021-02-12 Thread David Winsemius



Sent from my iPhone

> On Feb 12, 2021, at 9:01 PM, David Winsemius  wrote:
> 
> 
> 
> Sent from my iPhone
> 
>> On Feb 12, 2021, at 1:35 PM, Jibrin Alhassan  
>> wrote:
>> 
>> Hello Romanus,
>> You are to post only the code and the error messages and not all the
>> information from your terminal in R session.
> 
> That’s not actually the best practice for rhelp questions. More info is 
> better than less. What’s missing, however, is the data. 
> 
> — 
> David
>> 
>>> On Fri, Feb 12, 2021, 4:35 PM Romanus Ejike 
>>> wrote:
>>> 
>>> Please, I need help from anyone that can solve this problem.
>>> I wanted to plot a world map with locations and names of the locations but
>>> could not. The codes I have tried are as shown below.
>>> ugwoke@ugwoke-HP-ENVY-Laptop-13-aq0xxx:~/Desktop$ R
>>> 
>>> R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
>>> Copyright (C) 2020 The R Foundation for Statistical Computing
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>> 
>>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>>> You are welcome to redistribute it under certain conditions.
>>> Type 'license()' or 'licence()' for distribution details.
>>> 
>>> Natural language support but running in an English locale
>>> 
>>> R is a collaborative project with many contributors.
>>> Type 'contributors()' for more information and
>>> 'citation()' on how to cite R or R packages in publications.
>>> 
>>> Type 'demo()' for some demos, 'help()' for on-line help, or
>>> 'help.start()' for an HTML browser interface to help.
>>> Type 'q()' to quit R.
>>> 
>>>> NMdata <-
>>> 
>>> read.table("NM1989.txt",col.names=c("SNAME","FNAME","NMTYPE","LAT","LON","ALTI"))
Here the file is named NMdata. 

>>>> library(ggplot2)
>>>> library(sf)
>>> Linking to GEOS 3.9.0, GDAL 3.2.0, PROJ 7.2.0
>>>> library(rnaturalearth)
>>>> library(rnaturalearthdata)
>>>> world <- ne_countries(scale = "medium", returnclass = "sf")
>>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>>> FALSE) + ggtitle("World map") + points(NMdata$LON,Nmdata$LAT,col = "red",
>>> cex = 0.01)
>>> Error in xy.coords(x, y) : object 'Nmdata' not found

But the error says Nmdata not found. SPELLING

— 
David
>>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>>> FALSE) + ggtitle("World map") + points(NMdata$LON,NMdata$LAT,col = "red",
>>> cex = 0.01)
>>> Error in plot.xy(xy.coords(x, y), type = type, ...) :
>>> plot.new has not been called yet
>>> In addition: Warning messages:
>>> 1: In xy.coords(x, y) : NAs introduced by coercion
>>> 2: In xy.coords(x, y) : NAs introduced by coercion
>>> 3: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>> locale not supported by Xlib: some X ops will operate in C locale
>>> 4: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>> X cannot set locale modifiers
>>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>>> FALSE) + ggtitle("World map") + points(NMdata$LON,NMdata$LAT,col = "red",
>>> cex = 0.01, pch = 20)
>>> Error in plot.xy(xy.coords(x, y), type = type, ...) :
>>> plot.new has not been called yet
>>> In addition: Warning messages:
>>> 1: In xy.coords(x, y) : NAs introduced by coercion
>>> 2: In xy.coords(x, y) : NAs introduced by coercion.
>>> I have also tried the codes below but it did not show the locations.
>>> ugwoke@ugwoke-HP-ENVY-Laptop-13-aq0xxx:~/Desktop$ R
>>> 
>>> R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
>>> Copyright (C) 2020 The R Foundation for Statistical Computing
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>> 
>>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>>> You are welcome to redistribute it under certain conditions.
>>> Type 'lice

Re: [R] Plotting world maps with locations.

2021-02-12 Thread David Winsemius



Sent from my iPhone

> On Feb 12, 2021, at 1:35 PM, Jibrin Alhassan  
> wrote:
> 
> Hello Romanus,
> You are to post only the code and the error messages and not all the
> information from your terminal in R session.

That’s not actually the best practice for rhelp questions. More info is better 
than less. What’s missing, however, is the data. 

— 
David
> 
>> On Fri, Feb 12, 2021, 4:35 PM Romanus Ejike 
>> wrote:
>> 
>> Please, I need help from anyone that can solve this problem.
>> I wanted to plot a world map with locations and names of the locations but
>> could not. The codes I have tried are as shown below.
>> ugwoke@ugwoke-HP-ENVY-Laptop-13-aq0xxx:~/Desktop$ R
>> 
>> R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
>> Copyright (C) 2020 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu (64-bit)
>> 
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>> 
>>  Natural language support but running in an English locale
>> 
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information and
>> 'citation()' on how to cite R or R packages in publications.
>> 
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>> 'help.start()' for an HTML browser interface to help.
>> Type 'q()' to quit R.
>> 
>>> NMdata <-
>> 
>> read.table("NM1989.txt",col.names=c("SNAME","FNAME","NMTYPE","LAT","LON","ALTI"))
>>> library(ggplot2)
>>> library(sf)
>> Linking to GEOS 3.9.0, GDAL 3.2.0, PROJ 7.2.0
>>> library(rnaturalearth)
>>> library(rnaturalearthdata)
>>> world <- ne_countries(scale = "medium", returnclass = "sf")
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>> FALSE) + ggtitle("World map") + points(NMdata$LON,Nmdata$LAT,col = "red",
>> cex = 0.01)
>> Error in xy.coords(x, y) : object 'Nmdata' not found
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>> FALSE) + ggtitle("World map") + points(NMdata$LON,NMdata$LAT,col = "red",
>> cex = 0.01)
>> Error in plot.xy(xy.coords(x, y), type = type, ...) :
>>  plot.new has not been called yet
>> In addition: Warning messages:
>> 1: In xy.coords(x, y) : NAs introduced by coercion
>> 2: In xy.coords(x, y) : NAs introduced by coercion
>> 3: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>  locale not supported by Xlib: some X ops will operate in C locale
>> 4: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>  X cannot set locale modifiers
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>> FALSE) + ggtitle("World map") + points(NMdata$LON,NMdata$LAT,col = "red",
>> cex = 0.01, pch = 20)
>> Error in plot.xy(xy.coords(x, y), type = type, ...) :
>>  plot.new has not been called yet
>> In addition: Warning messages:
>> 1: In xy.coords(x, y) : NAs introduced by coercion
>> 2: In xy.coords(x, y) : NAs introduced by coercion.
>> I have also tried the codes below but it did not show the locations.
>> ugwoke@ugwoke-HP-ENVY-Laptop-13-aq0xxx:~/Desktop$ R
>> 
>> R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
>> Copyright (C) 2020 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu (64-bit)
>> 
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>> 
>>  Natural language support but running in an English locale
>> 
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information and
>> 'citation()' on how to cite R or R packages in publications.
>> 
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>> 'help.start()' for an HTML browser interface to help.
>> Type 'q()' to quit R.
>> 
>>> library("ggplot2")
>>> library(sf)
>> Linking to GEOS 3.9.0, GDAL 3.2.0, PROJ 7.2.0
>>> library("rnaturalearth")
>>> library("rnaturalearthdata")
>>> theme_set(theme_bw())
>>> world <- ne_countries(scale = "medium", returnclass = "sf")
>>> class(world)
>> [1] "sf" "data.frame"
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> +
>> + + ggtitle("World map") + coord_sf(crs = "+proj=laea +lat_0=52 +lon_0=10
>> +x_0=4321000 +y_0=321 +ellps=GRS80 +units=m +no_defs ")
>> Error in +ggtitle("World map") : invalid argument to unary operator
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + ggtitle("World map") + coord_sf(crs = "+proj=laea + lat_0=52 + lon_0=10 +
>> x_0=4321000 + y_0=321 + ellps=GRS80 + units=m + no_defs ")
>> Warning messages:
>> 1: In 

Re: [R] dependent nested for loops in R

2021-02-01 Thread David Winsemius



Sent from my iPhone

> On Feb 1, 2021, at 10:16 PM, David Winsemius  wrote:
> 
> Or perhaps: 
> 
> W <- 1:2000
> W[z>4|z<2] <- 0

Another way:

W <- (1:2000)*(z>4|z<2)

As I said earlier you really should study logical class vectors and the 
operators that use them and how to apply them as indices. 
> Sent from my iPhone
> 
>>> On Feb 1, 2021, at 9:56 PM, David Winsemius  wrote:
>>> 
>> Or perhaps you wanted:
>> 
>> W <- z
>> W[z>4|z<2] <- 0
>> 
>> Sent from my iPhone
>> 
>>>> On Feb 1, 2021, at 9:41 PM, David Winsemius  wrote:
>>>> 
>>> Just drop the “+” if you want logical. 
>>> 
>>> Sent from my iPhone
>>> 
>>>>> On Feb 1, 2021, at 9:36 PM, Shaami  wrote:
>>>>> 
>>>> 
>>>> Hi Prof. David
>>>> 
>>>> Thank you. I will always follow your advice. The suggested code worked. It 
>>>> gives either 1 or 0 depending on the condition to be true. I want index of 
>>>> z for which the condition is true (instead of 1) else zero. Could you 
>>>> please suggest? 
>>>> 
>>>> Thank you
>>>> 
>>>> Shaami
>>>> 
>>>>> On Tue, Feb 2, 2021 at 10:16 AM David Winsemius  
>>>>> wrote:
>>>>> Cc’ed the list as should always be your practice. 
>>>>> 
>>>>> Here’s one way (untested):
>>>>> 
>>>>> W <- +(z>4| z<2) # assume z is of length 20
>>>>> 
>>>>> — 
>>>>> David
>>>>> 
>>>>> Sent from my iPhone
>>>>> 
>>>>>>> On Feb 1, 2021, at 7:08 PM, Shaami  wrote:
>>>>>>> 
>>>>>> 
>>>>>> Hi Prof. David
>>>>>> 
>>>>>> In the following state
>>>>>> 
>>>>>> W = (1:2000)[z >4|z<2)
>>>>>> 
>>>>>> Could you please guide how  I can assign zero if condition is not 
>>>>>> satisfied?
>>>>>> 
>>>>>> Best Regards 
>>>>>> 
>>>>>> Shaami
>>>>>> 
>>>>>>> On Mon, 1 Feb 2021, 11:01 am David Winsemius,  
>>>>>>> wrote:
>>>>>>> 
>>>>>>> On 1/31/21 1:26 PM, Berry, Charles wrote:
>>>>>>> >
>>>>>>> >> On Jan 30, 2021, at 9:32 PM, Shaami  wrote:
>>>>>>> >>
>>>>>>> >> Hi
>>>>>>> >> I have made the sample code again. Could you please guide how to use
>>>>>>> >> vectorization for variables whose next value depends on the previous 
>>>>>>> >> one?
>>>>>>> >>
>>>>>>> 
>>>>>>> I agree with Charles that I suspect your results are not what you 
>>>>>>> expect. You should try using cat or print to output intermediate 
>>>>>>> results 
>>>>>>> to the console. I would suggest you limit your examination to a more 
>>>>>>> manageable length, say the first 10 results while you are working out 
>>>>>>> your logic. After you have the logic debugged, you can move on to long 
>>>>>>> sequences.
>>>>>>> 
>>>>>>> 
>>>>>>> This is my suggestion for a more compact solution (at least for the 
>>>>>>> inner loop calculation):
>>>>>>> 
>>>>>>> set.seed(123)
>>>>>>> 
>>>>>>> x <- rnorm(2000)
>>>>>>> 
>>>>>>> z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)
>>>>>>> 
>>>>>>> w<- numeric(2000)
>>>>>>> 
>>>>>>> w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
>>>>>>> overwritten and end up all being 2000
>>>>>>> 
>>>>>>> 
>>>>>>> I would also advise making a natural language statement of the problem 
>>>>>>> and goals. I'm thinking that you may be missing certain aspects of the 
>>>>>>> underying problem.
>>>>>>> 
>>>>>>> -- 
>>>>>>> 
>>>>>>> David.
>>>>>>> 
>>>>>>> >
>>>>>>> > Glad to help.
>>>>>>> >
>>>>>>> > First, it could help you to trace your code.  I suspect that the 
>>>>>>> > results are not at all what you want and tracing would help you see 
>>>>>>> > that.
>>>>>>> >
>>>>>>> > I suggest running this revision and printing out x, z, and w.
>>>>>>> >
>>>>>>> > #+begin_src R
>>>>>>> >w = NULL
>>>>>>> >for(j in 1:2)
>>>>>>> >{
>>>>>>> >  z = NULL
>>>>>>> >  x = rnorm(10)
>>>>>>> >  z[1] = x[1]
>>>>>>> >  for(i in 2:10)
>>>>>>> >  {
>>>>>>> >z[i] = x[i]+5*z[i-1]
>>>>>>> >if(z[i]>4 | z[i]<1) {
>>>>>>> >   w[j]=i
>>>>>>> >} else {
>>>>>>> >   w[j] = 0
>>>>>>> >}
>>>>>>> >  }
>>>>>>> >}
>>>>>>> > #+end_src
>>>>>>> >
>>>>>>> >
>>>>>>> > You should be able to see that the value of w can easily be obtained 
>>>>>>> > outside of the `i' loop.
>>>>>>> >

[[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] dependent nested for loops in R

2021-02-01 Thread David Winsemius
Or perhaps: 

W <- 1:2000
W[z>4|z<2] <- 0

Sent from my iPhone

> On Feb 1, 2021, at 9:56 PM, David Winsemius  wrote:
> 
> Or perhaps you wanted:
> 
> W <- z
> W[z>4|z<2] <- 0
> 
> Sent from my iPhone
> 
>>> On Feb 1, 2021, at 9:41 PM, David Winsemius  wrote:
>>> 
>> Just drop the “+” if you want logical. 
>> 
>> Sent from my iPhone
>> 
>>>> On Feb 1, 2021, at 9:36 PM, Shaami  wrote:
>>>> 
>>> 
>>> Hi Prof. David
>>> 
>>> Thank you. I will always follow your advice. The suggested code worked. It 
>>> gives either 1 or 0 depending on the condition to be true. I want index of 
>>> z for which the condition is true (instead of 1) else zero. Could you 
>>> please suggest? 
>>> 
>>> Thank you
>>> 
>>> Shaami
>>> 
>>>> On Tue, Feb 2, 2021 at 10:16 AM David Winsemius  
>>>> wrote:
>>>> Cc’ed the list as should always be your practice. 
>>>> 
>>>> Here’s one way (untested):
>>>> 
>>>> W <- +(z>4| z<2) # assume z is of length 20
>>>> 
>>>> — 
>>>> David
>>>> 
>>>> Sent from my iPhone
>>>> 
>>>>>> On Feb 1, 2021, at 7:08 PM, Shaami  wrote:
>>>>>> 
>>>>> 
>>>>> Hi Prof. David
>>>>> 
>>>>> In the following state
>>>>> 
>>>>> W = (1:2000)[z >4|z<2)
>>>>> 
>>>>> Could you please guide how  I can assign zero if condition is not 
>>>>> satisfied?
>>>>> 
>>>>> Best Regards 
>>>>> 
>>>>> Shaami
>>>>> 
>>>>>> On Mon, 1 Feb 2021, 11:01 am David Winsemius,  
>>>>>> wrote:
>>>>>> 
>>>>>> On 1/31/21 1:26 PM, Berry, Charles wrote:
>>>>>> >
>>>>>> >> On Jan 30, 2021, at 9:32 PM, Shaami  wrote:
>>>>>> >>
>>>>>> >> Hi
>>>>>> >> I have made the sample code again. Could you please guide how to use
>>>>>> >> vectorization for variables whose next value depends on the previous 
>>>>>> >> one?
>>>>>> >>
>>>>>> 
>>>>>> I agree with Charles that I suspect your results are not what you 
>>>>>> expect. You should try using cat or print to output intermediate results 
>>>>>> to the console. I would suggest you limit your examination to a more 
>>>>>> manageable length, say the first 10 results while you are working out 
>>>>>> your logic. After you have the logic debugged, you can move on to long 
>>>>>> sequences.
>>>>>> 
>>>>>> 
>>>>>> This is my suggestion for a more compact solution (at least for the 
>>>>>> inner loop calculation):
>>>>>> 
>>>>>> set.seed(123)
>>>>>> 
>>>>>> x <- rnorm(2000)
>>>>>> 
>>>>>> z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)
>>>>>> 
>>>>>> w<- numeric(2000)
>>>>>> 
>>>>>> w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
>>>>>> overwritten and end up all being 2000
>>>>>> 
>>>>>> 
>>>>>> I would also advise making a natural language statement of the problem 
>>>>>> and goals. I'm thinking that you may be missing certain aspects of the 
>>>>>> underying problem.
>>>>>> 
>>>>>> -- 
>>>>>> 
>>>>>> David.
>>>>>> 
>>>>>> >
>>>>>> > Glad to help.
>>>>>> >
>>>>>> > First, it could help you to trace your code.  I suspect that the 
>>>>>> > results are not at all what you want and tracing would help you see 
>>>>>> > that.
>>>>>> >
>>>>>> > I suggest running this revision and printing out x, z, and w.
>>>>>> >
>>>>>> > #+begin_src R
>>>>>> >w = NULL
>>>>>> >for(j in 1:2)
>>>>>> >{
>>>>>> >  z = NULL
>>>>>> >  x = rnorm(10)
>>>>>> >  z[1] = x[1]
>>>>>> >  for(i in 2:10)
>>>>>> >  {
>>>>>> >z[i] = x[i]+5*z[i-1]
>>>>>> >if(z[i]>4 | z[i]<1) {
>>>>>> >   w[j]=i
>>>>>> >} else {
>>>>>> >   w[j] = 0
>>>>>> >}
>>>>>> >  }
>>>>>> >}
>>>>>> > #+end_src
>>>>>> >
>>>>>> >
>>>>>> > You should be able to see that the value of w can easily be obtained 
>>>>>> > outside of the `i' loop.
>>>>>> >

[[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] dependent nested for loops in R

2021-02-01 Thread David Winsemius
Or perhaps you wanted:

W <- z
W[z>4|z<2] <- 0

Sent from my iPhone

> On Feb 1, 2021, at 9:41 PM, David Winsemius  wrote:
> 
> Just drop the “+” if you want logical. 
> 
> Sent from my iPhone
> 
>>> On Feb 1, 2021, at 9:36 PM, Shaami  wrote:
>>> 
>> 
>> Hi Prof. David
>> 
>> Thank you. I will always follow your advice. The suggested code worked. It 
>> gives either 1 or 0 depending on the condition to be true. I want index of z 
>> for which the condition is true (instead of 1) else zero. Could you please 
>> suggest? 
>> 
>> Thank you
>> 
>> Shaami
>> 
>>> On Tue, Feb 2, 2021 at 10:16 AM David Winsemius  
>>> wrote:
>>> Cc’ed the list as should always be your practice. 
>>> 
>>> Here’s one way (untested):
>>> 
>>> W <- +(z>4| z<2) # assume z is of length 20
>>> 
>>> — 
>>> David
>>> 
>>> Sent from my iPhone
>>> 
>>>>> On Feb 1, 2021, at 7:08 PM, Shaami  wrote:
>>>>> 
>>>> 
>>>> Hi Prof. David
>>>> 
>>>> In the following state
>>>> 
>>>> W = (1:2000)[z >4|z<2)
>>>> 
>>>> Could you please guide how  I can assign zero if condition is not 
>>>> satisfied?
>>>> 
>>>> Best Regards 
>>>> 
>>>> Shaami
>>>> 
>>>>> On Mon, 1 Feb 2021, 11:01 am David Winsemius,  
>>>>> wrote:
>>>>> 
>>>>> On 1/31/21 1:26 PM, Berry, Charles wrote:
>>>>> >
>>>>> >> On Jan 30, 2021, at 9:32 PM, Shaami  wrote:
>>>>> >>
>>>>> >> Hi
>>>>> >> I have made the sample code again. Could you please guide how to use
>>>>> >> vectorization for variables whose next value depends on the previous 
>>>>> >> one?
>>>>> >>
>>>>> 
>>>>> I agree with Charles that I suspect your results are not what you 
>>>>> expect. You should try using cat or print to output intermediate results 
>>>>> to the console. I would suggest you limit your examination to a more 
>>>>> manageable length, say the first 10 results while you are working out 
>>>>> your logic. After you have the logic debugged, you can move on to long 
>>>>> sequences.
>>>>> 
>>>>> 
>>>>> This is my suggestion for a more compact solution (at least for the 
>>>>> inner loop calculation):
>>>>> 
>>>>> set.seed(123)
>>>>> 
>>>>> x <- rnorm(2000)
>>>>> 
>>>>> z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)
>>>>> 
>>>>> w<- numeric(2000)
>>>>> 
>>>>> w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
>>>>> overwritten and end up all being 2000
>>>>> 
>>>>> 
>>>>> I would also advise making a natural language statement of the problem 
>>>>> and goals. I'm thinking that you may be missing certain aspects of the 
>>>>> underying problem.
>>>>> 
>>>>> -- 
>>>>> 
>>>>> David.
>>>>> 
>>>>> >
>>>>> > Glad to help.
>>>>> >
>>>>> > First, it could help you to trace your code.  I suspect that the 
>>>>> > results are not at all what you want and tracing would help you see 
>>>>> > that.
>>>>> >
>>>>> > I suggest running this revision and printing out x, z, and w.
>>>>> >
>>>>> > #+begin_src R
>>>>> >w = NULL
>>>>> >for(j in 1:2)
>>>>> >{
>>>>> >  z = NULL
>>>>> >  x = rnorm(10)
>>>>> >  z[1] = x[1]
>>>>> >  for(i in 2:10)
>>>>> >  {
>>>>> >z[i] = x[i]+5*z[i-1]
>>>>> >if(z[i]>4 | z[i]<1) {
>>>>> >   w[j]=i
>>>>> >} else {
>>>>> >   w[j] = 0
>>>>> >}
>>>>> >  }
>>>>> >}
>>>>> > #+end_src
>>>>> >
>>>>> >
>>>>> > You should be able to see that the value of w can easily be obtained 
>>>>> > outside of the `i' loop.
>>>>> >

[[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] dependent nested for loops in R

2021-02-01 Thread David Winsemius
Just drop the “+” if you want logical. 

Sent from my iPhone

> On Feb 1, 2021, at 9:36 PM, Shaami  wrote:
> 
> 
> Hi Prof. David
> 
> Thank you. I will always follow your advice. The suggested code worked. It 
> gives either 1 or 0 depending on the condition to be true. I want index of z 
> for which the condition is true (instead of 1) else zero. Could you please 
> suggest? 
> 
> Thank you
> 
> Shaami
> 
>> On Tue, Feb 2, 2021 at 10:16 AM David Winsemius  
>> wrote:
>> Cc’ed the list as should always be your practice. 
>> 
>> Here’s one way (untested):
>> 
>> W <- +(z>4| z<2) # assume z is of length 20
>> 
>> — 
>> David
>> 
>> Sent from my iPhone
>> 
>>>> On Feb 1, 2021, at 7:08 PM, Shaami  wrote:
>>>> 
>>> 
>>> Hi Prof. David
>>> 
>>> In the following state
>>> 
>>> W = (1:2000)[z >4|z<2)
>>> 
>>> Could you please guide how  I can assign zero if condition is not satisfied?
>>> 
>>> Best Regards 
>>> 
>>> Shaami
>>> 
>>>> On Mon, 1 Feb 2021, 11:01 am David Winsemius,  
>>>> wrote:
>>>> 
>>>> On 1/31/21 1:26 PM, Berry, Charles wrote:
>>>> >
>>>> >> On Jan 30, 2021, at 9:32 PM, Shaami  wrote:
>>>> >>
>>>> >> Hi
>>>> >> I have made the sample code again. Could you please guide how to use
>>>> >> vectorization for variables whose next value depends on the previous 
>>>> >> one?
>>>> >>
>>>> 
>>>> I agree with Charles that I suspect your results are not what you 
>>>> expect. You should try using cat or print to output intermediate results 
>>>> to the console. I would suggest you limit your examination to a more 
>>>> manageable length, say the first 10 results while you are working out 
>>>> your logic. After you have the logic debugged, you can move on to long 
>>>> sequences.
>>>> 
>>>> 
>>>> This is my suggestion for a more compact solution (at least for the 
>>>> inner loop calculation):
>>>> 
>>>> set.seed(123)
>>>> 
>>>> x <- rnorm(2000)
>>>> 
>>>> z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)
>>>> 
>>>> w<- numeric(2000)
>>>> 
>>>> w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
>>>> overwritten and end up all being 2000
>>>> 
>>>> 
>>>> I would also advise making a natural language statement of the problem 
>>>> and goals. I'm thinking that you may be missing certain aspects of the 
>>>> underying problem.
>>>> 
>>>> -- 
>>>> 
>>>> David.
>>>> 
>>>> >
>>>> > Glad to help.
>>>> >
>>>> > First, it could help you to trace your code.  I suspect that the results 
>>>> > are not at all what you want and tracing would help you see that.
>>>> >
>>>> > I suggest running this revision and printing out x, z, and w.
>>>> >
>>>> > #+begin_src R
>>>> >w = NULL
>>>> >for(j in 1:2)
>>>> >{
>>>> >  z = NULL
>>>> >  x = rnorm(10)
>>>> >  z[1] = x[1]
>>>> >  for(i in 2:10)
>>>> >  {
>>>> >z[i] = x[i]+5*z[i-1]
>>>> >if(z[i]>4 | z[i]<1) {
>>>> >   w[j]=i
>>>> >} else {
>>>> >   w[j] = 0
>>>> >}
>>>> >  }
>>>> >}
>>>> > #+end_src
>>>> >
>>>> >
>>>> > You should be able to see that the value of w can easily be obtained 
>>>> > outside of the `i' loop.
>>>> >

[[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] dependent nested for loops in R

2021-02-01 Thread David Winsemius
IMTS length 2000

Sent from my iPhone

> On Feb 1, 2021, at 9:16 PM, David Winsemius  wrote:
> 
> Cc’ed the list as should always be your practice. 
> 
> Here’s one way (untested):
> 
> W <- +(z>4| z<2) # assume z is of length 20
> 
> — 
> David
> 
> Sent from my iPhone
> 
>>> On Feb 1, 2021, at 7:08 PM, Shaami  wrote:
>>> 
>> 
>> Hi Prof. David
>> 
>> In the following state
>> 
>> W = (1:2000)[z >4|z<2)
>> 
>> Could you please guide how  I can assign zero if condition is not satisfied?
>> 
>> Best Regards 
>> 
>> Shaami
>> 
>>> On Mon, 1 Feb 2021, 11:01 am David Winsemius,  
>>> wrote:
>>> 
>>> On 1/31/21 1:26 PM, Berry, Charles wrote:
>>> >
>>> >> On Jan 30, 2021, at 9:32 PM, Shaami  wrote:
>>> >>
>>> >> Hi
>>> >> I have made the sample code again. Could you please guide how to use
>>> >> vectorization for variables whose next value depends on the previous one?
>>> >>
>>> 
>>> I agree with Charles that I suspect your results are not what you 
>>> expect. You should try using cat or print to output intermediate results 
>>> to the console. I would suggest you limit your examination to a more 
>>> manageable length, say the first 10 results while you are working out 
>>> your logic. After you have the logic debugged, you can move on to long 
>>> sequences.
>>> 
>>> 
>>> This is my suggestion for a more compact solution (at least for the 
>>> inner loop calculation):
>>> 
>>> set.seed(123)
>>> 
>>> x <- rnorm(2000)
>>> 
>>> z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)
>>> 
>>> w<- numeric(2000)
>>> 
>>> w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
>>> overwritten and end up all being 2000
>>> 
>>> 
>>> I would also advise making a natural language statement of the problem 
>>> and goals. I'm thinking that you may be missing certain aspects of the 
>>> underying problem.
>>> 
>>> -- 
>>> 
>>> David.
>>> 
>>> >
>>> > Glad to help.
>>> >
>>> > First, it could help you to trace your code.  I suspect that the results 
>>> > are not at all what you want and tracing would help you see that.
>>> >
>>> > I suggest running this revision and printing out x, z, and w.
>>> >
>>> > #+begin_src R
>>> >w = NULL
>>> >for(j in 1:2)
>>> >{
>>> >  z = NULL
>>> >  x = rnorm(10)
>>> >  z[1] = x[1]
>>> >  for(i in 2:10)
>>> >  {
>>> >z[i] = x[i]+5*z[i-1]
>>> >if(z[i]>4 | z[i]<1) {
>>> >   w[j]=i
>>> >} else {
>>> >   w[j] = 0
>>> >}
>>> >  }
>>> >}
>>> > #+end_src
>>> >
>>> >
>>> > You should be able to see that the value of w can easily be obtained 
>>> > outside of the `i' loop.
>>> >

[[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] dependent nested for loops in R

2021-02-01 Thread David Winsemius
Cc’ed the list as should always be your practice. 

Here’s one way (untested):

W <- +(z>4| z<2) # assume z is of length 20

— 
David

Sent from my iPhone

> On Feb 1, 2021, at 7:08 PM, Shaami  wrote:
> 
> 
> Hi Prof. David
> 
> In the following state
> 
> W = (1:2000)[z >4|z<2)
> 
> Could you please guide how  I can assign zero if condition is not satisfied?
> 
> Best Regards 
> 
> Shaami
> 
>> On Mon, 1 Feb 2021, 11:01 am David Winsemius,  wrote:
>> 
>> On 1/31/21 1:26 PM, Berry, Charles wrote:
>> >
>> >> On Jan 30, 2021, at 9:32 PM, Shaami  wrote:
>> >>
>> >> Hi
>> >> I have made the sample code again. Could you please guide how to use
>> >> vectorization for variables whose next value depends on the previous one?
>> >>
>> 
>> I agree with Charles that I suspect your results are not what you 
>> expect. You should try using cat or print to output intermediate results 
>> to the console. I would suggest you limit your examination to a more 
>> manageable length, say the first 10 results while you are working out 
>> your logic. After you have the logic debugged, you can move on to long 
>> sequences.
>> 
>> 
>> This is my suggestion for a more compact solution (at least for the 
>> inner loop calculation):
>> 
>> set.seed(123)
>> 
>> x <- rnorm(2000)
>> 
>> z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)
>> 
>> w<- numeric(2000)
>> 
>> w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
>> overwritten and end up all being 2000
>> 
>> 
>> I would also advise making a natural language statement of the problem 
>> and goals. I'm thinking that you may be missing certain aspects of the 
>> underying problem.
>> 
>> -- 
>> 
>> David.
>> 
>> >
>> > Glad to help.
>> >
>> > First, it could help you to trace your code.  I suspect that the results 
>> > are not at all what you want and tracing would help you see that.
>> >
>> > I suggest running this revision and printing out x, z, and w.
>> >
>> > #+begin_src R
>> >w = NULL
>> >for(j in 1:2)
>> >{
>> >  z = NULL
>> >  x = rnorm(10)
>> >  z[1] = x[1]
>> >  for(i in 2:10)
>> >  {
>> >z[i] = x[i]+5*z[i-1]
>> >if(z[i]>4 | z[i]<1) {
>> >   w[j]=i
>> >} else {
>> >   w[j] = 0
>> >}
>> >  }
>> >}
>> > #+end_src
>> >
>> >
>> > You should be able to see that the value of w can easily be obtained 
>> > outside of the `i' loop.
>> >

[[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] dependent nested for loops in R

2021-01-31 Thread David Winsemius



On 1/31/21 1:26 PM, Berry, Charles wrote:



On Jan 30, 2021, at 9:32 PM, Shaami  wrote:

Hi
I have made the sample code again. Could you please guide how to use
vectorization for variables whose next value depends on the previous one?



I agree with Charles that I suspect your results are not what you 
expect. You should try using cat or print to output intermediate results 
to the console. I would suggest you limit your examination to a more 
manageable length, say the first 10 results while you are working out 
your logic. After you have the logic debugged, you can move on to long 
sequences.



This is my suggestion for a more compact solution (at least for the 
inner loop calculation):


set.seed(123)

x <- rnorm(2000)

z <- Reduce( function(x,y) { sum(y+5*x) }, x, accumulate=TRUE)

w<- numeric(2000)

w <-  (1:2000)[ z >4 | z < 1 ]  # In your version the w values get 
overwritten and end up all being 2000



I would also advise making a natural language statement of the problem 
and goals. I'm thinking that you may be missing certain aspects of the 
underying problem.


--

David.



Glad to help.

First, it could help you to trace your code.  I suspect that the results are 
not at all what you want and tracing would help you see that.

I suggest running this revision and printing out x, z, and w.

#+begin_src R
   w = NULL
   for(j in 1:2)
   {
 z = NULL
 x = rnorm(10)
 z[1] = x[1]
 for(i in 2:10)
 {
   z[i] = x[i]+5*z[i-1]
   if(z[i]>4 | z[i]<1) {
w[j]=i
   } else {
w[j] = 0
   }
 }
   }
#+end_src


You should be able to see that the value of w can easily be obtained outside of 
the `i' loop.



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


  1   2   3   4   5   6   7   8   9   10   >