Re: [R] Linear regression with a rounded response variable

2015-10-21 Thread peter dalgaard
> On 21 Oct 2015, at 19:57 , Charles C. Berry wrote: > > On Wed, 21 Oct 2015, Ravi Varadhan wrote: > >> [snippage] > > If half the subjects have a value of 5 seconds and the rest are split between > 4 and 6, your assertion that rounding induces an error of > dunif(epsilon,-0.5,0.5) is surely

Re: [R] Linear regression with a rounded response variable

2015-10-21 Thread peter salzman
here is one thought: if you plug in your numbers into any kind of regression you will get prediction that are real numbers and not necessarily integers, it may be that you predictions are good enough with this approximate value of Y. you could test this by randomly shuffling your data by +- 0.5 an

Re: [R] Linear regression with a rounded response variable

2015-10-21 Thread Gabor Grothendieck
This could be modeled directly using Bayesian techniques. Consider the Bayesian version of the following model where we only observe y and X. y0 is not observed. y0 <- X b + error y <- round(y0) The following code is based on modifying the code in the README of the CRAN rcppbugs R package.

[R] Update dataframe based on some conditions

2015-10-21 Thread Jorge I Velez
Dear R-help, I am working on what it seems to be a simple problem, but after several hours trying to come up with a solution, unfortunately I have not been able to. I would like to go from "datain" to "dataout", that is, create the NEWREF variable according with some restrictions, and update the

Re: [R] Reordering of numerical vector

2015-10-21 Thread Marlin Keith Cox
Got it. During a read.csv I used stringsAsFactors=FALSE M. Keith Cox, Ph.D. Principal MKConsulting 17105 Glacier Hwy Juneau, AK 99801 U.S. 907.957.4606 On Wed, Oct 21, 2015 at 10:31 AM, Marlin Keith Cox wrote: > I do not have a dataset to share as I do not believe it needs it and I am > not su

Re: [R] Linear regression with a rounded response variable

2015-10-21 Thread Victor Tian
Hi Ravi, Thanks for this interesting question. My thoughts are given below. If you believe the rounding is indeed uniformly distributed, then the problem is equivalent with adding a uniform random error between (-0.5, 0.5) for every observation in addition to the standard normal error, which will

[R] Reordering of numerical vector

2015-10-21 Thread Marlin Keith Cox
I do not have a dataset to share as I do not believe it needs it and I am not sure I could reproduce easily. I have a column of numerical data (Days) and another of a a measurement (Resistance). After subsetting, I do a linear regression of the two, and it reorders the day (x axis) into some other

Re: [R] Linear regression with a rounded response variable

2015-10-21 Thread Charles C. Berry
On Wed, 21 Oct 2015, Ravi Varadhan wrote: Hi, I am dealing with a regression problem where the response variable, time (second) to walk 15 ft, is rounded to the nearest integer. I do not care for the regression coefficients per se, but my main interest is in getting the prediction equation fo

[R] Linear regression with a rounded response variable

2015-10-21 Thread Ravi Varadhan
Hi, I am dealing with a regression problem where the response variable, time (second) to walk 15 ft, is rounded to the nearest integer. I do not care for the regression coefficients per se, but my main interest is in getting the prediction equation for walking speed, given the predictors (age,

[R] Can't Get Contents and Centers of gg2plot stat_hexbin Histograms

2015-10-21 Thread SirDoctorGentleman .
To find the bin centers, I've tried gg2plot_build(), but the center-coordinates it provides are not what's plotted. In the below example there are several misplaced "o" symbols and some bins w/o a symbol on them. library(ggplot2) dat <- data.frame(x = rnorm(10, 6, 2), y = rnorm(10, 6, 2))

Re: [R] r-markdown - keeping figures

2015-10-21 Thread Yihui Xie
Yes, setting the fig.path option will prevent rmarkdown from deleting the figure files, and the more natural way to preserve these intermediate files is to set the rmarkdown option keep_tex or keep_md (depending on your output format) to yes, e.g. --- output: pdf_document: keep_tex: yes ht

Re: [R] threshold and replace values in a matrix

2015-10-21 Thread Alaios via R-help
Thanks. replace also looks to work okay. On Wednesday, October 21, 2015 3:43 PM, PIKAL Petr wrote: Hi I wonder why you are asking that after quite a long use of R. test[test < (-.5)] <- (-1) Double loops seems to me the last resort in R if any other approach fails. Cheers Petr

Re: [R] threshold and replace values in a matrix

2015-10-21 Thread PIKAL Petr
Hi I wonder why you are asking that after quite a long use of R. test[test < (-.5)] <- (-1) Double loops seems to me the last resort in R if any other approach fails. Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios > via R-help

[R] threshold and replace values in a matrix

2015-10-21 Thread Alaios via R-help
Dear all I have a table as that. test<-matrix(data=rnorm(100),ncol=10) and I want to find the values that are below my thresholdthreshold<- -0.5and replace them with a -1 instead. I can of course write a double nested for loop to check one by one elementif (test[i,j]<= threshold)   test[i,j]<- -

Re: [R] r-markdown - keeping figures

2015-10-21 Thread Jeff Newmiller
I think the default now is to not save them unless you set the fig.path chunk option. http://kbroman.org/knitr_knutshell/pages/Rmarkdown.html --- Jeff NewmillerThe . . Go Live... DCN

Re: [R] apply function across dataframe columns for non-exclusive groups

2015-10-21 Thread Jeff Newmiller
The calculation appears to be sum(a)/(sum(a)+sum(b)). library(dplyr) library(tidyr) result <- ( this_df %>% gather( group, truth, -c(a,b) ) %>% group_by( group, truth ) %>% summarise( calc = sum(a)/(sum(a)+sum(b)) ) %>% as.data.frame ) -

Re: [R] r-markdown - keeping figures

2015-10-21 Thread Bob O'Hara
The figures should be saved somewhere. e.g. if you have x.Rmd, you should have a X_files/ folder with subfolders for the figures (e.g. X-html or X-latex). At least that's what I have. Bob On 20 October 2015 at 18:18, Witold E Wolski wrote: > I am running r-markdown from r-studio and can't work o

[R] apply function across dataframe columns for non-exclusive groups

2015-10-21 Thread Alexander Shenkin
Hello all, I've been banging my head over what must be a simple solution. I would like to apply a function across columns of a dataframe for rows grouped across different columns. These groups are not exclusive. See below for an example. Happy to use dplyr, data.table, or whatever. Any g

Re: [R] r-markdown - keeping figures

2015-10-21 Thread John Kane
It may not be elegant but you can just embed a png() command in the knitr code. Code from RStudio example with png() command added. ```{r, echo=FALSE} plot(cars) png("~/Rjunk/pnd.png") plot(cars) dev.off() ``` John Kane Kingston ON Canada > -Original Message- > From: wewol...@gmail.c

[R] quantreg package: residuals

2015-10-21 Thread T.Riedle
Greetings R Community, I am running quantile regressions using quantreg in R. I also plot the residuals in a QQplot which indicate fat tails. I would like to try using Student distribution, but I do not know if the R software allows it for my task in hand. In my opinion it is very likely that

Re: [R] ggplot2: discontinuous ribbon

2015-10-21 Thread sbihorel
Thanks! On 10/21/2015 5:25 AM, Thierry Onkelinx wrote: Dear Sebastien, You are looking for geom_polygon(). Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assuran

Re: [R] ggplot2: discontinuous ribbon

2015-10-21 Thread Thierry Onkelinx
Dear Sebastien, You are looking for geom_polygon(). Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the

[R] ggplot2: discontinuous ribbon

2015-10-21 Thread sbihorel
Hi I would like to use ggplot2 to create a 2d plot showing a series of shaded areas that are not continuous with respect to the x-axis variable. The expected result is illustrated below using lattice/grid functions. - pdata <- data.frame( x=c(1,2,2,1,NA,3,4,4,3,NA,5,6,6,5), y

Re: [R] Transfer a 3-dimensional array to a matrix in R

2015-10-21 Thread Chunyu Dong
thank you very much! Both the two methods work well for my data. Best wishes, Chunyu At 2015-10-20 19:48:18, "William Dunlap" wrote: >Or use aperm() (array index permuation): > > array(aperm(x, c(2,1,3)), c(6,3)) > [,1] [,2] [,3] > [1,]17 13 > [2,]4 10 16 >

Re: [R] Error in rep.int() invalid 'times' value

2015-10-21 Thread marammagdysalem
Thanks a lot Petr for ur reply and advice. Hope I 'd be able to minmize time as much as possible. Regards, Maram Salem Sent from my iPhone > On Oct 21, 2015, at 9:28 AM, PIKAL Petr wrote: > > Hi > > Several options > > Coding in C+ or other similar language (you seem to be more familiar wit

Re: [R] Error in rep.int() invalid 'times' value

2015-10-21 Thread PIKAL Petr
Hi Several options Coding in C+ or other similar language (you seem to be more familiar with them) Using debug and find out how your function behaves in steps Using function with smaller m, n with Rprof to see where the time is spent. I believe that coding in R like it was C+ is the way to hel