Re: [R] R parallel / foreach - aggregation of results

2015-08-01 Thread Martin Spindler
Dear Jim,

Thank you very much for your response. It seems to work now, but the return 
value is not the required matrix but a list of matrices (one for each repition 
j).
Any idea how it is possible to return only the last matrix and not all?

Thanks and best,

Martin
 
 

Gesendet: Freitag, 31. Juli 2015 um 18:22 Uhr
Von: "jim holtman" 
An: "Martin Spindler" 
Cc: "r-help@r-project.org" 
Betreff: Re: [R] R parallel / foreach - aggregation of results

Try this chance to actually return values:
 
 
library(doParallel)
Simpar3 <- function(n1) {
   L2distance <- matrix(NA, ncol=n1, nrow=n1)
   data <- rnorm(n1)
   diag(L2distance)=0
   cl <- makeCluster(4)
   registerDoParallel(cl)
   x <- foreach(j=1:n1)  %dopar% {
 library(np)
 datj <- data[j]
 for(k in j:n1) {
   L2distance[j,k] <- k*datj
 }
 L2distance  # return the value
   }
   stopCluster(cl)
   return(x)
 }
 Res <- Simpar3(100)
 

Jim Holtman
Data Munger Guru
 
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it. 
On Fri, Jul 31, 2015 at 8:39 AM, Martin Spindler  
wrote:Dear all,

when I am running the code attached below, it seems that no results are 
returned, only the predefined NAs. What mistake do I make?
Any comments and help is highly appreciated.

Thanks and best,

Martin


Simpar3 <- function(n1) {
  L2distance <- matrix(NA, ncol=n1, nrow=n1)
  data <- rnorm(n1)
  diag(L2distance)=0
  cl <- makeCluster(4)
  registerDoParallel(cl)
  foreach(j=1:n1)  %dopar% {
    library(np)
    datj <- data[j]
    for(k in j:n1) {
      L2distance[j,k] <- k*datj
    }
  }
  stopCluster(cl)
  return(L2distance)
}

Res <- Simpar3(100)

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

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

[R] R parallel / foreach - aggregation of results

2015-07-31 Thread Martin Spindler
Dear all,

when I am running the code attached below, it seems that no results are 
returned, only the predefined NAs. What mistake do I make?
Any comments and help is highly appreciated.

Thanks and best,

Martin


Simpar3 <- function(n1) {
  L2distance <- matrix(NA, ncol=n1, nrow=n1)
  data <- rnorm(n1)
  diag(L2distance)=0
  cl <- makeCluster(4)
  registerDoParallel(cl)
  foreach(j=1:n1)  %dopar% {
library(np)
datj <- data[j]
for(k in j:n1) {
  L2distance[j,k] <- k*datj
}
  }
  stopCluster(cl)
  return(L2distance)
}

Res <- Simpar3(100)

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

2015-07-31 Thread Martin Spindler
Thank you very much to you both for your help.

I knew that parallelizing has some additional "overhead" costs, but I was 
surprised be the order of magnitude (it was 10 times slower.) Therefore I 
thought I made some mistake or that there is a more clever way to do it.

Best,

Martin
 
 

Gesendet: Donnerstag, 30. Juli 2015 um 15:28 Uhr
Von: "jim holtman" 
An: "Jeff Newmiller" 
Cc: "Martin Spindler" , "r-help@r-project.org" 

Betreff: Re: [R] R parallel - slow speed

I ran a test on my Windows box with 4 CPUs.  THere were 4 RScript processes 
started in response to the request for a cluster of 4.  Each of these ran for 
an elapsed time of around 23 seconds, making the median time around 0.2 seconds 
for 100 iterations as reported by microbenchmark.  The 'apply' only takes about 
0.003 seconds for a single iteration - again what microbenchmark is reporting.
 
The 4 RScript processes each use about 3 CPU seconds in the 23 seconds of 
elapsed time, most of that is probably the communication and startup time for 
the processes and reporting results.
 
So as was pointed out previous there is overhead is running in parallel.  You 
probably have to have at least several seconds of heavy computation for a 
iteration to make trying to parallelize something.  You should also investigate 
exactly what is happening on your system so that you can account for the time 
being spent.
 

Jim Holtman
Data Munger Guru
 
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it. 
On Thu, Jul 30, 2015 at 8:56 AM, Jeff Newmiller  
wrote:Parallelizing comes at a price... and there is no guarantee that you can 
afford it. Vectorizing your algorithms is often a better approach. 
Microbenchmarking  is usually overkill for evaluating parallelizing.

You assume 4 cores... but many CPUs have 2 cores and use hyperthreading to make 
each core look like two.

The operating system can make a difference also... Windows processes are more 
expensive to start and communicate between than *nix processes are. In 
particular, Windows seems to require duplicated RAM pages while *nix can share 
process RAM (at least until they are written to) so you end up needing more 
memory and disk paging of virtual memory becomes more likely.
---
Jeff Newmiller                        The     .       .  Go Live...
DCN:        Basics: ##.#.   
    ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On July 30, 2015 8:26:34 AM EDT, Martin Spindler 
 wrote:
>Dear all,
>
>I am trying to parallelize the function npnewpar given below. When I am
>comparing an application of "apply" with "parApply" the parallelized
>version seems to be much slower (cf output below). Therefore I would
>like to ask how the function could be parallelized more efficient.
>(With increasing sample size the difference becomes smaller, but I was
>wondering about this big differences and how it could be improved.)
>
>Thank you very much for help in advance!
>
>Best,
>
>Martin
>
>
>library(microbenchmark)
>library(doParallel)
>
>n <- 500
>y <- rnorm(n)
>Xc <- rnorm(n)
>Xd <- sample(c(0,1), replace=TRUE)
>Weights <- diag(n)
>n1 <- 50
>Xeval <- cbind(rnorm(n1), sample(c(0,1), n1, replace=TRUE))
>
>
>detectCores()
>cl <- makeCluster(4)
>registerDoParallel(cl)
>microbenchmark(apply(Xeval, 1, npnewpar, y=y, Xc=Xc, Xd = Xd,
>Weights=Weights, h=0.5),  parApply(cl, Xeval, 1, npnewpar, y=y, Xc=Xc,
>Xd = Xd, Weights=Weights, h=0.5), times=100)
>stopCluster(cl)
>
>
>Unit: milliseconds
>                           expr       min        lq      mean    median
>apply(Xeval, 1, npnewpar, y = y, Xc = Xc, Xd = Xd, Weights = Weights,
>   h = 0.5)  4.674914  4.726463  5.455323  4.771016
>parApply(cl, Xeval, 1, npnewpar, y = y, Xc = Xc, Xd = Xd, Weights =
>Weights,      h = 0.5) 34.168250 35.434829 56.553296 39.438899
>        uq       max neval
>  4.843324  57.01519   100
> 49.777265 347.77887   100
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>npnewpar <- function(y, Xc, Xd, Weights, h, xeval) {
>  xc <- xeval[1]
>  xd <- xeval[2]
>  l <- function(x,X) {
>    w <-  Weights[x,X]
>    return(w)
>  }
>  u <- (Xc-xc)/h
>  #K <- kernel(u)
>  K <- dnorm(u)
>  L <- l(xd,Xd)
>  nom <- sum(y*K*L)
>  denom <- sum(K*L)
>  ghat <- nom/denom
>  return

Re: [R] R parallel - slow speed

2015-07-31 Thread Martin Spindler
Thank you very much for your help.
 
I tried it under Unix and then the parallel version was faster than under 
Windows (but still slower than the non parall version). This is an important 
point to keep in mind. Thanks for this.
 
Best,
 
Martin

 
 

Gesendet: Donnerstag, 30. Juli 2015 um 14:56 Uhr
Von: "Jeff Newmiller" 
An: "Martin Spindler" , "r-help@r-project.org" 

Betreff: Re: [R] R parallel - slow speed
Parallelizing comes at a price... and there is no guarantee that you can afford 
it. Vectorizing your algorithms is often a better approach. Microbenchmarking 
is usually overkill for evaluating parallelizing.

You assume 4 cores... but many CPUs have 2 cores and use hyperthreading to make 
each core look like two.

The operating system can make a difference also... Windows processes are more 
expensive to start and communicate between than *nix processes are. In 
particular, Windows seems to require duplicated RAM pages while *nix can share 
process RAM (at least until they are written to) so you end up needing more 
memory and disk paging of virtual memory becomes more likely.
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---
Sent from my phone. Please excuse my brevity.

On July 30, 2015 8:26:34 AM EDT, Martin Spindler  wrote:
>Dear all,
>
>I am trying to parallelize the function npnewpar given below. When I am
>comparing an application of "apply" with "parApply" the parallelized
>version seems to be much slower (cf output below). Therefore I would
>like to ask how the function could be parallelized more efficient.
>(With increasing sample size the difference becomes smaller, but I was
>wondering about this big differences and how it could be improved.)
>
>Thank you very much for help in advance!
>
>Best,
>
>Martin
>
>
>library(microbenchmark)
>library(doParallel)
>
>n <- 500
>y <- rnorm(n)
>Xc <- rnorm(n)
>Xd <- sample(c(0,1), replace=TRUE)
>Weights <- diag(n)
>n1 <- 50
>Xeval <- cbind(rnorm(n1), sample(c(0,1), n1, replace=TRUE))
>
>
>detectCores()
>cl <- makeCluster(4)
>registerDoParallel(cl)
>microbenchmark(apply(Xeval, 1, npnewpar, y=y, Xc=Xc, Xd = Xd,
>Weights=Weights, h=0.5), parApply(cl, Xeval, 1, npnewpar, y=y, Xc=Xc,
>Xd = Xd, Weights=Weights, h=0.5), times=100)
>stopCluster(cl)
>
>
>Unit: milliseconds
> expr min lq mean median
>apply(Xeval, 1, npnewpar, y = y, Xc = Xc, Xd = Xd, Weights = Weights,
> h = 0.5) 4.674914 4.726463 5.455323 4.771016
>parApply(cl, Xeval, 1, npnewpar, y = y, Xc = Xc, Xd = Xd, Weights =
>Weights, h = 0.5) 34.168250 35.434829 56.553296 39.438899
> uq max neval
> 4.843324 57.01519 100
> 49.777265 347.77887 100
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>npnewpar <- function(y, Xc, Xd, Weights, h, xeval) {
> xc <- xeval[1]
> xd <- xeval[2]
> l <- function(x,X) {
> w <- Weights[x,X]
> return(w)
> }
> u <- (Xc-xc)/h
> #K <- kernel(u)
> K <- dnorm(u)
> L <- l(xd,Xd)
> nom <- sum(y*K*L)
> denom <- sum(K*L)
> ghat <- nom/denom
> return(ghat)
>}
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html[http://www.R-project.org/posting-guide.html]
>and provide commented, minimal, self-contained, reproducible code.
 

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

[R] R parallel - slow speed

2015-07-30 Thread Martin Spindler
Dear all,

I am trying to parallelize the function npnewpar given below. When I am 
comparing an application of "apply" with "parApply" the parallelized version 
seems to be much slower (cf output below). Therefore I would like to ask how 
the function could be parallelized more efficient. (With increasing sample size 
the difference becomes smaller, but I was wondering about this big differences 
and how it could be improved.)

Thank you very much for help in advance!

Best,

Martin


library(microbenchmark)
library(doParallel)

n <- 500
y <- rnorm(n)
Xc <- rnorm(n)
Xd <- sample(c(0,1), replace=TRUE)
Weights <- diag(n)
n1 <- 50
Xeval <- cbind(rnorm(n1), sample(c(0,1), n1, replace=TRUE))


detectCores()
cl <- makeCluster(4)
registerDoParallel(cl)
microbenchmark(apply(Xeval, 1, npnewpar, y=y, Xc=Xc, Xd = Xd, Weights=Weights, 
h=0.5),  parApply(cl, Xeval, 1, npnewpar, y=y, Xc=Xc, Xd = Xd, Weights=Weights, 
h=0.5), times=100)
stopCluster(cl)


Unit: milliseconds

   expr   minlq  meanmedian
apply(Xeval, 1, npnewpar, y = y, Xc = Xc, Xd = Xd, Weights = Weights,   
   h = 0.5)  4.674914  4.726463  5.455323  4.771016
 parApply(cl, Xeval, 1, npnewpar, y = y, Xc = Xc, Xd = Xd, Weights = Weights,   
   h = 0.5) 34.168250 35.434829 56.553296 39.438899
uq   max neval
  4.843324  57.01519   100
 49.777265 347.77887   100














npnewpar <- function(y, Xc, Xd, Weights, h, xeval) {
  xc <- xeval[1]
  xd <- xeval[2]
  l <- function(x,X) {
w <-  Weights[x,X]
return(w)
  }
  u <- (Xc-xc)/h
  #K <- kernel(u)
  K <- dnorm(u)
  L <- l(xd,Xd)
  nom <- sum(y*K*L)
  denom <- sum(K*L)
  ghat <- nom/denom
  return(ghat)
}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
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 with predict.lm()

2015-04-29 Thread Martin Spindler
Thank you! I think I now understand where the problem was.

Best,

Martin
 
 

Gesendet: Mittwoch, 29. April 2015 um 16:50 Uhr
Von: "David L Carlson" 
An: "Martin Spindler" , "r-help@r-project.org" 

Betreff: RE: [R] Problem with predict.lm()
Since you passed a matrix to lm() and then a data.frame to predict(), predict 
can't match up what variables to use for the prediction so it falls back on the 
original data. This seems to work:

> set.seed(42)
> y <- rnorm(100)
> X <- matrix(rnorm(100*10), ncol=10)
> Xd <- data.frame(X)
> lm <- lm(y~., Xd)
> Xnew <- matrix(rnorm(100*20), ncol=10)
> Xnewd <- data.frame(Xnew)
> ynew <- predict(lm, newdata=Xnewd)
> head(ynew)
1 2 3 4 5 6
0.35404067 0.14073495 -0.45442499 0.31065562 -0.02091366 0.25358175
> head(predict(lm))
1 2 3 4 5 6
0.75474817 0.06024122 -0.27221466 -0.20344713 0.20218135 -0.24045859
>

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Spindler
Sent: Wednesday, April 29, 2015 9:21 AM
To: r-help@r-project.org
Subject: [R] Problem with predict.lm()

Dear all,
 
the following example somehow uses the "old data" (X) to make the predictions, 
but not the new data Xnew as intended.
 
y <- rnorm(100)
X <- matrix(rnorm(100*10), ncol=10)
lm <- lm(y~X)
Xnew <- matrix(rnorm(100*20), ncol=10)
ynew <- predict(lm, newdata=as.data.frame(Xnew)) #prediction in not made for 
Xnew
 
How can I foce predict.lm to use use the new data?
 
Thank you very much for your efforts in advance!
 
Best,
 
Martin

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

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

Re: [R] Problem with predict.lm()

2015-04-29 Thread Martin Spindler
Dear Arnab,
 
Thank you very much for your reply. It does not give an error message.
The problem is that predict does "work and predict" on the old data and does 
not make the predictions with the provided new data.
 
Best,
 
Martin
 
 

Gesendet: Mittwoch, 29. April 2015 um 16:51 Uhr
Von: "ARNAB KR MAITY" 
An: "Martin Spindler" , "r-help@r-project.org" 

Betreff: Re: [R] Problem with predict.lm()

Hi,
 
It seems to be working in my R. Although it is throwing the warning message
 
Warning message:
 
'newdata' had 200 rows but variables found have 100 rows 
 
 y
  [1] -1.071307580  0.102414204 -0.965046207  1.386057875  0.726835339
  [6] -0.186549950 -0.777144258  1.137210314 -1.069446945 -0.696084338
 [11] -0.467686285  0.997316781  0.776265490 -1.385720997 -0.007438381
 [16]  0.302821728  0.024075173 -0.590401970  0.877104292  0.652724314
 [21]  2.142135078  2.023051454 -0.547221960  0.342600702  0.080848203
 [26]  0.074609232  0.255946197 -0.191242759  1.036445108  0.895068954
 [31]  0.589477883  0.123230750  1.467210735 -1.636657283 -0.131504288
 [36] -0.665000122  0.390977868  0.546802014  0.445498091  1.063872749
 [41]  1.406788635 -0.037147550 -1.047190960 -0.189105987  0.069617165
 [46] -0.049760285 -1.454279226  0.358351554  0.246587937 -0.060735329
 [51]  1.664530111 -0.475931484  0.405480604  1.560446941 -0.030537155
 [56] -1.060319583 -1.828624216 -0.429391165  0.301697744 -0.029593593
 [61] -1.696307754  0.342678986 -0.433965195 -0.947338037  0.318186677
 [66]  0.539630789 -1.354555193  0.086168702  0.002950100  1.783486665
 [71] -1.182419158 -0.930524123  0.376579158 -1.085035387  1.186125702
 [76]  0.719738391 -0.486692820 -2.105396602  0.531238276  1.302812739
 [81]  0.347851244  0.016452693  0.417535566  0.277705766  2.286275977
 [86]  1.610183518  2.032037030  1.319074179  1.129375593  0.176684807
 [91] -0.630517144  1.302785450  0.994275267 -0.060116993 -0.655966924
 [96]  1.628197169  1.935532651 -1.635783346 -1.172511179  1.238336597
> ynew
           1            2            3            4            5            6 
-0.270916637  0.169149841  0.191348061 -0.009541999  0.112027155  0.016242323 
           7            8            9           10           11           12 
-0.062178365  0.275322344  0.397030485  0.565078468  0.301230303  0.305405674 
          13           14           15           16           17           18 
 0.552136794 -0.151275710  0.470280882  0.349631748  0.022005869  0.181384646 
          19           20           21           22           23           24 
 0.143719339  0.478791323  0.518731127  0.229860133 -0.199433324  0.310576455 
          25           26           27           28           29           30 
 0.127612633 -0.157347145  0.413807523  0.007961485 -0.288867750  0.208759771 
          31           32           33           34           35           36 
 0.286165027  0.299492579  0.197312294  0.135601904  0.452828662  0.187191405 
          37           38           39           40           41           42 
 0.335596502 -0.109960231 -0.303770506 -0.276385255  0.429700474  0.003930969 
          43           44           45           46           47           48 
 0.184186301  0.140858190  0.479882236  0.182523553 -0.133845870  0.443940376 
          49           50           51           52           53           54 
 0.070571673 -0.383780163  0.362153269  0.202527841  0.164299813  0.327998904 
          55           56           57           58           59           60 
 0.047612361 -0.032167295  0.060976285  0.231929803 -0.449532973  0.109925656 
          61           62           63           64           65           66 
 0.468842330  0.108507841  0.158697337 -0.125813680  0.501159861  0.101646132 
          67           68           69           70           71           72 
 0.194383106 -0.006185569  0.354467348  0.340013811  0.088757961  0.439984356 
          73           74           75           76           77           78 
 0.330976669  0.449337326  0.081841142 -0.190123754  0.337794560 -0.111895039 
          79           80           81           82           83           84 
 0.598231564  0.444399789  0.388313945  0.244270482  0.200026237  0.009025077 
          85           86           87           88           89           90 
 0.341093767 -0.164196034  0.825849472  0.325975911  0.494473323  0.270037159 
          91           92           93           94           95           96 
 0.369787280  0.247455471  0.282701738 -0.541688411 -0.145796547  0.073172268 
          97           98           99          100 
 0.685833173 -0.079174316 -0.193161949 -0.137517175 
 
 
 

Arnab Kumar Maity
Graduate Teaching Assistant
Division of Statistics
Northern Illinois University
DeKalb,
Illinois 60115
U.S.A 

--------
From: Martin Spindler 
To: r-help@r-project.org
Sent: Wednesday, April 29, 2015 9:21 AM
Subject: [R] Problem with p

[R] Problem with predict.lm()

2015-04-29 Thread Martin Spindler
Dear all,
 
the following example somehow uses the "old data" (X) to make the predictions, 
but not the new data Xnew as intended.
 
y <- rnorm(100)
X <- matrix(rnorm(100*10), ncol=10)
lm <- lm(y~X)
Xnew <- matrix(rnorm(100*20), ncol=10)
ynew <- predict(lm, newdata=as.data.frame(Xnew)) #prediction in not made for 
Xnew
 
How can I foce predict.lm to use use the new data?
 
Thank you very much for your efforts in advance!
 
Best,
 
Martin

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

[R] Using openBLAS in R under Unix / Linux

2014-08-28 Thread Martin Spindler
Dear all,
I would like to us openBLAS in R under Linux / Unix.
Which steps do I have to undertake? Does someone know a detailed 
description? (I found some sources on the web, but none was really 
helpful for me.)
Thanks and best,
Martin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Standardisation of variables with Lasso (glmnet)

2014-02-13 Thread Martin Spindler

   Dear all,

   I am working with glmnet but the problem arises also in all other Lasso
   implementations:
   It is ususally recommended to standardize the variables / use intercept and
   this works well with the implemented options:

   x <- matrix(rnorm(1), ncol=50)
   y <- rnorm(200)
   cv.out =cv.glmnet(x,y, alpha =1, intercept=T , standardize=T)
   coef <- coef(cv.out, s = "lambda.min")
   ind1 <- which(coef>0)
   coef[ind1,]

   but when I would like to do this by hand:

   xs <- apply(x,2, function(x) (x-mean(x))/sqrt(var(x)))
   ys <- y - mean(y)
   cv.out =cv.glmnet(xs,ys, alpha =1, intercept=F , standardize=F)
   coef <- coef(cv.out, s = "lambda.min")
   ind1 <- which(coef>0)
   coef[ind1,]

   The following error appears:

   > cv.out =cv.glmnet(xs,ys, alpha =1, intercept=F , standardize=F)
   Error in elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian,  :
NA/NaN/Inf in foreign function call (arg 5)

   Therefore  my  question is what am I doing wrong and what is the "best
   practice" with Lasso (intercept yes / no, standardisation by hand, ...)

   Thank you very much for your efforts and replies in advance!

   Best,

   Martin
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Negative Binomial Regression - glm.nb

2013-02-27 Thread Martin Spindler
Dear all,

I would like to ask, if there is a way to make the variance / dispersion 
parameter $\theta$ (referring to MASS, 4th edition, p. 206) in the function 
glm.nb dependent on the data, e.g. $1/ \theta = exp(x \beta)$ and to estimate 
the parameter vector $\beta$ additionally.

If this is not possible with glm.nb, is there another function / package which 
might do that?

Thank you very much for your answer in advance!

Best,

Martin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Splitting up of a dataframe according to the type of variables

2012-12-17 Thread Martin Spindler
Dear R users,

I have a dataframe which consists of variables of type numeric and factor.
What is the easiest way to split up the dataframe to two dataframe which 
contain all variables of the type numeric resp. factors?

Thank you very much for your efforts in advance!

Best,

Martin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function for Generating all Permutations with Repetition

2012-03-05 Thread Martin Spindler
Dear all,

I am looking for a function in R which returns all possible permutations of an 
object x with r number of repitions. For example

If x <- c(0,1) and r <-3 the result should be

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1 
1 1 0
1 1 1

and consist of 2^3=8 elements.
Unfortunately, I have found only functions which return the combinations for 
"choose n over k" but not the case described above.
I would appreciate hints and help highly.

Best,

Martin

--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non-finite finite-difference value

2012-02-23 Thread Martin Spindler
Dear all,

when applying the optim function the following error occured
"non-finite finite-difference value"

Therefore I would like to ask how one can try to handle such a problem and 
which strategies have proven useful. (There is only litte guidance on the help 
list for this kind of problem.)

Thank you in advance for your efforts!

Best,

Martin
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] problem with as.Date

2011-10-22 Thread Martin Spindler
Dear all,

I would like to convert the first column of a dataframe to a date (original
format: year (4 digits) and month (last 2 digits))

>str(dat_FF)
'data.frame':   1022 obs. of  4 variables:
 $ date : int  192607 192608 192609 192610 192611 192612 192701 192702
192703 192704 ...
 $ Rm.Rf: num  2.69 2.52 0 -3.06 2.42 2.66 0 4.29 0.51 0.57 ...
 $ SMB  : num  -2.49 -1.25 -1.38 -0.2 -0.34 -0.07 -0.11 0.35 -1.87 0.44 ...
 $ HML  : num  -2.91 4.25 0.22 0.71 -0.4 -0.11 4.92 3.17 -2.92 1.33 ...

But

>dat_FF$date <- as.Date(as.character(dat_FF$date), format="%Y%m")

delievers NAs:

>str(dat_FF)
'data.frame':   1022 obs. of  4 variables:
 $ date : Date, format: NA NA ...

I am very grateful for hints! Thanks in advance!

Best,

Martin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] package VGAM: vglm.fit()

2011-06-16 Thread Martin Spindler
Dear all,

 

I am estimating a bivariate probit model using the package VGAM:

 

fit1 = vglm(cbind(y1, y2) ~ x1+x2, binom2.rho, data=dat, trace=TRUE)

 

I would like to estimate this via the method vglm.fit (in an analogous way
as lm.fit for lm or glm.fit for glm). Unfortunately my trials did not
succeed.

Therefore I would like to ask if this is possible at all and - if yes - how
one can access this function.

 

Thank you very much for your efforts in advance!

 

Best,

 

Martin

 

 

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] conversion of matrix into list

2011-06-01 Thread Martin Spindler
Dear all,

 

I have a matrix X which consists of 2 columns. I would like to convert this
matrix into a list where every entry of the list consists of a single row of
the matrix.

Does anyone have a suggestions how to manage this?

 

Thank you for your efforts in advance!

 

Best,

 

Martin

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] partial evaluation of a function with several arguments

2011-02-07 Thread Martin Spindler
Dear all,

I have the following problem:

add <- function(x,y) {x+y}

What is the easiest / most elegant way to create a new function (e.g. with the 
name "addev") that sets the second argument of the function "add" to a fixed 
value (e.g. y=3), i.e. addev <- add(x,3). But this does not work.

Thank you for your efforts in advance!

Best,

Martin
-- 




-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 with two factors

2010-12-10 Thread Martin Spindler
Hey Michael,

Thank you very much. It works!

Best,

Martin


 Original-Nachricht 
> Datum: Fri, 10 Dec 2010 22:35:56 +1100
> Von: Michael Bedward 
> An: Martin Spindler 
> CC: r-help@r-project.org
> Betreff: Re: [R] subset with two factors

> Hello Martin,
> 
> You were almost there :)
> 
> T1 <- subset(daten1, Geschlecht=="M" & GG=="A")
> 
> Hope this helps.
> 
> Michael
> 
> On 10 December 2010 22:25, Martin Spindler  wrote:
> > Dear all,
> >
> > I have a dataframe of the following strucutre
> >
> >  numacc_b coverage_b Geschlecht GG
> > 1        0          1          W  A
> > 2        0          1          M  A
> > 3        0          1          M  B
> > 4        0          1          M  B
> > 5        0          1          W  A
> > 6        0          1          M  B
> >
> > I would like to form a subset consisting of all entries with
> Geschlecht=M and GG=A.
> >
> > Using
> >
> >>T1 <- subset(daten1, Geschlecht=="M", GG=="A")
> >
> > delievers
> >
> > data frame with 0 columns and 6 rows
> >
> >> T1 <- subset(daten1, Geschlecht=="M")
> >
> > delievers
> >
> >  numacc_b coverage_b Geschlecht GG
> > 2         0          1          M  A
> > 3         0          1          M  B
> > 4         0          1          M  B
> > 6         0          1          M  B
> > 9         0          1          M  B
> > 10        0          1          M  B
> >
> > But I want to select the dataframe according to both factos.
> >
> > What can I do?
> >
> > Thank you answers in advance!
> >
> > Best,
> >
> > Martin
> > --
> > GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit
> > gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >

-- 
GRATIS! Movie-FLAT mit über 300 Videos. 



-- 
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] subset with two factors

2010-12-10 Thread Martin Spindler
Dear all,

I have a dataframe of the following strucutre

 numacc_b coverage_b Geschlecht GG
10  1  W  A
20  1  M  A
30  1  M  B
40  1  M  B
50  1  W  A
60  1  M  B

I would like to form a subset consisting of all entries with Geschlecht=M and 
GG=A.

Using

>T1 <- subset(daten1, Geschlecht=="M", GG=="A")

delievers

data frame with 0 columns and 6 rows

> T1 <- subset(daten1, Geschlecht=="M")

delievers

  numacc_b coverage_b Geschlecht GG
2 0  1  M  A
3 0  1  M  B
4 0  1  M  B
6 0  1  M  B
9 0  1  M  B
100  1  M  B

But I want to select the dataframe according to both factos.

What can I do?

Thank you answers in advance!

Best,

Martin
-- 
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 concerning VGAM

2010-07-04 Thread Martin Spindler
Hello everyone,

 

using the VGAM package and the following code

 

library(VGAM)

bp1 <- vglm(cbind(daten$anzahl_b, daten$deckung_b) ~ ., binom2.rho,
data=daten1)

summary(bp1)

coef(bp1, matrix=TRUE)

 

produced this error message:

 

error in object$coefficients : $ operator not defined for this S4 class

 

I am bit confused because some day ago this error message did not show up
and everything was fine.

 

Thank you very much in advance for your help.

 

Best,

 

Martin


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] linear predicted values of the index function in an ordered probit model

2010-06-28 Thread Martin Spindler
Hello,

 

currently I am estimating an ordered probit model with the function polr
(MASS package).

Is there a simple way to obtain values for the prediction of the index
function ($X*\hat{\beta}$)?

 (E..g. in the GLM function there is  the linear.prediction value for this
purpose).

 

If not, is there another function / package where this feature is
implemented?

 

Thank you very much for your answer in advance!

 

Best,

 

Martin


[[alternative HTML version deleted]]

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