Re: [R] graph together 4 series after HP filter

2016-09-06 Thread Giorgio Garziano
Hi Sebastian,

here are examples with ggplot2 and basic graphic.

http://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2-on-the-same-graph

http://stackoverflow.com/questions/17150183/r-plot-multiple-lines-in-one-graph


You may also impress your audience by using iterative graphs as provided by 
dygraphs package.

https://blog.rstudio.org/2015/04/14/interactive-time-series-with-dygraphs/

You have to convert your xts objects starting from your ts ones.

An example:

getSymbols("AAPL", src = "yahoo", from = as.Date("2013-07-01"), to = 
as.Date("2016-06-30"))
getSymbols("YHOO", src = "yahoo", from = as.Date("2013-07-01"), to = 
as.Date("2016-06-30"))
getSymbols("CPHD", src = "yahoo", from = as.Date("2013-07-01"), to = 
as.Date("2016-06-30"))
getSymbols("EMC", src = "yahoo", from = as.Date("2013-07-01"), to = 
as.Date("2016-06-30"))
AAPL.xts <- Ad(AAPL)
YHOO.xts <- Ad(YHOO)
CPHD.xts <- Ad(CPHD)
EMC.xts <- Ad(EMC)

df <- data.frame(AAPL.xts, YHOO.xts, CPHD.xts, EMC.xts)
head(df)

library(dygraphs)
dygraph(df)

--

Best,

GG





[[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] outliers in Box Plot

2016-09-06 Thread Giorgio Garziano
Hi Rosa,

you may take advantage of the extremevalues package.

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

An example:

set.seed(1023)
v3 <- c(rnorm(100, 0, 0.2), rnorm(5, 4, 0.1), rnorm(5, -4, 0.1))
v4 <- sample(v3, length(v3))
nam <- as.character(1:length(v4))
df <- data.frame(names = nam, values = v4)


library(extremevalues)

res <- getOutliersI(as.vector(df[,"values"]), FLim=c(0.001, 0.999), 
distribution="normal")

# indexes where outliers are located
res$iLeft
res$iRight

outliers_idx <- c(res$iLeft, res$iRight)

df_outliers <- data.frame(index= outliers_idx, values = 
df[outliers_idx,"values"])
df_outliers

outlierPlot(df[,"values"], L=res)


--

Best

GG



[[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] Need advice on linear programming in R

2016-09-04 Thread Giorgio Garziano
Hi Michael,

On top of all suggestions, I can mention the following packages for linear 
programming problems:


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


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


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

(see clue package solve_LSAP function)


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


As a reference book, "Using R for Numerical Analysis in Science and 
Engineering", CRC press:


https://www.crcpress.com/Using-R-for-Numerical-Analysis-in-Science-and-Engineering/Bloomfield/p/book/9781439884485



Further, I share with you the code implementing a greedy solution to your 
assignment problem:

set.seed(1023)
nbin <- 5
nrow <- 100
nvalue <- nbin*nrow

# generating random values
gMat2 <- matrix(as.integer(Mod(rnorm(nvalue, 5, 10))), nrow = nrow)
gMat2

# since you want to maximize the minimum bin sums value
# let us already find the maximum value per row and store its corresponding
# column id inside rowmax
rowmax <- apply(gMat2, 1, function(x) {which.max(x)})
rowmax

# maximum value per each row
max_per_row <- sapply(1:nrow, function(x) gMat2[x, rowmax[x]])
names(max_per_row) <- as.character(1:nrow)
max_per_row

# sorting max_per_row values in descreasing order
sorted <- base::sort(max_per_row, decreasing=TRUE)
sorted

# bin where to store sums
bin <- vector(mode="numeric", length = nbin)

# assignment output based on sorted vector
output <- c()

# looping on sorted and assign the bin with minimum current sum
for (i in seq_along(sorted)) {
  s <- sorted[i]
  min.bin <- which.min(bin)
  bin[min.bin] <- bin[min.bin] + s
  output <- c(output, min.bin)
}

df <- cbind(sorted, output)
ord <- order(as.integer(rownames(df)))

df2 <- df[ord,]
colnames(df2) <- c("value", "selected_bin")
df2 <- data.frame(selected_column = rowmax, df2)

# assignments table
df2

# resulting bins sum
bin

-

Best,

GG



[[alternative HTML version deleted]]

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


Re: [R] Help regarding Community Detection Algorithm in R (like Propagation, Walktrap)

2016-05-02 Thread Giorgio Garziano
You may look at:

http://rseek.org/?q=community%20detection


--

Best,

GG

[[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] selecting columns from a data frame or data table by type, ie, numeric, integer

2016-04-29 Thread Giorgio Garziano
Hi,

I was able to replicate the solution as suggested by William in case of
data.frame class, not in case of data.table class.
In case of data.table, I had to do some minor changes as shown below.


library(data.table)
a <- 1:10
b <- c("a","b","c","d","e","f","g","h","i","j")
c <- seq(1.1, .2, length = 10)

# in case of data frame
dt1 <- data.frame(a,b,c)
dt1[vapply(dt1, FUN=is.numeric, FUN.VALUE=NA)]

a   c
1   1 1.1
2   2 1.0
3   3 0.9
4   4 0.8
5   5 0.7
6   6 0.6
7   7 0.5
8   8 0.4
9   9 0.3
10 10 0.2

# in case of data table
dt1 <- data.table(a,b,c)
dt1[, vapply(dt1, FUN=is.numeric, FUN.VALUE=NA), with=FALSE]

a   c
1   1 1.1
2   2 1.0
3   3 0.9
4   4 0.8
5   5 0.7
6   6 0.6
7   7 0.5
8   8 0.4
9   9 0.3
10 10 0.2


--

Best,

GG




[[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] multiplication by groups

2016-04-24 Thread Giorgio Garziano
df1 <- data.frame(ID = c(1,1,2,2,3,3,4,4,5,5),
   A = c(1,0,5,1,1,NA,0,3,2,7),
   B = c(2,3,NA,3,4,NA,1,0,5,NA))

df2 <- data.frame(ID = c(1,2,3,4,5),
   A = c(1,6,1,3,9),
   B = c(5,3,4,1,5))

m <- match(df1$ID, df2$ID)

sel <- c("A", "B")

for (i in 1:nrow(df1)) {
  df1[i,sel] <- round(df1[i,sel]/df2[m[i],sel], 2)
}

> df1
   IDA   B
1   1 1.00 0.4
2   1 0.00 0.6
3   2 0.83  NA
4   2 0.17 1.0
5   3 1.00 1.0
6   3   NA  NA
7   4 0.00 1.0
8   4 1.00 0.0
9   5 0.22 1.0
10  5 0.78  NA
>

--

Best,

GG




[[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] Inserting a blank row to every other row

2016-04-24 Thread Giorgio Garziano
Starting from this data frame:

my.df <- data.frame(num = 1:5, let = letters[1:5])

> my.df
  num let
1   1   a
2   2   b
3   3   c
4   4   d
5   5   e
>

and inserting a blank row (NAs row) for each one of my.df rows.

na.df <- data.frame(num = NA, let = NA)

my.df <- do.call(rbind, apply(my.df, 1, function(x) {rbind(x, na.df)}))

> my.df
num  let
1 1a
2   
3 2b
4   
5 3c
6   
7 4d
8   
9 5e
10  

--

Best,

GG


[[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] Finding Highest value in groups

2016-04-22 Thread Giorgio Garziano
Since the aggregate S3 method for class formula already has got na.action = 
na.omit,

## S3 method for class 'formula'
aggregate(formula, data, FUN, ...,
  subset, na.action = na.omit)


I think that to deal with NA's, it is enough:

   aggregate(Value~ID, dta, max)

Moreover, passing na.rm = FALSE/TRUE is "don't care":

aggregate(Value~ID, dta, max, na.rm=FALSE) result is:

  ID Value
1  1  0.69
2  2  0.99
3  3  1.00
4  4  1.00
5  5  0.50

which is the same of na.rm=TRUE.

On the contrary, in the following cases:

aggregate(Value~ID, dta, max, na.action = na.pass)

  ID Value
1  1  0.69
2  2  0.99
3  3  1.00
4  4NA
5  5  0.50

aggregate(Value~ID, dta, max, na.action = na.fail)

  Error in na.fail.default(list(Value = c(0.69, 0.31, 0.01, 0.99, 1, NA


the result is different.

--

Best,

GG





[[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] Finding Highest value in groups

2016-04-22 Thread Giorgio Garziano
idvalues <- data.frame (ID = c(1, 1, 2, 2, 3, 4, 4, 4, 5, 5),
Value = c(0.69, 0.31, 0.01, 0.99, 1.00, NA, 0,1, 0.5, 
0.5))

aggregate(Value~ID, data=idvalues, max)

ID Value
1  1  0.69
2  2  0.99
3  3  1.00
4  4  1.00
5  5  0.50

--

Best,

GG




[[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] subset by multiple letters condition

2016-04-22 Thread Giorgio Garziano
You may investigate a solution based on regular expressions.

Some tutorials to help:

http://www.regular-expressions.info/rlanguage.html

http://www.endmemo.com/program/R/grep.php

http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SvetlanaEdenRFiles/regExprTalk.pdf

https://rstudio-pubs-static.s3.amazonaws.com/74603_76cd14d5983f47408fdf0b323550b846.html

http://stat545.com/block022_regular-expression.html

https://www.youtube.com/watch?v=q8SzNKib5-4


--

Best,

GG





[[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] Add a vertical arrow to a time series graph using ggplot and xts

2016-04-20 Thread Giorgio Garziano
Please see updates to df2 assignment as shown below.

library(xts)  # primary
#library(tseries)   # Unit root tests
library(ggplot2)
library(vars)
library(grid)
dt_xts<-xts(x = 1:10, order.by = seq(as.Date("2016-01-01"),
 as.Date("2016-01-10"), by = "1 day"))
colnames(dt_xts)<-"gdp"
xmin<-min(index(dt_xts))
xmax<-max(index(dt_xts))
df1<-data.frame(x = index(dt_xts), coredata(dt_xts))
p<-ggplot(data = df1, mapping= aes(x=x, y=gdp))+geom_line()
rg<-ggplot_build(p)$panel$ranges[[1]]$y.range
y1<-rg[1]
y2<-rg[2]


# x = as.Date(..) in place of x = "2016-01-05"
df2<-data.frame(x = as.Date("2016-01-05"), y1=y1, y2=y2 )

p1<-p+geom_segment(mapping=aes(x=x, y=y1, xend=x, yend=y2), data=df2,
   arrow=arrow())
--

Best,

GG




[[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] Plotting data on a map

2016-04-06 Thread Giorgio Garziano
Some tutorials and examples may help.

http://www.zoology.ubc.ca/~kgilbert/mysite/Miscellaneous_files/R_MakingMaps.pdf

http://coulmont.com/cartes/rcarto.pdf

https://pakillo.github.io/R-GIS-tutorial/

http://www.milanor.net/blog/maps-in-r-plotting-data-points-on-a-map/

https://www.youtube.com/watch?v=PTti7OMbURo

https://www.nceas.ucsb.edu/scicomp/usecases/CreateMapsWithRGraphics


--

Best,

GG



[[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] Good pointers for understanding the R language implementation

2016-04-06 Thread Giorgio Garziano
Guessing that you may want to take a look at:

http://adv-r.had.co.nz/Expressions.html


https://www.opencpu.org/


Anyway, as David wrote, that it is too vague for specific hints.


--

Best,

GG



[[alternative HTML version deleted]]

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


Re: [R] R cases on predictive maintenance

2016-04-05 Thread Giorgio Garziano
Generically:

http://rseek.org/?q=predictive+maintenance

and among those:

https://rpubs.com/Simionsv/97830

http://blog.revolutionanalytics.com/2016/03/predictive-maintenance.html


--

Best,

GG

This Communication is Ericsson Confidential.
We only send and receive email on the basis of the term set out at 
http://www.ericsson.com/email_disclaimer




[[alternative HTML version deleted]]

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


Re: [R] converting a class dataframe (chars) to transaction class

2016-03-31 Thread Giorgio Garziano
A more specific reproducible example.

set.seed(1023)
library(arules)

# starting from a dataframe whose fields are characters (see stringsAsFactors = 
FALSE), as asked
products <- c("P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10")
mydf <- data.frame(user = sample(LETTERS[1:20], 100, replace=T),
   prod = sample(products, 100, replace=T),
   stringsAsFactors=FALSE)
str(mydf)

# convert to factors
mydf$user <- factor(mydf$user)
mydf$prod <- factor(mydf$prod)

# splitting by user
prodlist <- split(x=mydf[,"prod"], f=mydf$user)
prodlist

# remove duplicates
prodlist <- lapply(prodlist, unique)
prod.trans <- as(prodlist, "transactions")
itemFrequency(prod.trans)

# generating rules
rules <- apriori(prod.trans,parameter=list(support=.1, confidence=.5))
inspect(rules)

--

Best,

GG





[[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] ts or xts with high-frequency data within a year

2016-03-31 Thread Giorgio Garziano
Ryan,

>From "decompose()" source code, two conditions can trigger the error message:

   "time series has no or less than 2 periods"

based on the frequency value, specifically:

  1. f <= 1
  2. length(na.omit(x)) < 2 * f

It appears to me that your reproducible code has got a typo error, it should be:

  Z=ts(X[,3],frequency=24*365)

I mean X[,3] in place of X[,2].


Further, frequency=24*365, 2*frequency > 6000 = length(X[,3]), and that 
triggers the second condition.

>From R console:

> decompose
function (x, type = c("additive", "multiplicative"), filter = NULL)
{
type <- match.arg(type)
l <- length(x)
f <- frequency(x)
if (f <= 1 || length(na.omit(x)) < 2 * f)
stop("time series has no or less than 2 periods")


--

Best,

GG



[[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] Filtering based on the occurrence

2016-03-30 Thread Giorgio Garziano

# your code
Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", "5")
dates <- seq(as.Date('2011-01-01'),as.Date('2011-01-12'), by = 1)
deps <- c("A", "B", "C", "C", "D", "A", "F", "G", "A", "F", "A", "D")
df <- data.frame(Subject, dates, deps)
df
final<-c("2 2011-01-02B","2 2011-01-03C","3 2011-01-05D","3 
2011-01-06A",
 "4 2011-01-07F","4 2011-01-08G","5 2011-01-10F","5 
2011-01-11A",
 "5 2011-01-12D")

# here below my code
dep.list <- c("B", "D", "F")
sel.row = NULL
for (dep in dep.list) {
  f <- which(df$deps == dep)
  sel.row <- c(sel.row, c(f, f+1))
}
sel.row[sel.row > nrow(df)] <- NA
sel.row <- na.omit(sel.row)
df.sel <- df[sel.row,]
df.sel.ord <- df.sel[order(df.sel$dates),]

# showing and comparing with final
> df.sel.ord
   Subject  dates deps
22 2011-01-02B
32 2011-01-03C
53 2011-01-05D
63 2011-01-06A
74 2011-01-07F
84 2011-01-08G
10   5 2011-01-10F
11   5 2011-01-11A
12   5 2011-01-12D

> data.frame(final)
  final
1 2 2011-01-02B
2 2 2011-01-03C
3 3 2011-01-05D
4 3 2011-01-06A
5 4 2011-01-07F
6 4 2011-01-08G
7 5 2011-01-10F
8 5 2011-01-11A
9 5 2011-01-12D

--

Best

GG


[[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] converting a class dataframe (chars) to transaction class

2016-03-29 Thread Giorgio Garziano

mydf <- data.frame(d1 = LETTERS[1:10], d2 = letters[11:20])

> str(mydf)
'data.frame':   10 obs. of  2 variables:
$ d1: Factor w/ 10 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 10
$ d2: Factor w/ 10 levels "k","l","m","n",..: 1 2 3 4 5 6 7 8 9 10
>

library(arules)
trans1 <- as(mydf, "transactions")


> trans1
transactions in sparse format with
10 transactions (rows) and
20 items (columns)

> str(trans1)
Formal class 'transactions' [package "arules"] with 3 slots
  ..@ data   :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
  .. .. ..@ i   : int [1:20] 0 10 1 11 2 12 3 13 4 14 ...
  .. .. ..@ p   : int [1:11] 0 2 4 6 8 10 12 14 16 18 ...
  .. .. ..@ Dim : int [1:2] 20 10
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. .. ..@ factors : list()
  ..@ itemInfo   :'data.frame': 20 obs. of  3 variables:
  .. ..$ labels   : chr [1:20] "d1=A" "d1=B" "d1=C" "d1=D" ...
  .. ..$ variables: Factor w/ 2 levels "d1","d2": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ levels   : Factor w/ 20 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 
10 ...
  ..@ itemsetInfo:'data.frame': 10 obs. of  1 variable:
  .. ..$ transactionID: chr [1:10] "1" "2" "3" "4" ...>


Reference:

http://www.inside-r.org/packages/cran/arules/docs/transactionInfo


--

Best,

GG

[[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 can I count data points outside the main plot line?

2016-03-29 Thread Giorgio Garziano
As a "quick solution", I would explore the use of stat_smooth() and then 
extract fit data from,
as herein shown:

library(ggplot2)
p <- qplot(hp, wt, data=mtcars) + stat_smooth(method="loess")
p
ggplot_build(p)$data[[2]]

   xy ymin ymaxse PANEL group  colour   fill
1   52.0 1.993594 1.149150 2.838038 0.433 1-1 #3366FF grey60
2   55.58228 2.039986 1.303264 2.776709 0.3586695 1-1 #3366FF grey60
3   59.16456 2.087067 1.443076 2.731058 0.3135236 1-1 #3366FF grey60

Reference:

http://stackoverflow.com/questions/9789871/method-to-extract-stat-smooth-line-fit


In place of mtcars, your dataset.

Then, some more work to compare each (x,y) of your dataset with {(x,ymin), 
(x.ymax)} of
table above and to determine if (x,y) point stays within the smooth lines band 
or not.

Anyway, I would be interested in hearing about other approaches.

--

Best,

GG

[[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] Open source project that needs performance optimizations

2016-03-28 Thread Giorgio Garziano
Yes, I think it is worth evaluating what available at:

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

and as a thesis to tackle a "real-life" use case where R language and some of 
those High Performance Computing packages
are used to solve problems about.
Or you may implement a new R package to provide solution to a performance 
optimization scenario of your interest.

Also consider what available at:

http://www.teraproc.com/front-page-posts/r-on-demand/


Best,

--
GG



[[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] hourly prediction time series

2016-02-05 Thread Giorgio Garziano
Some good references:

https://www.otexts.org/fpp

http://link.springer.com/book/10.1007%2F978-0-387-88698-5

http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf


Best,

--

GG

This Communication is Ericsson Confidential.
We only send and receive email on the basis of the term set out at 
http://www.ericsson.com/email_disclaimer




[[alternative HTML version deleted]]

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


Re: [R] R Sig-Geo group - loop for creating spatial matrix

2016-02-02 Thread Giorgio Garziano
Dear Francesco,

from that point ahead, you have to handle a list of “nb” objects.
I used class() in order to show you what the list is made of.

The R code outlined in your reply may follow a pattern like this (showing an 
option):

for (val in z) {
dlwknn.B <- nb2listw(neighbors.knn[[val]], style="B", zero.policy=TRUE)
globalG.test(CRIME, dlwknn.B, zero.policy=F)
}


You may want to collect the results of the GlobalG.test in a list as well, the

help(globalG.test) provides an example at the bottom of its R help page.

To further point out that R language makes possible to implement functions call
over a list without specifying “for” loops. Some examples at:

http://www.r-bloggers.com/using-apply-sapply-lapply-in-r/


The R-SIG-Geo mailing list is reachable at:

https://stat.ethz.ch/pipermail/r-sig-geo/

if that was your original intention.


Best,

--
GG

From: Francesco Perugini [mailto:francesco.perug...@yahoo.it]
Sent: martedì 2 febbraio 2016 09:24
To: Giorgio Garziano
Subject: Re: [R] R Sig-Geo group - loop for creating spatial matrix

Dear Giorgio,
thanks a lot for your reply.
From here now,  I want to implement the Global G test for spatial 
autocorrelation for the generated different matrix and plot the Global G 
statistic (on the y-axes) against different val (on the x-axis). How should the 
code be? I've tried the following:

# Global G
dlwknn.B <- nb2listw(class(neighbors.knn[[val]]), style="B", zero.policy=TRUE)
globalG.test(CRIME, dlwknn.B, zero.policy=F)

but it is not working. Thanks a lot for your help..
franc.per


________
Da: Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>>
A: "r-help@r-project.org<mailto:r-help@r-project.org>" 
mailto:r-help@r-project.org>>
Cc: "francesco.perug...@yahoo.it<mailto:francesco.perug...@yahoo.it>" 
mailto:francesco.perug...@yahoo.it>>
Inviato: Lunedì 1 Febbraio 2016 20:39
Oggetto: Re: [R] R Sig-Geo group - loop for creating spatial matrix

You may handle that as a list of “nb” objects.

library(spdep)
example(columbus)
coord <- coordinates(columbus)

z <- c(1,2,3,4,5,6,7,8,9)
neighbors.knn <- list()

for (val in z) {
  neighbors.knn <- c(neighbors.knn, list(knn2nb(knearneigh(coord, val, 
longlat=F), sym=F)))
}

class(neighbours.knn)

class(neighbors.knn[[1]])
plot(neighbors.knn[[1]], coord)

class(neighbors.knn[[2]])
plot(neighbors.knn[[2]], coord)

and so on.

Best,

--
GG



[[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] Modelling non-Negative Time Series

2016-02-01 Thread Giorgio Garziano

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


Best,

--
GG



[[alternative HTML version deleted]]

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


Re: [R] R Sig-Geo group - loop for creating spatial matrix

2016-02-01 Thread Giorgio Garziano
You may handle that as a list of "nb" objects.

library(spdep)
example(columbus)
coord <- coordinates(columbus)

z <- c(1,2,3,4,5,6,7,8,9)
neighbors.knn <- list()

for (val in z) {
  neighbors.knn <- c(neighbors.knn, list(knn2nb(knearneigh(coord, val, 
longlat=F), sym=F)))
}

class(neighbours.knn)

class(neighbors.knn[[1]])
plot(neighbors.knn[[1]], coord)

class(neighbors.knn[[2]])
plot(neighbors.knn[[2]], coord)

and so on.

Best,

--
GG


[[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] Plotting Dates Time Series Data

2016-02-01 Thread Giorgio Garziano
This tutorial may help:

http://faculty.washington.edu/ezivot/econ424/Working%20with%20Time%20Series%20Data%20in%20R.pdf

See pages 20 and 27 for your specific issue.


Best,

--
GG




[[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] cross correlation of filtered Time series

2016-01-13 Thread Giorgio Garziano
I used frequency=60 to make it quickly work in order to show some sample code.
About the frequency parameter in time series, i.e. ts() stats package,  you may 
take a look at:

http://stats.stackexchange.com/questions/120806/frequency-value-for-seconds-minutes-intervals-data-in-r

corenv() f parameter unit measure is Hertz as seewave use case is about time 
waves.
About the corenv() results based on your data, I do not have the chance to 
investigate further.

Best,

--
GG

-Original Message-
From: Sudheer Joseph [mailto:s...@incois.gov.in] 
Sent: mercoledì 13 gennaio 2016 06:11
To: Giorgio Garziano; r-help@r-project.org
Subject: RE: [R] cross correlation of filtered Time series

Thank you,
 May I know the reason for keeping frequency as 60, the package 
says  it expects frequency in hertz, how does it work if I input daily data?. 
The correlation max shown by the plot is at around 55 -ve lag (0.36). which is 
not the actual case, so there is some thing which I am not understanding in 
this case.
With best regards,
Sudheer





From: Giorgio Garziano [giorgio.garzi...@ericsson.com]
Sent: Tuesday, January 12, 2016 9:38 PM
To: r-help@r-project.org
Cc: Sudheer Joseph
Subject: Re: [R] cross correlation of filtered Time series

Hello,

I think that the package "seewave" may help you. See corenv() function.

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


library(seewave)
sst.ts <- ts(dc$sst, frequency=60)
t2m.ts <- ts(dc$t2m, frequency=60)
corenv(sst.ts, t2m.ts)
corenv.res <- corenv(sst.ts, t2m.ts, plot=FALSE) corenv.res

Best,

--
GG





Email secured by Check Point

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] cross correlation of filtered Time series

2016-01-12 Thread Giorgio Garziano
Hello,

I think that the package "seewave" may help you. See corenv() function.

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


library(seewave)
sst.ts <- ts(dc$sst, frequency=60)
t2m.ts <- ts(dc$t2m, frequency=60)
corenv(sst.ts, t2m.ts)
corenv.res <- corenv(sst.ts, t2m.ts, plot=FALSE)
corenv.res

Best,

--
GG




[[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] create one bigger matrix with one smaller matrix

2015-12-31 Thread Giorgio Garziano
A <- matrix(c(1,2,3,4),2,2)

B <- matrix(A, nrow=14, ncol=14)

> B
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,]131313131 3 1 3 1 3
[2,]242424242 4 2 4 2 4
[3,]313131313 1 3 1 3 1
[4,]424242424 2 4 2 4 2
[5,]131313131 3 1 3 1 3
[6,]242424242 4 2 4 2 4
[7,]313131313 1 3 1 3 1
[8,]424242424 2 4 2 4 2
[9,]131313131 3 1 3 1 3
[10,]242424242 4 2 4 2 4
[11,]313131313 1 3 1 3 1
[12,]424242424 2 4 2 4 2
[13,]131313131 3 1 3 1 3
[14,]242424242 4 2 4 2 4
>


Happy New Year!

--
GG


[[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] rugarch package: VaR exceedances plot

2015-12-28 Thread Giorgio Garziano
My suggestion is to inspect the VaRplot source code and, also with the help of 
debug() if necessary,
you may verify how ylim results with your data.

> VaRplot
function (alpha, actual, VaR, title = paste("Daily Returns and Value-at-Risk 
\nExceedances\n",
"(alpha=", alpha, ")", sep = ""), ylab = "Daily Log Returns",
xlab = "Time")
{
period = diff(index(actual))
if (attr(period, "units") == "mins") {
A = as.numeric(actual)
V = as.numeric(VaR)
ep <- axTicksByTime(actual)
plot(A, type = "n", main = title, ylab = ylab, xlab = xlab,
ylim = c(min(A, V), max(A, V)), ann = FALSE, xaxt = "n",
cex.main = 0.8, cex.lab = 0.9, cex.axis = 0.8)
...
}
else {
plot(index(actual), as.numeric(actual), type = "n", main = title,
ylab = ylab, xlab = xlab, ylim = c(min(actual, VaR),
max(actual, VaR)), ann = FALSE, cex.main = 0.8,
cex.lab = 0.9, cex.axis = 0.8)

}
return(invisible())
}


File: rugarch-plots.R

Good luck,

--
GG

[[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] need for help for solving operations in a vector

2015-12-25 Thread Giorgio Garziano
I think that the rle() function may help you to tackle the problem in a more 
general way.

https://stat.ethz.ch/R-manual/R-devel/library/base/html/rle.html

Using William's suggested series:

x <- c(2,2,3,4,4,4,4,5,5,5,3,1,1,0,0,0,1,1,1)

> x
[1] 2 2 3 4 4 4 4 5 5 5 3 1 1 0 0 0 1 1 1

rle.x <- rle(x)
rle.x
Run Length Encoding
  lengths: int [1:8] 2 1 4 3 1 2 3 3
  values : num [1:8] 2 3 4 5 3 1 0 1

And then you can apply diff() to rle.x$values while keeping in mind the run 
lengths (rle.x$lengths).

Good luck,

--
GG


[[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] creating a xts object

2015-12-25 Thread Giorgio Garziano
Some hints at the following link where the "order.by requires an appropriate 
time-based object" error is commented.

http://stackoverflow.com/questions/23224142/converting-data-frame-to-xts-order-by-requires-an-appropriate-time-based-object


--
GG

[[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] to change the size of the line in the plot created in ggplot2

2015-12-25 Thread Giorgio Garziano
Hi Marna,

here is another example that should appear more similar to your scenario
than my previous one.

x <- seq(1:100)

y1 <- x*x
g1 <- rep("y1", 100)
df1 <- as.data.frame(cbind(x, y1), stringsAsFactors=FALSE)
df1 <- as.data.frame(cbind(df1, g1))
colnames(df1)<- c("x", "value", "variable")

y2 <- y1+1500
g2 <- rep("y2", 100)
df2 <- as.data.frame(cbind(x, y2), stringsAsFactors=FALSE)
df2 <- as.data.frame(cbind(df2, g2))
colnames(df2)<- c("x", "value", "variable")

y3 <- y1+6000
g3 <- rep("y3", 100)
df3 <- as.data.frame(cbind(x, y3), stringsAsFactors=FALSE)
df3 <- as.data.frame(cbind(df3, g3))
colnames(df3)<- c("x", "value", "variable")

avg <- (y1+y2+y3)/3
df4 <- as.data.frame(cbind(x, avg))
g4 <- rep("average", 100)
df4 <- as.data.frame(cbind(df4, g4))
colnames(df4) <- c("x", "value", "variable")

df <- data.frame(rbind(df1, df2, df3, df4))

# this is the data to start with ggplot()
df

# the df rows where the average value is stored
sel <- which(df[,"variable"]=="average")

library(ggplot2)

ggplot(data = df[-sel,], aes(x=x, y=value, group=variable)) + geom_line() +
  geom_line(data = df[sel,], aes(x=x, y=value, group=variable), size=0.5, 
linetype="dashed", color="blue")


Merry Christmas,

--
GG


[[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] to change the size of the line in the plot created in ggplot2

2015-12-24 Thread Giorgio Garziano
Hi Marna,

I prepared this toy example that should help you.

x <- seq(1:100)
y <- x*x
avg <- mean(y)
avg.v <- rep(avg,100) # your average column data
df <- as.data.frame(cbind(x, y, avg.v))

library(ggplot2)
ggplot(data=df[,-3], aes(x=x, y=y)) + geom_line() +
  geom_line(data=df[,c(1,3)], color='blue', aes(x=x, y=avg))


Best,

--
GG

[[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] to change the size of the line in the plot created in ggplot2

2015-12-24 Thread Giorgio Garziano
You can do it this way, for example:

geom_line(linetype="dashed", size=1, colour="blue")

Further info at:

http://docs.ggplot2.org/current/geom_line.html


--
GG



[[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] assigning values to elements of matrixes

2015-12-23 Thread Giorgio Garziano
I think this may help.

my_assign <- function(operand, value) {
  assignment <- paste(operand, value, sep = "<-")
  e <- parse(text = assignment)
  eval.parent(e)
}

a <- rep(0,5)
> a
[1] 0 0 0 0 0

my_assign("a[2]", 7)

> a
[1] 0 7 0 0 0

my_assign("a[4]", 12)

> a
[1] 0 7 0 12 0


--
GG

[[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] Trying to avoid the loop while merging two data frames

2015-12-22 Thread Giorgio Garziano
Library dplyr to use arrange() for ordering, in the case.

library(dplyr)

result.order <- arrange(result, d, version, a, b, c)
dim(result.order)
[1] 30005

head(result.order)
 d versiona  b   c
1 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
2 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
3 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
4 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
5 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
6 -2.986456069   3 0.2236414154 0.004258038663 1.089406822


my.merge <- merge(myinfo, mydata, by="version")
result2 <- my.merge[,c("d", "version", "a", "b", "c")]
result2.order <- arrange(result2, d, version, a, b, c)
dim(result2.order)
[1] 30005

head(result2.order)
 d versiona  b   c
1 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
2 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
3 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
4 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
5 -2.986456069   1 0.2236414154 0.004258038663 1.089406822
6 -2.986456069   3 0.2236414154 0.004258038663 1.089406822

all.equal(result.order, result2.order)
[1] TRUE


--

GG

[[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] Checkpoints in Caret

2015-12-22 Thread Giorgio Garziano
Further, trying to be more specific about checkpoint with R, I may suggest the 
following readings.



Look for "checkpoint models" in:




http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/docs-website/h2o-docs/booklets/DeepLearning_Vignette.pdf



Look for "checkpointing" in:



https://github.com/h2oai/h2o-training-book/blob/master/hands-on_training/deep_learning.md





However, that is not exactly what you asked for.


--
GG



[[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] Checkpoints in Caret

2015-12-22 Thread Giorgio Garziano
I found some information about parallel processing in R that might be of your 
interest:

http://topepo.github.io/caret/parallel.html

http://www.vikparuchuri.com/blog/parallel-r-model-prediction-building/

https://www.r-project.org/nosvn/conferences/useR-2013/Tutorials/kuhn/user_caret_2up.pdf

http://michaeljkoontz.weebly.com/uploads/1/9/9/4/19940979/parallel.pdf


Also consider:

http://www.teraproc.com/front-page-posts/r-on-demand/


Hope it helps.

--

GG



[[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 running predict

2015-12-22 Thread Giorgio Garziano
You forgot to put the comma after "-intrain" in the following assignment:

testing <- spam[-intrain, ]

"make" is one of the data columns of spam dataset.

> colnames(spam)
[1] "make"


--
GG


[[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] neuralnet to discriminate a given outcome by giving cutoff outputs

2015-12-20 Thread Giorgio Garziano
About my previous answer, I should have taken advantage of glm() in place of 
lm(), as the response is binomial.

--
GG


[[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] neuralnet to discriminate a given outcome by giving cutoff outputs

2015-12-20 Thread Giorgio Garziano
I would tackle the problem in the following way:

lm.model <- lm(z~ x + y, data=m)
summary(lm.model)



Call:

lm(formula = z ~ x + y, data = m)



Residuals:

Min  1Q  Median  3Q Max

-0.34476713 -0.09571506 -0.01786731  0.05225554  0.51693389



Coefficients:

Estimate   Std. Error  t value   Pr(>|t|)

(Intercept) -0.071612058  0.041196651 -1.73830  0.0876543 .

x0.003952998  0.001336833  2.95699  0.0045417 **

y9.968145059  0.461213516 21.61286 < 0.000222 ***

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1



Residual standard error: 0.157775 on 56 degrees of freedom

Multiple R-squared:  0.905464, Adjusted R-squared:  0.9020877

F-statistic: 268.1834 on 2 and 56 DF,  p-value: < 0.00022204


coef.model <- coef(lm.model)

z.hat <- coef.model[1]+coef.model[2]*x+coef.model[3]*y

z.hat.discrete <- rep(1, length(z.hat))
z.hat.discrete[z.hat <0.4] <- 0


> all.equal(z, z.hat.discrete)

[1] TRUE


I apologise for using such naif approach in place of neural net.

--
GG

http://around-r.blogspot.it


[[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] Create a data.table by looping over variable names

2015-12-16 Thread Giorgio Garziano
library(data.table)
dat <- as.data.table(matrix(100, nrow=1, ncol=100))
colnames(dat) <- gsub("V", "i", colnames(dat))

--
GG




[[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] Print minified XML in tree format

2015-12-14 Thread Giorgio Garziano
I may suggest this quick guide:

http://gastonsanchez.com/work/webdata/getting_web_data_r4_parsing_xml_html.pdf

and the following link:

http://www.r-datacollection.com/


I apologize for not being more specific.


--
GG



[[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 use confusionMatrix function in solving multi-classes problem

2015-12-13 Thread Giorgio Garziano
You may use the "caret" package.

At the following link 2-classes and 3-classes examples:

http://www.inside-r.org/node/86995


--
GG



[[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] define number of clusters in kmeans/apcluster analysis

2015-12-13 Thread Giorgio Garziano
And in case you would like to explore the supervised clustering approach, I may 
suggest to explore the
use of knn() fed by a training set determined by your cluster assignments 
expectations.
Some "quick code" to show what I mean.

z <- as.data.frame(cbind(scale(x), scale(y)))
colnames(z) <- c("x", "y")

n <- nrow(z)
train <- seq(1,0.3*n,1)
ztrain <- as.data.frame(z[train,])
cl <- vector(mode="numeric", length=length(train))

for (i in 1:nrow(ztrain)) {
  if (ztrain[i,"y"] > 2 | ztrain[i,"x"] > 0) {
cl[i] <- 2
  }  else {
cl[i] <- 1
  }
}
plot(ztrain, col=cl)

library(class)
ztest<- as.data.frame(z[-train,])
knn.model <- knn(ztrain, ztest, cl, k = 3)
plot(ztest, col=knn.model)

ztrain$cl <- cl
ztest$cl <- knn.model

z.res <- rbind(ztrain,ztest)
plot(z.res$x, z.res$y, col=z.res$cl)

--
GG

[[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] stopifnot with logical(0)

2015-12-11 Thread Giorgio Garziano
I think the inspection of the "stopifnot()" source code may help.

> stopifnot
function (...)
{
n <- length(ll <- list(...))
if (n == 0L)
return(invisible())
mc <- match.call()
for (i in 1L:n) if (!(is.logical(r <- ll[[i]]) && !anyNA(r) &&
all(r))) {
ch <- deparse(mc[[i + 1]], width.cutoff = 60L)
if (length(ch) > 1L)
ch <- paste(ch[1L], "")
stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all 
TRUE"),
ch), call. = FALSE, domain = NA)
}
invisible()
}


The following code may help in understanding.

(arg <- (logical(0) == 1))
(arg <- (logical(0) == TRUE))
(arg <- (logical(0) == FALSE))

n <- length(ll <- list(arg))
n

if (n == 0L)
  return(invisible())

for (i in 1L:n) {
  print(is.logical(r <- ll[[i]]))
  print(!anyNA(r))
  print(all(r))
  if (! (is.logical(r <- ll[[i]]) && !anyNA(r) &&  all(r)) ) {
print("stop")
  }
}

Executing such code:

> (arg <- (logical(0) == 1))
logical(0)
> (arg <- (logical(0) == TRUE))
logical(0)
> (arg <- (logical(0) == FALSE))
logical(0)
>
> n <- length(ll <- list(arg))
> n
[1] 1
>
> if (n == 0L)
+   return(invisible())
>
> for (i in 1L:n) {
+   print(is.logical(r <- ll[[i]]))
+   print(!anyNA(r))
+   print(all(r))
+   if (! (is.logical(r <- ll[[i]]) && !anyNA(r) &&  all(r)) ) {
+ print("stop")
+   }
+ }
[1] TRUE
[1] TRUE
[1] TRUE
>

See also help(all) and what its "Note" states about all(logical(0))
and consider that:

> is.logical(logical(0))
[1] TRUE


--
GG

[[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] change col types of a df/tbl_df

2015-12-10 Thread Giorgio Garziano
my_convert <- function(col) {
  v <- grep("[0-9]{2}.[0-9]{2}.[0-9]{4}", col);
  w <- grep("[0-9]+,[0-9]+", col)
  col2 <- col
  if (length(v) == length(col)){
col2 <- as.Date(col, format="%d.%m.%y")
  } else if (length(w) == length(col)) {
col2 <- as.numeric(gsub(",", "", col))
  }
  col2
}

myDf <- as.data.frame(lapply(myDf, my_convert), stringsAsFactors = FALSE)


--
GG


[[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] matrix which results singular but at the same time positive definite

2015-12-10 Thread Giorgio Garziano
Decrease the "tol" parameter specified into the "is.non.singular.matrix() call,
for example as:

m <- matrix(c( 1.904255e-12, -1.904255e-12, -8.238960e-13, -1.240294e-12,
   -1.904255e-12,  3.637979e-12,  1.364242e-12,  1.818989e-12,
   -8.238960e-13,  1.364242e-12,  4.809988e+00,  7.742369e-01,
   -1.240294e-12,  1.818989e-12,  7.742369e-01,  1.090411e+00),
nrow=4, ncol=4)


> m

  [,1]  [,2]  [,3]  [,4]

[1,]  1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12

[2,] -1.904255e-12  3.637979e-12  1.364242e-12  1.818989e-12

[3,] -8.238960e-13  1.364242e-12  4.809988e+00  7.742369e-01

[4,] -1.240294e-12  1.818989e-12  7.742369e-01  1.090411e+00


> print(is.non.singular.matrix(m, tol = 1e-24))
[1] TRUE

> print(is.positive.definite(m, tol=1e-18))
[1] TRUE


--

GG

http://around-r.blogspot.it





[[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] Use of R for estimation of Discrete Choice Models incorporating latent variables

2015-12-10 Thread Giorgio Garziano
My educated guess:

package: RSGHB

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

http://www.inside-r.org/packages/cran/RSGHB/docs/doHB


Wondering if also package ltm may help.

There is available R package search at:

http://rseek.org/


My apologies if abovementioned packages do not fit well your needs.

--
GG



[[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] change the x axis tickmarks when using plot function in drc package

2015-12-09 Thread Giorgio Garziano
Looking at the source code of the package drc, there is something that may 
somehow explain what
you are experiencing:

file: plot.drc.R, function addAxes(), lines 543-626

ceilingxTicks <- ceiling(log10(xaxisTicks[-1]))
...
xaxisTicks <- c(xaxisTicks[1], 10^(unique(ceilingxTicks)))

xLabels <- as.character(xaxisTicks)


I may suggest two options:


1.  provide the x labels at plot() call time:



   plot(mod, type="all", log="x", xtlab = c(-2, -1, 0, 1, 2), xlab="log(dose)")


2.  try to use the option logDose in drm():

  mod <- drm(y~log(dose), fct = LL.4(), logDose=10)
  plot(mod, type="all")

Not sure if that second option fits your needs.


--
GG


[[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] Custom manual legend in ggplot2

2015-12-09 Thread Giorgio Garziano
Last "+theme_bw()" to be deleted.

Try this:

ggplot(data1, aes(x=x1, y=y1))+
  geom_point()+
  geom_smooth(method="glm", family="gaussian",aes(linetype="equation1"))+
  geom_smooth(aes(x=x1, y=y1, linetype="equation2"),data=data2, method="glm", 
family="gaussian")+
  scale_linetype_manual(values = c("solid","dashed"),name="Equations",
labels = c("Equation 1","Equation 2"),guide="legend")+
  theme(plot.title = element_text(lineheight=.8, face="bold"), 
legend.position="top")


--

GG

http://around-r.blogspot.it




[[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] Custom manual legend in ggplot2

2015-12-09 Thread Giorgio Garziano
Try to look at the link:

http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/


Also consider:

help(theme)

legend.backgroundbackground of legend (element_rect; inherits from rect)
legend.margin   extra space added around legend (unit)
legend.key background underneath legend keys (element_rect; inherits from rect)
legend.key.size size of legend keys (unit; inherits from legend.key.size)
legend.key.heightkey background height (unit; inherits from legend.key.size)
legend.key.width key background width (unit; inherits from legend.key.size)
legend.text legend item labels (element_text; inherits from text)
legend.text.alignalignment of legend labels (number from 0 (left) to 1 
(right))
legend.titletitle of legend (element_text; inherits from title)
legend.title.align   alignment of legend title (number from 0 (left) to 1 
(right))
legend.position the position of legends ("none", "left", "right", "bottom", 
"top", or two-element numeric vector)
legend.direction layout of items in legends ("horizontal" or "vertical")
legend.justification anchor point for positioning legend inside plot ("center" 
or two-element numeric vector)
legend.box arrangement of multiple legends ("horizontal" or "vertical")
legend.box.just justification of each legend within the overall bounding box, 
when there are multiple legends ("top", "bottom", "left", or "right")

--

GG

[[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] column means dropping column minimum

2015-12-08 Thread Giorgio Garziano
First, your code has flaws in the assignment of NA and in passing na.rm=TRUE to 
colMeans().

It should be:

test2 <- test
for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]=NA}
print(test2)


samp1 samp2 samp3

16060NA

2506065

3NA9065

490NA90



print(colMeans(test2,na.rm = TRUE))

   samp1samp2samp3

66.7 70.0 73.3

For your purpose, I suggest the following:

apply(test, 2, function(x) { mean(x[-which.min(x)])})


GG



[[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] ts.intersect() not working

2015-11-10 Thread Giorgio Garziano
It appears to be a numerical precision issue introduced while computing the 
"end" value of a time series,
if not already specified at ts() input parameter level.

You may want to download the R source code:

  https://cran.r-project.org/src/base/R-3/R-3.2.2.tar.gz

and look into R-3.2.2\src\library\stats\R\ts.R, specifically at code block 
lines 52..64,
where "end" is handled.

Then look at block code 140-142 ts.R, where a comparison is performed in order 
to determine if
the time series are overlapping.

In your second scenario (b2, b3) it happens that:

> tsps
   [,1]   [,2]
[1,] 2009.58333 2009.7
[2,] 2009.5 2009.7
[3,]   12.0   12.0
> st <- max(tsps[1,])
> en <- min(tsps[2,])
> st
[1] 2009.7
> en
[1] 2009.5

And (st > en) triggers the "non-intersecting series" warning.

That issue has origin inside the ts() function in the "end" computation based 
on start, ndata and frequency.

What basically happens can be so replicated:

start = c(2009, 8)
end = c(2009,9)
frequency=12
ndata=2

start <- start[1L] + (start[2L] - 1)/frequency
start
[1] 2009.58333

end <- end[1L] + (end[2L] - 1)/frequency
end
[1] 2009.7

end <- start + (ndata - 1)/frequency
end
[1] 2009.5

Note the difference between the two "end" values above.

As workaround, you can specify the "end" parameter in the ts() call.


> b2 <- ts(data = c(10, 20), start = c(2009, 8), end = c(2009,9), frequency = 
> 12);
> b2
 Aug Sep
2009  10  20
>
> b3 <- ts(data = matrix(data = 4:6, nrow = 1), start = c(2009, 9), end = 
> c(2009,9), frequency = 12);
> b3
 Series 1 Series 2 Series 3
Sep 2009456
>
> bb <- ts.intersect(b2, b3);
> bb
 b2 b3.Series 1 b3.Series 2 b3.Series 3
Sep 2009 20   4   5   6


Hope this helps

--
GG

[[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] Problem in SVM model generation

2015-10-16 Thread Giorgio Garziano
>From R prompt, input:

memory.limit()

which returns the amount of memory available to R.

Then, before allocating that vector, run:

library(pryr)
mem_used()

To see current memory in use.

Should be: memory.limit() - mem_used() >= 2.4GBytes

--
GG


[[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] processing time line by line

2015-10-16 Thread Giorgio Garziano
I may suggest this tutorial:


http://www.stat.berkeley.edu/~nolan/stat133/Fall05/lectures/profilingEx.html


and this discussion:


http://stackoverflow.com/questions/3650862/how-to-efficiently-use-rprof-in-r


which inspired this example:


Rprof("profile1.out", line.profiling=TRUE)
for(i in 1:1) {
  rnorm(100,1,1);
  rbinom(1000,1,1)
  rbinom(1,1,1)
}
Rprof(NULL)
summaryRprof("profile1.out", lines = "show")

$by.self
   self.time self.pct total.time total.pct
#4  4.4486.72   4.44 86.72
#3  0.38 7.42   0.38  7.42
#2  0.30 5.86   0.30  5.86

$by.total
   total.time total.pct self.time self.pct
#4   4.44 86.72  4.4486.72
#3   0.38  7.42  0.38 7.42
#2   0.30  5.86  0.30 5.86

$by.line
   self.time self.pct total.time total.pct
#2  0.30 5.86   0.30  5.86
#3  0.38 7.42   0.38  7.42
#4  4.4486.72   4.44 86.72

$sample.interval
[1] 0.02

$sampling.time
[1] 5.12


--
GG

[[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] DeSolve package

2015-10-16 Thread Giorgio Garziano
It is likely the "p" variable is not defined in your R environment.



Inside your function model.LIDR, the variable "p" is used before being 
initialized

in any of the environments reachable by the search path, included the model.LIDR

function environment.



The remedy is to define and initialize "p" before it is being referenced (used).



It is not about any deSolve package specific error.



--

GG



[[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] Variable names conflict

2015-10-15 Thread Giorgio Garziano
May this be fine ?

foo <- function(df) {
  x <- df[, 1, drop = FALSE]
  available <- rev(letters[(letters %in% colnames(df)) == FALSE])
  colnames(x) <- available[1]
  dfOut <- data.frame(df, x)
  dfOut
}

Data <- data.frame(x = c(1, 2), y = c(3, 4))
foo(Data)

  x y z
1 1 3 1
2 2 4 2

--
GG



[[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] (no subject)

2015-10-04 Thread Giorgio Garziano
Good question.

> str(Empl[c(2,4)])
List of 2
$ family:List of 3
  ..$ spouse: chr "Fred"
  ..$ children  : num 3
  ..$ child.ages: num [1:3] 4 7 9
$ family:List of 3
  ..$ spouse: chr "Mary"
  ..$ children  : num 2
  ..$ child.ages: num [1:2] 14 17
>

> Empl[c(2,4)][1]
$family
$family$spouse
[1] "Fred"

$family$children
[1] 3

$family$child.ages
[1] 4 7 9


> Empl[c(2,4)][2]
$family
$family$spouse
[1] "Mary"

$family$children
[1] 2

$family$child.ages
[1] 14 17


> Empl[c(2,4)][[1]][1]
$spouse
[1] "Fred"

> Empl[c(2,4)][[2]][1]
$spouse
[1] "Mary"


> Empl[c(2,4)][[1]]$spouse
[1] "Fred"


> Empl[c(2,4)][[2]]$spouse
[1] "Mary"


[[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] denstrip package: densregion when density is not provided

2015-10-04 Thread Giorgio Garziano
It is likely you have some list structure you should not.
Check the class of the elements of your matrixes, to see if any list class 
shows up.

Not clear from your code what is "y" passed to densregion(..).

Anyway, one way to reproduce your error is the following:

# this does not work
> a <- list(a=1:10, b=30:40)
> a
$a
[1]  1  2  3  4  5  6  7  8  9 10

$b
[1] 30 31 32 33 34 35 36 37 38 39 40

rank(a, ties.method = "min", na.last = "keep")

Error in rank(a, ties.method = "min", na.last = "keep") :
  unimplemented type 'list' in 'greater'

# this works
b <- sample(1:10)
> b
[1]  8  9  5  2  4  1  7 10  3  6
> rank(b)
[1]  8  9  5  2  4  1  7 10  3  6
>

You may also try to debug the densregion() function.
Using RStudio it pretty straightforward.
Call this before running your code.

debug(densregion)

when executing densregion() the RStudio source-viewer will show up the 
densregion.default code and
step by step (F10) you can go through the code lines see what is going wrong.

To stop debugging, click red Stop button on console pane and then if you do not 
need to re-run the debugging,
call:

undebug(densregion)


Good luck.

--
GG

[[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] denstrip package: densregion when density is not provided

2015-10-03 Thread Giorgio Garziano
>From the "densregion" help page I can read that:

z is a matrix of densities on the grid defined by x and y,
with rows corresponding to elements of x
and columns corresponding to elements of y.

So in your scenario z must be a 3 rows x 100 columns matrix, if you like to
take advantage of densregion().

z cannot be a data frame, otherwise you get the error you mentioned.

Run this to verify.

require(denstrip)
set.seed(11)

x <- 0:2
nx <- length(x)
y <- seq(0, 1, length=100)
ny <- length(y)

# z is a matrix
z <- matrix(nrow=nx, ncol=ny)
for(i in 1:nx)
  z[i,] <- dnorm(y, 0, 1)

dim(z)
class(z)

# works
plot(x, type="n", ylim=c(-1, 1))
densregion(x, y, z, colmax="darkgreen")

# does not work
z.df <- data.frame(z)
densregion(x, y, z.df, colmax="darkgreen")

Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = 
decreasing)) :
  undefined columns selected


--
GG


[[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] Rayleigh Distribution

2015-10-02 Thread Giorgio Garziano
Similarly to what can be read on help(qqplot), however using Rayleigh 
distribution:

library(VGAM)
p <- ppoints(100)
x <- qrayleigh(p)
y <- rrayleigh(100)
qqplot(x,y)
qqline(y, distribution = function(p) qrayleigh(p),
   prob = c(0.1, 0.6), col = 2)

--
GG

[[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] problem of Mahalanobis distance matching using MatchIT

2015-10-02 Thread Giorgio Garziano
About the "distance = NA" issue, please see if this comment helps:

https://lists.gking.harvard.edu/pipermail/matchit/2011-January/000174.html


Furthermore, the Mahalanobis NA distance values are hard-wired in the code, 
file matchit.R:

  ## no distance for full mahalanobis matching
  if(fn1=="distance2mahalanobis"){
distance[1:length(distance)] <- NA
class(out2) <- c("matchit.mahalanobis","matchit")
  }


About the resulting MDM matrix, I was able to create some "unmatching" by 
changing T1
so that its values do not always exactly map 1:1 to a pair of values each one 
taken
from the distribution values set control and treated (x1_.., x2_..).

n<-100
set.seed(1023)
x1_contr<-runif(n,0,5)
x2_contr<-runif(n,0,5)
x_contr<-cbind(x1=x1_contr,x2=x2_contr)
x1_treat<-runif(n,1,6)
x2_treat<-runif(n,1,6)

x_treat<-cbind(x1=x1_treat,x2=x2_treat)

T1<-c(rep(0,n/2),rep(1,3*n/2))

X.all<-rbind(x_contr,x_treat)

my.data<-data.frame(T1,X.all)
rownames(my.data)<-paste("ID",1:dim(my.data)[1])

library(MatchIt)
mdm.out<-matchit(T1~x1+x2,data=my.data, method="nearest", 
distance="mahalanobis",
 mahvars=c("x1","x2"), caliper=0.15, replace=FALSE)

Sample sizes:
  Control Treated
All50 150
Matched50  50
Unmatched   0 100
Discarded   0   0


Hope this helps.

--

GG

[[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] merging tables based on both row and column names

2015-10-01 Thread Giorgio Garziano
Replacing na.omit() with !is.na() appears to improve performance with time.

  rm(list=ls())

  test1 <- (rbind(c(0.1,0.2),0.3,0.1))
  rownames(test1)=c('y1','y2','y3')
  colnames(test1) = c('x1','x2');
  test2 <- (rbind(c(0.8,0.9,0.5),c(0.5,0.1,0.6)))
  rownames(test2) = c('y2','y5')
  colnames(test2) = c('x1','x3','x2')

  solution_3 <- function(test1, test2) {
lTest12 <- list(test1, test2)
namesRow <- unique( unlist( lapply(lTest12, rownames)))
namesCol <- unique( unlist( lapply(lTest12, colnames)))
tmp1 <- sapply(lTest12, function(x) as.vector(x[match(namesRow, 
rownames(x)), match(namesCol, colnames(x))]))
tmp2 <- apply(tmp1, 1, function(x) { x[!is.na(x)] })
dimnames1 <- list(namesRow, namesCol)
tmp3 <- array(data = tmp2, dim = sapply(dimnames1, length), dimnames = 
dimnames1)
tmp3
  }

  system.time(for(i in 1:1) {solution_3(test1, test2)})




[[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] merging tables based on both row and column names

2015-10-01 Thread Giorgio Garziano
I reworked Frank Schwidom's solution to make it shorter than its original 
version.

  test1 <- (rbind(c(0.1,0.2),0.3,0.1))
  rownames(test1)=c('y1','y2','y3')
  colnames(test1) = c('x1','x2');
  test2 <- (rbind(c(0.8,0.9,0.5),c(0.5,0.1,0.6)))
  rownames(test2) = c('y2','y5')
  colnames(test2) = c('x1','x3','x2')

  lTest12 <- list(test1, test2)
  namesRow <- unique( unlist( lapply(lTest12, rownames)))
  namesCol <- unique( unlist( lapply(lTest12, colnames)))

# here reworked code starts

  tmp1 <- sapply(lTest12, function(x) as.vector( x[match(namesRow, 
rownames(x)), match(namesCol, colnames(x))]))
  tmp2 <- apply(tmp1, 1, function(x) { na.omit(x) })
  dimnames1 <- list(namesRow, namesCol)
  tmp3 <- array(data = tmp2, dim = sapply(dimnames1, length), dimnames = 
dimnames1)
  tmp3

  > paste(tmp3)
  [1] "0.1" "c(0.3, 0.8)" "0.1" "0.5" "0.2"
  [6] "c(0.3, 0.5)" "0.1" "0.6" "numeric(0)"  "0.9"
  [11] "numeric(0)"  "0.1"

  > tmp3
  x1   x2x3
  y1 0.1   0.2   Numeric,0
  y2 Numeric,2 Numeric,2 0.9
  y3 0.1   0.1   Numeric,0
  y5 0.5   0.6   0.1
  >

  > tmp3["y2","x1"]
  [[1]]
  [1] 0.3 0.8

  > tmp3["y2","x2"]
  [[1]]
  [1] 0.3 0.5


[[alternative HTML version deleted]]

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


Re: [R] Splitting data frame into columns with dplyr

2015-10-01 Thread Giorgio Garziano
library(dplyr)
df <- data.frame(z = rep(c("A", "B")), x = 1:6, y = 7:12) %>%
arrange(z)

temp <- reshape(df, v.names = c("x", "y"), idvar = c("x", "y"), timevar = "z", 
direction = "wide")
lA <- na.omit(temp[,c("x.A", "y.A")])
lB <- na.omit(temp[,c("x.B", "y.B")])
df.long <- as.data.frame(cbind(lA,lB))
colnames(df.long) <- c("A.x", "A.y", "B.x", "B.y")
df.long

  A.x A.y B.x B.y
1   1   7   2   8
2   3   9   4  10
3   5  11   6  12


Reference:

http://blog.wildintellect.com/blog/reshape


--
GG




[[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] (subscript) logical subscript too long

2015-10-01 Thread Giorgio Garziano
If you are running a 32-bit Windows, there are following upper limits:

https://cran.r-project.org/bin/windows/base/rw-FAQ.html#There-seems-to-be-a-limit-on-the-memory-it-uses_0021


starts by:

memory.limit(size=1920)

and try increasing value of size as a parameter for memory.limit().


I use Intel i5 Windows-7 64-bit 16GB RAM.


GG



From: Maram SAlem [mailto:marammagdysa...@gmail.com]
Sent: giovedì 1 ottobre 2015 14:12
To: Giorgio Garziano
Cc: r-help@r-project.org
Subject: Re: [R] (subscript) logical subscript too long

Thanks a lot Giorgio, I used

memory.limit(size=4096)

but got

 don't be silly!: your machine has a 4Gb address limit

I'm working on my Ph.D. thesis and I have a huge code of which this is just a 
very small part, so does this error mean that I need a new computer with 
extended capabilites to be able to execute my code?? I'm currently using intel 
core i3, windows 7

Thanks for helping.

Maram


On 1 October 2015 at 13:37, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Check your memory size by:

memory.limit()

try to increase it by:

memory.limit(size=4096)



From: Maram SAlem 
[mailto:marammagdysa...@gmail.com<mailto:marammagdysa...@gmail.com>]
Sent: giovedì 1 ottobre 2015 13:22
To: Giorgio Garziano
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] (subscript) logical subscript too long

Thanks Giorgio, I got it.

 I managed to reach the matrix s whose rows represent  all the possible 
combinations. Here is the code:

> n=12
> m=7
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))
> ED<-as.matrix(ED)
> lk<-which(rowSums(ED)<=(n-m))
> s<-ED[lk,]

The problem now is that the code works only for relatively small values of n 
and m, but when I use, for ex., n=20 and m=9, I got this error

> n=20
> m=9
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))

Error: cannot allocate vector of size 1.6 Gb

Any Suggestions please?

Thanks Again.
Maram

On 30 September 2015 at 17:41, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Be:

log <- (rowSums(ED) <= (n - m))


Compare the following two values:





length(log)





nrow(w)





--

GG


[[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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

Re: [R] (subscript) logical subscript too long

2015-10-01 Thread Giorgio Garziano
The “4096” was just an example.

Try:

memory.limit(size=3968)


Furthermore, to overcome memory size limits vs. in memory R data management 
beyond your 4Gb,
you may explore package “ff”.

--
Cheers,

GG

From: Maram SAlem [mailto:marammagdysa...@gmail.com]
Sent: giovedì 1 ottobre 2015 14:12
To: Giorgio Garziano
Cc: r-help@r-project.org
Subject: Re: [R] (subscript) logical subscript too long

Thanks a lot Giorgio, I used

memory.limit(size=4096)

but got

 don't be silly!: your machine has a 4Gb address limit

I'm working on my Ph.D. thesis and I have a huge code of which this is just a 
very small part, so does this error mean that I need a new computer with 
extended capabilites to be able to execute my code?? I'm currently using intel 
core i3, windows 7

Thanks for helping.

Maram


On 1 October 2015 at 13:37, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Check your memory size by:

memory.limit()

try to increase it by:

memory.limit(size=4096)



From: Maram SAlem 
[mailto:marammagdysa...@gmail.com<mailto:marammagdysa...@gmail.com>]
Sent: giovedì 1 ottobre 2015 13:22
To: Giorgio Garziano
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] (subscript) logical subscript too long

Thanks Giorgio, I got it.

 I managed to reach the matrix s whose rows represent  all the possible 
combinations. Here is the code:

> n=12
> m=7
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))
> ED<-as.matrix(ED)
> lk<-which(rowSums(ED)<=(n-m))
> s<-ED[lk,]

The problem now is that the code works only for relatively small values of n 
and m, but when I use, for ex., n=20 and m=9, I got this error

> n=20
> m=9
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))

Error: cannot allocate vector of size 1.6 Gb

Any Suggestions please?

Thanks Again.
Maram

On 30 September 2015 at 17:41, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Be:

log <- (rowSums(ED) <= (n - m))


Compare the following two values:





length(log)





nrow(w)





--

GG


[[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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

Re: [R] (subscript) logical subscript too long

2015-10-01 Thread Giorgio Garziano
Check your memory size by:

memory.limit()

try to increase it by:

memory.limit(size=4096)



From: Maram SAlem [mailto:marammagdysa...@gmail.com]
Sent: giovedì 1 ottobre 2015 13:22
To: Giorgio Garziano
Cc: r-help@r-project.org
Subject: Re: [R] (subscript) logical subscript too long

Thanks Giorgio, I got it.

 I managed to reach the matrix s whose rows represent  all the possible 
combinations. Here is the code:

> n=12
> m=7
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))
> ED<-as.matrix(ED)
> lk<-which(rowSums(ED)<=(n-m))
> s<-ED[lk,]

The problem now is that the code works only for relatively small values of n 
and m, but when I use, for ex., n=20 and m=9, I got this error

> n=20
> m=9
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))

Error: cannot allocate vector of size 1.6 Gb

Any Suggestions please?

Thanks Again.
Maram

On 30 September 2015 at 17:41, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Be:

log <- (rowSums(ED) <= (n - m))


Compare the following two values:





length(log)





nrow(w)





--

GG


[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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

Re: [R] (subscript) logical subscript too long

2015-09-30 Thread Giorgio Garziano
Be:

log <- (rowSums(ED) <= (n - m))


Compare the following two values:





length(log)





nrow(w)





--

GG


[[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] dplyr complete.cases(.) works one way but not another

2015-09-30 Thread Giorgio Garziano
The "pronoun dot"  is used in conjunction with %>% in dplyr (which imports 
magrittr).

See pag.9, paragraph "Placing lhs elsewhere in rhs call" of the document:

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

--
GG
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] dplyr complete.cases(.) works one way but not another

2015-09-30 Thread Giorgio Garziano
This works:

filter(mydata, complete.cases(mydata))

About dplyr "pronoun dot", see:

http://www.r-bloggers.com/dplyr-0-2/


--
GG




[[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] Theme white bands blue and grey or other color

2015-09-30 Thread Giorgio Garziano
  library(quantmod)
  getSymbols("YHOO")

  chartSeries(YHOO, theme="white")

  b1 <- addBBands(50,2)
  b1@params$colors$bg.col="#FF"
  b1

  b2 <- addBBands(100,2)
  b2@params$colors$bg.col="#FF"
  b2


[[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 functions called by my functions

2015-09-30 Thread Giorgio Garziano
See if this may help:


http://stackoverflow.com/questions/11872879/finding-out-which-functions-are-called-within-a-given-function


--

GG

[[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] flatten a list

2015-09-29 Thread Giorgio Garziano
To mention also:

temp <- list(1:3, list(letters[1:3], duh= 5:8),  zed=15:17)

library(rlist)
list.flatten(temp)


[[1]]

[1] 1 2 3



[[2]]

[1] "a" "b" "c"



$duh

[1] 5 6 7 8



$zed

[1] 15 16 17


---

Giorgio Garziano

[[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] flatten a list

2015-09-29 Thread Giorgio Garziano
If you need further info on flattening a list, check this out:

http://stackoverflow.com/questions/8139677/how-to-flatten-a-list-to-a-list-without-coercion/8139959#8139959




[[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] Creating World Map with Points

2015-09-29 Thread Giorgio Garziano
I had to update low/up longitude and latitude attributes of the zoom=1 map
with those of zoom=2 map.

library(ggmap)

# the zoom=2 map works with ggmap(), however it does not show Americas and all 
Pacific Ocean

map <- get_map(location = 'India', zoom=2)
bb <- attr(map, "bb")
bb

# the zoom=1 shows all entire world

map <- get_map(location = 'India', zoom=1)
attr(map, "bb")

# changing latitude and longitude upper and lower bounds
attr(map, "bb") <- bb
bb

# now your code
n <- 1000
set.seed(1234)
long <- runif(n,-180, 180)
lat <- runif(n,-90, 90)
size <- runif(n, 1,5)
data <- cbind(long, lat, size)
data <- as.data.frame(data)

gpl <- ggmap(map) +
  geom_point(data = data, aes(x = long, y = lat), size=data$size,
     alpha=1, color="blue", show.legend  = F)
plot(gpl)


--
Giorgio Garziano


[[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] merging tables based on both row and column names

2015-09-29 Thread Giorgio Garziano
Another approach:

test1 <- data.frame(rbind(c(0.1,0.2),0.3,0.1))
rownames(test1) = c('y1','y2','y3')
colnames(test1) = c('x1','x2');
test2 <- data.frame(rbind(c(0.8,0.9,0.5),c(0.5,0.1,0.6)))
rownames(test2) = c('y2','y5')
colnames(test2) = c('x1','x3','x2')

> test1
x1  x2
y1 0.1 0.2
y2 0.3 0.3
y3 0.1 0.1

> test2
x1  x3  x2
y2 0.8 0.9 0.5
y5 0.5 0.1 0.6

t1.r <- rownames(test1)
t2.r <- rownames(test2)
t1.c <- colnames(test1)
t2.c <- colnames(test2)

col <- unique(union(t1.c, t2.c))
ncol <- length(col)
row <- unique(union(t1.r, t2.r))
nrow <- length(row)

m <- matrix(list(), nrow=nrow, ncol=ncol)
rownames(m) <- row
colnames(m) <- col

for (i in 1:nrow) {
 for (j in 1:ncol) {
 rowname <- row[i]
 colname <- col[j]
 v <- c()
 if (!is.null(test1[rowname, colname]) && !is.na(test1[rowname, colname])) {
   v <- c(test1[rowname, colname])
 }
 if (!is.null(test2[rowname, colname]) && !is.na(test2[rowname, colname])) {
   v <- c(v, test2[rowname, colname])
 }
 if (!is.null(v)) {
   m[rowname, colname] <- list(v)
 } else {
   m[rowname, colname] <- NA
 }
  }
}


> m
x1    x2    x3
y1 0.1   0.2   NA
y2 Numeric,2 Numeric,2 0.9
y3 0.1   0.1   NA
y5 0.5   0.6   0.1


> m["y2",]
$x1
[1] 0.3 0.8

$x2
[1] 0.3 0.5

$x3
[1] 0.9

--
Giorgio Garziano

[[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] a question on write.table

2015-09-28 Thread Giorgio Garziano
Try this:

X<-c("A","B","C","D","E")
Y<-c(0,1,2,3,4)

for (i in 0:3) {
  Y<-Y+i
  data<-data.frame(X,Y)
  fe.flag <- file.exists("test.csv")
  write.table(data, "test.csv", row.names = FALSE, col.names = !fe.flag, 
sep=";", append = fe.flag)
}




[[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] Hide Legend

2015-09-28 Thread Giorgio Garziano
library(quantmod)



getSymbols("YHOO")

chartSeries(YHOO, theme="white", type='line')

chartSeries(YHOO, theme="white", type='line', TA=NULL)

chartSeries(Cl(YHOO), theme="white", type='line')

chartSeries(YHOO, theme="white", type='line', name="")


chartSeries(YHOO, type='line', theme='white')

b <- BBands(HLC(YHOO))
addTa(b, legend=NULL)

--

Giorgio Garziano



[[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] Rattle installation

2015-09-27 Thread Giorgio Garziano
This is what I can observe for rattle 3.5.0 on Windows

pack <- available.packages()

pack["rattle","Depends"]
[1] "R (>= 2.13.0), RGtk2"


pack["rattle", "Suggests"]



[1] "pmml (>= 1.2.13), bitops, colorspace, ada, amap, arules,\narulesViz, 
biclust, cairoDevice, cba, corrplot, descr, doBy,\ndplyr, e1071, ellipse, 
fBasics, foreign, fpc, gdata, ggdendro,\nggplot2, gplots, graph, grid, gtools, 
gWidgetsRGtk2, hmeasure,\nHmisc, kernlab, Matrix, methods, mice, nnet, 
odfWeave, party,\nplaywith, plyr, psych, randomForest, RBGL, 
RColorBrewer,\nreadxl, reshape, rggobi, RGtk2Extras, ROCR, RODBC, 
rpart,\nrpart.plot, SnowballC, stringr, survival, timeDate, tm,\nverification, 
wskm, XML, pkgDepTools, Rgraphviz"


pack["rattle", "Imports"]

[1] NA

In general, the package installation by RStudio is straightforward as it takes 
care of dependencies.

--
Giorgio Garziano

[[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] Analysis of causal relations between rare (categorical) events

2015-09-26 Thread Giorgio Garziano
Hi,

I may suggest the following book introducing event history analysis with R and
showing some datasets to work with:

https://www.crcpress.com/Event-History-Analysis-with-R/Brostrm/9781439831649

I am not sure it can answer all your questions about your specific problem 
(rare events),
however it may help.

Giorgio Garziano





[[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] Randomness tests

2015-09-25 Thread Giorgio Garziano
By "interested in any kind of deviation from randomness", I mean that
I would like to apply all "randtests" R package randomness tests, if
they give reliable results for {-1, 1} sequences.


[[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] Randomness tests

2015-09-25 Thread Giorgio Garziano
Good suggestion, thanks.

-Original Message-
From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] 
Sent: venerdì 25 settembre 2015 18:49
To: Giorgio Garziano; r-help@r-project.org
Subject: Re: [R] Randomness tests

You are way off topic for this list. Perhaps stats.stackexchange.com would be a 
better place to ask such a question.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On September 25, 2015 9:31:15 AM PDT, Giorgio Garziano 
 wrote:
>I am interested in any kind of deviation from randomness.
>
>I would like to know if the fact that a time series can take values 
>only from the set {-1, 1} restricts the type of randomness tests that 
>can be done.
>
>--
>
>Giorgio Garziano
>
>
>
>   [[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] Randomness tests

2015-09-25 Thread Giorgio Garziano
I am interested in any kind of deviation from randomness.

I would like to know if the fact that a time series can take values only from 
the set {-1, 1} restricts
the type of randomness tests that can be done.

--

Giorgio Garziano



[[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] Quantmod several indicators

2015-09-25 Thread Giorgio Garziano
Hi,

Both following code examples plot Bollinger bands over the ticker main plot
and William's Percent below the main plot.

1. chartSeries(YHOO,theme="white",TA = c(addBBands(200,2), addWPR(n=300)))

2. chartSeries(IB,theme="white",TA = c(addBBands(200,2)))
   addWPR(n=300)

In general, if you like to plot indipendently a trading indicator computed by 
quantmod,
you can do:

wpr <- addWPR(n=300)
plot(wpr@TA.values, type='l')   -- or any other R plot library you like

as in @TA.values are stored trading indicator values for any quantmod indicator.


Giorgio Garziano



[[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] Randomness tests

2015-09-22 Thread Giorgio Garziano
Hi,

to test randomness of time series whose values can only be +1 and -1, are all 
following
randomness tests applicable or only a part of ?

cox.stuart.test
difference.sign.test
bartels.rank.test
rank.test
runs.test

Tests provided by the randtests R package.

Thanks.

Giorgio Garziano



[[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] Variance-covariance matrix

2015-05-10 Thread Giorgio Garziano
Hi Tsjerk,

Yes, I understand your point. Thanks for drawing my attention on that aspect.

Let me then rephrase my question.

I would need some R package function able to compute the variance-covariance 
matrix
for multivariate series as defined at:

http://stattrek.com/matrix-algebra/covariance-matrix.aspx


About what outlined in the book reference I mentioned, I shall open a separate 
thread
in the case.

Thanks.

---

Giorgio

Genoa, Italy

From: Tsjerk Wassenaar [mailto:tsje...@gmail.com]
Sent: domenica 10 maggio 2015 22:31
To: Giorgio Garziano
Cc: r-help@r-project.org
Subject: Re: [R] Variance-covariance matrix

Hi Giorgio,

This is for a multivariate time series. x1 is variable 1 of the observation 
vector x, x2, variable 2, etc. If you need x(i) and x(i+1), etc, then you're 
looking for the autocovariance/autocorrelation matrix, which is a quite 
different thing (and David showed the way). You can easily see that you don't 
have N-1 degrees of freedom per entry, because you have fewer 'observations' 
for larger lag times.

Cheers,

Tsjerk



On Sun, May 10, 2015 at 10:25 PM, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Hi Tsjerk,

Yes, seriously.

Time series:

X = [x1, x2, x3, ,xn]

The variance-covariance matrix is V matrix:

V=


Σ x12 / (N-1)

Σ x1 x2 / (N-1)

. . .

Σ x1 xn / (N-1)

Σ x2 x1 / (N-1)

Σ x22 / (N-1)

. . .

Σ x2 xn / (N-1)

. . .

. . .

. . .

. . .

Σ xn x1 / (N-1)

Σ xn x2 / (N-1)

. . .

Σ xn2 / (N-1)




Reference: “Time series and its applications – with R examples”, Springer,
 $7.8 “Principal Components” pag. 468, 469

Cheers,

Giorgio


From: Tsjerk Wassenaar [mailto:tsje...@gmail.com<mailto:tsje...@gmail.com>]
Sent: domenica 10 maggio 2015 22:11

To: Giorgio Garziano
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] Variance-covariance matrix

Hi Giorgio,

For a univariate time series? Seriously?

data <- rnorm(10,2,1)
as.matrix(var(data))

Cheers,

Tsjerk


On Sun, May 10, 2015 at 9:54 PM, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Hi,

Actually as variance-covariance matrix I mean:

http://stattrek.com/matrix-algebra/covariance-matrix.aspx

that I compute by:

data <- rnorm(10,2,1)
n <- length(data)
data.center <- scale(data, center=TRUE, scale=FALSE)
var.cov.mat <- (1/(n-1)) * data.center %*% t(data.center)

--
Giorgio Garziano


-Original Message-
From: David Winsemius 
[mailto:dwinsem...@comcast.net<mailto:dwinsem...@comcast.net>]
Sent: domenica 10 maggio 2015 21:27
To: Giorgio Garziano
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] Variance-covariance matrix


On May 10, 2015, at 4:27 AM, Giorgio Garziano wrote:

> Hi,
>
> I am looking for a R package providing with variance-covariance matrix 
> computation of univariate time series.
>
> Please, any suggestions ?

If you mean the auto-correlation function, then the stats package (loaded by 
default at startup) has facilities:

?acf
# also same help page describes partial auto-correlation function
#Auto- and Cross- Covariance and -Correlation Function Estimation

--

David Winsemius
Alameda, CA, USA

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



--
Tsjerk A. Wassenaar, Ph.D.



--
Tsjerk A. Wassenaar, Ph.D.

[[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] Variance-covariance matrix

2015-05-10 Thread Giorgio Garziano
Hi Tsjerk,

Yes, seriously.

Time series:

X = [x1, x2, x3, ,xn]

The variance-covariance matrix is V matrix:

V=


Σ x12 / (N-1)

Σ x1 x2 / (N-1)

. . .

Σ x1 xn / (N-1)

Σ x2 x1 / (N-1)

Σ x22 / (N-1)

. . .

Σ x2 xn / (N-1)

. . .

. . .

. . .

. . .

Σ xn x1 / (N-1)

Σ xn x2 / (N-1)

. . .

Σ xn2 / (N-1)




Reference: “Time series and its applications – with R examples”, Springer,
 $7.8 “Principal Components” pag. 468, 469

Cheers,

Giorgio


From: Tsjerk Wassenaar [mailto:tsje...@gmail.com]
Sent: domenica 10 maggio 2015 22:11
To: Giorgio Garziano
Cc: r-help@r-project.org
Subject: Re: [R] Variance-covariance matrix

Hi Giorgio,

For a univariate time series? Seriously?

data <- rnorm(10,2,1)
as.matrix(var(data))

Cheers,

Tsjerk


On Sun, May 10, 2015 at 9:54 PM, Giorgio Garziano 
mailto:giorgio.garzi...@ericsson.com>> wrote:
Hi,

Actually as variance-covariance matrix I mean:

http://stattrek.com/matrix-algebra/covariance-matrix.aspx

that I compute by:

data <- rnorm(10,2,1)
n <- length(data)
data.center <- scale(data, center=TRUE, scale=FALSE)
var.cov.mat <- (1/(n-1)) * data.center %*% t(data.center)

--
Giorgio Garziano


-Original Message-
From: David Winsemius 
[mailto:dwinsem...@comcast.net<mailto:dwinsem...@comcast.net>]
Sent: domenica 10 maggio 2015 21:27
To: Giorgio Garziano
Cc: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] Variance-covariance matrix


On May 10, 2015, at 4:27 AM, Giorgio Garziano wrote:

> Hi,
>
> I am looking for a R package providing with variance-covariance matrix 
> computation of univariate time series.
>
> Please, any suggestions ?

If you mean the auto-correlation function, then the stats package (loaded by 
default at startup) has facilities:

?acf
# also same help page describes partial auto-correlation function
#Auto- and Cross- Covariance and -Correlation Function Estimation

--

David Winsemius
Alameda, CA, USA

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



--
Tsjerk A. Wassenaar, Ph.D.

[[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] Variance-covariance matrix

2015-05-10 Thread Giorgio Garziano
Hi,

Actually as variance-covariance matrix I mean:

http://stattrek.com/matrix-algebra/covariance-matrix.aspx

that I compute by:

data <- rnorm(10,2,1)
n <- length(data)
data.center <- scale(data, center=TRUE, scale=FALSE)
var.cov.mat <- (1/(n-1)) * data.center %*% t(data.center)

--
Giorgio Garziano 


-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: domenica 10 maggio 2015 21:27
To: Giorgio Garziano
Cc: r-help@r-project.org
Subject: Re: [R] Variance-covariance matrix


On May 10, 2015, at 4:27 AM, Giorgio Garziano wrote:

> Hi,
> 
> I am looking for a R package providing with variance-covariance matrix 
> computation of univariate time series.
> 
> Please, any suggestions ?

If you mean the auto-correlation function, then the stats package (loaded by 
default at startup) has facilities:

?acf
# also same help page describes partial auto-correlation function
#Auto- and Cross- Covariance and -Correlation Function Estimation

-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Variance-covariance matrix

2015-05-10 Thread Giorgio Garziano
Hi,

I am looking for a R package providing with variance-covariance matrix 
computation of univariate time series.

Please, any suggestions ?

Regards,

Giorgio


[[alternative HTML version deleted]]

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


Re: [R] Question about base::rank results

2015-04-27 Thread Giorgio Garziano
Ok. Thanks for your explanation.

Cheers,
Giorgio Garziano

-Original Message-
From: Rolf Turner [mailto:r.tur...@auckland.ac.nz] 
Sent: lunedì 27 aprile 2015 09:24
To: Giorgio Garziano; r-help@r-project.org
Subject: Re: [R] Question about base::rank results

On 26/04/15 20:17, Giorgio Garziano wrote:
> Hi,
>
> I cannot understand why rank(x) behaves as outlined below. Based on 
> the results of first x vector values ranking, which is as expected in 
> my opinion, I cannot explain the following results.
>
>> x <- c(12,34,15,77,78)
>> x[rank(x)]
> [1] 12 15 34 77 78  (OK)
>
>> x <- c(12,34,15,77,78,22)
>> x[rank(x)]
> [1] 12 77 34 78 22 15   (?)
>
>> x <- c(12,34,77,15,78)
>> x[rank(x)]
> [1] 12 77 15 34 78  (?)
>
> Please any feedback ? Thanks.


What did you expect to get?

To take your 2nd example:

x <- c(12,34,15,77,78,22)
x[rank(x)]
[1] 12 77 34 78 22 15   (?)

Why (?) ?

The rank of 12 is 1.
The rank of 34 is 4.
The rank of 15 is 2.
The rank of 77 is 5.
The rank of 78 is 6.
The rank of 22 is 3.

Thus x[rank(x)] gives you the 1st, 4th, 2nd, 5th, 6th and 3rd entries of x.  In 
that order.

What on earth is puzzling you?

I can think of no good reason for ever looking at x[rank(x)].

Perhaps, judging from your first example which you say is "OK", you want 
x[order(x)].

cheers,

Rolf Turner

--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Question about base::rank results

2015-04-27 Thread Giorgio Garziano
Hi,

I cannot understand why rank(x) behaves as outlined below.
Based on the results of first x vector values ranking, which is as expected in 
my opinion,
I cannot explain the following results.

> x <- c(12,34,15,77,78)
> x[rank(x)]
[1] 12 15 34 77 78  (OK)

> x <- c(12,34,15,77,78,22)
> x[rank(x)]
[1] 12 77 34 78 22 15   (?)

> x <- c(12,34,77,15,78)
> x[rank(x)]
[1] 12 77 15 34 78  (?)

Please any feedback ? Thanks.

BR,

Giorgio Garziano



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