Re: [R] [External] Using the pipe, |>, syntax with "names<-"

2024-07-20 Thread Richard M. Heiberger
I think Iris's solution should be added to the help file: ?|>
there are no examples there now that show assignment or replacement using the 
"_"

> On Jul 20, 2024, at 18:21, Duncan Murdoch  wrote:
>
> On 2024-07-20 6:02 p.m., Iris Simmons wrote:
>> z <- data.frame(a = 1:3, b = letters[1:3])
>> z |> names() |> _[2] <- "foo"
>> z
>
> That's a great suggestion!
>
> Duncan Murdoch
>
> __
> 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] Printout and saved results

2024-03-25 Thread Richard M. Heiberger
dstat4 <- function(data) {
  Mean<- apply(data, 2, mean, na.rm=TRUE)
  Std.dev <- apply(data, 2, sd,  na.rm=TRUE)
  Min <- apply(data, 2, min, na.rm=TRUE)
  Max <- apply(data, 2, max, na.rm=TRUE)
  Obs <- dim(data)[1]
  data.frame(Mean, Std.dev, Min, Max, Obs)
}

## don't round inside a function.
## rounding is for printing, not for calculating.
## use a space after a comma
## use a space on both sides of assignment <-

## I made the result a data.frame to allow $ selection to work.

x1 <- rnorm(n=5, mean=5, sd=1)
x2 <- rnorm(n=5, mean=10, sd=2)
w <- rnorm(n=5, mean=2, sd=0.3)
mydata <- data.frame(x1, x2, w)

dstat4(mydata)

round(v <- dstat4(mydata), digits=3)

v

v$Mean

round(v$Mean, 3)


> On Mar 25, 2024, at 22:02, Steven Yen  wrote:
>
> How can I have both printout and saved results at the same time.
>
> The subroutine first return "out" and the printout gets printed, but not 
> saved.
>
> I then run the "invisible" line. Results got saved and accessible but no 
> printout.
>
> How can I have both printout and also have the results saved? Thank you!
>
> > dstat4 <- function(data,digits=3){
> +   Mean<- apply(data,2,mean,na.rm=TRUE)
> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
> +   Min <- apply(data,2,min,na.rm=TRUE)
> +   Max <- apply(data,2,max,na.rm=TRUE)
> +   Obs <- dim(data)[1]
> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
> +   out
> + # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
> + }
> > x1<-rnorm(n=5,mean=5, sd=1)
> > x2<-rnorm(n=5,mean=10,sd=2)
> > w<-rnorm(n=5,mean=2,sd=0.3)
> > mydata<-data.frame(cbind(x1,x2))
> > v<-dstat4(mydata); v
>  Mean Std.dev   MinMax Obs
> x1  5.000   0.922 3.900  6.282   5
> x2 10.769   1.713 9.209 13.346   5
> > v$Mean
> Error in v$Mean : $ operator is invalid for atomic vectors
> > dstat4 <- function(data,digits=3){
> +   Mean<- apply(data,2,mean,na.rm=TRUE)
> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
> +   Min <- apply(data,2,min,na.rm=TRUE)
> +   Max <- apply(data,2,max,na.rm=TRUE)
> +   Obs <- dim(data)[1]
> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
> + # out
> +   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
> + }
>
> > v<-dstat4(mydata)
> > v$Mean
>   x1   x2
> 4.233051 9.564454
>
> __
> 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] dput(..., file = stderr())

2024-03-01 Thread Richard M. Heiberger
I see the same thing in a fresh R session

> dput(letters, file = stderr())
c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", 
"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", 
"z")
Warning message:
In dput(letters, file = stderr()) : wrote too few characters
> dput(letters, file = stdout())
c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", 
"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", 
"z")
> version
   _  
platform   aarch64-apple-darwin20 
arch   aarch64
os darwin20   
system aarch64, darwin20  
status Patched
major  4  
minor  3.2
year   2024   
month  01 
day23 
svn rev85822  
language   R  
version.string R version 4.3.2 Patched (2024-01-23 r85822)
nickname   Eye Holes  
> 



> On Mar 1, 2024, at 10:54, Benjamin Tyner  wrote:
> 
> dput(letters, file = stderr())

__
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] converting MATLAB -> R | element-wise operation

2024-02-29 Thread Richard M. Heiberger
I added two more rows

library(microbenchmark)

NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
lambda <- c(2, 3, 4)  # Example vector
colNN <- t(NN)
matlam <- matrix(lambda, byrow=TRUE, nrow=2, ncol=3)

microbenchmark(
  sweep = sweep(NN, 2, lambda, "/"),
  transpose = t(t(NN)/lambda),
  colNN = colNN/lambda,
  fullsize  = NN / matrix(lambda, byrow=TRUE, nrow=2, ncol=3),
  rowlam  = NN / matlam
)

Unit: nanoseconds
  expr   minlq mean  median  uq   max neval cld
 sweep 12546 12792 13919.91 12997.0 13325.0 85608   100 a
 transpose  1640  1763  1986.04  1947.5  2050.0  7462   100  b
 colNN8282   161.13   123.0   123.0  3854   100   c
  fullsize   738   820   932.34   881.5   963.5  2829   100  bc
rowlam82   123   168.92   164.0   164.0   820   100   c

reshaping the denominator to the correct size in advance is very helpful if you 
will be doing this division more than once.



> On Feb 29, 2024, at 18:12, Richard M. Heiberger  wrote:
>
> I decided to do a direct comparison of transpose and sweep.
>
>
> library(microbenchmark)
>
> NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
> lambda <- c(2, 3, 4)  # Example vector
> colNN <- t(NN)
>
> microbenchmark(
>  sweep = sweep(NN, 2, lambda, "/"),
>  transpose = t(t(NN)/lambda),
>  colNN = colNN/lambda
> )
>
>
> Unit: nanoseconds
>  expr   minlq mean median  uq   max neval cld
> sweep 13817 14145 15115.06  14350 14657.5 75932   100 a
> transpose  1845  1927  2151.68   2132  2214.0  7093   100  b
> colNN82   123   141.86123   164.0   492   100   c
>
> Note that transpose is much faster than sweep because it is doing less work,
> I believe essentially just changing the order of indexing.
>
> Using the natural sequencing for column-ordered matrices is much much faster.
>
>> On Feb 28, 2024, at 18:43, peter dalgaard  wrote:
>>
>>> rbind(1:3,4:6)/t(matrix(c(2,3,4), 3,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] [External] converting MATLAB -> R | element-wise operation

2024-02-29 Thread Richard M. Heiberger
I decided to do a direct comparison of transpose and sweep.


library(microbenchmark)

NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
lambda <- c(2, 3, 4)  # Example vector
colNN <- t(NN)

microbenchmark(
  sweep = sweep(NN, 2, lambda, "/"),
  transpose = t(t(NN)/lambda),
  colNN = colNN/lambda
)


Unit: nanoseconds
  expr   minlq mean median  uq   max neval cld
 sweep 13817 14145 15115.06  14350 14657.5 75932   100 a  
 transpose  1845  1927  2151.68   2132  2214.0  7093   100  b 
 colNN82   123   141.86123   164.0   492   100   c

Note that transpose is much faster than sweep because it is doing less work,
I believe essentially just changing the order of indexing.

Using the natural sequencing for column-ordered matrices is much much faster.

> On Feb 28, 2024, at 18:43, peter dalgaard  wrote:
> 
>> rbind(1:3,4:6)/t(matrix(c(2,3,4), 3,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.


Re: [R] [External] converting MATLAB -> R | element-wise operation

2024-02-27 Thread Richard M. Heiberger
> t(t(NN)/lambda)
 [,1]  [,2] [,3]
[1,]  0.5 0.667 0.75
[2,]  2.0 1.667 1.50
>

R  matrices are column-based. MATLAB matrices are row-based.

> On Feb 27, 2024, at 14:54, Evan Cooch  wrote:
>
> So, trying to convert a very long, somewhat technical bit of lin alg
> MATLAB code to R. Most of it working, but raninto a stumbling block that
> is probaably simple enough for someone to explain.
>
> Basically, trying to 'line up' MATLAB results from an element-wise
> division of a matrix by a vector with R output.
>
> Here is a simplified version of the MATLAB code I'm translating:
>
> NN = [1, 2, 3; 4, 5, 6];  % Example matrix
> lambda = [2, 3, 4];  % Example vector
> result_matlab = NN ./ lambda;
>
> which yields
>
>  0.5   0.7   0.75000
>  2.0   1.7   1.5
>
>
> So, the only way I have stumbled onto in R to generate the same results
> is to use 'sweep'. The following 'works', but I'm hoping someone can
> explain why I need something as convoluted as this seems (to me, at least).
>
> NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
> lambda <- c(2, 3, 4)  # Example vector
> sweep(NN, 2, lambda, "/")
>
>
>  [,1]  [,2] [,3]
> [1,]  0.5 0.667 0.75
> [2,]  2.0 1.667 1.50
>
> First tried the more 'obvious' NN/lambda, but that yields 'the wrong
> answer' (based solely on what I'm trying to accomplish):
>
>
>[,1] [,2] [,3]
> [1,] 0.50  0.5  1.0
> [2,] 1.33  2.5  1.5
>
> So, why 'sweep'?
>
> [[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] [External] Extracting Plot Arguments

2024-02-23 Thread Richard M. Heiberger
Does the grid.echo function in the gridGraphics package do what you want?

Description
Convert a scene that was drawn using the graphics package to an identical scene 
drawn with the
grid package.

> On Feb 21, 2024, at 22:49, Reed A. Cartwright  wrote:
>
> Hi All,
>
> I'm building an autograding framework for my biostatistics class this
> semester, and I am exploring different ways to automatically grade
> figures.
>
> In other classes, I teach ggplot2 and I extract information directly
> from the ggplot2 object. However, in this class we are using base R
> and I need to extract information from base-r graphics.
>
> I've tried several different approaches, but I'm not sure which one is
> the easiest and most effective. Has anyone ever tried this? Are there
> any packages to help with this?
>
> (1) Storing `recordedplots` objects and trying to extract information
> from them. This data structure felt very low level, and I wasn't sure
> how easy it was to map the results to user-level function calls.
>
> (2) Use the `svglite` device to produce svg files, which can be
> parsed. This also worked, but required a lot of code to parse the
> resulting images and identify things like labels, and coordinate
> locations. I got tired of having to figure how to extract information
> from an SVG.
>
> (3) Use a wrapper on specific graphics functions that records the
> function arguments. This turns out to be a bit too high level, as I
> have to manually massage inputs. E.g. handle both xy plots and formula
> + data plots. (We teach both styles.)
>
> Are there any other ideas that I can try? My students are using an
> RMarkdown worksheet and answering questions by putting code in
> specific chunks. I've already hooked into knitr so I can record the
> chunk lines as they are being run and  get the results and
> side-effects.
>
> Thanks,
> Reed
>
> --
> Reed A. Cartwright, PhD
> Associate Professor of Genomics, Evolution, and Bioinformatics
> School of Life Sciences and The Biodesign Institute
> Arizona State University
> ==
> Address: The Biodesign Institute, PO Box 876401, Tempe, AZ 85287-6401 USA
> Packages: The Biodesign Institute, 1001 S. McAllister Ave, Tempe, AZ
> 85287-6401 USA
> Office: Biodesign B-220C, 1-480-965-9949
> Website: http://cartwrig.ht/
>
> __
> 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] need help with plotmath and/or plotting unicode characters

2023-06-08 Thread Richard M. Heiberger
Use * instead of ~

XX <- 5
YY <- 10
plot(1:10)
mtext(side=3, bquote(N <= .(XX) ~":" ~ .(YY)))
mtext(side=1, bquote(N <= .(XX) *":" * .(YY)))


> On Jun 7, 2023, at 22:14, Dennis Fisher  wrote:
>
> R 4.2.3
> OS X
>
> Colleagues
>
> This should be easy -- but not for me.
>
> I want to plot text similar to this:
> N ≥ XX: YY
>
> where XX can be either 1 or 50 and YY is an integer
>
> I envision that there would be two solutions:
>
> UNICODE: If I can generate "≥" via unicode, the problem is solved:
> mtext(side=3, paste0("N ", UNICODE, " ", XX, ": ", YY))
>
> PLOTMATH:
> mtext(side=3, bquote(N <= .(XX) ~":" ~ .(YY)))
> This comes close:
> N ≤ 2 : 13
> but I want to remove the space between the 2 and ":"
>
> Dennis
>
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> http://www.plessthan.com/
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-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] latticeExtra

2023-06-05 Thread Richard M. Heiberger
This works.
> d$zz <- factor(d$z, levels=c("low","med","high"))
> d$xx <- as.factor(d$x)
> cloud(y~xx+zz, d, panel.3d.cloud=panel.3dbars, col.facet='grey', 
+   xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), 
+   par.settings = list(axis.line = list(col = "transparent")))
> 

the default levels for factor are alphabetic.  That is ok for d$x.

__
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] Error in percentage stacked barplot

2023-05-03 Thread Richard M. Heiberger
likert is built on the lattice barchart function.
Hence everything in
?panel.barchart
?xyplot
applies.  The legend is constructed with the auto.key argument.

You can move the legend to the left, but that is not a good idea for a 
horizontal barchart.

likert(t(hellisheidi), ReferenceZero=.5,
xlab="X-lab", ylab="Y-lab", main="stacked bar chart",
auto.key=list(space="left", columns=1))

Note that the legend is vertical and the plot is horizontal, making it difficult
to read both simultaneously.

Rich

> On May 3, 2023, at 04:58, Maria Lathouri  wrote:
>
>
> Dear Richard,
>
> Thank you very much for your reply. I went through the code and it worked. I 
> was also able to change the colours.
>
> I was wondering if I can change the legend position; instead of being in the 
> bottom to be on the left side.
>
> I tried the following but without any success
>
> strip = FALSE
> strip.right = TRUE
>
> likert(t(hellisheidi), ReferenceZero=.5, xlab="X-lab", ylab="Y-lab", 
> main="Stacked bar chart", col=c("#E94E1B", "#F7AA4E", "#BEBEBE", "#6193CE", 
> "#00508C", "#E94E1B", "#BEBEBE"), legend.position="left")
>
> Once again, thank you very much.
>
> Kind regards,
> Maria
>
>
> Στις Τρίτη 2 Μαΐου 2023 στις 08:51:16 μ.μ. GMT+1, ο χρήστης Richard M. 
> Heiberger  έγραψε:
>
>
>
>
>
> ## you may need to install HH
> install.packagess("HH")
>
> library(HH)
>
> hellisheidi <- read.table(text="
> Component  Sample1  Sample2  Sample3
> CaO455248
> SiO2  252218
> Al2O3151114
> TiO26  56
> Na2O5  45
> CuO  335
> Cl1  34"
> , header=TRUE, row.names="Component")
>
> likert(t(hellisheidi), ReferenceZero=.5,
>   xlab="X-lab", ylab="Y-lab", main="Stacked bar chart")
>
>
>> On May 2, 2023, at 15:23, Maria Lathouri via R-help  
>> wrote:
>>
>> Dear all,
>> I am trying to plot the following table in stacked barplot in percentages 
>> and also horizontal.
>> Component  Sample 1  Sample 2  Sample 3CaO45 
>>5248SiO2  25
>> 2218Al2O31511
>> 14TiO2 6  56  Na2O5  
>> 45CuO  3  3  
>>   5Cl1  3
>> 4
>> When I tried the following functionbarplot(data,
>> +main = "Stacked bar chart",
>> +sub = "Subtitle",
>> +xlab = "X-lab",
>> +ylab = "Y-lab",
>> +axes = TRUE, horiz = TRUE)
>> I got the following error
>> Error in barplot.default(hellisheidi, main = "Stacked bar chart", sub = 
>> "Subtitle",  :
>>   'height' must be a vector or a matrix
>> I also tried barplot(as.matrix(hellisheidi)) but what I was getting was the 
>> three stacked columns for Samples 1, 2 and 3 but I was getting an empty 
>> column for Component, instead of being the variable in the Samples.
>>
>>
>> I was hoping if you could help me on that.
>> Thank you very much in advance.
>> Kind regards,Maria
>>
>>
>>
>> <1683055323500blob.jpg>__
>> 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] Error in percentage stacked barplot

2023-05-02 Thread Richard M. Heiberger
## you may need to install HH
install.packagess("HH")

library(HH)

hellisheidi <- read.table(text="
Component  Sample1  Sample2  Sample3
CaO455248
SiO2   252218
Al2O3 151114
TiO2  6  56
Na2O5  45
CuO  335
Cl 1  34"
, header=TRUE, row.names="Component")

likert(t(hellisheidi), ReferenceZero=.5,
   xlab="X-lab", ylab="Y-lab", main="Stacked bar chart")


> On May 2, 2023, at 15:23, Maria Lathouri via R-help  
> wrote:
> 
> Dear all, 
> I am trying to plot the following table in stacked barplot in percentages and 
> also horizontal.
> Component  Sample 1  Sample 2  Sample 3CaO45  
>   5248SiO2   2522 
>18Al2O3 1511
> 14TiO2 6  56  Na2O
> 5  45CuO  
> 3  35 Cl 1
>   34
> When I tried the following functionbarplot(data,
> + main = "Stacked bar chart",
> + sub = "Subtitle",
> + xlab = "X-lab",
> + ylab = "Y-lab",
> + axes = TRUE, horiz = TRUE)
> I got the following error
> Error in barplot.default(hellisheidi, main = "Stacked bar chart", sub = 
> "Subtitle",  : 
>  'height' must be a vector or a matrix
> I also tried barplot(as.matrix(hellisheidi)) but what I was getting was the 
> three stacked columns for Samples 1, 2 and 3 but I was getting an empty 
> column for Component, instead of being the variable in the Samples. 
> 
> 
> I was hoping if you could help me on that. 
> Thank you very much in advance. 
> Kind regards,Maria
> 
> 
> 
> <1683055323500blob.jpg>__
> 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] linux, emacs, R on iPhone/iPad

2022-11-21 Thread Richard M. Heiberger
I discovered that the "iSH shell" is available for the iPhone/iPad from the 
Applications app.
this is Alpine linux
Once iSH is loaded from the App store, then open it to a shell and download

apk add emacs
apk add R

emacs works well for writing files and sending them to a bigger computer by 
airdrop or email etc.
This is the real Emacs, not the "Not Emacs" app.
The emacs uses a variant of the iPhone keyboard augmented with tab, control, 
escape, arrows keys
and allows swiping for typing.

R works sometimes in the linux shell outside emacs, but not yet from the emacs 
*shell*.
I haven't figures out how to download ESS.

iSH's help page for R
https://github.com/ish-app/ish/wiki/Installing-R-and-any-package-from-the-CRAN
gives a long docker-related way of getting arbitrary packages to work.

Is there interest in forming R-sig-iOS and CRAN support for an iOS binary 
repository?

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.


Re: [R] [External] Fwd: Reading very large text files into R

2022-09-29 Thread Richard M. Heiberger
I think you need the
  fill=TRUE
argument. See 
?read.table

> On Sep 29, 2022, at 11:14, Enrico Schumann  wrote:
> 
> On Thu, 29 Sep 2022, Nick Wray writes:
> 
>> -- Forwarded message -
>> From: Nick Wray 
>> Date: Thu, 29 Sept 2022 at 15:32
>> Subject: Re: [R] Reading very large text files into R
>> To: Ben Tupper 
>> 
>> 
>> Hi Ben
>> Beneath is an example of the text (also in an attachment) and it's the "B",
>> of which there are quite a few scattered throughout the text doc which
>> causes the reading in error message (btw I don't need the "RAIN" column or
>> the 1's after it or the last four elements). I have also attached the
>> snippet as text file
>> 
>> 1980-01-01 10:00, 225620, RAIN, 1, 1, WAHRAIN, 5091, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 226918, RAIN, 1, 1, WAHRAIN, 5124, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 228562, RAIN, 1, 1, WAHRAIN, 491, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 231581, RAIN, 1, 1, WAHRAIN, 5213, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 232671, RAIN, 1, 1, WAHRAIN, 487, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 232913, RAIN, 1, 1, WAHRAIN, 5243, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 234362, RAIN, 1, 1, WAHRAIN, 5265, 1001, 0, , 10009, 0, ,
>> , B
>> 1980-01-01 10:00, 234682, RAIN, 1, 1, WAHRAIN, 5271, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 235389, RAIN, 1, 1, WAHRAIN, 5279, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 236466, RAIN, 1, 1, WAHRAIN, 497, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 243350, RAIN, 1, 1, SREW, 484, 1001, 0, , 9, 0, , ,
>> 1980-01-01 10:00, 243350, RAIN, 1, 1, WAHRAIN, 484, 1001, 0, 0, 9, 9, , ,
>> 
>> Thanks Nick
>> 
>> On Thu, 29 Sept 2022 at 15:12, Ben Tupper  wrote:
>> 
>>> Hi Nick,
>>> 
>>> It's hard to know without seeing at least a snippet of the data.
>>> Could you do the following and paste the result into a plain text
>>> email? If you don't set your email client to plain text (from rich
>>> text or html) then we are apt to see a jumble of output on our email
>>> clients.
>>> 
>>> 
>>> ## start
>>> x <- readLines(filename, n = 20)
>>> cat(x, sep = "\n")
>>> ## end
>>> 
>>> Cheers,
>>> Ben
>>> 
>>> 
>>> On Thu, Sep 29, 2022 at 9:54 AM Nick Wray  wrote:
 
 Hello I may be offending the R purists with this question but it is
 linked to R, as will become clear. I have very large data sets from the
>>> UK
 Met Office in notepad form. Unfortunately, I can’t read them directly
 into R because, for some reason, although most lines in the text doc
 consist of 15 elements, every so often there is a sixteenth one and R
 doesn’t like this and gives me an error message because it has assumed
>>> that
 every line has 15 elements and doesn’t like finding one with more. I
>>> have
 tried playing around with the text document, inserting an extra element
 into the top line etc, but to no avail.
 
 Also unfortunately you need access permission from the Met Office to get
 the files in question so this link probably won’t work:
 
 https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcatalogue.ceda.ac.uk%2Fuuid%2Fbbd6916225e7475514e17fdbf11141c1&data=05%7C01%7Crmh%40temple.edu%7C3c7f7571b0204227932408daa22d6a35%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C638000614056886333%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FolfWagLVB9RNAAR3L88YUnOG8wwDHZFPm5%2BWVWgZ7Y%3D&reserved=0
 
 So what I have done is simply to copy and paste the text docs into excel
 csv and then read them in, which is time-consuming but works. However
>>> the
 later datasets are over the excel limit of 1048576 lines. I can paste in
 the first 1048576 lines but then trying to isolate the remainder of the
 text doc to paste it into a second csv doc is proving v difficult – the
 only way I have found is to scroll down by hand and that’s taking ages.
>>> I
 cannot find another way of editing the notepad text doc to get rid of the
 part which I have already copied and pasted.
 
 Can anyone help with a)ideally being able to simply read the text tables
 into R or b)suggest a way of editing out the bits of the text file I
>>> have
 already pasted in without laborious scrolling?
 
 Thanks Nick Wray
 
> 
> [...]
> 
>>> 
>>> --
>>> Ben Tupper (he/him)
>>> Bigelow Laboratory for Ocean Science
>>> East Boothbay, Maine
>>> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bigelow.org%2F&data=05%7C01%7Crmh%40temple.edu%7C3c7f7571b0204227932408daa22d6a35%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C638000614056886333%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Qmpsx1aA7kL9lYJYshs1U7PrPqFpYFbzOQWXQvW1RLI%3D&reserved=0
>>> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Feco.bigelow.org%2F&data=05%7C01%7Crmh%40temple.edu%7C3c7f7571b0204227932408daa22d6a35%7C716e81efb522447

Re: [R] [External] categorizing data

2022-05-29 Thread Richard M. Heiberger
Orig <- read.table(text="
tree shrub grass
32 11 47
23 41 26
49 23 18
", header=TRUE)

New <- Orig
for (i in seq(nrow(Orig)))
  New[i,] <- c(10, 30, 50)[order(unlist(Orig[i,]))]

New


> On May 29, 2022, at 15:28, Janet Choate  wrote:
> 
> Hi R community,
> I have a data frame with three variables, where each row adds up to 90.
> I want to assign a category of low, medium, or high to the values in each
> row - where the lowest value per row will be set to 10, the medium value
> set to 30, and the high value set to 50 - so each row still adds up to 90.
> 
> For example:
> Data: Orig
> tree  shrub  grass
> 32 11   47
> 23  41  26
> 49  23  18
> 
> Data: New
> tree  shrub  grass
> 30  10  50
> 10   50 30
> 50   30 10
> 
> I am not attaching any code here as I have not been able to write anything
> effective! appreciate help with this!
> thank you,
> JC
> 
> --
> 
>   [[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-help&data=05%7C01%7Crmh%40temple.edu%7C165bca7d509542fc339d08da41a98821%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637894493792524879%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ZxDMzULApfm9p%2BnnXhToAfvFNZx7du6e%2BbqoaNc6iYE%3D&reserved=0
> PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Crmh%40temple.edu%7C165bca7d509542fc339d08da41a98821%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637894493792524879%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=oVJe7FTikuD7Y59kbg9O1k4od357HPwTcylhTn6ZLWw%3D&reserved=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] [External] A simple lattice histogram

2022-04-20 Thread Richard M. Heiberger
start here

 library(latticeExtra)
 c(histogram(~ card, data=CreditCard), histogram(~ reports, data=CreditCard))

then continue with

 resizePanels(c(histogram(~ card, data=CreditCard), histogram(~ reports, 
data=CreditCard), y.same=TRUE), w=c(2,16))

> On Apr 20, 2022, at 11:27, Naresh Gurbuxani  
> wrote:
> 
> library(lattice)
> library(AER)
> data(CreditCard)
> histogram( ~ card + reports, data = CreditCard, scales = "free")

__
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] Calculation error found

2022-04-07 Thread Richard M. Heiberger
Probably numerical precision.  See FAQ 7.31 which is on your computer.
Enter
 system(paste("open",file.path(base::system.file(), 
"../../doc/manual/R-FAQ.pdf")))
and the FAQ file will open.

x <- 20
y <- 19.99
x-y
x == y

> On Apr 07, 2022, at 12:20, Sara Bortot  wrote:
> 
> Good evening,
> I was doing some calculations with R when I noticed an error in one of
> the answers.
> I am attaching the screenshot of the page. There you will see that the two
> calculations are written in a different way but they should give the same
> result, because they're equivalent.
> Let me know if it is a solvable problem,
> 
> Kind regards
> __
> 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-help&data=04%7C01%7Crmh%40temple.edu%7C415d01fbba264cd4d1ad08da18bc8805%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637849495421702100%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=v0xknDQUdAFoQ7HK8fDegMcGLOHuasMkQHq9XqazQlg%3D&reserved=0
> PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C415d01fbba264cd4d1ad08da18bc8805%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637849495421702100%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=lVntKkDO9OnmMrZslJhZU8VydPepHERDjSTSsOTb9wY%3D&reserved=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] [External] Convert a character string to variable names

2022-02-07 Thread Richard M. Heiberger
> x <- c("mtcars$disp", "mtcars$hp", "mtcars$cyl")
> x
[1] "mtcars$disp" "mtcars$hp"   "mtcars$cyl" 
> eval(parse(text=x))
 [1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
> for (i in x) print(eval(parse(text=i)))
 [1] 160.0 160.0 108.0 258.0 360.0 225.0 360.0 146.7 140.8 167.6 167.6 275.8 
275.8 275.8 472.0 460.0 440.0  78.7  75.7  71.1 120.1 318.0
[23] 304.0 350.0 400.0  79.0 120.3  95.1 351.0 145.0 301.0 121.0
 [1] 110 110  93 110 175 105 245  62  95 123 123 180 180 180 205 215 230  66  
52  65  97 150 150 245 175  66  91 113 264 175 335 109
 [1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4


> On Feb 07, 2022, at 17:55, Erin Hodgess  wrote:
> 
>> .x
> 
> [1] "mtcars$disp" "mtcars$hp"   "mtcars$cyl"

__
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] Funky calculations

2022-02-01 Thread Richard M. Heiberger
I apologize if my tone came across wrong.  I enjoy reading your comments on 
this list.

My goal was to describe what the IEEE and R interpret "careful coding" to be.

> On Feb 01, 2022, at 20:42, Avi Gross  wrote:
> 
> Richard,
> 
> I think it was fairly clear I was explaining how people do arithmetic 
> manually and often truncate or round to some number of decimal places. I said 
> nothing about what R does or what the IEEE standards say and I do not 
> particularly care when making MY point.
> 
> My point is that humans before computers also had trouble writing down any 
> decimals that continue indefinitely. It cannot be expected computer versions 
> of arithmetic can do much better. Different people can opt to do the 
> calculation with the same or different numbers of digits ad when compared to 
> each other they may not match.
> 
> I do care what it does in my programs, of course. My goal here was to explain 
> to someone that the anomaly found was not really an anomaly and that careful 
> coding may be required in these situations.
> 
> 
> -Original Message-
> From: Richard M. Heiberger 
> To: Avi Gross 
> Cc: Nathan Boeger ; r-help@r-project.org 
> 
> Sent: Tue, Feb 1, 2022 2:44 pm
> Subject: Re: [External] [R] Funky calculations
> 
> 
> RShowDoc('FAQ') 
> 
> 
> then search for 7.31
> 
> 
> This statement
> "If you stop at a 5 or 7 or 8 and back up to the previous digit, you round 
> up. Else you leave the previous result alone."
> is not quite right.  The recommendation in IEEE 754, and this is how R does 
> arithmetic, is to Round Even.
> 
> I ilustrate here with decimal, even though R and other programs use binary.
> 
>> x <- c(1.4, 1.5, 1.6, 2.4, 2.5, 2.6, 3.4, 3.5, 3.6, 4.4, 4.5, 4.6)
>> r <- round(x)
>> cbind(x, r)
> x r
> [1,] 1.4 1
> [2,] 1.5 2
> [3,] 1.6 2
> [4,] 2.4 2
> [5,] 2.5 2
> [6,] 2.6 3
> [7,] 3.4 3
> [8,] 3.5 4
> [9,] 3.6 4
> [10,] 4.4 4
> [11,] 4.5 4
> [12,] 4.6 5
>> 
> 
> Numbers whose last digit is not 5 (when in decimal) round to the nearest 
> integer.
> Numbers who last digit is 5 (1.5, 2.5, 3.5, 4.5 above) 
> round to the nearest EVEN integer.
> Hence 1.5 and 3.5 round up to the even numbers 2 and 4.
> 2.5 and 4.5 round down do the even numbers 2 and 4.
> 
> This way the round ups and downs average out to 0.  If we always went up from 
> .5 we would have
> an updrift over time.
> 
> For even more detail click on the link in FAQ 7.31 to my appendix
> https:// link.springer.com/content/pdf/bbm%3A978-1-4939-2122-5%2F1.pdf
> and search for "Appendix G".
> 
> Section G.5 explains Round to Even.
> Sections G.6 onward illustrate specific examples, such as the one that 
> started this email thread.
> 
> 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.


Re: [R] [External] how to plot numeric variable against several categories with lattice bwplot?

2022-01-16 Thread Richard M. Heiberger
My guess, continuing from Rolf, is that you should be using conditioning

 bwplot(~ y | f2, df, layout=c(3,1))

> On Jan 16, 2022, at 22:22, Rolf Turner  wrote:
> 
> xxx <- trellis.par.get("box.umbrella")
> xxx$lty <- 1
> trellis.par.set(box.umbrella=xxx)
> junk <- rnorm(42)
> bwplot(junk)

__
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] NAs are removed

2022-01-14 Thread Richard M. Heiberger
this is a related issue.  For this example, the ifelse statement is 10 times 
slower than
a much simpler != comparison.


> tmp <- sample(1:2, 40, TRUE)
> tmp
 [1] 2 2 2 2 1 2 1 2 1 1 1 1 1 2 1 2 2 1 1 2 1 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 
1 2 2
> ifelse(tmp==2, 0, 1)
 [1] 0 0 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 0 0 1 0 1 1 1 0 1 0 
1 0 0
> as.numeric(tmp != 2)
 [1] 0 0 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 0 0 1 0 1 1 1 0 1 0 
1 0 0
>??micro
> microbenchmark::microbenchmark(ifelse=ifelse(tmp==2, 0, 1), 
> notequal=as.numeric(tmp !=2))
Unit: nanoseconds
 expr  min   lqmean median   uq   max neval cld
   ifelse 2952 3239 3542.81 3382.5 3567 12464   100   b
 notequal  205  287  348.09  328.0  369  1599   100  a 


> 
> From: Neha gupta 
> Sent: Friday, January 14, 2022 5:11 PM
> To: Ebert,Timothy Aaron 
> Cc: Jim Lemon ; r-help mailing list 
> 
> Subject: Re: [R] NAs are removed
> 
> [External Email]
> I have a variable in dataset "CA", which has the following values:
> 
> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
> 1 1
> [40] 1 1 1 1 1 1 1 1 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
> 
> then I used this statement
> 
> prot <- ifelse(ts$CA == '2', 0, 1)
> 
> Is the problem exist here?
> 

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


Re: [R] [External] Re: Save a graph file use jpeg(file=file)

2022-01-05 Thread Richard M. Heiberger
you can make the rgl window full screen, and then stretch the graph to fill the 
window, and then use snapshot 3d

From: R-help  on behalf of Sorkin, John 

Sent: Wednesday, January 5, 2022 8:23:34 PM
To: Duncan Murdoch ; r-help@r-project.org 
(r-help@r-project.org) 
Subject: [External] Re: [R] Save a graph file use jpeg(file=file)

Ducan,

As always, you are very giving of your time to help R users. Thank you!

scatter3d is from the car package.

As I understand snapshot3d, it takes a screen shot and saves the resultant 
file. This implies that the resultant file will be 72 DPI. I need to get a 
higher resolution image, at least 300 DPI. Do you have any suggestions?

Thanks as always.

John


From: Duncan Murdoch 
Sent: Wednesday, January 5, 2022 2:58 PM
To: Sorkin, John; r-help@r-project.org (r-help@r-project.org)
Subject: Re: [R] Save a graph file use jpeg(file=file)

On 05/01/2022 2:45 p.m., Sorkin, John wrote:
> I am trying to create a 3-D graph (using scatter3d) and save the graph to a 
> file so I can insert the graph into a manuscript. I am able to create the 
> graph. When I run the code below an RGL window opens that has the graph. The 
> file is saved to disk after dev.odd() runs. Unfortunately, when I open the 
> saved file, all I see is a white window. Can someone tell me how to have the 
> file so I can subsequently read and place the file in a paper? The problem 
> occurs regardless of the format in which I try to save the file, e.g. png, 
> tiff.
>
>
> x <- 1:10
> y <- 2:11
> z <- y+rnorm(10)
> ForGraph<-data.frame(x=x,y=y,z=z)
> ForGraph
>
> gpathj <- file.path("C:","LAL","test.jpeg")
> gpathj
> jpeg(file = gpathj)
> par(mai = c(0.5, 0.5, 0.5, 0.5))
> scatter3d(z=ForGraph$x,
>y=ForGraph$y,
>x=ForGraph$z,
>surface=FALSE,grid=TRUE,sphere.size=4
>,xlab="Categories",ylab="ScoreRange",
>zlab="VTE Rate (%)",axis.ticks=TRUE)
> dev.off()
>
>

You didn't say what package you found scatter3d in, but you did say it
opens an rgl window.  rgl doesn't use R graphics devices, so jpeg() and
the like don't work.

To save an rgl image, you use the rgl::snapshot3d() function.  It only
has support for saving to PNG format.

If you are writing your manuscript in R Markdown or knitr Rnw, there are
ways to have the file included automatically.  There have been methods
to use with Sweave as well, but those aren't being maintained:  people
should use knitr instead.

Duncan Murdoch

[[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-help&data=04%7C01%7Crmh%40temple.edu%7C7efac70023f74f426dda08d9d0b337b8%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637770290874513198%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=QjooPjMvPZ%2BTnPh%2B9SOISOyeGVRYFMmU2NSfkel7rug%3D&reserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C7efac70023f74f426dda08d9d0b337b8%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637770290874513198%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=TCjwf2%2FaEiUl6d%2BUx37bRRQOsXjUx80DhvwKbeCnkHg%3D&reserved=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
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] lattice contourplot: how to change line width?

2021-11-17 Thread Richard M. Heiberger
It didn't work because you left out the ... on the inside.

it should be
panel.contourplot(..., lty=1, lwd = 3)

As Bert pointed out, you don't need to specify the panel function unless you 
are doing something complex.

> On Nov 17, 2021, at 13:06, Bert Gunter  wrote:
> 
>>> panel.contourplot(lty=1, lwd = 3)

__
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] ggplot2: multiple box plots, different tibbles/dataframes

2021-11-10 Thread Richard M. Heiberger
I don't understand your question.  It looks like the example in 
?lattice::panel.bwplot does
exactly what you want (modulo using ggplot instead of lattice).  Therefore it 
looks like creating a single column of y
from the y in each data.frame, and also a single column of x from the x in each 
data.frame should be enough.

Here is an even simpler example

y <- rnorm(20)
x <- rep(1:2, each=10)
library(lattice)
bwplot(x ~ y, horizontal=TRUE)


> On Nov 10, 2021, at 15:16, Rich Shepard  wrote:
> 
> On Wed, 10 Nov 2021, Rich Shepard wrote:
> 
>> I have the code to create ggplot2 boxplots using two attributes (e.g.,
>> chemical concentration and month) from the same tibble. Is there an
>> example from which I can learn how to make boxplots from different
>> tibbles/dataframes (e.g., chemical concentrations and monitoring
>> location)?
> 
> To clarify: I'd like to produce a plot such as Naomi Robbins presents in
> figure 4.11 of her book, "Creating More Effective Graphics."
> 
> In my case I want to present river boxplots of discharges over each
> monitoring site's period of record as a vertical stack of horizontal
> boxplots. The northern-most site actually has negative discharges twice a
> day as it's tidally influenced at about 125 River Miles from the ocean and
> the incoming tides push the water upriver.
> 
> Rich
> 
> __
> 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-help&data=04%7C01%7Crmh%40temple.edu%7C4cd107806f544ff7ef4308d9a4870974%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637721722866567947%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=t1sBLzlyyxPEq2%2F54BoDdmP1qkfLb9ABosQ0mI6rEjA%3D&reserved=0
> PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C4cd107806f544ff7ef4308d9a4870974%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637721722866567947%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=nu%2Bjxppbmi4UtEngfs3DrJXQWcyxUVNSoGYgnEDwi%2F8%3D&reserved=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] [External] Error: unexpected symbol in "read.csv(12agosto.csv after installing Monterey

2021-11-08 Thread Richard M. Heiberger
yes, follow David Winsemius' advice.

In this example, it looks not to be a mac issue, but a new R user issue.
The partial message in the subject says

read.csv(12agosto.csv

The correct syntax is to quote the name of a file, so it should be

read.csv("12agosto.csv")

> On Nov 08, 2021, at 23:14, David Winsemius  wrote:
> 
> 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<> code to illustrate>> \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://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhoraciodelacueva.blogspot.mx%2F&data=04%7C01%7Crmh%40temple.edu%7C21378c448b8c4ac5fe5108d9a3377ecc%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637720281054221658%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=H0J9lu2L13rA1OMGHVntWo4bRBl6Ckoyr1OlpvrMkqI%3D&reserved=0
>> 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://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7Crmh%40temple.edu%7C21378c448b8c4ac5fe5108d9a3377ecc%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637720281054221658%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=pHYoYETeVrMbKKNk7MKQ3EHD9tGrj8vLtns4xRbTzLs%3D&reserved=0
>> PLEASE do read the posting guide 
>> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C21378c448b8c4ac5fe5108d9a3377ecc%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637720281054221658%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=lu3zLdD%2FXtpYwZtOJM00DDZni6e1GBdSpRS4k2D7IjQ%3D&reserved=0
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> 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-help&data=04%7C01%7Crmh%40temple.edu%7C21378c448b8c4ac5fe5108d9a3377ecc%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637720281054221658%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=pHYoYETeVrMbKKNk7MKQ3EHD9tGrj8vLtns4xRbTzLs%3D&reserved=0
> PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C21378c448b8c4ac5fe5108d9a3377ecc%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637720281054221658%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=lu3zLdD%2FXtpYwZtOJM00DDZni6e1GBdSpRS4k2D7IjQ%3D&reserved=0
> and provide commented, minimal, self-contained, reproducible code.

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

Re: [R] [External] Rising and falling bar-plots simultaneously

2021-10-17 Thread Richard M. Heiberger
This does what I think you are asking for.

If this isn't what you are looking for, please draw by brute force what you want
for just the first 6 rows and post the R code.  Or draw by hand for just the 
first 6 rows and post a png.

## install.packages("HH") ## if you don't already have HH
library(HH)

tmp <- cbind(BAS1[,2], 0, BAS1[,1], 0)
tmp[c(3,102), c(2:1, 4:3)] <- tmp[c(3,102),]
likert(tmp, horizontal=FALSE, col=c("red","green","red","green"), 
scales=list(x=list(rot=90, cex=.4)))


> On Oct 17, 2021, at 21:14, Eliza Botto  wrote:
> 
>> BAS1)
> 
> structure(c(3, 4, 2, 3, 3, 4, 3, 3, 3, 3, 2, 3, 3, 4, 3, 2, 2,
> 3, 2, 3, 3, 3, 4, 5, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 4, 3, 3,
> 3, 4, 3, 3, 4, 5, 4, 4, 4, 3, 4, 3, 3, 3, 3, 4, 4, 5, 4, 3, 4,
> 4, 2, 3, 3, 3, 2, 4, 4, 3, 3, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 3,
> 3, 3, 3, 2, 5, 2, 4, 3, 2, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 2,
> 3, 4, 3, 4, 4, 3, 3, 3, 3, 5, 3, 3, 5, 3, 4, 2, 3, 3, 3, 3, 3,
> 4, 3, 3.93, 3.509, 2.464, 2.72, 2.304, 3.517, 3.517, 6.675, 6.597,
> 2.715, 2.849, 2.618, 3.126, 2.715, 3.931, 3.709, 3.931, 4.145,
> 6.585, 3.907, 3.132, 2.568, 3.883, 2.447, 3.517, 7.098, 3.027,
> 3.003, 7.098, 2.374, 2.065, 2.95, 3.559, 5.102, 3.907, 3.204,
> 3.207, 2.791, 2.116, 3.003, 3.003, 3.003, 6.049, 3.52, 2.241,
> 3.883, 4.145, 3.334, 3.151, 6.269, 4.04, 3.883, 2.27, 3.304,
> 2.464, 4.111, 2.728, 3.93, 3.911, 2.447, 3.202, 2.375, 2.442,
> 2.442, 2.592, 2.13, 3.122, 5.657, 6.076, 4.186, 2.115, 2.623,
> 6.076, 2.467, 2.623, 2.629, 2.517, 2.623, 2.517, 4.32, 4.045,
> 6.597, 4.079, 3.817, 3.521, 2.564, 3.071, 2.447, 3.334, 2.442,
> 2.248, 3.094, 4.045, 4.045, 2.252, 2.971, 3.727, 2.184, 2.783,
> 2.849, 3.529, 2.484, 2.184, 2.313, 2.512, 3.4, 4.096, 3.572,
> 2.663, 3.405, 5.102, 3.267, 2.987, 2.123, 3.47, 2.512, 2.783,
> 6.597, 6.435, 4.921, 3.351, 2.07, 2.07, 2.442), .Dim = c(124L,
> 2L))

__
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] Subset command

2021-10-15 Thread Richard M. Heiberger
the second  command doesn't tell R that the variables are in the data.frame 
mydata.

you will need
exclude <- with(mydata, 
 prim==-9 | etc)

also you will need logical negation !
not arithmetic negation -

> -c(TRUE,FALSE)
[1] -1  0
> as.logical(-c(TRUE,FALSE))
[1]  TRUE FALSE

> !c(TRUE,FALSE)
[1] FALSE  TRUE



> On Oct 15, 2021, at 21:23, Steven Yen  wrote:
> 
> The following "subset command works. I was hoping the second would as well 
> but it does not.
> 
> My definition of exclude is rejected.
> 
> Help please? Thanks.
> 
> > mydata<-subset(mydata,
> +prim>-9 & highsch>-9  & tert>-9 &
> +govt>-9 & nongovt>-9  &
> +married>-9  & urban>-9&
> +smhmyes>-9  & smhmno>-9   & smhmnoru>-9 &
> +workouts>-9 & seconhan>-9 & reliyes>-9)
> 
> > exclude<-  prim==-9 | highsch==-9  | tert==-9 |
> +govt==-9 | nongovt==-9  |
> +married==-9  | urban==-9|
> +smhmyes==-9  | smhmno==-9   | smhmnoru==-9 |
> +workouts==-9 | seconhan==-9 | reliyes==-9
> Error: object 'prim' not found
> > mydata<-subset(mydata,-exclude)
> Error in eval(e, x, parent.frame()) : object 'exclude' not found
> >
> 
> __
> 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-help&data=04%7C01%7Crmh%40temple.edu%7Ca1d470378fc24c832f7708d99043b804%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637699443365577347%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=DFLP8ZLggvu1NVs9ufyWUdT5hJNKd0v7UYwcHCXncVk%3D&reserved=0
> PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7Ca1d470378fc24c832f7708d99043b804%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637699443365577347%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=4g2tnLBCnnWezCp%2FZIYFRCxrIKa4VDD46WRQohT5Ftk%3D&reserved=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] [External] how to do inverse log of every value in every column in data frame

2021-10-14 Thread Richard M. Heiberger
> tmp <- data.frame(a=1:3,b=4:6)
> exp(tmp)
  a b
1  2.718282  54.59815
2  7.389056 148.41316
3 20.085537 403.42879
> 2.718281828^tmp
  a b
1  2.718282  54.59815
2  7.389056 148.41316
3 20.085537 403.42879


> On Oct 14, 2021, at 13:10, Ana Marija  wrote:
> 
>> 2.718281828^

__
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] Missing text in lattice key legend

2021-10-11 Thread Richard M. Heiberger
looks like a paren outof place.  the text is inside the points. it should be 
parallel to the points in the calling sequence.

Get Outlook for iOS

From: R-help  on behalf of Luigi Marongiu 

Sent: Monday, October 11, 2021 7:46:36 AM
To: r-help 
Subject: [External] [R] Missing text in lattice key legend

Hello,
I am drawing some data with lattice using:
```
library(lattice)
COLS = c("gold", "forestgreen", "darkslategray3", "purple")
xyplot(Value ~ Concentration,
   group = Substance, data = inf_avg,
   pch = 16, cex = 1.2, type = "b",
   xlab=expression(bold(paste("Concentration (", mu, "M)"))),
   ylab=expression(bold("Infection rate")),
   col=COLS,
   scales = list(x = list(log = 10, at=c(unique(inf_avg$Concentration))
  )
 ),
   key = list(space="top", columns=4, col = "black",
   points=list(pch=c(16, 16, 16, 16),
   col=COLS,
   text=list(c("6-PN", "8-PN", "IX", "XN")
)
   )
  ),
   panel = function(x,y) {
 panel.xyplot(x,y)
 errbar()
   }
)
```
It all works but the legend only shows the colored dots, there is no
text. Is it something missing from the syntax?
Thanks

--
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-help&data=04%7C01%7Crmh%40temple.edu%7C3f303633d643499924e208d98cacdaef%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637695496888670932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=98vQNMB7OcS%2B2R73ZMngEeg%2BP6PeP3oCAOUDHxs9SU8%3D&reserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C3f303633d643499924e208d98cacdaef%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637695496888670932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=1yzXmD57qql7UXEKNqdK8Iq1vhfkUYf%2BpX8gvfvD3p0%3D&reserved=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
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] conditional replacement of elements of matrix with another matrix column

2021-09-01 Thread Richard M. Heiberger
> A
  [,1] [,2]
 [1,]   12   NA
 [2,]   12   NA
 [3,]   12   NA
 [4,]   13   NA
 [5,]   13   NA
 [6,]   13   NA
 [7,]   14   NA
 [8,]   14   NA
 [9,]   14   NA
> B
  [,1] [,2]
 [1,]   116
 [2,]   117
 [3,]   118
 [4,]   139
 [5,]   13   10
 [6,]   13   11
 [7,]   14   12
 [8,]   14   13
 [9,]   14   14
> C
  [,1] [,2]
 [1,]   12   NA
 [2,]   12   NA
 [3,]   12   NA
 [4,]   139
 [5,]   13   10
 [6,]   13   11
 [7,]   14   12
 [8,]   14   13
 [9,]   14   14
> same <- A[,1] == B[,1]
> same
[1] FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE

> A[same,2] <- B[same,2]
> A
  [,1] [,2]
 [1,]   12   NA
 [2,]   12   NA
 [3,]   12   NA
 [4,]   139
 [5,]   13   10
 [6,]   13   11
 [7,]   14   12
 [8,]   14   13
 [9,]   14   14
> 

> On Sep 01, 2021, at 16:59, Eliza Botto  wrote:
> 
>> dput(A)
> 
> structure(c(12, 12, 12, 13, 13, 13, 14, 14, 14, NA, NA, NA, NA,
> NA, NA, NA, NA, NA), .Dim = c(9L, 2L))
> 
>> dput(B)
> 
> structure(c(11, 11, 11, 13, 13, 13, 14, 14, 14, 6, 7, 8, 9, 10,
> 11, 12, 13, 14), .Dim = c(9L, 2L))
> 
>> dput(C)
> 
> structure(c(12, 12, 12, 13, 13, 13, 14, 14, 14, NA, NA, NA, 9,
> 10, 11, 12, 13, 14), .Dim = c(9L, 2L))

__
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 Richard M. Heiberger
Thank you for the example.

Here is a simple function in base graphics that does what you ask for.

You can turn off the default borders and ticks and tick labels and xlab and 
ylab,
and add your own x tick labels, and then it will look exactly like the example 
you sent.

Rich


expt1 <- data.frame(from=c(1,1,2,2,3,3,4,4),
to=c("A","B","A","B","C","D","C","D"))

expt2 <-  data.frame(from=c(1,1,2,2,3,3,4,4),
 to=c("A","B","B","C","C","D","D","A"))


DesignGraph <- function(x, pch.from=19, pch.to=19) {
  from <- unique(x$from)
  to <- unique(x$to)


  n.from <- length(from)
  n.to <- length(to)
  Nrows<- max(1:n.from, 1:n.to)

  plot(1 ~ 1, type="n", xlim=c(1-.5, 2+.5), ylim=c(Nrows, 1))

  points(x=rep(1, n.from), y=1:n.from, pch=pch.from)
  text(x=1-.3, y=1:n.from, labels=from)

  points(x=rep(2, n.to), y=1:n.to, pch=pch.to)
  text(x=2+.3, y=1:n.to, labels=to)

  index.from <- which
  index.to <- which

  segments(1, match(x$from, from), 2, match(x$to, to))
}

DesignGraph(expt1)

DesignGraph(expt2)






> On Aug 18, 2021, at 10:29, 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-help&data=04%7C01%7Crmh%40temple.edu%7Cf18619e1691a4333682a08d962549a74%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637648937938659341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=0LTywXuQ5Y%2FymuUTKOQeeozEx4MpAnF9QavJBcd4FNE%3D&reserved=0
>> PLEASE do read the posting guide 
>> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7Cf18619e1691a4333682a08d962549a74%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637648937938659341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=GT1zdL3%2BOAuVkXGGRMysbsfucmiIz6Dqozr6xyNbm8s%3D&reserved=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] [External] Package for "design graphs"

2021-08-17 Thread Richard M. Heiberger
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-help&data=04%7C01%7Crmh%40temple.edu%7C00a59081bd66463e433d08d961b9e105%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637648273248735184%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=dNwMcJa6okIxlK97dprkVkCk4g5mn6hYsBr1Hez7m%2F8%3D&reserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C00a59081bd66463e433d08d961b9e105%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637648273248745142%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=YZlqRVki%2FaQMdaGQgddyLLmAH3bCsnhPTuhlnrSb1PE%3D&reserved=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
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] Data is not properly written in csv file

2021-06-21 Thread Richard M. Heiberger
copy and paste from pdf usually scrambles tables.  this package is probably 
suffering from that pdf characteristic.


> On Jun 20, 2021, at 11:03, Sri Priya  wrote:
> 
> Dear R Users,
> 
> I am working on extracting tables from PDF and I am writing that in a csv
> file. When I executed the code, the tables were not properly written in the
> csv file.
> 
> Here is my code:
> 
> library(tabulizer)
> # Location of pdf file.
> location <- '
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fkeic.mica-apps.net%2Fwwwisis%2FET_Annual_Reports%2FReligare_Enterprises_Ltd%2FRELIGARE-2017-2018.pdf&data=04%7C01%7Crmh%40temple.edu%7C1025b6434d6f4b4f7b5008d934f99be3%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637599069571109750%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=xLxqLIYvnriqWOoENpbWJvFi7wf03aHslYIz0jPZymY%3D&reserved=0
> '
> 
> # Extract the table
> out <- extract_tables(location)
> for(i in 1:length(out))
> {
>write.table(out[i], file='Output.csv',append=TRUE, sep=",",quote =
> FALSE)
> }
> I enclosed the screenshot of the output file. In that you can see
> the tables are incomplete.
> 
> Any help would be appreciated.
> 
> Thanks
> Sripriya.
> __
> 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] LHS random number generator

2021-04-12 Thread Richard M. Heiberger
I don't know the LHS package.  I don't see it on CRAN as either LHS, or more 
likely, as lhs (lower case).
When you write back to the list, using plain text, not HTML, please state where 
the LHS package is located.

I do see several potential problems.

You use a function randomLHS without first loading the package with a call 
something like
library(LHS)


Your use of the c() function turns the numbers into characters.  There is no 
indication
that you want to increment in units of .01:
> c("lmp", 0.40, 0.43)
[1] "lmp"  "0.4"  "0.43"



Explicit use of seq doesn't get what you are looking for.  Numbers in R (and 
most computer
programs) are binary and the representation in only a few decimal places is 
rounded. Thus:
> print(seq(.40, .43, .01), digits=17)
[1] 0.40002 0.41003 0.42004
[4] 0.42999


see FAQ 7.31 for discussion of number representations.
https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f



> On Apr 12, 2021, at 08:21, Shah Alam  wrote:
> 
> Hello everyone,
> 
> I am using the LHS package to generate a combination of a
> set of parameter values. However, I am not sure how to fix some parameter
> values to 2 decimal points.
> For example:
> 
> I want to make combinations in such a way that values for parameter
> c("lmp", 0.40, 0.43) are taken as 0.40, 0.41, 0.42,0.43.
> 
> My codes are:
> 
> prior_lhs <- list(c("r_mu", 0.00299, 0.0032),
>  c("r_sd", 0.001, 0.002),
>  c("lmp", 0.40, 0.43),
>  c("gr_mu", 0.14, 0.16),
>  c("gr_sd", 0.01, 0.020),
>  c("alpha1", 0.0001, 0.0018),
>  c("alpha2", 0.0017, 0.0028),
>  c("alpha3", 0.005, 0.009),
>  c("beta", 0.69, 0.75)
> )
> 
> 
> ### Simulation with priors from LHS 
> nb_simul <- 1
> nparam <- length(prior_lhs)
> random_tab = randomLHS(nb_simul, nparam)
> lhs_index = 1
> param <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
> 
> for (i in 1:nb_simul) {
>  temp_par <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
>  for (j in 1:nparam) {
>temp_par[j] = as.numeric(prior_lhs[[j]][2]) +
>  (as.numeric(prior_lhs[[j]][3]) - as.numeric(prior_lhs[[j]][2])) *
> random_tab[lhs_index, j]
>  }
>  param <- rbind(param, temp_par)
>  lhs_index <- lhs_index+1
> }
> param <- param[-1,]
> 
> Best regards,
> Shah
> 
>   [[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] [External] unanticipated axis labels

2021-03-17 Thread Richard M. Heiberger
exactly!
a warning when running would be very helpful.

Thank you.

Rich

> On Mar 17, 2021, at 02:41, Deepayan Sarkar  wrote:
> 
> On Tue, Mar 16, 2021 at 11:35 PM Richard M. Heiberger  wrote:
>> 
>> library(lattice)
>> library(latticeExtra)
>> 
>> barchart(matrix(c(1:6, 5:6)), main="unanticipated left axis labels", 
>> ylab="unanticipated inside labels") +
>>  latticeExtra::layer(panel.axis("left", half=FALSE, labels=1:8))
> 
> So to summarize, your problem case happens when you explicitly specify
> 'labels' but not 'at' in panel.axis(), right?
> 
> Unfortunately, this is not intended to work at all, so what you are
> seeing is undefined behaviour. This is hinted at, but not quite
> explicitly spelled out, in the documentation. I will fix that, and
> maybe add a warning as well.
> 
> -Deepayan
> 
>> barchart(matrix(c(1:6, 5:6)), main="ok 1", ylab="anticipated") +
>>  latticeExtra::layer(panel.axis("left", half=FALSE, labels=1:8, at=1:8))
>> 
>> barchart(matrix(c(1:6, 5:6)), main="ok 2", ylab="anticipated") +
>>  latticeExtra::layer(panel.axis("left", half=FALSE, at=1:8))
>> 
>> barchart(matrix(c(1:6, 5:6)), main="ok 3", ylab="anticipated") +
>>  latticeExtra::layer(panel.axis("left", half=FALSE))
>> 
>> 
>> 
>> __
>> 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] unanticipated axis labels

2021-03-16 Thread Richard M. Heiberger
library(lattice)
library(latticeExtra)

barchart(matrix(c(1:6, 5:6)), main="unanticipated left axis labels", 
ylab="unanticipated inside labels") +
  latticeExtra::layer(panel.axis("left", half=FALSE, labels=1:8))

barchart(matrix(c(1:6, 5:6)), main="ok 1", ylab="anticipated") +
  latticeExtra::layer(panel.axis("left", half=FALSE, labels=1:8, at=1:8))

barchart(matrix(c(1:6, 5:6)), main="ok 2", ylab="anticipated") +
  latticeExtra::layer(panel.axis("left", half=FALSE, at=1:8))

barchart(matrix(c(1:6, 5:6)), main="ok 3", ylab="anticipated") +
  latticeExtra::layer(panel.axis("left", half=FALSE))



__
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] Re: [External] Re: Help please

2021-03-11 Thread Richard M. Heiberger
The likert() function in library(likert) is not the same as
the likert() function in library(HH).

The likert function in the likert package creates an object that needs to be 
plotted.
For the likert package you left out the line
plot(likert::likert(scrounging))
This plot is not consistent with what your initial email said it was looking 
for.


Both Jim Lemon and I gave you plots that are consistent with your description.
You could probably get a similar plot from likert::likert(), but not by the 
lines you are using.
The likert::likert() function does not work with the table that HH::likert() 
and barplot() are using.
look at str(l29) to see what it needs

The likert package and the HH package cannot be loaded simultaneously.
Their use the same function names in incompatible ways.

How to get the ?likert::likert plot using HH:

HH::likert(t(sapply(items29, table)), as.percent=TRUE, positive.order=TRUE)

Here is a complete example using Jim Lemon's data.



## NO library() statements!
## The likert and HH packages have incompatible usage
## of the same function names.

## this is the example from ?likert::likert
data(pisaitems, package="likert")
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction",
"Non-fiction books", "Newspapers")
## plot using likert package
l29 <- likert::likert(items29)
likert:::plot.likert(l29)


## plot using HH package
HH::likert(t(sapply(items29, table)), as.percent=TRUE,
   positive.order=TRUE, main="HH::likert")

HH::likert(t(sapply(items29, table)), as.percent=TRUE,
   positive.order=TRUE, main="HH::likert",
   auto.key=list(columns=2),
   scales=list(y=list(tck=c(0,2 ## prettier



## Jim Lemon's example
scrounging <- data.frame(
  behav=sample(c("inactive","active","foraging","snoozing"),50,TRUE),
  substr=sample(c("tree","ground","vine","air"),50,TRUE))

scroungeTable <- t(table(scrounging))
scroungeTable
HH::likert(scroungeTable)

## I don't think Jim Lemon's example can be used directly in the likert package.
## look at
str(l29)
## and notice that it must include both raw data and the table
l29$results
head(l29$items)


## For any further discussion on this list please include the output from
dput(head(yourRealData))
## in the body of the email.

## Jim's example is based on base graphics barplot
## The HH likert() function is based on lattice barchart.
## the likert package's likert:::plot.likert() function is based on ggplot.



From: R-help  on behalf of Rasmus Liland 

Sent: Thursday, March 11, 2021 09:03
To: Areti Panopoulou
Cc: r-help
Subject: [External] Re: [R] [External] Re:  Help please

Dear Areti,

this dcast data.frame presents the same
info as Jim's barplot

reshape2::dcast(data=scrounging, formula=behav~substr, 
fun.aggregate=length)

yielding

 behav air ground tree vine
1   active   5  433
2 foraging   2  134
3 inactive   0  445
4 snoozing   3  513

I tried to use likert by the example in
the example in ?likert::likert

library(likert)
data(pisaitems)
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction",
   "Non-fiction books", "Newspapers")
l29 <- likert(items29)
l29
lapply(items29, levels)

like this

u <- unique(scrounging$behav)
levels.behav <- c("inactive", u[u!="inactive"])
scrounging$behav <- factor(x=scrounging$behav, levels=levels.behav)
u <- unique(scrounging$substr)
levels.substr <- c("ground", u[u!="ground"])
scrounging$substr <- factor(x=scrounging$substr, levels=levels.substr)
likert::likert(scrounging)

yielding

Item inactive active foraging snoozing
1  behav   36 20   20   24
2 substr   20 28   30   22

but I doubt this is meaningful ...

Best,
Rasmus

__
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] Re: Help please

2021-03-10 Thread Richard M. Heiberger
> table(scrounging)
  substr
behav  air ground tree vine
  active 1  536
  foraging   2  630
  inactive   6  113
  snoozing   2  137
> likert(t(table(scrounging)))


From: R-help  on behalf of Jim Lemon 

Sent: Wednesday, March 10, 2021 19:35
To: Areti Panopoulou; r-help mailing list
Subject: [External] Re: [R] Help please

Hi Areti,
Maybe this will help:

scrounging<-data.frame(
 behav=sample(c("inactive","active","foraging","snoozing"),50,TRUE),
 substr=sample(c("tree","ground","vine","air"),50,TRUE))
scrounge.tab<-table(scrounging)
barplot(scrounge.tab)
legend(3.8,14,c("inactive","active","foraging","snoozing"),
 fill=c("gray80","gray60","gray40","gray20"))

Jim

On Thu, Mar 11, 2021 at 9:54 AM Areti Panopoulou
 wrote:
>
> Hello,
>
> I am trying to make a stacked barplot with different behaviours
> ("inactive", "active", "foraging" etc) on different substrates ("tree",
> "ground" etc). I have found this function:
>
> # Stacked Bar Plot with Colors and Legend
> counts <- table(mtcars$vs, mtcars$gear)
> barplot(counts, main="Car Distribution by Gears and VS",
>   xlab="Number of Gears", col=c("darkblue","red"),
>   legend = rownames(counts))
>
> But don't know how to apply it. Can anybody help me apply the function to
> work with my variables ( I can send more information if necessary, or make
> any clarifications).
>
> This is a great help, thanks a lot.
>
> [[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] [External] Help please

2021-03-10 Thread Richard M. Heiberger
> counts <- with(mtcars, table(gear, vs))
> counts
vs
gear  0  1
   3 12  3
   4  2 10
   5  4  1
> likert(counts)
>

If this isn't enough, ask a more specific question.


From: R-help  on behalf of Richard M. Heiberger 

Sent: Wednesday, March 10, 2021 17:58
To: Areti Panopoulou; r-help@r-project.org
Subject: Re: [R] [External]  Help please

install.packages("HH")
library(HH)
?likert

>From your description, I think your data is set up to work with likert()


From: R-help  on behalf of Areti Panopoulou 

Sent: Wednesday, March 10, 2021 13:29
To: r-help@r-project.org
Subject: [External] [R] Help please

Hello,

I am trying to make a stacked barplot with different behaviours
("inactive", "active", "foraging" etc) on different substrates ("tree",
"ground" etc). I have found this function:

# Stacked Bar Plot with Colors and Legend
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",
  xlab="Number of Gears", col=c("darkblue","red"),
  legend = rownames(counts))

But don't know how to apply it. Can anybody help me apply the function to
work with my variables ( I can send more information if necessary, or make
any clarifications).

This is a great help, thanks a lot.

[[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] [External] Help please

2021-03-10 Thread Richard M. Heiberger
install.packages("HH")
library(HH)
?likert

>From your description, I think your data is set up to work with likert()


From: R-help  on behalf of Areti Panopoulou 

Sent: Wednesday, March 10, 2021 13:29
To: r-help@r-project.org
Subject: [External] [R] Help please

Hello,

I am trying to make a stacked barplot with different behaviours
("inactive", "active", "foraging" etc) on different substrates ("tree",
"ground" etc). I have found this function:

# Stacked Bar Plot with Colors and Legend
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",
  xlab="Number of Gears", col=c("darkblue","red"),
  legend = rownames(counts))

But don't know how to apply it. Can anybody help me apply the function to
work with my variables ( I can send more information if necessary, or make
any clarifications).

This is a great help, thanks a lot.

[[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] [External] Re: mpfr function in Rmpfr crashes R

2021-03-07 Thread Richard M. Heiberger
this is probably a Mac M1.
The problem and potential solution is described here:

https://stat.ethz.ch/pipermail/r-sig-mac/2021-February/014003.html


From: R-help  on behalf of Duncan Murdoch 

Sent: Sunday, March 7, 2021 13:03
To: Roger Bos; r-help@r-project.org
Subject: [External] Re: [R] mpfr function in Rmpfr crashes R

It works for me, on a slightly different system than yours:

 > Rmpfr::mpfr(pi, 120)
1 'mpfr' number of precision  120   bits
[1] 3.1415926535897931159979634685441851616
 > sessionInfo()
R version 4.0.3 Patched (2021-01-30 r79912)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:
/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

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

other attached packages:
[1] Rmpfr_0.8-2 gmp_0.6-1

loaded via a namespace (and not attached):
[1] compiler_4.0.3


On 06/03/2021 7:07 p.m., Roger Bos wrote:
> All,
>
> The following code crashes by R on my mac with a message "R session
> aborted.  A fatal error occured".
>
> ```
> library(Rmpfr)
> Rmpfr::mpfr(pi, 120)
> ```
>
> Does anyone have any suggestions?   My session info is below:
>
> R version 4.0.3 (2020-10-10)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Big Sur 10.16
>
> Matrix products: default
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] datasets  utils stats graphics  grDevices methods   base
>
> other attached packages:
>   [1] alphavantager_0.1.2 googlesheets4_0.2.0 googledrive_1.0.1
> clipr_0.7.1
>   [5] jsonlite_1.7.2  stringi_1.5.3   dtplyr_1.0.1
>   data.table_1.13.6
>   [9] dplyr_1.0.4 plyr_1.8.6  testthat_3.0.1
>   lubridate_1.7.9.2
> [13] timeDate_3043.102   sendmailR_1.2-1 rmarkdown_2.6
> devtools_2.3.2
> [17] usethis_2.0.0   xts_0.12.1  zoo_1.8-8
> MASS_7.3-53
> [21] fortunes_1.5-4
>
> loaded via a namespace (and not attached):
>   [1] tinytex_0.29  tidyselect_1.1.0  xfun_0.20 remotes_2.2.0
>purrr_0.3.4
>   [6] gargle_0.5.0  lattice_0.20-41   generics_0.1.0vctrs_0.3.6
>htmltools_0.5.1.1
> [11] base64enc_0.1-3   rlang_0.4.10  pkgbuild_1.2.0pillar_1.4.7
>   glue_1.4.2
> [16] withr_2.4.1   DBI_1.1.1 sessioninfo_1.1.1 lifecycle_0.2.0
>cellranger_1.1.0
> [21] evaluate_0.14 memoise_2.0.0 knitr_1.31callr_3.5.1
>fastmap_1.1.0
> [26] ps_1.5.0  curl_4.3  Rcpp_1.0.6openssl_1.4.3
>cachem_1.0.1
> [31] desc_1.2.0pkgload_1.1.0 fs_1.5.0  askpass_1.1
>digest_0.6.27
> [36] processx_3.4.5grid_4.0.3rprojroot_2.0.2   cli_2.3.0
>tools_4.0.3
> [41] magrittr_2.0.1tibble_3.0.6  crayon_1.4.0  pkgconfig_2.0.3
>ellipsis_0.3.1
> [46] prettyunits_1.1.1 httr_1.4.2assertthat_0.2.1  R6_2.5.0
>   compiler_4.0.3
> 19:05:52  >
>
> Thanks,
>
> Roger
>
>   [[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] [External] Concatenation?

2021-02-17 Thread Richard M. Heiberger
> paste(c("A","B","C"), c(1,2,3), sep="")
[1] "A1" "B2" "C3"

in your example
paste(site, depth, sep="")


From: R-help  on behalf of Parkhurst, David 

Sent: Wednesday, February 17, 2021 4:09 PM
To: r-help@r-project.org
Subject: [External] [R] Concatenation?

If I have a vector of site abbreviations and a vector of depths in those water 
bodies, is there a simple way in R to combine them to make a third vector?
Examples:

sitedepth   desired
MU  0   MU0
MU  1   MU1
MU  2   MU2
MC  0   MC0
MC  1   MC1
MC  2   MC2

The dataset has many more lines than this.  I can see how to do this with lots 
of if statements, but does R have magic that can make it happen easily?  I 
guess this would be called concatenation.

__
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] Dimensioning lists.

2021-02-14 Thread Richard M. Heiberger
Use double [[ ]]

> xxx[[2,3]]
$a
[1] "n"

$b
[1] 20

>


From: R-help  on behalf of Rolf Turner 

Sent: Sunday, February 14, 2021 10:35 PM
To: "r-help@R-project.org\"  "@r-project.org
Subject: [External] [R] Dimensioning  lists.


I have a setting in which it would be convenient to treat a list
as an array, i.e. to address its entries via a pair of indices.

A toy example:

xxx <- vector("list",9)
set.seed(42)
for(i in 1:9) xxx[[i]] <- list(a=sample(letters,1),b=sample(1:100,1))

I would like to be able to treat "xxx" as a 3 x 3 matrix.

I tried

   dim(xxx) <- c(3,3)

When I do, e.g.

xxx[2,3]

I get:

> [[1]]
> [[1]]$a
> [1] "n"
>
> [[1]]$b
> [1] 20

That is I get a list of length 1, whose (sole) entry is the desired
object.  I would *like* to get just the desired object, *not* wrapped in
a list, i.e.:

> $a
> [1] "n"
>
> $b
> [1] 20
>

(which is what I get by typing xxx[2,3][[1]]).

Is there any way to prevent the entries of xxx from being wrapped up in
lists of length 1?

Thanks for any enlightenment.

cheers,

Rolf Turner

--
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] [External] Re: [External] Adding a superscript 6 to a number

2020-12-29 Thread Richard M. Heiberger
It is a generalization.
Don't use paste() and expression() together because paste is a sort-of
inverse to expression.
In this example I start by typing several characters, and the result
of paste(expression()) is a string containing the characters I
initially typed.

> expression(12^6)
expression(12^6)
> paste(expression(12^6))
[1] "12^6"


expression(12^6)
paste(expression(12^6))

plot(0:1, 0:1)
text(.1, .4, labels=paste(expression(12^6)))
text(.1, .3, labels=expression(12^6))

On Tue, Dec 29, 2020 at 4:15 PM Jeff Newmiller  wrote:
>
> Why not? Is that a generalization, or specific to this case?
>
> On December 29, 2020 7:54:22 AM PST, "Richard M. Heiberger"  
> wrote:
> >paste() is the problem.  don’t use paste with expression()
> >
> >On Tue, Dec 29, 2020 at 10:50 Sorkin, John 
> >wrote:
> >
> >> Colleagues,
> >>
> >> I would like to create a number (stored in the variable x) to the
> >number
> >> with the exponent of, i.e. the number to the sixth power. The code I
> >have
> >> tried, pasted below does not work.
> >>
> >> # create plot
> >> plot(x=0.2,y=0.2,xlim=c(0,1),ylim=c(0,1))
> >> PNotSusp=0.69
> >> # Create a string containing the base and exponent.
> >> x <- 0.95123
> >> # Convert the base to text and add the exponent of 6
> >> mylab <- expression(paste(" ",character(x)^6))
> >> # Add the text to the plot
> >> text(0.4,0.8,labels=paste(PNotSusp,"=\n",mylab))
> >>
> >> I hope someone can show me how to create the text string I need.
> >>
> >> 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
> >>
> ><https://www.google.com/maps/search/10+North+Greene+Street?entry=gmail&source=g>
> >> 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.
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.

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


Re: [R] [External] Adding a superscript 6 to a number

2020-12-29 Thread Richard M. Heiberger
paste() is the problem.  don’t use paste with expression()

On Tue, Dec 29, 2020 at 10:50 Sorkin, John 
wrote:

> Colleagues,
>
> I would like to create a number (stored in the variable x) to the number
> with the exponent of, i.e. the number to the sixth power. The code I have
> tried, pasted below does not work.
>
> # create plot
> plot(x=0.2,y=0.2,xlim=c(0,1),ylim=c(0,1))
> PNotSusp=0.69
> # Create a string containing the base and exponent.
> x <- 0.95123
> # Convert the base to text and add the exponent of 6
> mylab <- expression(paste(" ",character(x)^6))
> # Add the text to the plot
> text(0.4,0.8,labels=paste(PNotSusp,"=\n",mylab))
>
> I hope someone can show me how to create the text string I need.
>
> 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.
>

[[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] [External] RGB -> CYMK, with consistent colors

2020-11-29 Thread Richard M. Heiberger
I had a long discussion on this topic with the Springer production
group when my book was in production.
Statistical Analysis and Data Display: An Intermediate Course with
Examples in R, second edition
Richard M. Heiberger and Burt Holland.
https://www.springer.com/gp/book/9781493921218

As I now understand it, the physical inks used in printing cannot
produce the same range of colors as the computer screens.
The issue is not the notation, but rather the underlying technology.

I chose to let the publisher make the conversion.  I looked at the set
of pdfs for your book, and to
anyone else but you, I think they would look fine in slightly different colors.

Rich

On Sun, Nov 29, 2020 at 8:26 AM Derek Jones  wrote:
>
> All,
>
> I used the very useful colorspace package for the plots in my book
> (pdf available here): http://knosof.co.uk/ESEUR/
>
> The color makes the plots look great, on screen.
> To get lots printed, the printer requires converting the images to use cmyk
> (a common requirement for larger  printers, I'm told).  See page 11 here:
> https://www.ingramspark.com/hubfs/downloads/file-creation-guide.pdf
>
> No problem, the script below uses ghostscript to achieve this:
>
> gs -o ESEUR-cmyk.pdf \
>  -sDEVICE=pdfwrite \
>  -sProcessColorModel=DeviceCMYK \
>  -sColorConversionStrategy=CMYK \
>  -sColorConversionStrategyForImages=CMYK \
>   ESEUR.pdf
>
> the problem is that the converted colors don't look nearly as
> good.  For instance the cyan now looks blue, and prints as pure blue.
>
> I can regenerate the images, and explicitly specify cmyk.  But using:
>
> pdf.options(colormodel="cymk")
>
> does not change anything.  The colors look remarkably similar to
> those produced via the ghostview route.
>
> I have been looking at color profiles and trying to find a
> way of modifying an ICC profile (yes, it looks difficult).
>
> Does anybody have any ideas for producing cmyk images that have
> the same (or close enough) look as the RGB?
>
> __
> 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] long integer handling

2020-11-13 Thread Richard M. Heiberger
You need the Rmpfr package.  Your calculation of 2^64 is an ordinary
double precision number with 53 bits of precision.

> library(Rmpfr)
Loading required package: gmp

Attaching package: ‘gmp’

The following objects are masked from ‘package:base’:

%*%, apply, crossprod, matrix, tcrossprod

C code of R package 'Rmpfr': GMP using 64 bits per limb


Attaching package: ‘Rmpfr’

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

outer

The following objects are masked from ‘package:stats’:

dbinom, dgamma, dnorm, dpois, pnorm

The following objects are masked from ‘package:base’:

cbind, pmax, pmin, rbind

> class(2)
[1] "numeric"
> class(2^32)
[1] "numeric"
> class(2^64)
[1] "numeric"
> Two <- mpfr(2, precBits=64)
> Two^64
1 'mpfr' number of precision  64   bits
[1] 18446744073709551616
> class(Two^64)
[1] "mpfr"
attr(,"package")
[1] "Rmpfr"
> Two^64 - 1
1 'mpfr' number of precision  64   bits
[1] 18446744073709551615
> getPrec(Two)
[1] 64
> getPrec(2.)
[1] 53
>

On Fri, Nov 13, 2020 at 8:45 PM Yousri Fanous  wrote:
>
> I want to calculate 2^64-1 which is
> 18446744073709551615
>
> I set the following options to prevent scientific notation
> options("scipen"=100, "digits"=4)
> > x<-2^64 -1
> > x
> [1] 18446744073709551616
>
> This is not correct. There seem to be still some approximation happening.
> How can I get the correct result?
>
> Yousri
> IBM Canada ltd
> Software developer
>
> [[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] [External] Re: how to order variables on correlation plot

2020-11-06 Thread Richard M. Heiberger
My guess is that the "%>% data.frame %>%" step turned something into a
character that you thought would be a factor.
See this example.  Remember that the stringsAFactors argument to
data.frame was recently changed.



> tmp <- data.frame(A=c("A","F","B","G","C"), B=1:5, CC=6:10)
> tmp
  A B CC
1 A 1  6
2 F 2  7
3 B 3  8
4 G 4  9
5 C 5 10
> sapply(tmp,class)
  A   B  CC
"character"   "integer"   "integer"
> tmp[order(tmp$A),]
  A B CC
1 A 1  6
3 B 3  8
5 C 5 10
2 F 2  7
4 G 4  9
> tmp$A <- factor(tmp$A, levels=unique(tmp$A))
> sapply(tmp,class)
A BCC
 "factor" "integer" "integer"
> tmp[order(tmp$A),]
  A B CC
1 A 1  6
2 F 2  7
3 B 3  8
4 G 4  9
5 C 5 10
>

On Fri, Nov 6, 2020 at 9:18 AM Ana Marija  wrote:
>
> sorry forgot to attach the plot.
>
> On Fri, Nov 6, 2020 at 8:07 AM Ana Marija  wrote:
> >
> > Hello
> >
> > I have data like this:
> >
> > > head(my_data)
> >   subjects DIABDUR HBA1C ESRD SEX AGE PHENO  C1   C2
> > 1 fam0110_G110  38   9.41   2  51 2 -0.01144980  0.002661140
> > 2 fam0113_G113  30  12.51   2  40 2 -0.00502052 -0.000929061
> > 3 fam0114_G114  23   8.42   2  45 2 -0.00251578 -0.003450950
> > 4 fam0117_G117  37   9.02   2  46 2 -0.00704917 -0.000573325
> > 5 fam0119_G119  22   9.41   1  46 1  0.00263433  0.001002370
> > 6 fam0119_G120  NANA1   1  71 1 -0.00354795 -0.002045940
> > C3  C4  C5   C6   C7  C8
> > 1  0.006028150 -0.00176795 -0.00148375  0.004543550 -0.006272170 -0.00535077
> > 2 -0.000453402 -0.00192162  0.00416229  0.007868230 -0.001957670 -0.00473148
> > 3 -0.001680860 -0.00620438 -0.00235092  0.000672831 -0.000278318  0.00647337
> > 4  0.001436740  0.00155568 -0.00556147 -0.000386401 -0.006885350  0.00135539
> > 5 -0.007396920  0.00326229  0.00355575 -0.011149400  0.009156510  0.00120833
> > 6  0.004532050  0.00869862 -0.00113207  0.002244520 -0.002119220  0.00657587
> >C9 C10
> > 1  0.00328111 -0.00113515
> > 2 -0.00495790  0.00320201
> > 3  0.00208591 -0.00874752
> > 4 -0.00967934  0.00607760
> > 5  0.00611030  0.00876190
> > 6 -0.00990661  0.00635349
> >
> > I am plotting it with:
> >
> > library(dplyr)
> > library(magrittr)
> > library(corrplot)
> > d=my_data %>% data.frame %>% set_rownames(.$subjects) %>% select(-subjects)
> > res <- cor(d, use = "complete.obs")
> > pdf("correlation.pdf")
> > corrplot(res, type = "upper", order = "hclust",
> >  tl.col = "black", tl.srt = 45)
> > dev.off()
> >
> > and I am getting the plot in attach. How to make it so that my
> > variables are shown on the plot in the order they are in my_data data
> > frame?
> >
> > Thanks
> > Ana
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] [External] Re: Package recommendations for outputting table with cell formatting

2020-10-23 Thread Richard M. Heiberger
To John and everyone else,

Please add Hmisc::latex to your  how-to-make-beautiful-tables-in-r document.
We first included latex() in S in 1995, and it is still actively
maintained and improved.

Rich

Here are the first few lines of ?latex

Convert an S object to LaTeX, and Related Utilities

Description:

 ‘latex’ converts its argument to a ‘.tex’ file appropriate for
 inclusion in a LaTeX2e document.  ‘latex’ is a generic function
 that calls one of ‘latex.default’, ‘latex.function’, ‘latex.list’.

 ‘latex.default’ does appropriate rounding and decimal alignment
 and produces a file containing a LaTeX tabular environment to
 print the matrix or data.frame ‘x’ as a table.

 ‘latex.function’ prepares an S function for printing by issuing
 ‘sed’ commands that are similar to those in the ‘S.to.latex’
 procedure in the ‘s.to.latex’ package (Chambers and Hastie, 1993).
 ‘latex.function’ can also produce ‘verbatim’ output or output that
 works with the ‘Sweavel’ LaTeX style at http://biostat.mc.vanderbilt.edu/SweaveTemplate>.


On Fri, Oct 23, 2020 at 11:11 PM John Kane  wrote:
>
> This comes with no guarantee since i have only tried one or two packages
> mentioned but have a look at https://rfortherestofus.com/2019/11/how-to-make-beautiful-tables-in-r/";> R
> Tables.
>
>
> On Fri, 23 Oct 2020 at 20:28, Dennis Fisher  wrote:
>
> > R 4.0.2
> > OS X
> >
> > Colleagues
> >
> > I have the unfortunate need to create a large number of tables (destined
> > for a Word document).  I need to color cells depending on the contents,
> > e.g., blue if the value is < 0.5, red if the value is > 1.5.
> > If the output went initially to Excel, that would work; outputting
> > directly to Word would be even better.
> > I expect that several packages can accomplish this.  I am looking for
> > recommendations as to which package (or combination) of packages is best to
> > accomplish this.
> >
> > Dennis
> >
> > Dennis Fisher MD
> > P < (The "P Less Than" Company)
> > Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> > www.PLessThan.com
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
> --
> John Kane
> Kingston ON Canada
>
> [[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] [External] openxlsx::read.xlsx can't read data without a header

2020-10-22 Thread Richard M. Heiberger
?openxlsx::read.xlsx
The fourth argument by default is TRUE
colNames: If ‘TRUE’, the first row of data will be used as column
  names.

You will need to specify it explicitly
as colNames=FALSE
The other arguments will probably also be useful to you.

On Thu, Oct 22, 2020 at 11:56 PM John  wrote:
>
> Hi,
>
>I try to read 6 rows (from 5th to 10th) from Excel, but I can always get
> 5. The first row of the 6 becomes the header. How can I add something like
> "header = FALSE" in the formula, so that the resulting data would be all
> the 6 rows? A similar problem occurs in readxl::read_xlsx. Thank you!
>
> > temp <- openxlsx::read.xlsx(fl_trilem_sgko, sheet="Korea", rows=5:10,
> cols=25,skipEmptyRows = FALSE, na.strings = "NA")
> > temp
>   0.12101775061124695
> 1  0.09613981
> 2  0.16259886
> 3  0.07914472
> 4  0.10195485
> 5  0.07700853
> > nrow(temp)
> [1] 5
>
>
> John
>
> [[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] [External] Function of "matrix"

2020-10-22 Thread Richard M. Heiberger
FAQ 7.31

> 10.1/.1
[1] 101
> print(10.1/.1, digits=17)
[1] 100.99
> floor(10.1/.1)
[1] 100
>  floor(10.1*10)
[1] 101
> matrix(0, 2.9, 3.9)
 [,1] [,2] [,3]
[1,]000
[2,]000
>

note that the dimension arguments are passed through floor() before
they are used.

On Thu, Oct 22, 2020 at 2:42 PM 奈良県奈良市  wrote:
>
> Dear R project team
>
> I used the function of "matrix" as follows:
> matrix(c(1:3030), 10.1/0.1)
> However, in the function, matrix, 10.1/0.1 was regarded as 100 not as 101.
> Therefore, a warning message appeared.
> On the other hand, matrix(c(1:3030), 101) or matrix(c(1:3030), 10.1*10) was
> OK. Of course, simply, 10.1/0.1 was successfully calculated. However,
> In the "matrix" environment, 10.1/0.1 was calculated as 100.
>
> Would you give me some answers?
>
> Sincerely
>
> Kazuki Sakura
>
> [[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] [External] Re: unable to access index for repository...

2020-10-08 Thread Richard M. Heiberger
I wonder if you are perhaps trying to solve the wrong problem.

If you like what the older version of the aod package does, but not
the current version,
then I think the solution is to propose an option to the aod
maintainer that would restore your
preferred algorithm into the current version, and then use the current R.

A less good, but possibly workable, option is to compile the old
version of aod into the current R.

On Thu, Oct 8, 2020 at 1:45 PM Jeff Newmiller  wrote:
>
> All support on this list is voluntary, and support for old versions of R is 
> not even necessarily on-topic here which is why you keep getting nudged to 
> upgrade. Your "need" for support for an old version is definitely not "our" 
> problem, so I suggest you start looking for a consultant if this issue is 
> that important to you. Such is the nature of volunteer-developed open source 
> software... so support your local experts.
>
> On October 8, 2020 10:22:54 AM PDT, Steven Yen  wrote:
> >Thanks for the help. I have a reason to continue with R-3.0.3. I used
> >maxLik to estimate econometric models and some of them are better
> >handled with R-3.0.3 (but not later)a sad reality I do not like.
> >
> >Here is what I did. I downloaded
> >
> >https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip
> >
> >and installed the zip file, which worked in both RStudio and R (without
> >
> >RStudio).
> >
> >In RStudio, I go Tools -> Install packages -> Install from -> (Choose
> >zip) -> (Browse to the zip file)
> >
> >IN R, I go Packages -> Install packages from local file(s) -> (Browse
> >to
> >the zip file)...
> >
> >Below is the command line generated and the prompt.
> >
> >> install.packages("C:/Users/USER/Downloads/aod_1.3.zip", repos = NULL,
> >
> >type = "win.binary")
> >package ‘aod’ successfully unpacked and MD5 sums checked
> >
> >I will always be able to download the proper .zip file from CRAC
> >Archive, right. So, this will always work for me? Thank you all !! If
> >there are more direct options that work, I would still be interested to
> >
> >know.
> >
> >Steven Yen
> >
> >On 2020/10/9 上午 12:49, Duncan Murdoch wrote:
> >> Don't choose a mirror.  That will override the repos choice.
> >>
> >> Do update R to a current version if you aren't able to debug this
> >> yourself.
> >>
> >> Duncan Murdoch
> >>
> >> On 08/10/2020 12:38 p.m., Steven Yen wrote:
> >>> Sorry Gentlemen and all. Now this is becoming a joke (to me). I
> >repeated
> >>> what I did earlier, with and without the option to set repos
> >suggested
> >>> by Duncan. Now it does not work. I wonder whether it is dependent on
> >the
> >>> mirror I chose, but I do not remember the one I chose earlier when
> >it
> >>> work.
> >>>
> >>> I need your help, gentlemen, as I need to use R-3.0.3 for my task.
> >>>
> >>>   > options(repos="https://cran-archive.r-project.org";)
> >>>   > chooseCRANmirror()
> >>>   > install.packages("aod")
> >>> Warning: unable to access index for repository
> >>> https://cran-archive.r-project.org/bin/windows/contrib/3.0
> >>> Warning: unable to access index for repository
> >>> http://lib.stat.cmu.edu/R/CRAN/bin/windows/contrib/3.0
> >>>
> >>>  package ‘aod’ is available as a source package but not as a
> >binary
> >>>
> >>> Warning message:
> >>> package ‘aod’ is not available (for R version 3.0.3)
> >>>   >
> >install.packages("aod",repos='https://cran-archive.r-project.org')
> >>> Warning: unable to access index for repository
> >>> https://cran-archive.r-project.org/bin/windows/contrib/3.0
> >>> Warning message:
> >>> package ‘aod’ is not available (for R version 3.0.3)
> >>>
> >>> On 2020/10/9 上午 12:02, Duncan Murdoch wrote:
>  Okay, so it's not an RStudio issue. However, I'd guess setting
> 
> options(repos = "https://cran-archive.r-project.org";)
> 
>  at the start of your session could make everything work.  (I'm
>  guessing you currently have it set to "http://cran.rstudio.com";,
> >which
>  is the source of the last warning below, probably due to an R bug.
>  But since you're using an obsolete version of R, it shouldn't
> >surprise
>  you that it has bugs that nobody else is seeing.)
> 
>  Duncan Murdoch
> 
>  On 08/10/2020 11:54 a.m., Steven Yen wrote:
> > Thanks. You gentlemen please tell me what this means. In R
> >(outside
> > of RStudio) I ran:
> >
> > install.packages("aod")
> >
> > Received a warning (and installation did not seem to go through).
> >
> > Then I tried
> >
> > install.packages("aod",repos='https://cran-archive.r-project.org')
> >
> > Received a warning but it went on to try
> >
> >
> >https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip
> >
> > and it worked. See log below.
> >
> > I expect to continue to use R-3.0.3 for a while and I very much
> >like
> > this to become a routine. Thank you all.
> >
> > Steven Yen
> >
> >   > insta

Re: [R] [External] Re: how to replace values in a named vector

2020-09-14 Thread Richard M. Heiberger
I can't understand non-words with that many letters.  I think this is what you
are looking for:

> tmp <- c(A="a",B="b",C="c",D="d")
> names(tmp)
[1] "A" "B" "C" "D"
> tmp
  A   B   C   D
"a" "b" "c" "d"
> ## change values of B and C to "x" and "y"
> names(tmp) %in% c("B","C")
[1] FALSE  TRUE  TRUE FALSE
> tmp[names(tmp) %in% c("B","C")]
  B   C
"b" "c"
> tmp[names(tmp) %in% c("B","C")] <- c("x","y")
> tmp
  A   B   C   D
"a" "x" "y" "d"
>

If not, please ask the question again with simpler-appearing vectors and show
us what you would like the answer to be.

On Mon, Sep 14, 2020 at 12:37 PM Ana Marija  wrote:
>
> sorry not replace with NA but with empty string for a name, for example
>
> for example this:
>
> > geneSymbol["Ku8QhfS0n_hIOABXuE"]
> Ku8QhfS0n_hIOABXuE
>"MACC1"
>
> would go when I subject it to
>
> > geneSymbol["Ku8QhfS0n_hIOABXuE"]
>
> Ku8QhfS0n_hIOABXuE
>
> On Mon, Sep 14, 2020 at 11:35 AM Ana Marija  
> wrote:
> >
> > Hello,
> >
> > I have a vector like this:
> >
> > > head(geneSymbol)
> > Ku8QhfS0n_hIOABXuE Bx496XsFXiAlj.Eaeo W38p0ogk.wIBVRXllY
> > QIBkqIS9LR5DfTlTS8 BZKiEvS0eQ305U0v34 6TheVd.HiE1UF3lX6g
> >"MACC1""GGACT"   "A4GALT"
> > "NPSR1-AS1""NPSR1-AS1" "AAAS"
> >
> > it has around 15000 entries. How do I replace all values with NA
> > expect these that are named like this:
> >
> > geneSymbol[c("0lQ1XozriVZTn.PezY","uaeFiCdegrnWFijF_s","ZOluqaxSe3ndekoNng","912ny6eCHjnlY2XSCU","odF3XHR8CVl4SAUaUQ")]
> >
> >
> > > geneSymbol[c("0lQ1XozriVZTn.PezY","uaeFiCdegrnWFijF_s","ZOluqaxSe3ndekoNng","912ny6eCHjnlY2XSCU","odF3XHR8CVl4SAUaUQ")]
> > 0lQ1XozriVZTn.PezY uaeFiCdegrnWFijF_s ZOluqaxSe3ndekoNng
> > 912ny6eCHjnlY2XSCU odF3XHR8CVl4SAUaUQ
> > "FLCN" "FLCN" "FLCN"
> > "UCA1" "IL1B"
> >
> > Thanks
> > Ana
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] [External] R rounding problem?

2020-09-03 Thread Richard M. Heiberger
FAQ 7.31

On Fri, Sep 4, 2020 at 12:47 AM array chip via R-help
 wrote:
>
> Hello,
>
> I made a mistake today on simple counting in R, that almost got me into 
> trouble. After trying multiple times, I finally figured out it's rounding 
> issue in R.
>
> For exmaple, when I just simply type:
>
> > (6.9-6.3) > 0.6
> [1] TRUE
>
> 6.9-6.3 should be 0.6 exactly, but R thinks that it's greater than 0.6!!
>
> Similarly, R thinks 5.6-5.5 is smaller than 0.1:
>
> > (5.6-5.5) < 0.1
> [1] TRUE
>
> Why is the above happening? This rounding issue seems to be small, but this 
> could cause serious problem in real world.
>
> Can anyone shed a light on how to avoid the issue?
>
> Thanks,
>
> Yi
>
> __
> 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] rNOMADS package

2020-08-24 Thread Richard M. Heiberger
incorrect double slash c://
use single slash c:/

On Mon, Aug 24, 2020 at 11:21 Philip  wrote:

> I am struggling to install a fix for the rNOMADS package which reads
> National Weather Service data.  I copied the fix (rNOMADS_2.5.0.tar.gz)
> from an email to a local drive and then tried to install it with the
> command below.  I also tried installing it without the .tar.gz extension
> and without the _2.5.0 extension but I get the same error message.  The
> author, Daniel Bowman, emailed me that the fix should work for R version
> 4.0 or better.
>
>
>
> Do I need to untar it?
>
>
>
>
> install.packages("C://Documents/Ballooning/WeatherBriefing/rNOMADS_2.5.0.tar.gz")
>
>
>
> Installing package into ‘C:/Users/Owner/Documents/R/win-library/4.0’
>
> (as ‘lib’ is unspecified)
>
> Warning in install.packages :
>
>   package ‘C://Documents/Ballooning/WeatherBriefing/rNOMADS_2.5.0.tar.gz’
> is not available (for R version 4.0.2)
>
> [[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] [External] finding nearest zip codes

2020-08-04 Thread Richard M. Heiberger
verify that you actually have five-digit zip codes stored as
characters. New Jersey and Massachusetts have zero as
the first digit.  When these codes are saved as numbers, they become
four-digit codes and will probably cause errors.
For example Cambridge, Mass is '02138', and would be reported as 2138
when interpreted as a number..

On Tue, Aug 4, 2020 at 9:29 PM Debasmita Sur  wrote:
>
> Dear R-experts,
> I have two lists of US zip codes and want to pick the nearest zip code from
> second list against my first list.e.g.30043 (from second list) is closest
> to the zip code 30094 (from first list).So,it should come against 30094.The
> code should compare the distance from each zip and pick the nearest one.
> I have written the following code. It is giving proper results for many,
> but in mindist, it is showing 'NAs'. But for some of the zip codes, it is
> giving proper minimum distance. Please note it will be effective for 5
> digit zip codes. Any help will be highly appreciated.
>
> df1<-read.csv("C:/Users/dxsur/Desktop/ZIP1.csv")
> df2<-read.csv("C:/Users/dxsur/Desktop/ZIP2.csv")
>
> results<-merge(x=df1,y=zipcode,all.x=TRUE)
> results1<-merge(x=df2,y=zipcode,all.x=TRUE)
> distance<-distm(subset(results,select=c(longitude,latitude)),subset(results1,select=c(longitude,latitude)))
>
> rnum=apply(distance, 1, which.min)
> mindist=apply(distance, 1, min)
>
> final<-cbind(results,results1$zip[unlist(rnum)],mindist)
>
>
> Thanks & Regards,
> *Debasmita *
>
> [[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] [External] Re: Playing a music file in R

2020-07-23 Thread Richard M. Heiberger
The R command
system.file()

tells you where the currently running version of R is located on your
machine and your operating system.

On the Macintosh it shows
> system.file()
[1] "/Library/Frameworks/R.framework/Resources/library/base"

You don't need to worry about the R version number, as R knows where
it is and gives you the location
of the currently running version.  You can now open a system directory
file (Finder on Mac, WindowsExplorer on Windows, etc)
and navigate up and down to what you are looking for.

Or, within R, you can navigate with .. and more directory statements,
thus the example from the original email

setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play")
  # path depends on your R version etc.

would be written
tmp <- system.file("../../bin/play")
and the result is the correct location (if it is there).
You will get an empty string if it is not ther, but this will get you
started on where to look.
then you write

setWavPlayer(tmp)   # path depends on your R version etc.

On Thu, Jul 23, 2020 at 7:21 AM bretschr  wrote:
>
> Dear Vahid,
>
>
> Re:
>
> > I have a question regarding the following code:
> > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play")
> ># path depends on your R version etc.
> >
> > How can I find the corresponding path on my laptop?
>
>
> This line ...
>
> setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play")
>
> ... is the path on my MacBook Air running Mac OS Mojave.
> The structure of R on similar computers and OS versions will be the same, but 
> I don't know if you use Windows or Linux.
> Maybe an R-user working with Windows or Linux can help.
> Success,
>
> Franklin
> 
>
>
>
> Franklin Bretschneider
> Dept of Biology
> Utrecht University
> f.bretschnei...@uu.nl
>
> __
> 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] Character (1a, 1b) to numeric

2020-07-10 Thread Richard M. Heiberger
> xc <-  c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c")
> xn <- c(1, 1.3, 1.5, 1.7, 2, 2.3, 2.5, 2.7)
> testdata <- rep(c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c"), times=1:8)
> testdata
 [1] "1"  "1a" "1a" "1b" "1b" "1b" "1c" "1c" "1c" "1c" "2"  "2"  "2"  "2"  "2"
[16] "2a" "2a" "2a" "2a" "2a" "2a" "2b" "2b" "2b" "2b" "2b" "2b" "2b" "2c" "2c"
[31] "2c" "2c" "2c" "2c" "2c" "2c"
> ?match
> xn[match(testdata, xc)]
 [1] 1.0 1.3 1.3 1.5 1.5 1.5 1.7 1.7 1.7 1.7 2.0 2.0 2.0 2.0 2.0 2.3 2.3 2.3 2.3
[20] 2.3 2.3 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.7 2.7 2.7 2.7 2.7 2.7 2.7 2.7
>

On Fri, Jul 10, 2020 at 1:51 PM Jean-Louis Abitbol  wrote:
>
> Dear All
>
> I have a character vector,  representing histology stages, such as for 
> example:
> xc <-  c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c")
>
> and this goes on to 3, 3a etc in various order for each patient. I do have of 
> course a pre-established  classification available which does change 
> according to the histology criteria under assessment.
>
> I would want to convert xc, for plotting reasons, to a numeric vector such as
>
> xn <- c(1, 1.3, 1.5, 1.7, 2, 2.3, 2.5, 2.7)
>
> Unfortunately I have no clue on how to do that.
>
> Thanks for any help and apologies if I am missing the obvious way to do it.
>
> JL
> --
> Verif30042020
>
> __
> 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] challenging data merging/joining problem

2020-07-05 Thread Richard M. Heiberger
Have you talked directly to the designers of the new database?
One would hope that they had a clear migration path in mind.
Perhaps they just didn't document it to your satisfaction.

Rich

On Sun, Jul 5, 2020 at 2:51 PM Christopher W. Ryan  wrote:
>
> I've been conducting relatively simple COVID-19 surveillance for our
> jurisdiction. We get data on lab test results automatically, and then
> interview patients to obtain other information, like clinical details.
> We had been recording all data in our long-time data system (call it
> dataSystemA). But as of a particular date, there was a major change in
> the data system we were compelled to use. Call the new one dataSystemB.
> dataSystemA and dataSystemB contain very similar information,
> conceptually, but the variable names are all different, and there are
> some variables in one that do not appear in the other. Total number of
> variables in each is about 50-70.
>
> Furthermore, for about 2 weeks prior to the transition, lab test results
> started being deposited into dataSystemB while dataSystemA was still
> being used to record the full information from the interviews.
> Subsequent to the transition, lab test results and interview information
> are being recorded in dataSystemB, while the lab test results alone are
> still being automatically deposited into dataSystemA.
>
> Diagrammatically:
>
> dataSystemA usage:  >>
>
> dataSystemB usage:   ..._>>
>
> where  represents full data and . represents partial data,
> and >> represents the progress of time.
>
>
> The following will create MWE of the data wrangling problem, with the
> change in data systems made to occur overnight on 2020-07-07:
>
> library(dplyr)
> dataSystemA <- tibble(lastName = c("POTTER", "WEASLEY", "GRAINGER",
> "LONGBOTTOM"),
>   firstName = c("harry", "ron", "hermione", "neville"),
>   dob = as.Date(Sys.Date() + c(sample(-3650:-3000,
> size = 2), -3500, -3450)),
>   onsetDate = as.Date(Sys.Date() + 1:4),
>   symptomatic = c(TRUE, FALSE, NA, NA) )
> dataSystemB <- tibble(last_name = c("GRAINGER", "LONGBOTTOM", "MALFOY",
> "LOVEGOOD", "DIGGORY"),
>   first_name = c("hermione", "neville", "draco",
> "luna", "cedric"),
>   birthdate = as.Date(Sys.Date() + c(-3500, -3450,
> sample(-3650:-3000, size = 3))),
>   date_of_onset = as.Date(Sys.Date() + 3:7),
>   symptoms_present = c(TRUE, TRUE, FALSE, FALSE, TRUE))
>
>
>
> Obviously, this is all the same public health problem, so I don't want a
> big uninterpretable gap in my reports. I am looking for advice on the
> best strategy for combining two different tibbles with some overlap in
> observations (some patients appear in both data systems, with varying
> degrees of completeness of data) and with some of the same things being
> mesaured and recorded in the two data systems, but with different
> variable names.
>
> I've thought of two different strategies, neither of which seems ideal
> but either of which might work:
>
> 1. change the variable names in dataSystemB to match their
> conceptually-identical variables in dataSystemA, and then use some
> version of bind_rows()
>
> 2. Create a unique identifier from last names, first names, and dates of
> birth, use some type of full_join(), matching on that identifier,
> obtaining all columns from both tibbles, and then "collapse"
> conceptually-identical variables like onsetDate and date_of_onset using
> coalesce()
>
> Sorry for my long-windedness. Grateful for any advice.
>
> --Chris Ryan
>
> __
> 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] Re: R Software Risk Analysis

2020-06-18 Thread Richard M. Heiberger
You should start by reading
R: Regulatory Compliance and Validation Issues: A guidance document
for the use of R in regulated clinical trial environments.
https://www.r-project.org/doc/R-FDA.pdf

The official link to that file is at the R home page https://www.r-project.org/
In the left column, click on Certification.

That takes you to the page that offers the Compliance paper and a
paper on the R Development cycle.

Rich

On Thu, Jun 18, 2020 at 7:46 PM David Winsemius  wrote:
>
>
> On 6/18/20 3:41 PM, John Harrold wrote:
> > Hello Kristin,
> >
> > Are you talking about risk analysis from the perspective of software
> > vulnerabilities?
>
>
> It appears that is exactly what is being asked. What is not clear is
> whether the installation would be offered to persons or groups on the
> network with no other security wrappers. R has never claimed to be
> "web-safe". It offers access to system level commands and file system
> manipulation that would probably compromise security arrangements.  In
> fact, over the course of the last 12 years when I've been reading this
> mailing list, there has never been a credible suggestion to offer R
> applications to untrusted users. Quite the opposite. Naked R is surely
> not going to pass any sort threat or risk scrutiny.
>
>
> My suggestion would be to investigate various wrappers for R such as
> Rstudio or the Microsoft re-worked version of what used to be Revolution
> R. They have lawyers and offer "enterprise solutions" and would
> presumably be able to speak to some sort of security analysis.  Whether
> either of those approaches would provide the level of security needed by
> a healthcare organization would be an interesting question. Perhaps yopu
> can report back after completing your investigation?
>
>
> --
>
> David.
>
> >
> > John
> >
> > On Thu, Jun 18, 2020 at 3:21 PM Wait, Kristin  wrote:
> >
> >> HI all,
> >>
> >> I am with a NYS major trauma center and all programs that our
> >> employees/providers use must be vetted through the IT Department by way of
> >> a Risk Analysis.
> >> Is there someone I would talk to about this?
> >>
> >> I scoured your website and could not find a specific person.
> >>
> >> Thank you so much
> >> Kristin Wait
> >> Albany, NY
> >> - CONFIDENTIALITY NOTICE: This
> >> email and any attachments may contain confidential information that is
> >> protected by law and is for the sole use of the individuals or entities to
> >> which it is addressed. If you are not the intended recipient, please notify
> >> the sender by replying to this email and destroying all copies of the
> >> communication and attachments. Further use, disclosure, copying,
> >> distribution of, or reliance upon the contents of this email and
> >> attachments is strictly prohibited. To contact Albany Medical Center, or
> >> for a copy of our privacy practices, please visit us on the Internet at
> >> www.amc.edu.
> >>
> >>  [[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] [External] struggling with apply

2020-05-27 Thread Richard M. Heiberger
sapply(1:4, FUN=function(i, x, UB=c(2.5, 5.5, 8.5, 10.5)) {result <-
x[,i]; result[result > UB[i]] <- UB[i]; result}, x=somematrix)

On Wed, May 27, 2020 at 1:46 PM Michael Ashton
 wrote:
>
> Hi -
>
> I have a matrix of n rows and 4 columns.
>
> I want to cap the value in each column by a different upper bound. So, 
> suppose my matrix is
>
> somematrix <- matrix(c(1,4,3,6,3,9,12,8,5,7,11,11),nrow=3,ncol=4)
> > somematrix
>  [,1] [,2] [,3] [,4]
> [1,]16   127
> [2,]438   11
> [3,]395   11
>
> Now I want to have the maximum value in each column described by
> UB=c(2.5, 5.5, 8.5, 10.5)
>
> So that the right answer will look like:
>  [,1]  [,2][,3]   [,4]
> [1,]1  5.5 8.57
> [2,]2.538 10.5
> [3,]2.5   5.5  510.5
>
> I've tried a few things, like:
> newmatrix <- apply(somematrix,c(1,2),function(x) min(UB,x))
>
> but I can't figure out to apply the relevant element of the UB list to the 
> right element of the matrix. When I run the above, for example, it takes 
> min(UB,x) over all UB, so I get:
>
> newmatrix
>  [,1] [,2] [,3] [,4]
> [1,]  1.0  2.5  2.5  2.5
> [2,]  2.5  2.5  2.5  2.5
> [3,]  2.5  2.5  2.5  2.5
>
> I'm sure there's a simple and elegant solution but I don't know what it is!
>
> Thanks in advance,
>
> Mike
>
> Michael Ashton, CFA
> Managing Principal
>
> Enduring Investments LLC
> W: 973.457.4602
> C: 551.655.8006
> Schedule a Call: https://calendly.com/m-ashton
>
>
> [[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] [External] Help with sub-setting

2020-05-25 Thread Richard M. Heiberger
I think the syntax you are looking for is

datasubset <- data[ data$A ==1 & data$B ==  1 , ] )

This gives the subset of your original data for variable A with value
1 and variable B with value 1.


On Mon, May 25, 2020 at 12:57 PM Burgess, Jamie
 wrote:
>
> Dear all,
>
> I hope this message finds you well. I am currently trying to subset my data 
> by two variables, so far, I have tried two different ways to stratify 
> participants into groups. I would like to use the ‘summary’ and ‘table’ 
> arguments to characterise the data of participants based on the presence of 
> two variables and summarise this sub-set against a third variable.
> I have used this method:
>
> dgb001<-subset(data,data$variable==1 & data,data$variable)
>
>
> However, I get the following error: “Error: cannot allocate vector of size 
> 16.0 Gb”. Is there another method I can try?
>
>
> Kind regards,
>
>
> Jamie Burgess
>
> PhD Student Endocrinology and Diabetes
>
> University of Liverpool
>
> Aintree University Hospital &
>
> The Walton Centre
>
> Institute of Ageing & Chronic Disease
>
> 0151 529 5936
>
>
> [[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] [External] Re: access for free more than 500 essential Springer Nature textbooks

2020-05-22 Thread Richard M. Heiberger
The Excel file is what you need.
As Fabio remarked, the downloadable links are in column R

I normally read (and write) Excel files into R using library(openxlsx)
There are also several other packages on CRAN for reading and writing Excel.

MARC stands for
MAchine-Readable Cataloging.
Information is at the Library of Congress
 https://www.loc.gov/marc/faq.html

Rich

On Fri, May 22, 2020 at 2:24 PM Abby Spurdle  wrote:
>
> That sounds like progress.
>
> However, I was unable to use their website.
> All I can find is Excel documents (which I can't open) and MARC (?),
> which I don't have time to look into.
>
> Your post might have more value, if you provide a list of the titles
> (or a link to a list, in an easy to read open access format), ideally
> with a note on where to find open access copies of those texts,
> without spending a long time searching.
>
> On Sat, May 23, 2020 at 4:29 AM Richard M. Heiberger  wrote:
> >
> > Springer has just made available free access to many books through July.
> > This is part of their global program to support educators, students
> > and academics
> > affected by coronavirus lockdown.
> >
> > Their list includes about 20 statistics books in English and 2 in
> > German.  Several, including mine, have R in the title or subtitle.
> >
> > This link describes the program:
> > https://www.springernature.com/gp/librarians/news-events/all-news-articles/industry-news-initiatives/free-access-to-textbooks-for-institutions-affected-by-coronaviru/17855960?sap-outbound-id=07923935E132AFCC90201BAEA7D6755EC6C597DE&utm_source=hybris-campaign&utm_medium=email&utm_campaign=000_BARZ01_001531_AEXS_AWA_CB02_GL_txt_covid&utm_content=EN_internal_5917_20200522&mkt-key=42010A0550671EDA9BA73AC34F576EF6
> >
> > My book is
> > Statistical Analysis and Data Display, Richard M. Heiberger, Burt
> > Holland, 2nd ed. 2015
> > It is supported by the HH package available from CRAN.
> >
> > 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.


[R] access for free more than 500 essential Springer Nature textbooks

2020-05-22 Thread Richard M. Heiberger
Springer has just made available free access to many books through July.
This is part of their global program to support educators, students
and academics
affected by coronavirus lockdown.

Their list includes about 20 statistics books in English and 2 in
German.  Several, including mine, have R in the title or subtitle.

This link describes the program:
https://www.springernature.com/gp/librarians/news-events/all-news-articles/industry-news-initiatives/free-access-to-textbooks-for-institutions-affected-by-coronaviru/17855960?sap-outbound-id=07923935E132AFCC90201BAEA7D6755EC6C597DE&utm_source=hybris-campaign&utm_medium=email&utm_campaign=000_BARZ01_001531_AEXS_AWA_CB02_GL_txt_covid&utm_content=EN_internal_5917_20200522&mkt-key=42010A0550671EDA9BA73AC34F576EF6

My book is
Statistical Analysis and Data Display, Richard M. Heiberger, Burt
Holland, 2nd ed. 2015
It is supported by the HH package available from CRAN.

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.


Re: [R] [External] Re: [External] Get a result but an error message as well ?

2020-05-19 Thread Richard M. Heiberger
you need to pay attention to the intermediate structures that you generate.
If all you want is one number, then that is what you should create

mean(replicate( 500, my.experiment() ))

Since you do seem to want to store the intermediate values, then you must
name
the object according to its structure.  A one-dimensional vector takes
names(), not dimnames().
A two-dimensional structure takes dimnames, and the number of row names and
the number of column
names must match the number of rows and columns.


On Tue, May 19, 2020 at 5:25 PM varin sacha  wrote:

> Hi Rui,
>
> If I don't transpose t() the output of the replicate (my R code here
> below) I still get an error message !!
>
> 
> a=c(2,4,3,4,6,5,3,1,2,3,4,3,4,5,65)
> b=c(23,45,32,12,23,43,56,44,33,11,12,54,23,34,54)
> d=c(9,4,5,3,2,1,3,4,5,6,4,9,10,11,18)
>
> my.experiment <- function() {
>
> OLS <- lm( a ~ b+d )
>
> MSE_OLS<-mean(OLS$residuals^2)
>
> return( c(MSE_OLS) )
> }
>
> my.data = replicate( 500, my.experiment() )
> colnames(my.data) <- c("MSE_OLS")
> mean(my.data)
> 
>
>
>
>
>
>
> Le mardi 19 mai 2020 à 23:14:21 UTC+2, Rui Barradas 
> a écrit :
>
>
>
>
>
> Hello,
>
> Inline.
>
> Às 21:38 de 19/05/20, varin sacha via R-help escreveu:
> >
> > Hi Richard,
> >
> > Thanks for your response.
> > However, how can I correct my R code knowing that I want, as a result,
> only one value : the mean of the 500 MSE_OLS values ?
>
> Just don't transpose the output of replicate?
>
> Hope this helps,
>
> Rui Barradas
>
> >
> >
> >
> >
> >
> >
> >
> > Le mardi 19 mai 2020 à 21:59:07 UTC+2, Richard M. Heiberger <
> r...@temple.edu> a écrit :
> >
> >
> >
> >
> >
> >> dim(my.data)
> > [1]   1 500
> >
> > you have a matrix with a single row and 500 columns.
> > you gave a name to only the first column.
> >
> > Look at the result of replicate().  it is a vector.  You transposed it
> into a one-row matrix.
> >
> >>   tmp <- replicate( 500, my.experiment() )
> >> dim(tmp)
> > NULL
> >> length(tmp)
> > [1] 500
> >> dim(t(tmp))
> > [1]   1 500
> >
> >
> > On Tue, May 19, 2020 at 3:51 PM varin sacha via R-help <
> r-help@r-project.org> wrote:
> >> Dear R-experts,
> >>
> >> Here is my R code, I get a result but I also get an error message so I
> doubt I can trust the result I get.
> >> What is going wrong ? Many thanks.
> >>
> >> 
> >> a<-c(2,4,3,4,6,5,3,1,2,3,4,3,4,5,65)
> >> b<-c(23,45,32,12,23,43,56,44,33,11,12,54,23,34,54)
> >> d<-c(9,4,5,3,2,1,3,4,5,6,4,9,10,11,18)
> >>
> >> my.experiment <- function( ) {
> >>
> >> OLS <- lm( a ~ b+d )
> >> MSE_OLS<-mean(OLS$residuals^2)
> >> return( c(MSE_OLS) )
> >> }
> >>
> >> my.data = t(replicate( 500, my.experiment() ))
> >> colnames(my.data) <- c("MSE_OLS")
> >> mean(my.data)
> >> 
> >>
> >>
> >> __
> >> 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.
> >
>

[[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] [External] Get a result but an error message as well ?

2020-05-19 Thread Richard M. Heiberger
> dim(my.data)
[1]   1 500

you have a matrix with a single row and 500 columns.
you gave a name to only the first column.

Look at the result of replicate().  it is a vector.  You transposed it into
a one-row matrix.

>  tmp <- replicate( 500, my.experiment() )
> dim(tmp)
NULL
> length(tmp)
[1] 500
> dim(t(tmp))
[1]   1 500


On Tue, May 19, 2020 at 3:51 PM varin sacha via R-help 
wrote:

> Dear R-experts,
>
> Here is my R code, I get a result but I also get an error message so I
> doubt I can trust the result I get.
> What is going wrong ? Many thanks.
>
> 
> a<-c(2,4,3,4,6,5,3,1,2,3,4,3,4,5,65)
> b<-c(23,45,32,12,23,43,56,44,33,11,12,54,23,34,54)
> d<-c(9,4,5,3,2,1,3,4,5,6,4,9,10,11,18)
>
> my.experiment <- function( ) {
>
> OLS <- lm( a ~ b+d )
> MSE_OLS<-mean(OLS$residuals^2)
> return( c(MSE_OLS) )
> }
>
> my.data = t(replicate( 500, my.experiment() ))
> colnames(my.data) <- c("MSE_OLS")
> mean(my.data)
> 
>
>
> __
> 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] [External] sort

2020-05-14 Thread Richard M. Heiberger
## the data you gave us

DF1 <- read.table(text="name ddate
  A  2019-10-28
  A  2018-01-25
  A  2020-01-12
  A  2017-10-20
  B  2020-11-20
  B  2019-10-20
  B  2017-05-20
  B  2020-01-20
  c  2009-10-01  ",
  header=TRUE, colClasses=c("character", "POSIXct"))

DF1

D2 <- split(DF1, DF1$name)
D2

sapply(D2, function(x) {
  DD <- c(sort(x$ddate, decreasing=TRUE), min(x$ddate))
  DD[1]-DD[2]
})


## the data that your intended answer is based on

DF1 <- read.table(text="name ddate
  A  2019-01-12  ## intended value
  A  2018-01-25
  A  2020-01-12
  A  2017-10-20
  B  2020-11-20
  B  2019-10-20
  B  2017-05-20
  B  2020-01-20
  c  2009-10-01  ",
  header=TRUE, colClasses=c("character", "POSIXct"))

DF1

D2 <- split(DF1, DF1$name)
D2

sapply(D2, function(x) {
  DD <- c(sort(x$ddate, decreasing=TRUE), min(x$ddate))
  DD[1]-DD[2]
})

On Thu, May 14, 2020 at 11:00 PM Val  wrote:

> HI All,
> I have a sample of data frame
> DF1<-read.table(text="name ddate
>   A  2019-10-28
>   A  2018-01-25
>   A  2020-01-12
>   A  2017-10-20
>   B  2020-11-20
>   B  2019-10-20
>   B  2017-05-20
>   B  2020-01-20
>   c  2009-10-01  ",header=TRUE)
>
> 1. I want sort by name and ddate on decreasing order and the output
> should like as follow
>A  2020-01-12
>A  2019-01-12
>A  2018-01-25
>A  2017-10-20
>B  2020-11-21
>   B  2020-11-01
>   B  2019-10-20
>   B  2017-05-20
>   c  2009-10-01
>
> 2.  Take the top two rows by group( names) and the out put should like
>A  2020-01-12
>A  2019-01-12
>B  2020-11-21
>B  2020-11-01
> c  2009-10-01
>
> 3.  Within each group (name) get the date difference  between the
> first and second rows dates. If a group has only one row then the
> difference should be 0
>
> The final out put is
> Name diff
>A  365
> B  20
> C  0
>
> Here is my attempt and have an issue at the sorting
> DF1$DTime <- as.POSIXct(DF1$ddate , format = "%Y-%m-%d")
> DF2 <- DF1[order(DF1$name, ((as.Date(DF1$DTime, decreasing = TRUE, ]
>
> not working
> Any help?
>
> Thank you
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Loop inside dplyr::mutate

2020-05-09 Thread Richard M. Heiberger
## I start with sim_data_wide

sim_data_wide <- tidyr::spread(sim_data, quarter, pd)

## and calculate wide
wide1 <- with(sim_data_wide, cbind(PC_1 = P_1,
   PC_2 = 1-(1-P_1)*(1-P_2),
   PC_3 = 1-(1-P_1)*(1-P_2)*(1-P_3),
   PC_4 = 1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4),
   PC_5 = 1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5),
   PC_6 =
1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6),
   PC_7 =
1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7),
   PC_8 =
1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7)*(1-P_8),
   PC_9 =
1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7)*(1-P_8)*(1-P_9),
   PC_10 =
1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7)*(1-P_8)*(1-P_9)*(1-P_10)
  )
)

## this simpler sequence gets the same value

A <- 1-sim_data_wide[,2:11]
B <- t(apply(A, 1, cumprod)[-1,])
wide2 <- cbind(sim_data_wide[,2], 1-B)
dimnames(wide2)[[2]] <- paste0("PC_", 1:10)

all.equal(wide1, wide2)


On Sat, May 9, 2020 at 9:28 PM Jeff Newmiller 
wrote:

> Does this help?
>
> sim_wide2 <- (
> sim_data
> %>% arrange( borrower_id, quarter )
> %>% group_by( borrower_id )
> %>% mutate( cumpd = 1 - cumprod( 1 - pd ) )
> %>% ungroup()
> %>% mutate( qlbl = paste0( "PC_", quarter ) )
> %>% select( borrower_id, qlbl, cumpd )
> %>% spread( qlbl, cumpd )
> )
>
> On May 9, 2020 4:45:40 PM PDT, Axel Urbiz  wrote:
> >Hello,
> >
> >Is there a less verbose approach to obtaining the PC_i variables inside
> >the mutate?
> >
> >library(tidyverse)
> >sim_data <- data.frame(borrower_id = sort(rep(1:10, 20)),
> >   quarter = rep(1:20, 10),
> > pd = runif(length(rep(1:20, 10 # conditional probs
> >
> >sim_data_wide <- tidyr::spread(sim_data, quarter, pd)
> >colnames(sim_data_wide)[-1] <- paste0("P_",
> >colnames(sim_data_wide)[-1])
> >
> ># Compute cumulative probs
> >sim_data_wide <- sim_data_wide %>%
> >  mutate(PC_1 = P_1,
> > PC_2 = 1-(1-P_1)*(1-P_2),
> > PC_3 = 1-(1-P_1)*(1-P_2)*(1-P_3),
> > PC_4 = 1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4),
> >  PC_5 = 1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5),
> >  PC_6 = 1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6),
> >  PC_7 = 1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7),
> >PC_8 =
> >1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7)*(1-P_8),
> >PC_9 =
> >1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7)*(1-P_8)*(1-P_9),
> >PC_10 =
>
> >1-(1-P_1)*(1-P_2)*(1-P_3)*(1-P_4)*(1-P_5)*(1-P_6)*(1-P_7)*(1-P_8)*(1-P_9)*(1-P_10)
> >)
> >
> >
> >Thanks,
> >Axel.
> >   [[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.
>

[[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] Error: Cannot use `+.gg()` with a single argument.

2020-05-07 Thread Richard M. Heiberger
It is just like the message suggested. You have a + at the end of each line
and
the beginning of the next.  The one at the end is required.  The ones at
the beginning are
causing the error message.

Please put spaces around your assignment arrows.
Difficult to read:  r<-murders
Easy to read:r <- murders

On Thu, May 7, 2020 at 10:46 PM Ana Marija 
wrote:

> Hello,
>
> I got this error:
> Error: Cannot use `+.gg()` with a single argument. Did you
> accidentally put + on a new line?
>
> After running this:
> data(murders)
> library(ggplot2)
> library(dplyr)
> library(ggplot2)
> ggplot(data=murders)
>
> #define the slope of the line
> r<-murders %>% summarize(rate=sum(total)/sum(population)*10^6) %>%.$rate
> #mamke the plot
> murders %>% ggplot(aes(population/10^6,total,label=abb))+
>   +geom_abline(intercept = log10(r),lty=2,color="darkgrey")+
>   +geom_point(aes(col=region), size=3)+
>   +geom_text_repel()+
>   +scale_x_log10()+
>   +scale_y_log10()+
>   +xlab("Populations in millions (log scale)")+
>   +ylab("Total number of murders (log scale)")+
>   +ggtitle("US Gun Murders in US 2010")+
>   +scale_color_discrete(name="Region")+
>   +theme_economist()
>
> Is this an issue with my dplyr? Or how I can fix this code in order to
> work?
>
> Thanks
> Ana
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] [FORGED] Re: paste workable code to R 4.0.0 cause error

2020-04-28 Thread Richard M. Heiberger
I pasted it into Emacs ESS on Macintosh, Emacs ESS on Windows, and Rgui on
Windows.
All 4.0.0 .  It runs fine.

On Tue, Apr 28, 2020 at 11:36 PM Rolf Turner 
wrote:

>
> The (excellent) MWE that you provided runs just fine for me (in R 4.0.0
> under Ubuntu 18.04) either by sourcing "aaa.R" or by using copy-and-paste.
>
> Must be Windoze thing.  Switch to Linux!
>
> cheers,
>
> Rolf Turner
>
> n 29/04/20 2:25 pm, Jinsong Zhao wrote:
> > On 2020/4/29 8:05, Jinsong Zhao wrote:
> >> Hi there,
> >>
> >> I have a piece of source code with some inline comments in Chinese. It
> >> works well when I copy it from a editor (gvim here), and paste it to
> >> Rgui console on R 3.6.3, however, when I do the same thing, R 4.0.0
> >> give error message:
> >>
> >> Error: invalid multibyte character in parser at line 21
> >>
> >> If I source() the code from Rgui console, it can run without any error.
> >>
> >> Any hints?
> >>
> >> BTW, I do not make a minimal workable example yet.
> >>
> >
> > Here is the MWE:
> >
> > D:\system\Desktop>cat aaa.R
> > gz <- data.frame(x1 = rnorm(100), x10 = rnorm(100))
> > gz <- within(gz,
> >{
> >   a <- x1  #a中中中
> >   b <- x10 #b中中中a
> >   c <- x10 #c
> >   d <- x10 #d中b
> >   e <- x10 #e
> >   f <- x10 #f中c
> >})
> >
> > The ASCII character in the code could be replace by other ASCII
> > character. The Chinese character could be replace by other Chinese
> > character.
> >
> > Calling source("aaa.R") could run normally. If you select all the code
> > and paste it to Rgui console, it will give error:
> >
> >  > gz <- data.frame(x1 = rnorm(100), x10 = rnorm(100))
> >  > gz <- within(gz,
> > +   {
> > +  a <- x1  #a中中中
> > +  b <- x10 #b中中中a
> > +  c <- x10 #c
> > +  d <- x10 #d中b
> > +  e <- x10 #e
> > +  f <- x10 #f中c
> > Error: invalid multibyte character in parser at line 9
> >  >   })
> > Error: unexpected '}' in "  }"
> >  >
> >
> > If you delete any character from the comment, or add any character to
> > the comment. The code can paste to the console without any error.
> >
> > If you change the length of `b`...`f`, the code also could be
> > paste and run without any error.
> >
> > Best,
> > Jinsong
>
>
> --
> 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.
>

[[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] Rtools required

2020-04-28 Thread Richard M. Heiberger
did you change your path to the new location?

On Tue, Apr 28, 2020 at 07:25 Steven  wrote:

> Dear All
>
> I updated to R-4.0.0. and also installed the latest Rtools 4.0 (to now
> the new default folder c:\rtools40). While compiling a package (binary)
> I received the follow marning message saying Rtools is required. Any
> clues? Thanks.
>
> Steven Yen
>
> WARNING: Rtools is required to build R packages but is not currently
> installed. Please download and install the appropriate version of Rtools
> before proceeding: https://cran.rstudio.com/bin/windows/Rtools/
>
>
> [[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] [External Email] Re: arranging multiple lattice graphs on a page

2020-04-02 Thread Richard M. Heiberger
don't forget
library(latticeExtra)

latticeExtra provides many very useful user-level functions.

On Thu, Apr 2, 2020 at 7:52 PM Christopher W. Ryan  wrote:
>
> Thanks, I'll take a look. I also finally came across gridExtra, which allows 
> me to do it as well.
>
> --Chris Ryan
>
> On April 2, 2020 6:45:58 PM EDT, Bert Gunter  wrote:
> >See ?print.trellis, especially the "split" argument.
> >
> >
> >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 Thu, Apr 2, 2020 at 2:23 PM Christopher W. Ryan
> > wrote:
> >>
> >> I would like to place two separate plots, one above the other,
> >something
> >> like this (MWE for illustration):
> >>
> >> library(lattice)
> >> data(iris)
> >> layout(matrix(c(1,2), 2, 1, byrow = TRUE))
> >> with(iris, (plot(Sepal.Length ~ Petal.Length)))
> >> with(iris, (plot(Sepal.Length ~ Petal.Width)))
> >>
> >> but with lattice, so one of the plots can have panels. So something
> >like
> >> this:
> >>
> >> library(lattice)
> >> data(iris)
> >> layout(matrix(c(1,2), 2, 1, byrow = TRUE))
> >> xyplot(Sepal.Length ~ Petal.Length, data = iris)
> >> xyplot(Sepal.Length ~ Petal.Width | Species, data = iris, layout =
> >c(3,1))
> >>
> >> But the latter does not accomplish my goal. Appreciate any advice.
> >>
> >> Thanks.
> >>
> >> --Chris Ryan
> >> SUNY Upstate Medical University
> >> Binghamton, NY
> >>
> >> __
> >> 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 Android device with K-9 Mail. Please excuse my brevity.
> [[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] Not seeing the results of a function

2020-03-30 Thread Richard M. Heiberger
You need one more line In your function.

 addday <- function(stp,mcp,stpos,mcpos){
stpos<-c(stpos,stp)
mcpos<-c(mcpos,mcp)
days<-c(1:length(stpos))
list(mcpos=mcpos, days=days)
}

This and the other question I just answered together say that you need to
re-read an introduction to R.




On Mon, Mar 30, 2020 at 09:45 David  wrote:

> I’m trying to write a function that will add items to two vectors, and
> then to create a third vector that is of the form 1, 2, 3, …, length of
> one of the newly modified vectors.  My problem is that what I’ve written
> doesn’t seem to return any of those modifications.  How can I get the
> new values to be returned? Here’s the function below.  I want to add a
> value, stp, to the end of the stpos vector, a value mcp to the end of
> the mcpos vector, and the to create that days vector.  When I call this
> function with numerical values for stp and mcp, and then ask to see
> stpos, mcpos, and days, nothing has been changed.  How can I fix this?
>
> Here’s the function:
>  > addday <- function(stp,mcp,stpos,mcpos){stpos<-c(stpos,stp)
> + mcpos<-c(mcpos,mcp)
> + days<-c(1:length(stpos))}
>
> 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.
>

[[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] Program to produce multiple plots

2020-03-30 Thread Richard M. Heiberger
you probably forgot the print() statement.
Both lattice and ggplot require a print() in this situation.

See the help files.

On Mon, Mar 30, 2020 at 10:04 Ashim Kapoor  wrote:

> Dear David,
>
> Try this :-
> par(mfrow=c(1,2))
> hist(rnorm(100))
> hist(rnorm(100,100,1))
>
> Best Regards,
> Ashim
>
>
> On Mon, Mar 30, 2020 at 7:16 PM David  wrote:
>
> > I wrote a little program that asked to produce two plots, but when I ran
> > it, I saw only the second plot.  Is there a way to write a program that
> > will produce multiple visible plots?
> >
> > 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.
> >
>
> [[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] How to evaluate impact of factors on parameters

2020-03-18 Thread Richard M. Heiberger
Unfortunately, sending HTML mail scrambled the correct use of dput.
Please use "plain text mode" for all R mailing lists.

I unscrambled it here

df_test <-
structure(list(pc.col = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = c("B", "C"), class = "factor"), pc.filler = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("1", "2", "3"), class = "factor"),
pc.batch = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L
), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor"),
pc.op = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("A",
"B", "C", "D"), class = "factor"), pc.volume = c(16.7533110462178,
18.0143546656987, 15.6448655396281, 18.0281678426422, 13.7831255488576,
16.758396178001, 14.6938147409883, 15.1974804312962, 14.2077591655389,
15.9579675459773, 18.1500426178447, 14.2297691617968, 16.8646535945654,
14.2798441018389, 16.1341256681412, 15.9241734353476, 16.8583005443759,
16.3449003481023, 15.4175473098922, 16.7861703759254, 15.3079007135867,
14.8169564636873, 17.2688507060631, 15.6874484539888), pc.density
= c(1.25341925113923,
1.11243453179479, 1.14110454507519, 1.09177192905336, 1.1465474843639,
1.12333920013556, 1.34554594406146, 1.18442400447752, 1.45756680703941,
1.18602487934004, 1.27641549258776, 1.28052785172529, 1.30119623444795,
1.11228530554194, 1.27060268503477, 1.34131613229472, 1.19909272287678,
1.19954395487512, 1.54100836814473, 1.31241568978863, 1.14210653222791,
1.21694093094929, 1.2603211001675, 1.32986554107345)), row.names = c(NA,
-24L), class = "data.frame")


Your factor structure 2x3x4x6=144 has 144 cells, but there are only 24
data points.
I am plotting both response variables against one factor at a time.

library(lattice)
?xyplot
bwplot(pc.volume + pc.density ~ pc.col + pc.filler + pc.batch + pc.op,
data=df_test, outer=TRUE)
bwplot(pc.volume + pc.density ~ pc.col, data=df_test, outer=TRUE)
bwplot(pc.volume + pc.density ~ pc.filler, data=df_test, outer=TRUE)
bwplot(pc.volume + pc.density ~ pc.batch, data=df_test, outer=TRUE)
bwplot(pc.volume + pc.density ~ pc.op, data=df_test, outer=TRUE)


More information about the experiment is needed before anything else
can be attempted.

Rich

On Wed, Mar 18, 2020 at 10:11 AM lionel sicot via R-help
 wrote:
>
> Hello,
> One of my colleagues sent me a csv file with 12 columns and a lot of rows. 
> Column1 to Column10 are factors with 2 to 6 levels. Column11 and Column12 are 
> experimental results.I'm a bit lost with all these data.
> I would like- to determine which factors have the most impact, and in which 
> way, on Column10 (which has to be as high as possible) while Column 11, at 
> the same time, has to be as low as possible (I hope it is clear for at least 
> one of you ...).- to find a nice way to plot trends as there are several 
> factors.
>
> Below is a small data.frame from the SixSigma package (4 columns of factors 
> and 2 columns of values). I don't know if it can help you to show me how to 
> "play" with my data.If not, a package name or a tutorial can also be hepful.
> Thanks in advance,Ptit Bleu.
> df_test<-read.table(text="pc.col pc.filler pc.batch pc.op pc.volume 
> pc.densityC 1 1 A 16.7533110462178 1.25341925113923C 2 1 B 18.0143546656987 
> 1.11243453179479C 3 1 C 15.6448655396281 1.14110454507519C 1 1 D 
> 18.0281678426422 1.09177192905336C 2 2 A 13.7831255488576 1.1465474843639C 3 
> 2 B 16.758396178001 1.12333920013556C 1 2 C 14.6938147409883 
> 1.34554594406146C 2 2 D 15.1974804312962 1.18442400447752C 3 3 A 
> 14.2077591655389 1.45756680703941C 1 3 B 15.9579675459773 1.18602487934004C 2 
> 3 C 18.1500426178447 1.27641549258776C 3 3 D 14.2297691617968 
> 1.28052785172529B 1 4 A 16.8646535945654 1.30119623444795B 2 4 B 
> 14.2798441018389 1.11228530554194B 3 4 C 16.1341256681412 1.27060268503477B 1 
> 4 D 15.9241734353476 1.34131613229472B 2 5 A 16.8583005443759 
> 1.19909272287678B 3 5 B 16.3449003481023 1.19954395487512B 1 5 C 
> 15.4175473098922 1.54100836814473B 2 5 D 16.7861703759254 1.31241568978863B 3 
> 6 A 15.3079007135867 1.14210653222791B 1 6 B 14.8169564636873 
> 1.21694093094929B 2 6 C 17.2688507
 06
>  0631 1.2603211001675B 3 6 D 15.6874484539888 1.32986554107345", header=T)
>
>
> [[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://s

Re: [R] About the multiprecision computing package in R

2020-03-14 Thread Richard M. Heiberger
Rmpfr product and inner product are not doubling the nominal precision.
Small precision inner products are stored as 53-bit numeric.

library(Rmpfr)

 ## double with precBits=53
(5/17) * (5/17) ## 0.08650519 ## base 10
formatHex( (5/17) * (5/17) ) ##  +0x1.6253443526171p-4

## various precisions
fs5 <- 5*mpfr(1, precBits=5)/17
fs6 <- 5*mpfr(1, precBits=6)/17
fs7 <- 5*mpfr(1, precBits=7)/17
fs8 <- 5*mpfr(1, precBits=8)/17
fs9 <- 5*mpfr(1, precBits=9)/17

## product
formatHex(fs5*fs5) ## +0x1.7p-4

## All these are smaller
formatHex(fs6*fs6)
formatHex(fs7*fs7)
formatHex(fs8*fs8)
formatHex(fs9*fs9)

## and all round DOWN to +0x1.6p-4
formatHex(mpfr(  fs6*fs6 , precBits=5))
formatHex(mpfr(  fs7*fs7 , precBits=5))
formatHex(mpfr(  fs8*fs8 , precBits=5))
formatHex(mpfr(  fs9*fs9 , precBits=5))


## inner product, for low precision, is stored as 53-bit numeric
rounded to 6 bits
formatHex(fs5 %*% fs5) ## +0x1.69000p-4
class(fs5 %*% fs5)
getPrec(fs5 %*% fs5)
formatHex((fs5 %*% fs5)*(fs5 %*% fs5)) ## 12 bits ## +0x1.fd110p-8

## All these are smaller
formatHex(fs6 %*% fs6) ## same
formatHex(fs7 %*% fs7)
formatHex(fs8 %*% fs8)
formatHex(fs9 %*% fs9)

## and all round DOWN to +0x1.6p-4
formatHex(mpfr(  fs6 %*% fs6 , precBits=5)) ## same
formatHex(mpfr(  fs7 %*% fs7 , precBits=5))
formatHex(mpfr(  fs8 %*% fs8 , precBits=5))
formatHex(mpfr(  fs9 %*% fs9 , precBits=5))



## inner product, for high precision, stays at the specified precision
fs65 <- 5*mpfr(1, precBits=65)/17
formatHex(fs65 * fs65)   ## +0x1.62534435261707f8p-4

formatHex(fs65 %*% fs65) ## +0x1.62534435261707f8p-4
class(fs65 %*% fs65)
getPrec(fs65 %*% fs65)

fs130 <- 5*mpfr(1, precBits=130)/17
formatHex(fs130 * fs130)   ## +0x1.62534435261707f8e9dacbbcad9e8f800p-4
formatHex(mpfr( fs130 * fs130 , precBits=65))   ## +0x1.62534435261707f9p-4
## not the same as 65-bit inner product

On Sat, Mar 14, 2020 at 4:51 PM J C Nash  wrote:
>
> The issue is to avoid the storage and operational penalty. 100 x 100 matrix 
> in 100 decimals vs 100 x 100 matrix in 50
> decimals for many operations like copy, scale, etc. But accumulation of inner 
> products, you want to avoid digit loss,
> e.g., A and B are long vectors -- say 10 long, with a few "large" 
> elements but most smaller. However 99000 "small"
> numbers could add up and ...
>
> As with many such issues, it doesn't affect the vast majority of occurrences. 
> Indeed few of my own. IEEE arithmetic
> usually does the job (I was one of the members of the original committee). 
> This particular
> concern arose when trying to tease out a signal from a great deal of noise 
> from a spacecraft sensor.
>
> JN
>
>
> On 2020-03-14 4:28 p.m., Jeff Newmiller wrote:
> > Not sure I understand the concern. IEEE 754 double precision floating point 
> > was invented to allow for avoiding loss of precision when manipulating 
> > single precision floating point numbers... but then C just ignores single 
> > precision and you are expected to know that the precision of your answers 
> > may only be relied on at single precision for certain operations.
> >
> > Wouldn't you just set Rmpfr precision to double your actual desired 
> > precision and move on? Though I suppose you might consider  more than 
> > doubling the desired precision to deal with exponentiation [1].
> >
> > [1] https://en.m.wikipedia.org/wiki/Extended_precision#Working_range
> >
> > On March 14, 2020 1:10:19 PM PDT, J C Nash  wrote:
> >> Rmpfr does "support" matrix algebra, but I have been trying for some
> >> time to determine if it computes "double" precision (i.e., double the
> >> set level of precision) inner products. I suspect that it does NOT,
> >> which is unfortunate. However, I would be happy to be wrong about
> >> this.
> >>
> >> JN
> >>
> >> On 2020-03-14 3:41 p.m., Bert Gunter wrote:
> >>> Read its documentation yourself and unless you have good reason not
> >> to,
> >>> always cc the list (which I have done here).
> >>>
> >>>
> >>> 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 Sat, Mar 14, 2020 at 12:28 PM 林伟璐 <13917987...@163.com> wrote:
> >>>
>  Thanks. Does it support matrix algebra?
> 
> 
> 
>  林伟璐
>  邮箱:13917987...@163.com
> 
> 
> >> 
> 
>  签名由 网易邮箱大师  定制
> 
>  On 03/15/2020 03:18, Bert Gunter  wrote:
>  Use google instead, as I recommended. If that's impossible in China,
> >> you
>  should state that and what you tried (Baidu) in your query.
> 
>  You'

Re: [R] Increasing space for main title in a lattice (xyplot()) graphics.

2020-02-12 Thread Richard M. Heiberger
It works as anticipated for me

> xyplot(1 ~ 1,
+ main="The quick brown fox jumped\n over the lazy dog.")
> xyplot(1 ~ 1,
+ main="The quick brown fox jumped over the lazy dog.")

Something else you are doing is probably causing the difficulty.

Rich

On Wed, Feb 12, 2020 at 11:59 PM Rolf Turner  wrote:
>
>
> I'm trying to do an xyplot() with a longish main title that I'd like to
> split into two lines, something like
>
>  xyplot(,
> main="The quick brown fox jumped\n over the lazy dog.")
>
> When I do this I only get the last half, i.e. the "over the lazy dog."
> bit, and the first half doesn't appear.
>
> In base graphics I'd handle this sort of thing by increasing the third
> entry of the "mar" parameter.
>
> How can increase the space allocated for the title in lattice graphics?
> I've done a substantial amount of Googling and can't find anything
> helpful.  I've fiddled about with trellis.par.set() and cannot seem to
> get any effect.
>
> Could someone please give my poor feeble brain some guidance?  Ta.
>
> cheers,
>
> Rolf Turner
>
> --
> 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] Converting binary number to in Two´s complement representation

2020-01-25 Thread Richard M. Heiberger
no,

## I don't see any system in AISMessageFrame
tail(AISMessageFrame)
##  MessgeCode
## 95  85E:BR0F0P00032jS2P00DE7P3A00h0
## 96 1349B:3000rCtrn553aR@JHD2d4O
## 97   7933.883509997
## 98 B;s@N9h00>TtPFQAsm803wU5wP06
## 99 15B3SjrC9RD5=mOh40jB20SU
## 10015TgVbrCgVb57oFc;ARF2@67

at a minimum, collect this as character values, not factors.

On Sat, Jan 25, 2020 at 4:14 PM Paul Bernal  wrote:
>
> Dear friend Richard,
>
> Were you able to obtain the latitude and longitude values with that script?
>
> Thank you so much brother,
>
> Paul
>
> El sáb., 25 de enero de 2020 4:03 p. m., Richard M. Heiberger 
>  escribió:
>>
>> ## from2Comp uses base R functions only
>> from2Comp <- function(x, binDigits=8) {
>>   ## binDigits=8 means 8 significant digits plus a sign bit, thus nchar(x) 
>> == 9
>>   tmp <- strtoi(x, base=2)
>>   Neg <- (tmp > (2^binDigits - 1))
>>   tmp[Neg] <- tmp[Neg] - (2^(binDigits + 1))
>>   tmp
>> }
>>
>> from2Comp(substr(as.character(LatitudeFrame[,2]), 24, 31), 7)
>>
>> from2Comp(substr(as.character(LatitudeFrame[,2]), 23, 31), 8)
>> from2Comp(substr(as.character(LongitudeFrame[,2]), 23, 31), 8)
>>
>> from2Comp(as.character(LatitudeFrame[,2]), 30)
>> from2Comp(as.character(LongitudeFrame[,2]), 30)
>>
>>
>> ## I don't see any system in AISMessageFrame
>> tail(AISMessageFrame)
>> ##  MessgeCode
>> ## 95  85E:BR0F0P00032jS2P00DE7P3A00h0
>> ## 96 1349B:3000rCtrn553aR@JHD2d4O
>> ## 97   7933.883509997
>> ## 98 B;s@N9h00>TtPFQAsm803wU5wP06
>> ## 99 15B3SjrC9RD5=mOh40jB20SU
>> ## 10015TgVb0000rCgVb57oFc;ARF2@67
>>
>>
>> ## 180Long = -180Long, thus there is duplication.  How do you handle this?
>> ## 90Lat  != -90Lat, so there is no duplication.
>> ## How are minutes and seconds stored?
>>
>> On Fri, Jan 24, 2020 at 5:39 PM Richard M. Heiberger  wrote:
>> >
>> > I don't have my computer with me, so I am commenting right now on the 
>> > visual impression of the email.
>> >
>> > The latitude shows 90, 88, ... 2, 89, ...
>> > The labels are lexicographically ordered
>> > -1, -10, -11,...
>> >
>> > The latitude binrep look in correct order, and the labels looks like 
>> > binary in order.
>> >
>> > These things are identified as factors, not as character.
>> >
>> > Please ensure that character values are not misinterpreted as factor when 
>> > you construct your data frames.
>> >
>> > The four columns do not look to be in consistent order with each other. 
>> > This in itself could cause trouble.
>> >
>> > I will look more when I have my computer running R so I can follow the 
>> > rest of what you wrote.
>> >
>> > Rich
>> >
>> > On Fri, Jan 24, 2020 at 15:02 Paul Bernal  wrote:
>> >>
>> >> Dear friend Richard,
>> >>
>> >> Thank you for your interest in helping me through this challenge. As 
>> >> requested, I am providing the two lat and long frames you suggested, plus 
>> >> the one single column I am trying to decode:
>> >>
>> >> LatitudeFrame:
>> >>
>> >> > dput(LatitudeFrame)
>> >> structure(list(Latitude = structure(c(90L, 88L, 87L, 86L, 85L,
>> >> 84L, 83L, 82L, 81L, 80L, 79L, 77L, 76L, 75L, 74L, 73L, 72L, 71L,
>> >> 70L, 69L, 68L, 66L, 65L, 64L, 63L, 62L, 61L, 60L, 59L, 58L, 57L,
>> >> 55L, 54L, 53L, 52L, 51L, 50L, 49L, 48L, 47L, 46L, 44L, 43L, 42L,
>> >> 41L, 40L, 39L, 38L, 37L, 36L, 35L, 33L, 32L, 31L, 30L, 29L, 28L,
>> >> 27L, 26L, 25L, 24L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L,
>> >> 13L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 89L, 78L, 67L,
>> >> 56L, 45L, 34L, 23L, 12L, 1L, 91L, 92L, 103L, 114L, 125L, 136L,
>> >> 147L, 158L, 169L, 180L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
>> >> 101L, 102L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
>> >> 113L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
>> >> 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 137L,
>> >> 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 148L, 149L,
>> >> 150L, 151L, 152L, 153L, 154L, 155L

Re: [R] Converting binary number to in Two´s complement representation

2020-01-25 Thread Richard M. Heiberger
## from2Comp uses base R functions only
from2Comp <- function(x, binDigits=8) {
  ## binDigits=8 means 8 significant digits plus a sign bit, thus nchar(x) == 9
  tmp <- strtoi(x, base=2)
  Neg <- (tmp > (2^binDigits - 1))
  tmp[Neg] <- tmp[Neg] - (2^(binDigits + 1))
  tmp
}

from2Comp(substr(as.character(LatitudeFrame[,2]), 24, 31), 7)

from2Comp(substr(as.character(LatitudeFrame[,2]), 23, 31), 8)
from2Comp(substr(as.character(LongitudeFrame[,2]), 23, 31), 8)

from2Comp(as.character(LatitudeFrame[,2]), 30)
from2Comp(as.character(LongitudeFrame[,2]), 30)


## I don't see any system in AISMessageFrame
tail(AISMessageFrame)
##  MessgeCode
## 95  85E:BR0F0P00032jS2P00DE7P3A00h0
## 96 1349B:3000rCtrn553aR@JHD2d4O
## 97   7933.883509997
## 98 B;s@N9h00>TtPFQAsm803wU5wP06
## 99 15B3SjrC9RD5=mOh40jB20SU
## 10015TgVbrCgVb57oFc;ARF2@67


## 180Long = -180Long, thus there is duplication.  How do you handle this?
## 90Lat  != -90Lat, so there is no duplication.
## How are minutes and seconds stored?

On Fri, Jan 24, 2020 at 5:39 PM Richard M. Heiberger  wrote:
>
> I don't have my computer with me, so I am commenting right now on the visual 
> impression of the email.
>
> The latitude shows 90, 88, ... 2, 89, ...
> The labels are lexicographically ordered
> -1, -10, -11,...
>
> The latitude binrep look in correct order, and the labels looks like binary 
> in order.
>
> These things are identified as factors, not as character.
>
> Please ensure that character values are not misinterpreted as factor when you 
> construct your data frames.
>
> The four columns do not look to be in consistent order with each other. This 
> in itself could cause trouble.
>
> I will look more when I have my computer running R so I can follow the rest 
> of what you wrote.
>
> Rich
>
> On Fri, Jan 24, 2020 at 15:02 Paul Bernal  wrote:
>>
>> Dear friend Richard,
>>
>> Thank you for your interest in helping me through this challenge. As 
>> requested, I am providing the two lat and long frames you suggested, plus 
>> the one single column I am trying to decode:
>>
>> LatitudeFrame:
>>
>> > dput(LatitudeFrame)
>> structure(list(Latitude = structure(c(90L, 88L, 87L, 86L, 85L,
>> 84L, 83L, 82L, 81L, 80L, 79L, 77L, 76L, 75L, 74L, 73L, 72L, 71L,
>> 70L, 69L, 68L, 66L, 65L, 64L, 63L, 62L, 61L, 60L, 59L, 58L, 57L,
>> 55L, 54L, 53L, 52L, 51L, 50L, 49L, 48L, 47L, 46L, 44L, 43L, 42L,
>> 41L, 40L, 39L, 38L, 37L, 36L, 35L, 33L, 32L, 31L, 30L, 29L, 28L,
>> 27L, 26L, 25L, 24L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L,
>> 13L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 89L, 78L, 67L,
>> 56L, 45L, 34L, 23L, 12L, 1L, 91L, 92L, 103L, 114L, 125L, 136L,
>> 147L, 158L, 169L, 180L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
>> 101L, 102L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
>> 113L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
>> 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 137L,
>> 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 148L, 149L,
>> 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 159L, 160L, 161L,
>> 162L, 163L, 164L, 165L, 166L, 167L, 168L, 170L, 171L, 172L, 173L,
>> 174L, 175L, 176L, 177L, 178L, 179L, 181L), .Label = c("-1", "-10",
>> "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19",
>> "-2", "-20", "-21", "-22", "-23", "-24", "-25", "-26", "-27",
>> "-28", "-29", "-3", "-30", "-31", "-32", "-33", "-34", "-35",
>> "-36", "-37", "-38", "-39", "-4", "-40", "-41", "-42", "-43",
>> "-44", "-45", "-46", "-47", "-48", "-49", "-5", "-50", "-51",
>> "-52", "-53", "-54", "-55", "-56", "-57", "-58", "-59", "-6",
>> "-60", "-61", "-62", "-63", "-64", "-65", "-66", "-67", "-68",
>> "-69", "-7", "-70", "-71", "-72", "-73", "-74", "-75", "-76",
>> "-77", "-78", "-79", "-8", &

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Richard M. Heiberger
101010101",
> "11101010110", "11101010111",
> "11101011000", "11101011001",
> "11101011010", "11101011011",
> "11101011100", "11101011101",
> "1110100", "1110101",
> "1110110", "1110111",
> "11101100010", "11101100011",
> "11101100100", "11101100101",
> "11101100110", "11101100111",
> "11101101000", "11101101001",
> "11101101010", "11101101011",
> "11101101100", "11101101101",
> "11101101110", "1110110",
> "1110111", "11101110001",
> "11101110010", "11101110011",
> "11101110100", "11101110101",
> "11101110110", "11101110111",
> "1110000", "1110001",
> "1110010", "1110011",
> "1110100", "1110101",
> "1110110", "1110111",
> "000", "001",
> "010", "011",
> "111111111111100", "101",
> "110", "111",
> "0001000", "0001001",
> "0001010", "0001011",
> "0001100", "0001101",
> "0001110", "000",
> "001", "0010001",
> "0010010", "0010011",
> "0010100", "0010101",
> "0010110", "0010111",
> "0011000", "0011001",
> "0011010", "0011011",
> "0011100", "0011101",
> "000", "001",
> "010", "011",
> "0100010", "0100011",
> "0100100", "0100101",
> "0100110", "11110100111",
> "0101000", "0101001",
> "0101010", "0101011",
> "0101100", "0101101",
> "0101110", "010",
> "011", "0110001",
> "0110010", "0110011",
> "0110100", "0110101",
> "0110110", "0110111",
> "0111000", "0111001",
> "0111010", "0111011",
> "000", "001",
> "010"

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Richard M. Heiberger
now I am even more puzzled.

please complete the following two data.frames and send it to the list.

latDegrees lat2Comp
-90 
-89 
...
-1 
0 
1 
...
89 
90 

lonDegrees lon2Comp
-180 
-179 
...
-91 
-90 
-89 
...
-1 
0 
1 
...
89 
90 
91 
...
179 
180 

Your 8 bit 2C example has 7 digits of precision plus sign which gives
a range of (-127,127).  That suffices for latitude (-90,90).
For longitude you will need 9 bits of twos complement for 8 bits of
precision plus sign to cover (-255,255), thus more than enough for
(-180,180).
This assumes that precision to the degree is sufficient.  If you need
precision to minutes and seconds, or to meters, then you
will need even more bits in 2C.

Since it looks like you need a different number of bits for each
variable, I am asking for two data.frames.

Rich

On Fri, Jan 24, 2020 at 1:46 PM Paul Bernal  wrote:
>
> Hi Richard,
>
> That was just an example, to show that, for that particular string of binary 
> numbers, the code works as expected. That is absolutely no related to the 
> dataset I provided. If I try the function on the dataset, I get values well 
> over the latitude and longitude boundaries (which should range from -90 to + 
> 90, and -180 to +180).
>
> Regards,
>
> Paul
>
> El vie., 24 ene. 2020 a las 12:23, Richard M. Heiberger () 
> escribió:
>>
>> You show the example
>>
>> > fun("10110010")
>> [1] -78
>>
>> as satisfactory.  Where in your posted data set do you find the input
>> string "10110010"?
>>
>> Please post a set of relevant input strings, and the answers you want from 
>> them.
>> The rest of the columns are not helpful for this specific exercise.
>>
>> On Fri, Jan 24, 2020 at 11:34 AM Paul Bernal  wrote:
>> >
>> > Dear friend Rui,
>> >
>> > Hope you are doing great. Firstly, I want to thank you for your super
>> > valuable and kind support of always. As I mentioned in earlier e-mails, I
>> > am trying to decode AIS type messages, and the only ones I am having a real
>> > hard time with, is with latitude and longitude.
>> >
>> > I tried the function you provided me in one of your replies, and it works
>> > well with the examples  you provided, but in other cases it doesn´t.
>> >
>> > The messages I am trying to decode are in the 6th column of the data. I
>> > will provide you with a small sample first, and then the complete dataset
>> > (which has 100 rows). This is the small sample:
>> >
>> > > head(dat)
>> > ...1 ...2 ...3 ...4 ...5 ...6 ...7   ...8
>> > ...9 ...10 ...11 ...12 ...13
>> > 1 !AIVDM11   NAA 15?f5H?P00rCQat5:Oah0?wn2@S6 0*54 1485907200
>> > NANANA  
>> > 2 !AIVDM11   NAA 1349B:3000rCtrn553aR@JH02PRp 0*39 1485907200
>> > NANANA  
>> > 3 !AIVDM11   NAA  D03Iuph1TNfp4dv9J<`N000 2*0D 1485907200
>> > NANANA  
>> > 4 !AIVDM11   NAA  D03Iu6QGLN01MdN01StN000 2*43 1485907200
>> > NANANA  
>> > 5 !AIVDO11   NA  B;s@N9h00>TtPEQAslh03wuUwP06 0*29 1485907200
>> > NANANA  
>> > 6 !AIVDM11   NAA 15A@av3P00rClHn53> > NANANA  
>> >
>> > It is worth mentioning that each row of the 6th column provides several
>> > information about maritime vessels, like speed over ground, latitude,
>> > longitude, vessel ID, etc. I am only concerned with latitude and longitude
>> > since those are the only two fields I have not been able to decode
>> > successfully. Also, I am working on R version 3.6.2 for windows 64-bit OS.
>> >
>> > The messages to decode are of the following format:
>> > 15?f5H?P00rCQat5:Oah0?wn2@S6,  1349B:3000rCtrn553aR@JH02PRp, etc.
>> >
>> > Now, here is the complete dataset:
>> >
>> > > dput(dat)
>> > structure(list(...1 = c("!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>> > "!AIVDO", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM", "!AIVDM",
>> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Richard M. Heiberger
You show the example

> fun("10110010")
[1] -78

as satisfactory.  Where in your posted data set do you find the input
string "10110010"?

Please post a set of relevant input strings, and the answers you want from them.
The rest of the columns are not helpful for this specific exercise.

On Fri, Jan 24, 2020 at 11:34 AM Paul Bernal  wrote:
>
> Dear friend Rui,
>
> Hope you are doing great. Firstly, I want to thank you for your super
> valuable and kind support of always. As I mentioned in earlier e-mails, I
> am trying to decode AIS type messages, and the only ones I am having a real
> hard time with, is with latitude and longitude.
>
> I tried the function you provided me in one of your replies, and it works
> well with the examples  you provided, but in other cases it doesn´t.
>
> The messages I am trying to decode are in the 6th column of the data. I
> will provide you with a small sample first, and then the complete dataset
> (which has 100 rows). This is the small sample:
>
> > head(dat)
> ...1 ...2 ...3 ...4 ...5 ...6 ...7   ...8
> ...9 ...10 ...11 ...12 ...13
> 1 !AIVDM11   NAA 15?f5H?P00rCQat5:Oah0?wn2@S6 0*54 1485907200
> NANANA  
> 2 !AIVDM11   NAA 1349B:3000rCtrn553aR@JH02PRp 0*39 1485907200
> NANANA  
> 3 !AIVDM11   NAA  D03Iuph1TNfp4dv9J<`N000 2*0D 1485907200
> NANANA  
> 4 !AIVDM11   NAA  D03Iu6QGLN01MdN01StN000 2*43 1485907200
> NANANA  
> 5 !AIVDO11   NA  B;s@N9h00>TtPEQAslh03wuUwP06 0*29 1485907200
> NANANA  
> 6 !AIVDM11   NAA 15A@av3P00rClHn53 NANANA  
>
> It is worth mentioning that each row of the 6th column provides several
> information about maritime vessels, like speed over ground, latitude,
> longitude, vessel ID, etc. I am only concerned with latitude and longitude
> since those are the only two fields I have not been able to decode
> successfully. Also, I am working on R version 3.6.2 for windows 64-bit OS.
>
> The messages to decode are of the following format:
> 15?f5H?P00rCQat5:Oah0?wn2@S6,  1349B:3000rCtrn553aR@JH02PRp, etc.
>
> Now, here is the complete dataset:
>
> > dput(dat)
> structure(list(...1 = c("!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDO", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDO", "!AIVDM", "$GPRMC", "!AIVDM", "!AIVDM", "!AIVDM", "$GPGBS",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDM", "!AIVDO", "$GPRMC", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDM", "$GPGBS", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM",
> "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
> "!AIVDM", "$GPRMC", "!AIVDO", "!AIVDM", "!AIVDM"), ...2 = c(1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 50002, 1, 2, 2, 50002, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
> 1, 50006, 1, 1, 1, 1, 1, 50006, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 50010, 1,
> 1, 1), ...3 = c("1", "1", "1", "1", "1", "1", "1", "1", "1",
> "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
> "1", "1", "1", "1", "1", "A", "1", "1", "2", "1.3", "1", "1",
> "1", "1", "1", "1", "1", "1", "1", "1", "2", "1", "1", "1", "1",
> "1", "1", "1", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1",
> "2", "1", "A", "1", "1", "1", "1", "1", "1.3999",
> "1", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
> "1", "1", "2", "1", "1", "1", "1", "2", "1", "1", "1", "1", "1",
> "1", "A", "1", "1", "1"), ...4 = c(NA, NA, NA, NA, NA, NA, NA,
> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> NA, NA, NA, NA, 856.96783, NA, 7, 7, 1.5, NA, NA, NA, NA, NA,
> NA, NA, NA, NA, 8, 8, NA, NA, NA, NA, NA, NA, 9, 9, NA, NA, NA,
> NA, NA, NA, NA, NA, 0, 0, NA, 856.96805, NA, NA, NA, NA, NA,
> 1.5, 1, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2,
> 2, NA, NA, NA, 3, 3, NA, NA, NA, NA, NA, NA, 856.96827, NA, NA,
> NA), ...5 = c("A", "A", "A", "A", NA, "A", "A", "B", "B", "A",
> "A", "A", "A", "B", "B", NA, "B", "A", "B", "A", "B", "B", "A",
> "B", "A", NA, "B", "N", "B", "A", "A", "3.2002",
> "B", "A", "A", NA, "A", "A", "A", "A", "B", "A", "A", NA, "B",
> "A", "A", "A", "A", "A", "A", NA, "A", "A", "A", "B", "B", "B",
> "B", "A", "A", NA, "N", "A", "A", "B", "B", "B", "3.2998",
> "B", 

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Richard M. Heiberger
Use the Rmpfr  package.
it will print numbers in any base from 2  to 62
> library(Rmpfr)
> ?Rmpfr
> b15 <- mpfr(15, precBits=6)
> formatBin(b15)
[1] +0b1.11100p+3
>

On Fri, Dec 27, 2019 at 10:43 AM Paul Bernal  wrote:
>
> Dear friends,
>
> Hope you are all doing well. I need to find a way to convert ascii numbers
> to six digit binary numbers:
>
> I am working with this example, I converted the string to ascii, and
> finally to decimal, but I am having trouble converting the decimal numbers
> into their six digit binary representation. The code below is exactly what
> I have so far:
>
> ascii_datformat <- utf8ToInt("133m@ogP00PD;88MD5MTDww@2D7k")
> ascii_datformat
>
> Base <- ascii_datformat - 48
>
> ifelse(Base > 40, Base-8, Base)
>
> x <- rev(intToBits(Base))
> dec2bin <- function(x) paste(as.integer(rev(intToBits(x))), collapse = "")
> dec2bin
>
> any guidance will be greatly appreciated,
>
> Best regards,
>
> Paul
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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 CMD Batch on Windows and use of the ampersand

2019-12-25 Thread Richard M. Heiberger
Hi Erin.

I think the easiest way is to use sh, which is included as part of Rtools.

>From the CMD command line, enter
c:/Rtools/bin/sh -i

You are now running a Unix shell, and all the behaviors you expect are
there, including ";" and "&"

Rich

On Wed, Dec 25, 2019 at 12:16 PM Erin Hodgess  wrote:
>
> Hello!  Merry Christmas to those of you celebrating it, and happy
> holidays to those celebrating other holidays.
>
> Here is a question about R CMD BATCH on Windows.  We know that
>
> R CMD BATCH infile outfile &
>
> On Linux or Mac will let you continue interactively from the command line.
> However, it does not work with the interactive component from Windows.  Is
> there a workaround for this, please?
> Thanks,
> 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] Errors in R package installation

2019-12-12 Thread Richard M. Heiberger
Directory and file names with embedded blanks frequently don't work on
WIndows.  Use the 8.3 version of the name.
Since you were able to get the package onto your machine, you can
install it from there.

The downloaded source packages are in
‘C:\Users\David
Stevens\AppData\Local\Temp\Rtmpk5NqrI\downloaded_packages’

In the windows shell

cd c:\Users
dir /x David*

It will tell you something like
DavidS~1

Then in R you can write

install.packages("c:/Users/DavidS~1/AppData/Local/Temp/Rtmpk5NqrI/downloaded_packages/callr_3.4-0.tar.gz")

Make sure you use the correct full name of the downloaded source package.

Rich

On Thu, Dec 12, 2019 at 12:03 PM David Stevens  wrote:
>
> Thanks Eric - I'll follow up with this link. I'd tried some of these
> things before but I'll keep after it.
>
> Best
>
> David
>
> On 12/12/2019 9:52 AM, Eric Berger wrote:
> > Actually there was progress as after it failed it removed the folder
> > c:/myRlib/callr, which means it had used it. Seems good.
> > I think you might find the discussion here to be relevant
> >
> > https://community.rstudio.com/t/cant-install-package-remotes-when-trying-to-install-devtools/34121
> >
> > Good luck,
> > Eric
> >
> > On Thu, Dec 12, 2019 at 6:08 PM David Stevens  wrote:
> >> Thanks Eric - I had tried this and failed with
> >>
> >> install.packages('callr',destdir='c:/myRLib')
> >> Installing package into ‘C:/myRLib’
> >> (as ‘lib’ is unspecified)
> >>
> >>There is a binary version available but the source version is
> >>later:
> >>binary source needs_compilation
> >> callr  3.3.2  3.4.0 FALSE
> >>
> >> installing the source package ‘callr’
> >>
> >> trying URL 'https://cloud.r-project.org/src/contrib/callr_3.4.0.tar.gz'
> >> Content type 'application/x-gzip' length 100129 bytes (97 KB)
> >> downloaded 97 KB
> >>
> >> * installing *source* package 'callr' ...
> >> ** package 'callr' successfully unpacked and MD5 sums checked
> >> ** using staged installation
> >> ** R
> >> ** inst
> >> ** byte-compile and prepare package for lazy loading
> >> Fatal error: cannot open file 'C:\Users\David': No such file or directory
> >>
> >> ERROR: lazy loading failed for package 'callr'
> >> * removing 'C:/myRLib/callr'
> >> Warning in install.packages :
> >>installation of package ‘callr’ had non-zero exit status
> >>
> >> I also tried
> >>
> >> install.packages('callr',lib='c:/myRLib',destdir='c:/myRLib')
> >>
> >> with the same result. There's something more here that I'm unable to 
> >> discover.
> >>
> >> Best
> >> David
> >> On 12/12/2019 8:56 AM, Eric Berger wrote:
> >>
> >> Apparently it does not like that the fact that your user 'David
> >> Stevens' has a blank.
> >> Looking at the documentation ?install.packages
> >> it seems that if you modify your call to something like
> >>
> >> install.packages('callr',destdir='C:\tmp')
> >>
> >> you might be ok. (caveat: I did not try this)
> >>
> >> You should make the directory C:\tmp (or whatever you use instead)
> >> before you issue this call.
> >>
> >> HTH,
> >> Eric
> >>
> >> On Thu, Dec 12, 2019 at 5:48 PM David Stevens 
> >>  wrote:
> >>
> >>
> >> Certain R packages will not install properly on my Windows 10 computer. 
> >> For example, if I
> >>
> >> install.packages('callr')
> >>
> >> The result is
> >>
> >> trying URL 'https://cloud.r-project.org/src/contrib/callr_3.4.0.tar.gz'
> >> Content type 'application/x-gzip' length 100129 bytes (97 KB)
> >> downloaded 97 KB
> >>
> >> Warning: invalid package 'C:\Users\David'
> >> Warning: invalid package 
> >> 'Stevens\AppData\Local\Temp\Rtmpk5NqrI/downloaded_packages/callr_3.4.0.tar.gz'
> >> Error: ERROR: no packages specified
> >> Warning in install.packages :
> >>installation of package ‘callr’ had non-zero exit status
> >>
> >> The downloaded source packages are in
> >>  ‘C:\Users\David 
> >> Stevens\AppData\Local\Temp\Rtmpk5NqrI\downloaded_packages’
> >>
> >> both using RStudio 1.2.5019 and the Rgui.exe 3.6.2. I look in the download 
> >> folder and the callr_3.4.0.tar.gz is there but the installer can't find 
> >> it. This happens on only a subset of packages I install or update. I 
> >> assume the cause is the space in my name in the c:\users folder. I've been 
> >> unable to locate the environment variable or registry value that routes 
> >> the tar.gz files to this location. Any ideas on how to fix this? This is a 
> >> relatively recent issue (i.e. I never saw it before November - I've used R 
> >> for ~15 years).
> >>
> >> Best regards
> >>
> >> David Stevens
> >>
> >>
> >>
> >>  [[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, 

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

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

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

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


Re: [R] Order axis by number of entries in lattice plot

2019-11-04 Thread Richard M. Heiberger
## The likert function would work well for this example.
## Continuing from your example

## install.packages("HH") ## if necessary
library(HH)

likert(Family ~ Normal+Tumour+Metastasis, data = df,
   main = "likert, data-order, ReferenceZero=0\nDuplicates your example",
   ReferenceZero=0,
   as.table=FALSE,
   xlab = expression(bold("Number of species")),
   ylab = expression(bold("Families")),
   auto.key = list(space = "top", columns=3),
   col = COLS)

likert(Family ~ Normal+Tumour+Metastasis, data = df,
   main = "likert, positive.order=TRUE, ReferenceZero=0\nThis is
what you asked for",
   positive.order=TRUE,
   ReferenceZero=0,
   xlab = expression(bold("Number of species")),
   ylab = expression(bold("Families")),
   auto.key = list(space = "top", columns=3),
   col = COLS)

likert(Family ~ Normal+Tumour+Metastasis, data = df,
   main = "likert, positive.order=TRUE, ReferenceZero=1.5\nThis
puts Normal on left and not-Normal on right",
   positive.order=TRUE,
   ReferenceZero=1.5,
   xlab = expression(bold("Number of species")),
   ylab = expression(bold("Families")),
   auto.key = list(space = "top", columns=3),
   col = COLS)

## For information on the likert function
?likert

## For more examples
demo("likert-paper", package="HH")

## for the paper, open
http://www.jstatsoft.org/v57/i05/
## and click on
##   Download PDF

On Mon, Nov 4, 2019 at 8:32 AM Luigi Marongiu  wrote:
>
> Dear all,
> I am plotting some values with lattice barchart: the y-axis is
> automatically ordered alphabetically; is it possible to order the
> entries by number, so that the 'larger' histograms would be at the top
> of the plot?
> This is a working example
>
> ```
> library(lattice)
> Family = c("Adenoviridae", "Baculoviridae",  "Herpesviridae",   "Mimiviridae",
> "Myoviridae", "Pandoraviridae",  "Phycodnaviridae", "Podoviridae",
> "Polydnaviridae",  "Retroviridae", "Siphoviridae","Unassigned")
> Normal = c(7, 15, 24,  8, 65, 24, 17, 16,  8, 15, 49 , 9)
> Tumour =c(  17,  75,  94,  14, 242,  28,  41,  69,  12,  11, 305,  51)
> Metastasis =c(41,  66,  95,   3, 173,  22,  33, 101,  12,  12, 552,  57)
> df = data.frame(Family, Normal, Tumour, Metastasis, stringsAsFactors = FALSE)
> COLS = c("darkolivegreen3", "brown3", "darkorchid3")
> barchart(Family ~ Normal+Tumour+Metastasis, data = df, stack = TRUE,
>  xlim=c(1,1000),
>  main = "Alphabetical order",
>  xlab = expression(bold("Number of species")),
>  ylab = expression(bold("Families")),
>  auto.key = list(space = "top", columns=3),
>  par.settings = list(superpose.polygon = list(col = COLS)))
> ```
>
>
> --
> 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.


Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-19 Thread Richard M. Heiberger
Look at
methods(as.data.frame)
Define your specialized columns to have a newly defined class, say "myclass".
Then write as.data.frame.myclass
It will be similar to the function you already have in the lapply statement.
Now your statement
X <- X[ok,]
should work.

Rich

On Sat, Oct 19, 2019 at 8:20 PM Rolf Turner  wrote:
>
>
> I am writing a function that involves a data frame "X" some columns of
> which have attributes.  I replace X by a data frame with a subset of the
> rows of X:
>
>  X <- X[ok,]
>
> where "ok" is a logical vector.  When I do this the attributes of the
> columns (which I need to retain) are lost (except for the "class" and
> "levels" attributes of columns which are factors).
>
> Is there any sexy way to retain the attributes of the columns?
>
> So far the only approach that I can work out is to extract the
> attributes prior to subsetting and put them back after subsetting.
>
> Like unto:
>
>  SaveAt <- lapply(X,attributes)
>  X <- X[ok,]
>  lX <- lapply(names(X),function(nm,x,Sat){
> attributes(x[[nm]]) <- Sat[[nm]]
> x[[nm]]},x=X,Sat=SaveAt)
>  names(lX) <- names(X)
>  X <- as.data.frame(lX)
>
> This seems to work, but is rather kludgy.  Is there a better way?
>
> Thanks for any pointers.
>
> cheers,
>
> Rolf Turner
>
> --
> 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] "chi-square" | "chi-squared" | "chi squared" | "chi square" ?

2019-10-18 Thread Richard M. Heiberger
What a delightful question.  Bill Cochran discussed this in class
one day about 50 years ago.  He said the British usage (which I think
he said was chi-squared,
as is consistent with the other memories in this thread)
is what he learned and previously used.  But he had been in the US for
so long that he was now using
the American preference (chi-square).

Rich

On Fri, Oct 18, 2019 at 8:51 AM Martin Maechler
 wrote:
>
> As it's Friday ..
>
> and I also really want to clean up help files and similar R documents,
> both in R's own sources and in my new 'DPQ' CRAN package :
>
> As a trained mathematician, I'm uneasy if a thing has
> several easily confusable names, .. but as somewhat
> humanistically educated person, I know that natural languages,
> English in this case, are much more flexible than computer
> languages or math...
>
> Anyway, back to the question(s) .. which I had asked myself a
> couple of months ago, and already remained slightly undecided:
>
> The 0-th (meta-)question of course is
>
>   0. Is it worth using only one written form for the
>  χ² - distribution, e.g. "everywhere" in R?
>
> The answer is not obvious, as already the first few words of the
> (English) Wikipedia clearly convey:
>
> The URL is  https://en.wikipedia.org/wiki/Chi-squared_distribution
> and the main title therefore also
> "Chi-squared distribution"
>
> Then it reads
>
> > This article is about the mathematics of the chi-squared
> > distribution. For its uses in statistics, see chi-squared
> > test. For the music [...]
>
> > In probability theory and statistics, the chi-square
> > distribution (also chi-squared or χ2-distribution) with k
> > degrees of freedom is the distribution of a sum of the squares
> > of k independent standard normal random variables.
>
> > The chi-square distribution is a special case of the gamma
> > distribution and is one of the most widely used probability
> > distributions in inferential statistics, notably in hypothesis
> > testing []
> > []
>
> So, in title and 1st paragraph its "chi-squared", but then
> everywhere(?) the text used "chi-square".
>
> Undoubtedly, Wilson & Hilferty (1931) has been an important
> paper and they use "Chi-square" in the title;
> also  Johnson, Kotz & Balakrishnan (1995)
> see R's help page ?pchisq use  "Chi-square" in the title of
> chapter 18 and then, diplomatically for chapter 29,
>  "Noncentral χ²-Distributions" as title.
>
> So it seems, that historically and using prestigious sources,
> "chi-square" to dominate (notably if we do not count "χ²" as an
> alternative).
>
> Things look a bit different when I study R's sources; on one
> hand, I find all 4 forms (s.Subject); then in the "R source
> history", I see
>
>   $ svn log -c11342
>   
>   r11342 | <> | 2000-11-14 ...
>
>   Use `chi-squared'.
>   
>
> which changed 16 (if I counted correctly) cases of 'chi-square' to 
> 'chi-squared'.
>
> I have not found any R-core internal (or public) reasoning about
> that change, but had kept it in mind and often worked along that "goal".
>
> As a consequence, "statistically" speaking, much of R's own use has been
> standardized to use "chi-squared"; but as I mentioned, I still
> find all  4  variants even in "R base" package help files
> (which of course I now could quite quickly change  (using Emacs M-x grep, 
> plus a script);
> but
>
> ... "as it is Friday" ... I'm interested to hear what others
> think, notably if you are native English (or "American" ;-)
> speaking and/or have some extra good knowledge on such
> matters...
>
> Martin Maechler
> ETH Zurich
>
> __
> 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] Surprising Symbolic Model Formula Evaluations

2019-10-11 Thread Richard M. Heiberger
I can't duplicate your examples
This is what I see
> y ~ 1:x
y ~ 1:x

Please try again in a vanilla R session, and send a reproducible example.
vanilla means start R from the operating system command line with
R --vanilla

this prevents any of your initialization files from being loaded.  See
?Startup
for details.

On Fri, Oct 11, 2019 at 1:05 PM Emi Tanaka  wrote:
>
> Hi,
>
> I'm wondering about some logics behind the following simplifications:
>
> y ~ 1:x simplifies to y ~ 1
> y ~ x:1 simplifies to y ~ 1
> y ~ x*1 simplifies to y ~ x
> y ~ 1*x simplifies to y ~ 1
>
> Mainly I would have expected y ~ 1:x to simplify to y ~ x and the cross
> operator to be invariant to order.
>
> I have some further surprising cases below that I'd also like to know more
> about but just above will also be great.
>
> https://rpubs.com/emitanaka/unexpected-formula-eval
>
> Best,
>
> Emi
>
> *Dr. Emi Tanaka* | Lecturer in Statistics
>
> Faculty of Science, School of Mathematics and Statistics
>
>
> Secretary, NSW Branch, Statistical Society of Australia
> 
>
> Social Media Coordinator, Central, International Biometrics Society
> 
>
>
> *THE UNIVERSITY OF SYDNEY*
> 827, Carslaw F07 | The University of Sydney | NSW | 2006
> *Phone:* +61 2 9351 3039
> *Website:* * *https://emitanaka.github.io/
> *Twitter: *@statsgen
>
> CRICOS 00026A
> This email plus any attachments to it are confidential.
> Any unauthorised use is strictly prohibited. If you receive this email in
> error, please delete it and any attachments. Please think of our
> environment and only print this e-mail if necessary.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-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] bi-directional bar chart with a central axis

2019-09-17 Thread Richard M. Heiberger
I would use the likert function in the HH package

> library(HH)
> likert(my.dta)
> as.pyramidLikert(likert(my.dta))
>

See the demo

demo("likert-paper", package="HH", ask=FALSE)

for more complex examples,  including the population pyramid.
We can also get the multiple coloring that your posted example shows.

Rich

On Tue, Sep 17, 2019 at 6:23 PM Sabatier, Jennifer F.
(CDC/DDPHSIS/CGH/DGHP) via R-help  wrote:
>
> Hi R-help,
>
> I have this data:
>
> my.dta <-data.frame(matrix(c(
> 26.3,   21.4,
> 20.1,   13.4,
> 7.9,3.9,
> 16.5,   14.6,
> 5.3,3.6,
> 38.6,   25.6,
> 34.4,   21.6,
> 77.4,   79.5,
> 58.2,   56.1,
> 80.5,   84,
> 37.7,   31.9,
> 19.9,   28.1,
> 6.2,5.9
> ), nrow=13, ncol=2, byrow=T,
> dimnames=list(c('A','B','C','D','E','F','G',   'H',   
>   'I','J','K','L','M'),
> c("Males", "Females"))
> ))
>
> I want to make a graph that looks like this:
>
> https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/backtoback11.jpg?resize=864%2C379&ssl=1
>
> Any help would be highly appreciated!
>
> Best,
>
> Jen
>
> __
> 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] R wrong, Python rigth in calcution

2019-09-17 Thread Richard M. Heiberger
Your numbers are 70 bits long, R double precision numbers are 53 bits long.
You need Rmpfr to get the higher precision.

> log(569936821221962380720, 2)
[1] 68.94936
> print(569936821221962380720, digits=22)
[1] 569936821221962350592

> library(Rmpfr)
> mpfr("569936821221962380720", 70)
1 'mpfr' number of precision  70   bits
[1] 569936821221962380720
>
> mpfr("569936821221962380720", 210)^3 + (mpfr("-569936821113563493509", 
> 210))^3 + (mpfr("-472715493453327032", 210))^3
1 'mpfr' number of precision  210   bits
[1] 3

See FAQ 7.31 and the help files for Rmpfr

Rich




On Tue, Sep 17, 2019 at 6:13 PM Duncan Murdoch  wrote:
>
> On 17/09/2019 6:02 p.m., Martin Møller Skarbiniks Pedersen wrote:
> > Hi,
> >I don't understand why R computes this wrong.
>
> This is pretty well documented.  R uses double precision floating point
> values for these expressions, which have about 15 digit precision.  I
> believe for whole numbers Python uses variable size integer values, so
> should get integer calculations exactly right.
>
> You can also tell R to use exact 32 bit integer calculations, but your
> values are too big for that, so it wouldn't work in this example.
>
>
>
>   I know I can use gmp and
> > R will do it correctly.
> >
> > $ echo '569936821221962380720^3 + (-569936821113563493509)^3 +
> > (-472715493453327032)^3' | Rscript - [1] -4.373553e+46
> > Correct answer is 3 and Python can do it:
> >
> > $ echo
> > 'pow(569936821221962380720,3)+pow(-569936821113563493509,3)+pow(-472715493453327032,3)'|python3
> > 3
> >
> >   [[alternative HTML version deleted]]
>
> Please don't post HTML to the list -- it's a plain text list.  That's
> also pretty well documented.
>
> Duncan Murdoch
>
> __
> 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] [R-devel] Source Code for function

2019-09-06 Thread Richard M. Heiberger
You might also want to look at the codetools package, for example the
showTree function " Prints a Lisp-style representation of R
expression."

> library(codetools)

> showTree(quote(x %*% x))
(%*% x x)
> showTree(quote(a+b))
(+ a b)
> showTree(quote(y ~ a+b))
(~ y (+ a b))

On Fri, Sep 6, 2019 at 2:30 PM Bert Gunter  wrote:
>
> The following may be of use (it gives the parse tree of the text):
>
> > z <- as.list(parse(text = "function(x)x %*% x"))
> > z[[1]]
> function(x) x %*% x
> > z[[c(1,1)]]
> `function`
> > z[[c(1,2)]]
> $x
> > z[[c(1,3)]]
> x %*% x
> > z[[c(1,3,1)]]
> `%*%`
> > z[[c(1,3,2)]]
> x
> > z[[c(1,3,3)]]
> x
>
>
> Bert Gunter
>
>
>
> On Fri, Sep 6, 2019 at 10:14 AM Wang Jiefei  wrote:
>
> > If you are looking for an R code parser, I think the `parse` and `eval`
> > function might be a good start point. See the example below.
> >
> > > parse(text="function(x)message(x)")
> > expression(function(x)message(x))
> > > eval(parse(text="function(x)message(x)"))
> > function(x)message(x)
> >
> > Best,
> > Jiefei
> >
> > On Fri, Sep 6, 2019 at 12:55 PM Golden, Shelby 
> > wrote:
> >
> >> Hello Bert,
> >>
> >> Thank you for the reply and your clarifications. Yes, it might be helpful
> >> to look into R’s formal grammar to see how “function” parses input to
> >> delegate correct syntax. Is that accessible online?
> >>
> >> Thank you,
> >> Shelby
> >>
> >>
> >> From: Bert Gunter 
> >> Date: Friday, September 6, 2019 at 10:44 AM
> >> To: "Golden, Shelby" 
> >> Cc: "r-help@R-project.org" , "Gillenwater, Lucas" <
> >> gillenwat...@njhealth.org>
> >> Subject: Re: [R] [R-devel] Source Code for function
> >>
> >> 1. This is a plain text list; all html is stripped. So there is no red
> >> highlighting.
> >>
> >> 2. There is no "source code" for "function" -- it is a reserved keyword.
> >> Or are you looking for R's formal grammar -- e.g. how it parses input to
> >> determine correct syntax?
> >>
> >>
> >>
> >> Bert Gunter
> >>
> >> "The trouble with having an open mind is that people keep coming along
> >> and sticking things into it."
> >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>
> >>
> >> On Fri, Sep 6, 2019 at 8:51 AM Golden, Shelby  >> > wrote:
> >> Hi all,
> >>
> >> I have been attempting to access the source code for the keyword
> >> “function” to better understand how it assigns and stores logical inputs,
> >> like in the subset() [base] function. Does anyone know how I can access the
> >> source code for this?
> >>
> >> For example, if I have
> >> norm <- function(x){
> >>   sqrt(x%*%x))
> >> }
> >> I am looking for the source code for the “function” portion, highlighted
> >> in red.
> >>
> >> Thank you for your time and assistance,
> >> Shelby Golden
> >> Lab Researcher Technician
> >> Dr. Russell Bowler’s Lab
> >> Department of Medicine
> >> National Jewish Health in Denver, CO
> >> Phone: (303) 270-2598
> >>
> >> NOTICE: This email message is for the sole use of the intended
> >> recipient(s) and may contain confidential and privileged information. Any
> >> unauthorized review, use, disclosure or distribution is prohibited. If you
> >> are not the intended recipient, please contact the sender by reply email
> >> and destroy all copies of the original message.
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To
> >> UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help<
> >> http://mx2.njhealth.org:32224/?dmVyPTEuMDAxJiZmMWRiYmMxZjFmNmI5ZDBkMz01RDcyOEQwN18yMjk2OF8zOTk2XzEmJjljNzlmMDA4YWRmZTZjMz0xMjMzJiZ1cmw9aHR0cHMlM0ElMkYlMkZzdGF0JTJFZXRoeiUyRWNoJTJGbWFpbG1hbiUyRmxpc3RpbmZvJTJGci1oZWxw
> >> >
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html<
> >> http://mx2.njhealth.org:32224/?dmVyPTEuMDAxJiZlMTkwYmMwMzFlNjk4ZTAzNz01RDcyOEQwN18yMjk2OF8zOTk2XzEmJmFkYTkxMWRkMWRhZTFkNz0xMjMzJiZ1cmw9aHR0cCUzQSUyRiUyRnd3dyUyRVItcHJvamVjdCUyRW9yZyUyRnBvc3RpbmctZ3VpZGUlMkVodG1s
> >> >
> >> 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 m

Re: [R] How to create Pivot table in r?

2019-07-05 Thread Richard M. Heiberger
daT1 <- structure(list(ID = structure(c(13L, 11L, 18L, 8L, 12L, 7L, 15L,
2L, 1L, 17L, 16L, 14L, 10L, 9L, 6L, 3L, 5L, 4L), .Label = c("1B82",
"7A1D", "848A8", "8737SP", "87E6E", "941FD", "942C", "9C39",
"9D10B", "A1271", "A253", "A451", "C27A", "C767D", "CBA8", "CDF10",
"D5DB", "FB3E"), class = "factor"), site1 = structure(c(3L, 1L,
2L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L
), .Label = c("3-Mar-2015", "30-Mar-2015", "31-Mar-2015"), class = "factor"
),
site2 = structure(c(1L, 3L, 1L, 1L, 6L, 1L, 6L, 1L, 2L, 5L,
5L, 1L, 1L, 1L, 4L, 1L, 1L, 4L), .Label = c("", "14-Apr-2015",
"17-Apr-2015", "2-May-2015", "22-Apr-2015", "9-Mar-2015"), class =
"factor")), .Names = c("ID",
"site1", "site2"), class = "data.frame", row.names = c(NA, -18L
))

daT1
sapply(daT1, class) ## factors interfere with what you want.

## make ID "character" and the two date columns "Date"
daT2 <- data.frame(ID=as.character(daT1$ID),
   site1=as.Date(daT1$site1, format = "%d-%b-%Y"),
   site2=as.Date(daT1$site2, format = "%d-%b-%Y"),
   stringsAsFactors=FALSE)
sapply(daT2, class)

result <- tapply(daT2$ID, daT2[,2:3], c)
result
result[3,4:5]

On Fri, Jul 5, 2019 at 12:48 PM Marna Wagley  wrote:
>
> Hi Rui,
> Thank you very much for the code. It is great as it gave the number of
> individuals encountered in each cell but- is it possible to see which
> individuals were in that cell?
> for example - site2 (2015-05-02) and site2(2015-03-31) has value 2, is it
> possible to show these two  "941FD","8737SP" IDs in that cell? It must be
> hard to create this type of table.
>
> daT1<-structure(list(ID = structure(c(13L, 11L, 18L, 8L, 12L, 7L, 15L,
>
> 2L, 1L, 17L, 16L, 14L, 10L, 9L, 6L, 3L, 5L, 4L), .Label = c("1B82",
>
> "7A1D", "848A8", "8737SP", "87E6E", "941FD", "942C", "9C39",
>
> "9D10B", "A1271", "A253", "A451", "C27A", "C767D", "CBA8", "CDF10",
>
> "D5DB", "FB3E"), class = "factor"), site1 = structure(c(3L, 1L,
>
> 2L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L
>
> ), .Label = c("3-Mar-2015", "30-Mar-2015", "31-Mar-2015"), class = "factor"
> ),
>
> site2 = structure(c(1L, 3L, 1L, 1L, 6L, 1L, 6L, 1L, 2L, 5L,
>
> 5L, 1L, 1L, 1L, 4L, 1L, 1L, 4L), .Label = c("", "14-Apr-2015",
>
> "17-Apr-2015", "2-May-2015", "22-Apr-2015", "9-Mar-2015"), class =
> "factor")), .Names = c("ID",
>
> "site1", "site2"), class = "data.frame", row.names = c(NA, -18L
>
> ))
>
>
> daT1$site1 <- as.Date(daT1$site1, format = "%d-%b-%Y")
>
> daT1$site2 <- as.Date(daT1$site2, format = "%d-%b-%Y")
>
> AA<-xtabs(~ site2 + site1, daT1)
>
> AA
>
>
> Once again, I am very grateful to you.
>
> Thanks
>
>
>
> On Fri, Jul 5, 2019 at 1:57 AM  wrote:
>
> > Hello,
> >
> > Maybe you want to take a look at function xtabs.
> >
> > xtabs(~ site2 + site1, daT1)
> >
> > Note that the results are different if you convert to class "Date" first.
> >
> > daT1$site1 <- as.Date(daT1$site1, format = "%d-%b-%Y")
> > daT1$site2 <- as.Date(daT1$site2, format = "%d-%b-%Y")
> > xtabs(~ site2 + site1, daT1)
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> >
> > Citando Marna Wagley :
> >
> > > Hi R users,
> > > I was trying  to create a pivot table (cross tabulated) by Site1date
> > (rows)
> > > and Site2 date (columns), and spent substantial time but no luck to
> > create
> > > it. Is there any possibility to create it?
> > > I would be very grateful to your help.
> > >
> > > "daT1" is row data, in which three columns (speciesID, detected at SiteA,
> > > Site B) and cell has date in which they were detected. From this data, I
> > > wanted to create a table to show a joint detection between site1 and
> > Site2.
> > >
> > > I was trying to get the table similar to "daT2", which is a cross
> > tabulated
> > > table by Site1 date (rows), and Site2 date (columns). After that I would
> > > like to see another table related sum of the detecttions in each cell (
> > > "daT3" table)
> > >
> > > The example data are given below (daT1) and output tables (daT2, daT3). I
> > > appreciate your help very much.
> > >
> > > Sincerely
> > >
> > >
> > >
> > > daT1<-structure(list(ID = structure(c(13L, 11L, 18L, 8L, 12L, 7L, 15L,
> > > 2L, 1L, 17L, 16L, 14L, 10L, 9L, 6L, 3L, 5L, 4L), .Label = c("1B82",
> > > "7A1D", "848A8", "8737SP", "87E6E", "941FD", "942C", "9C39",
> > > "9D10B", "A1271", "A253", "A451", "C27A", "C767D", "CBA8", "CDF10",
> > > "D5DB", "FB3E"), class = "factor"), site1 = structure(c(3L, 1L,
> > > 2L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L
> > > ), .Label = c("3-Mar-2015", "30-Mar-2015", "31-Mar-2015"), class =
> > > "factor"),
> > > site2 = structure(c(1L, 3L, 1L, 1L, 6L, 1L, 6L, 1L, 2L, 5L,
> > > 5L, 1L, 1L, 1L, 4L, 1L, 1L, 4L), .Label = c("", "14-Apr-2015",
> > > "17-Apr-2015", "2-May-2015", "22-Apr-2015", "9-Mar-2015"), class =
> > > "factor")), .Names = c("ID",
> > > "site1", "site2"), class = "data.frame", row.names = c(NA, -18L
> > > ))
> > >
> > > daT2<-

Re: [R] Matrix - remove [,1] from top row

2019-07-02 Thread Richard M. Heiberger
give your a matrix an empty column name.

> tmp <- matrix(1:4, 4, 1, dimnames=list(letters[1:4], NULL))
> tmp
  [,1]
a1
b2
c3
d4
> dimnames(tmp)[[1]]
[1] "a" "b" "c" "d"
> dimnames(tmp)[[2]]
NULL
> dimnames(tmp)[[2]] <- ""
> tmp

a 1
b 2
c 3
d 4

On Tue, Jul 2, 2019 at 5:09 PM  wrote:
>
> Hello,
>
> That is not a row, what you seem to have is an object of class
> "matrix" and when it's printed it prints the column names or [,1]
> [,2] etc if there aren't any colnames. So your matrix has just one
> column and 4 rows with rownames 'date', 'Peeps', 'days', 'worn'.
>
>
> Hope this helps,
>
> Rui Barradas
>
>
>
>
> Citando Nicola Cecchino :
>
> > Hello,
> >
> > I am simply trying to remove the [,1] row from a matrix.  I tried to
> > search Google to see if I could find how that is removed, but could
> > not find a way to do it.
> >
> > So I have the following:
> >
> > [,1]
> > date  2019-7-01
> > Peeps   5
> > days 7
> > worn  9
> >
> > this is what I want:
> >
> > date  2019-7-01
> > Peeps   5
> > days 7
> > worn  9
> >
> > Any ideas?
> >
> > Nic
> >
> > __
> > 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] Help with a third ggplot error

2019-06-15 Thread Richard M. Heiberger
you did something like this:

> mydf <- data.frame(y=1:16,
+AA=rep(factor(letters[1:8]), 2),
+BB=rep(factor(LETTERS[12:13]), each=8),
+CC=rep(factor(rep(LETTERS[9:11], times=c(3,1,4))), 2))
> ggplot(mydf, aes(ls, y))
Don't know how to automatically pick scale for object of type
function. Defaulting to continuous.
Error: All columns in a tibble must be 1d or 2d objects:
* Column `x` is function
Call `rlang::last_error()` to see a backtrace
>

you will have to figure out which of your variables is not properly specified.

Rich

On Fri, Jun 14, 2019 at 3:30 PM Bill Poling  wrote:
>
> #RStudio Version 1.2.1335
> sessionInfo()
> #R version 3.5.3 (2019-03-11)
> #Platform: x86_64-w64-mingw32/x64 (64-bit)
> #Running under: Windows >= 8 x64 (build 9200)
>
> Hello I am fitting an Arima model and all appears to go well until I get to 
> the ggplot, (again, lots of laughs).
> Deja Vu all over again! (God I hope it's not a typo!)
>
> The error at the point of the plot is:
> # Don't know how to automatically pick scale for object of type function. 
> Defaulting to continuous.
> # Error: All columns in a tibble must be 1d or 2d objects:
> # * Column `x` is function
>
> I hope someone recognizes my problem.
>
> Thank you for any assistance.
>
> #Here is the code and particulars of the data being plotted
>
> #Fit the arima model
>
> fit_arima2 <- train_tbl %>%
>   tk_ts(select = NetEditRev, frequency = 364) %>%
>   Arima(order = c(1,0,2),
> seasonal=c(0,1,0),
> include.drift = TRUE)
>
> #Forecast with Sweep Functions
>
> fcast_arima_tbl <- forecast(fit_arima2, h = nrow(test_tbl)) %>%
>   sw_sweep(timetk_idx = TRUE, rename_index = "date")
>
> #Save the DF
>
> fs::dir_create("00_model")
>
> fcast_arima_tbl %>% write_rds("00_model/fcast_arima_tbl.rds")
>
> fcast_arima_tbl1 <- read_rds("00_model/fcast_arima_tbl.rds")
>
> head(fcast_arima_tbl1)
>
> # A tibble: 6 x 7
>   date   keyNetEditRev lo.80 lo.95 hi.80 hi.95
>   
> 1 2017-01-01 actual  -923.NANANANA
> 2 2017-01-02 actual 19222.NANANANA
> 3 2017-01-03 actual -8397.NANANANA
> 4 2017-01-04 actual 37697.NANANANA
> 5 2017-01-05 actual 46075.NANANANA
> 6 2017-01-06 actual 38329.NANANANA
>
> str(fcast_arima_tbl1)
> Classes 'tbl_df', 'tbl' and 'data.frame':892 obs. of  7 variables:
>  $ date  : Date, format: "2017-01-01" "2017-01-02" "2017-01-03" 
> "2017-01-04" ...
>  $ key   : chr  "actual" "actual" "actual" "actual" ...
>  $ NetEditRev: num  -923 19222 -8397 37697 46075 ...
>  $ lo.80 : num  NA NA NA NA NA NA NA NA NA NA ...
>  $ lo.95 : num  NA NA NA NA NA NA NA NA NA NA ...
>  $ hi.80 : num  NA NA NA NA NA NA NA NA NA NA ...
>  $ hi.95 : num  NA NA NA NA NA NA NA NA NA NA ...
>
> #Plot the model
>
> g4 <- fcast_arima_tbl1 %>%
>   ggplot(aes(date, NetEditRev, color = key)) +
>   geom_point(data = test_tbl %>% mutate(key = "actual")) +
>   geom_point(alpha = 0.5) +
>   theme_tq() +
>   scale_color_tq() +
>   labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue")
>
> g4
> # Don't know how to automatically pick scale for object of type function. 
> Defaulting to continuous.
> # Error: All columns in a tibble must be 1d or 2d objects:
> # * Column `x` is function
>
> ggplotly(g4) %>%
>   layout(xaxis = list(rangeslider = list(type = "date")))
> # Don't know how to automatically pick scale for object of type function. 
> Defaulting to continuous.
> # Error: All columns in a tibble must be 1d or 2d objects:
> # * Column `x` is function
>
>
> #Alternative changes that I have tried based on google searches, but have 
> their own errors.
>
> # g4 <- fcast_arima_tbl1 %>%
> #   ggplot(aes(date, NetEditRev, color = key)) +
> #   geom_point(data = test_tbl %>% filter(key = "actual")) + #Try using filter
> #   geom_point(alpha = 0.5) +
> #   theme_tq() +
> #   scale_color_tq() +
> #   labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue")
> # #Error: `key` (`key = "actual"`) must not be named, do you need `==`?
> #
> # g4 <- fcast_arima_tbl1 %>%
> #   ggplot(aes(date, NetEditRev, color = key)) +
> #   geom_point(data = test_tbl %>% filter(key == "actual")) + #Try using 
> filter with ==
> #   geom_point(alpha = 0.5) +
> #   theme_tq() +
> #   scale_color_tq() +
> #   labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue")
> # #Error: object 'key' not found
> #
> # g4 <- fcast_arima_tbl1 %>%
> #   ggplot(aes(date, NetEditRev, color = key)) +
> #   geom_point(data = test_tbl) +
> #   filter(fcast_arima_tbl1$key = "actual") + #Try filter with 
> fcast_arima_tbl1$key and repositioned with +
> #   geom_point(alpha = 0.5) +
> #   theme_tq() +
> #   scale_color_tq() +
> #   labs(title = "ARIMA(1,0,2)(0,1,0 with Drift For Net Edit Revenue")
> # #Error: Cannot add ggproto objects together. Did you forget to add this 
> o

Re: [R] URGENT help-Problem with panel barplot spacing

2019-05-28 Thread Richard M. Heiberger
I think this is what you want.  You didn't send a reproducible example
(no values for djf.gcms or for cores1).

For what I think you are doing, lattice would be much simpler.  It
handles the repetition within each panel for you.

## generate some data
djf.gcms <- matrix(sample(50, size=9*12, replace=TRUE), 9, 12)

library(lattice)
library(latticeExtra)

djfs <- cbind(stack(data.frame(djf.gcms)), letter=factor(letters[1:9]))
head(djfs)

tmp <-
barchart(letter ~ values | ind, group=letter, col=1:9, data=djfs,
horizontal=TRUE,
 stack=TRUE, type="i",
 scales=list(x=list(alternating=FALSE, axs="i", limits=c(0,59))),
 origin=0, layout=c(4, 3), between=list(x=1, y=2)) +
  layer(panel.text(x=x+5, y, label=x)) +
  layer(panel.abline(v=seq(0,50,10), col="gray"), under=TRUE)
tmp

Rich

The best place to start learning lattice is the trellis book
http://geog.uoregon.edu/GeogR/pdfs/trellis.user.pdf

The definitive reference is Deepayan Sarkar's book,
 Lattice: Multivariate Data Visualization with R
https://www.e-reading.club/bookreader.php/137342/Lattice._Multivariate_Data_Visualization_with_R.pdf

My book (HH2) is
Heiberger, Richard M. and Holland, Burt (2015).
 Statistical Analysis and Data Display: An Intermediate Course with
Examples in R.
 Springer, second edition. ISBN 978-1-4939- 2121-8.
https://www.springer.com/us/book/9781493921218

See HH2 Chapter 4 Graphs for a general discussion
and many examples throughout the book and in the accompanying CRAN package HH.

install.packages("HH")

On Tue, May 28, 2019 at 6:42 AM Kwesi A. Quagraine
 wrote:
>
> Hello All,
>
> I am struggling to control the spaces between barplots I have panelled. I
> would be grateful for any help in reducing the spaces between the plots.
> For instance, how I can reduce distance between 1 and 2, 2 and 3 etc.
>
> I would appreciate any help on this.
>
> Thanks
>
> Here’s a snippet of my code and attached is the current image I generate
> from the command;
>
> ##for djf
> postscript("fig_paper2_fre_obs_models_djf_1980_2013_4x3_new.eps",width=10,height=8,paper="special",horizontal=T,onefile=T)
>
> par(mfrow=c(3,4))
> par(mar=c(6,11,1,2))
>
> a =1
> for (j in a) {
>   djf.bar<- barplot(djf.gcms[,j],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> j,type="n",font.main = 1, cex.main = 1.5,las=1, axisnames = T, width =
> 0.8,cex.names=1.5,horiz = TRUE)
>   abline(v=c(seq(0,50,10)),col='grey',lwd=0.2)
>   par(new=TRUE)
>   djf.bar<-barplot(djf.gcms[,j],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> j,font.main = 1, cex.main = 1.5,las=1, axisnames = T, width =
> 0.8,cex.names=1.5,horiz = TRUE)
>   ## Add text at top of bars
>   text(y = djf.bar, x = djf.gcms[,j], label = round(djf.gcms[,j],
> digits=0), pos = 4, cex = 1.2)
> }
>
>
> for (i in 2:4) {
>   djf.bar<-barplot(djf.gcms[,i],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> i, yaxs="i",type="n",font.main = 1, cex.main = 1.1,las=1, axisnames =
> FALSE, width = 0.8,cex.names=1.0,horiz = TRUE)
>   abline(v=c(seq(0,50,10)),col='grey',lwd=0.2)
>   par(new=TRUE)
>   djf.bar<-barplot(djf.gcms[,i],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> i, yaxs="i",font.main = 1, cex.main = 1.1,las=1, axisnames = FALSE, width =
> 0.8,cex.names=1.0,horiz = TRUE)
>   text(y = djf.bar, x = djf.gcms[,i], label = round(djf.gcms[,i],
> digits=0), pos = 4, cex = 1.0)
>
> }
>
> b=5
> for (k in b) {
>   djf.bar<-barplot(djf.gcms[,k],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> k,type="n",font.main = 1, cex.main = 1.1,las=1, axisnames = T, width =
> 0.8,cex.names=1.5,horiz = TRUE)
>   abline(v=c(seq(0,50,10)),col='grey',lwd=0.2)
>   par(new=TRUE)
>   djf.bar<-barplot(djf.gcms[,k],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> k,font.main = 1, cex.main = 1.1,las=1, axisnames = T, width =
> 0.8,cex.names=1.5,horiz = TRUE)
>   text(y = djf.bar, x = djf.gcms[,k], label = round(djf.gcms[,k],
> digits=0), pos = 4, cex = 1.2)
>
> }
>
> for (n in 6:8) {
>   barplot(djf.gcms[,n],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> n,type="n",font.main = 1, cex.main = 1.1,las=1, axisnames = FALSE, width =
> 0.8,cex.names=1.0,horiz = TRUE)
>   abline(v=c(seq(0,50,10)),col='grey',lwd=0.2)
>   par(new=TRUE)
>   barplot(djf.gcms[,n],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> n,font.main = 1, cex.main = 1.1,las=1, axisnames = FALSE, width =
> 0.8,cex.names=1.0,horiz = TRUE)
>   text(y = djf.bar, x = djf.gcms[,n], label = round(djf.gcms[,n],
> digits=0), pos = 4, cex = 1.0)
>
> }
>
> c = 9
> for (m in c) {
>   djf.bar<-barplot(djf.gcms[,m],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> m,type="n",font.main = 1, cex.main = 1.1,las=1, axisnames = T, width =
> 0.8,cex.names=1.5,horiz = TRUE)
>   abline(v=c(seq(0,50,10)),col='grey',lwd=0.2)
>   par(new=TRUE)
>   djf.bar<-barplot(djf.gcms[,m],ylim=c(0,9),xlim=c(0,50),col=cores1,main =
> m,font.main = 1, cex.main = 1.1,las=1, axisnames = T, width =
> 0.8,cex.names=1.5,horiz = TRUE)
>   title("Frequency (%)", line = -17.0)
>   text(y = djf.bar, x = djf.gcms[,m], label = round(djf.gcms[,m],
>

Re: [R] linear model contrast in R

2019-05-13 Thread Richard M. Heiberger
I think you might be looking for
?contrasts
to form the contrast matrix.

Rich

On Mon, May 13, 2019 at 7:31 AM Witold E Wolski  wrote:
>
> I am looking for a function to compute contrasts with a interface
> similar to that of
>
> lmerTest::contest
> multcomp::glht
>
> i.e. taking the model and a contrast vector or matrix as an argument,
> but for linear models, and without the multiple testing adjusted made
> by multcomp::glht.
>
> Thank you
>
>
> --
> Witold Eryk Wolski
>
> __
> 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] Define pch and color based on two different columns

2019-04-09 Thread Richard M. Heiberger
conditions look better as factors (their values are displayed in the
strip label).
groups should be a factor to get the uniqueness over panels.
To use two factors together for groups, take their interaction.
col and pch should be integers


xyplot(mpg ~ wt | factor(cyl), data=mtcars,
   groups = factor(carb),
   col = mtcars$gear,
   pch = mtcars$carb
)
xyplot(mpg ~ wt | factor(cyl), data=mtcars,
   groups = interaction(factor(carb), factor(gear)),
   col = mtcars$gear,
   pch = mtcars$carb
)

On Wed, Apr 10, 2019 at 12:54 AM Peter Langfelder
 wrote:
>
> Sorry for being late to the party, but has anyone suggested a minor
> but important modification of the code from stack exchange?
>
> xyplot(mpg ~ wt | cyl,
>   panel = function(x, y, ..., groups, subscripts) {
>   pch <- mypch[factor(carb)[subscripts]]
>   col <- mycol[factor(gear)[subscripts]]
>   grp <- c(gear,carb)
>   panel.xyplot(x, y, pch = pch, col = col)
>   }
> )
>
> From the little I understand about what you're trying to do, this may
> just do the trick.
>
> Peter
>
> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder  wrote:
> >
> > I am making a lattice plot and I would like to use the value in one column
> > to define the pch and another column to define color of points. Something
> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >data=mtcars,
> >col = gear,
> >pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as they
> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >data=mtcars,
> >groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >   panel = function(x, y, ..., groups, subscripts) {
> >   pch <- mypch[factor(carb[subscripts])]
> >   col <- mycol[factor(gear[subscripts])]
> >   grp <- c(gear,carb)
> >   panel.xyplot(x, y, pch = pch, col = col)
> >   }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do this?
> >
> > Ps, I had to post this via email because the Nabble site kept sending me an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > matthew.snyd...@rockets.utoledo.edu
> > msnyder...@gmail.com
> >
> >
> >
> > [image: Mailtrack]
> > 
> > Sender
> > notified by
> > Mailtrack
> > 
> > 04/09/19,
> > 1:49:27 PM
> >
> > [[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] Convert a character to numeric

2019-04-09 Thread Richard M. Heiberger
My guess is that numbers formatted with commas are causing an unwanted coercion.
Remove the commas with gsub before converting to numeric.

> as.numeric(NA)
[1] NA
> as.numeric("1,234,567")
[1] NA
Warning message:
NAs introduced by coercion
> as.numeric(gsub(",", "", "1,234,567"))
[1] 1234567
>

On Tue, Apr 9, 2019 at 10:36 AM Alfredo Cortell
 wrote:
>
> Hi Bienvenue,
>
> I believe that your problem is that R can't translate "one" to a number,
> because it is not a number. R could translate to numeric for example this
> vector, where numbers are expressed as strings,
>
> c("1","4","7")
>
> but "one" is just letters put together, therefore R can't understand their
> meaning, and returns NA.
>
> I believe that your best shot is to go with gsub, so that you translate
> your "string letters" to "string numbers", and then you can do as.numeric
> no problem
>
> Try this
>
> vec<-c("1",NA,"one")
> num_vec<-gsub("one",1,vec)
> num_vec<-as.numeric(num_vec)
>
> Good luck,
>
> Alfredo
>
>
> El mar., 9 abr. 2019 a las 15:07, Duncan Murdoch ()
> escribió:
>
> > On 09/04/2019 7:30 a.m., Jim Lemon wrote:
> > > Hi Bienvenue,
> > > Perhaps you should ask whether you really want to "sort it out". The
> > > warning is telling you that you are converting the NA values to NA in
> > > the returned numeric vector.
> >
> > I don't think that's what it is saying.  I think it is saying that a
> > non-NA value is being converted to NA, because R can't figure out what
> > number it is.  For example,
> >
> >  > as.numeric(c("1", NA))
> > [1]  1 NA
> >  > as.numeric(c("1", NA, "one"))
> > [1]  1 NA NA
> > Warning message:
> > NAs introduced by coercion
> >
> >
> >   I can't think of anything more sensible
> > > to do with NA values. You may also have character strings that cannot
> > > be converted into numbers, which will also generate NA values.
> >
> > I think that's the only way that message will appear.
> >
> > Duncan Murdoch
> >
> >   Maybe a
> > > little example will help us to understand:
> > >
> > > charstr<-c("5","foot","2",NA,"eyes","of","blue")
> > > as.numeric(charstr)
> > > [1]  5 NA  2 NA NA NA NA
> > >
> > > Jim
> > >
> > > On Tue, Apr 9, 2019 at 9:16 PM bienvenidoz...@gmail.com
> > >  wrote:
> > >>
> > >> Hi,
> > >>
> > >> I am applyin function as.numeric to a vector having many values as NA
> > >> and it is giving :
> > >> Warning message:
> > >> NAs introduced by coercion
> > >>
> > >> Can anyone help me to know how to remove this warning and sor it out?
> > >>
> > >> Thanks
> > >> Bienvenue
> > >>  [[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.
> >
>
> [[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] Potential Issue with lm.influence

2019-04-03 Thread Richard M. Heiberger
fortune nomination.


The lesson to me here is that if you fit a sufficiently unreasonable
model to data, the computations may break down.

On Wed, Apr 3, 2019 at 10:18 AM Fox, John  wrote:
>
> Dear Eric,
>
> I'm afraid that your argument doesn't make sense to me. As you saw when you 
> tried
>
> fit3 <- update(fit, subset = !(Name %in% c("Jupiter ", "Saturn ")))
>
> glm.nb() effectively wasn't able to estimate the theta parameter of the 
> negative binomial model. So why would it be better to base deletion 
> diagnostics on actually refitting the model?
>
> The lesson to me here is that if you fit a sufficiently unreasonable model to 
> data, the computations may break down. Other than drawing attention to the 
> NaN with an explicit warning, I don't see what more could usefully be done.
>
> Best,
>  John
>
> > On Apr 2, 2019, at 9:08 PM, Eric Bridgeford  wrote:
> >
> > Hey John,
> >
> > I am aware they are high leverage points, and that the model is not the
> > best for them. The purpose of this dataset was to explore high leverage
> > points, and diagnostic statistics through which one would identify them.
> >
> > What I am saying is that the current behavior of the function seems a
> > little non-specific to me; the influence for this problem is
> > finite/computable manually by fitting n models to n-1 points (manually
> > holding out each point individually to obtain the loo-variance, and
> > computing the influence in the non-approximate way).
> >
> > I am just suggesting that it seems the function could be improved by, say,
> > throwing specific warnings when NaNs may arise. Ie, "Your have points that
> > are very high leverage. The approximation technique is not numerically
> > stable for these points and the results should be used with caution"
> > etc...; I am sure there are other also pre-hoc approaches to diagnose other
> > ways in which this function could fail). The approximation technique not
> > behaving well for points that are ultra high leverage just seems peculiar
> > that that would return an NaN with no other recommendations/advice/specific
> > warnings, especially since the influence is frequently used to diagnosing
> > this specific issue.
> >
> > Alternatively, one could afford an optional argument type="manual" that
> > computes the held-out variance manually rather than the approximate
> > fashion, and add a comment to use this in the help menu when you have high
> > leverage points (this is what I ended up doing to obtain the true influence
> > and the externally studentized residual).
> >
> > I just think some more specificity could be of use for future users, to
> > make the R:stats community even better :) Does that make sense?
> >
> > Sincerely,
> > Eric
> >
> > On Tue, Apr 2, 2019 at 7:53 PM Fox, John  wrote:
> >
> >> Dear Eric,
> >>
> >> Have you looked at your data? -- for example:
> >>
> >>plot(log(Moons) ~ Volume, data = moon_data)
> >>text(log(Moons) ~ Volume, data = moon_data, labels=Name, adj=1,
> >> subset = Volume > 400)
> >>
> >> The negative-binomial model doesn't look reasonable, does it?
> >>
> >> After you eliminate Jupiter there's one very high leverage point left,
> >> Saturn. Computing studentized residuals entails an approximation to
> >> deleting that as well from the model, so try fitting
> >>
> >>fit3 <- update(fit, subset = !(Name %in% c("Jupiter ", "Saturn ")))
> >>summary(fit3)
> >>
> >> which runs into numeric difficulties.
> >>
> >> Then look at:
> >>
> >>plot(log(Moons) ~ Volume, data = moon_data, subset = Volume < 400)
> >>
> >> Finally, try
> >>
> >>plot(log(Moons) ~ log(Volume), data = moon_data)
> >>fit4 <- update(fit2, . ~ log(Volume))
> >>rstudent(fit4)
> >>
> >> I hope this helps,
> >> John
> >>
> >> -
> >> John Fox
> >> Professor Emeritus
> >> McMaster University
> >> Hamilton, Ontario, Canada
> >> Web: https://socialsciences.mcmaster.ca/jfox/
> >>
> >>
> >>
> >>
> >>> -Original Message-
> >>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Eric
> >>> Bridgeford
> >>> Sent: Tuesday, April 2, 2019 5:01 PM
> >>> To: Bert Gunter 
> >>> Cc: R-help 
> >>> Subject: Re: [R] Fwd: Potential Issue with lm.influence
> >>>
> >>> I agree the influence documentation suggests NaNs may result; however, as
> >>> these can be manually computed and are, indeed, finite/existing (ie,
> >>> computing the held-out influence by manually training n models for n
> >> points
> >>> to obtain n leave one out influence measures), I don't possibly see how
> >> the
> >>> function SHOULD return NaN, and given that it is returning NaN, that
> >>> suggests to me that there should be either a) Providing an alternative
> >>> method to compute them that (may be slower) that returns the correct
> >>> results in the even that lm.influence does not return a good
> >> approximation
> >>> (ie, a command line argument for typ

  1   2   3   4   5   6   7   8   9   >