Re: [R] Cansisc: Error in eigen(eHe, symmetric = TRUE)

2014-07-10 Thread Michael Friendly
Maria

The variables 
Araceae,Begoniaceae,Bromeliaceae,Clusiaceae,Cyclanthaceae,Ericaceae,Gesneriaceae,
 
Melastomataceae,Orchidaceae,Piperaceae,Pteridophyta
are frequencies (abundances?) of which most are 0 and this is not 
appropriate
as multivariate normal data.

There is probably a version of canonical analysis that takes such 
variables into account,
but I don't know specifically.  Have you looked at the vegan package and 
its references?

HTH
-Michael



On 10/07/2014 12:54 AM, Maria Judith Carmona H wrote:
 Dear John,

 I am including abundance values ​​in my data set so obviously I have 
 zero abundances.
 The problem is that if plot only the factors (biomasa, altdosel, 
 altsoto, cobertura, riqarb, elevacion, temperatura, precipitacion) I 
 get the graphic, the same happen when I included only the families, 
 but I want to see the effect of all these factors+families on this 
 plot . In fact I included only certain families:

 prueba4 - 
 lm(cbind(biomasa,altdosel,altsoto,cobertura,riqarb,elevacion,temperatura,precipitacion,
 Araceae,Begoniaceae,Bromeliaceae,Clusiaceae,Cyclanthaceae,Ericaceae,Gesneriaceae,
 Melastomataceae,Orchidaceae,Piperaceae,Pteridophyta) ~ sitio, 
 data=bosques.p)
 canprueba2 - candisc(prueba2, term=sitio, data=bosques.p, ndim=1)
 Error in eigen (EHD, symmetric = TRUE): infinite or missing values ​​ 
 in 'x'
 In addition: Warning message:
 In sqrt (wmd): NaNs produced

 You see I get the same error.

 Best regards,
 Judith


 On Wed, Jul 9, 2014 at 5:30 PM, John Fox j...@mcmaster.ca 
 mailto:j...@mcmaster.ca wrote:

 Dear Maria Judith Carmona Higuita,

 Since you didn't include enough information (such as your access
 to your data) to reproduce the error, one can only guess. My
 guess: you have fewer observations in your data set than response
 variables on the LHS of the multivariate linear model.

 I hope this helps,
  John

 
 John Fox, Professor
 McMaster University
 Hamilton, Ontario, Canada
 http://socserv.mcmaster.ca/jfox/

 On Wed, 9 Jul 2014 11:36:35 -0500
  Maria Judith Carmona H juditycarm...@gmail.com
 mailto:juditycarm...@gmail.com wrote:
  Hi,
 
  I have a problem using the function Candisc from Candisc Package.
 
  bosques1-read.csv(bosques1.csv,header=TRUE,encoding=latin1)
  bosques1-na.exclude(bosques1)
  attach(bosques1)
 
  #Modelo de regresión
  mod -
 
 
 lm(cbind(biomasa,altdosel,altsoto,cobertura,riqarb,elevacion,temperatura,precipitacion,
  Acanthaceae, Apocinaceae, Araceae, Araliaceae,
 Arecaceae,
  Aspleniaceae, Begoniaceae,
  Blechnaceae, Bromeliaceae, Clusiaceae,
 Cyclanthaceae,
  Davalliaceae, Denstaedtiaceae,
  Dryopteridaceae, Ericaceae, Gesneriaceae,
 Hymenophyllaceae,
  indet., Lauraceae, Lomariopsidaceae, Lycopodiaceae, Melastomataceae,
  Moraceae, Myrsinaceae, Ophioglossaceae,
  Orchidaceae, Peperomia, Piperaceae, Poaceae,
 Polypodiaceae,
  Primulaceae, Pteridaceae,
  Pteridophyta.taxa, Rubiaceae, Vittariaceae) ~ sitio,
  data=bosques1)
  summary(mod)
 
  #Gráfico 1
  can - candisc(mod, term=sitio,data=bosques1,ndim=1,eig=T)
  ### The error happens here, so I can not run the plot.
  plot(can,titles.1d = c(Puntuación canónica, Estructura))
  summary(can, means = FALSE, scores = TRUE, coef = c(std),
 digits = 2)
 
  The error is:
  Error in eigen(eHe, symmetric = TRUE) : infinite or missing
 values in 'x'
  In addition: Warning message:
  In sqrt(wmd) : NaNs produced
 
  Please help!
 
  --
  Maria Judith Carmona Higuita.
  Estudiante de Biología - Universidad de Antioquia
  Medellín - Colombia
 
  La felicidad ocurre cuando encajas en tu vida, cuando encajas
  tan armónicamente que cualquier cosa que hagas es una alegría
 para ti. De
  repente lo sabrás y la meditación te seguirá. Si amas el trabajo
 que haces,
  si amas la manera como vives, entonces ya estás meditando y nada
 puede
  distraerte. Osho
 
[[alternative HTML version deleted]]
 







 -- 
 Maria Judith Carmona Higuita.
 Estudiante de Biología - Universidad de Antioquia
 Medellín - Colombia

 La felicidad ocurre cuando encajas en tu vida, cuando encajas 
 tan armónicamente que cualquier cosa que hagas es una alegría para ti. 
 De repente lo sabrás y la meditación te seguirá. Si amas el trabajo 
 que haces, si amas la manera como vives, entonces ya estás meditando y 
 nada puede distraerte. Osho



-- 
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.  Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   

[R] R 3.1.1 is released

2014-07-10 Thread Peter Dalgaard
The build system rolled up R-3.1.1.tar.gz (codename Sock it to Me) this 
morning.

The list below details the changes in this release.

You can get the source code from

http://cran.r-project.org/src/base/R-3/R-3.1.1.tar.gz

or wait for it to be mirrored at a CRAN site nearer to you.

Binaries for various platforms will appear in due course. Perhaps with some 
delays due to vacations. In particular, the Mac OS X maintainer is traveling 
and may be without Internet access for some days yet.

For the R Core Team

Peter Dalgaard


These are the md5sums for the freshly created files, in case you wish
to check that they are uncorrupted:

MD5 (AUTHORS) = cbf6da8f886ccd8d0dda0cc7ffd1b8ec
MD5 (COPYING) = eb723b61539feef013de476e68b5c50a
MD5 (COPYING.LIB) = a6f89e2100d9b6cdffcea4f398e37343
MD5 (FAQ) = 19b98552686c3f3c95a6028596c533e9
MD5 (INSTALL) = 3964b9119adeaab9ceb633773fc94aac
MD5 (NEWS) = bf2c79e7fd7e2dff621a3a8410c89bb4
MD5 (NEWS.0) = bfcd7c147251b5474d96848c6f57e5a8
MD5 (NEWS.1) = eb78c4d053ec9c32b815cf0c2ebea801
MD5 (NEWS.2) = e840d32b7ef7a7603455d30d6d54fda7
MD5 (NEWS.html) = 206dc0c4dc31004f245813b403ec6d6a
MD5 (R-latest.tar.gz) = 2598f5bbbedb00e463e0c1385e6fe999
MD5 (README) = aece1dfbd18c1760128c3787f5456af6
MD5 (RESOURCES) = c7cb32499ebbf85deb064aab282f93a4
MD5 (THANKS) = d4b45e302b7cad0fc4bb50d2cfe69649
MD5 (R-3/R-3.1.1.tar.gz) = 2598f5bbbedb00e463e0c1385e6fe999


This is the relevant part of the NEWS file


  NEW FEATURES:

* When attach() reports conflicts, it does so compatibly with
  library() by using message().

* R CMD Sweave no longer cleans any files by default, compatibly
  with versions of R prior to 3.1.0.  There are new options
  --clean, --clean=default and --clean=keepOuts.

* tools::buildVignette() and tools::buildVignettes() with clean =
  FALSE no longer remove any created files.  buildvignette() gains
  a keep argument for more cleaning customization.

* The Bioconductor 'version' used by setRepositories() can now be
  set by environment variable R_BIOC_VERSION at runtime, not just
  when R is installed.  (It has been stated that Bioconductor will
  switch from 'version' 2.14 to 'version' 3.0 during the lifetime
  of the R 3.1 series.)

* Error messages from bugs in embedded Sexpr code in Sweave
  documents now report the source location.

* type.convert(), read.table() and similar read.*() functions get a
  new numerals argument, specifying how numeric input is converted
  when its conversion to double precision loses accuracy.  The
  default value, allow.loss allows accuracy loss, as in R
  versions before 3.1.0.

* For some compilers, integer addition could overflow without a
  warning.  R's internal code for both integer addition and
  subtraction is more robust now.  (PR#15774)

* The function determining the default number of knots for
  smooth.spline() is now exported, as .nknots.smspl().

* dbeta(, a,b), pbeta(), qbeta() and rbeta() are now defined also
  for a = 0, b = 0, or infinite a and b (where they typically
  returned NaN before).

* Many package authors report that the RStudio graphics device does
  not work correctly with their package's use of dev.new().  The
  new option dev.new(noRStudioGD = TRUE) replaces the RStudio
  override by the default device as selected by R itself, still
  respecting environment variables R_INTERACTIVE_DEVICE and
  R_DEFAULT_DEVICE.

* readRDS() now returns visibly.

* Modifying internal logical scalar constants now results in an
  error instead of a warning.

* install.packages(repos = NULL) now accepts http:// or ftp:// URLs
  of package archives as well as file paths, and will download as
  required.  In most cases repos = NULL can be deduced from the
  extension of the URL.

* The warning when using partial matching with the $ operator on
  data frames is now only given when
  options(warnPartialMatchDollar) is TRUE.

* Package help requests like package?foo now try the package foo
  whether loaded or not.

* General help requests now default to trying all loaded packages,
  not just those on the search path.

* Added a new function promptImport(), to generate a help page for
  a function that was imported from another package (and presumably
  re-exported, or help would not be needed).

  INSTALLATION and INCLUDED SOFTWARE:

* configure option --with-internal-tzcode can now be used with
  variable rsharedir.

* The included version of PCRE has been updated to 8.35.

* There is a new target make uninstall-libR to remove an installed
  shared/static libR.

  make install-libR now works if a sub-architecture is used,
  although the user will need to specify libdir differently for
  different sub-architectures.

* There is more extensive advice on which LaTeX packages are
  required to install 

[R] linearHypothesis() ERROR-Message

2014-07-10 Thread Katharina Mersmann
Dear Community,

unfortunately I can´t give you an reproducable example, because I really do
not understand why this messages pops up.

I estimate an Fixed Effects Modell, controlling for HAC, because F-statistic
changes, I want to compute it, for the other model-specifications it works,

But for this special one I get the following error: 

 

 fixed.interest3-plm(CSmean~ numfull_FCRlong_adj+exp(numfull_FCRlong_adj),

+  data=data.plm,index = c(countrynr,quartal),
model=within)

 ###F-Test

 coefs - names(coef(fixed.interest3))

 linearHypothesis(fixed.interest3,coefs,test=F, vcov=function(x)
vcovHC(x, method = arellano)) 

Fehler in solve.default(L %*% V %*% t(L)) : 

  System ist für den Rechner singulär: reziproke Konditionszahl =
1.37842e-19  „system is computationally singular reciprocal condition
number”

 drop(coefs)

[1] numfull_FCRlong_adj exp(numfull_FCRlong_adj)

 

 

Is something wrong in the code. Or is it because of the model?

 

 

Thanks in advance and a really nice day

Katie


[[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] Median expected survival

2014-07-10 Thread Lars Bishop
Hi All,

Apologies for the simple question, but I could not find a straightforward
answer based on my limited knowledge of survival analysis.

I’m trying to obtain the predicted median survival time for each subject on
a new dataset from a fitted coxph{survival} or cph{rms} object. Would the
quantile.survfit function (as used below) return the expected median
survival? Why this function returns NAs in this case, when all predictors
have non-missing values?

As an alternative, I’ve tried to use the Quntile{rms} function as in my
second chunk of code, but in this case I get an error message (most likely
due to my lack of understanding as well).

library(MASS)

library(survival)

library(rms)

data(gehan)

leuk.cox -coxph(Surv(time, cens) ~ treat + factor(pair), data = gehan)

leuk_new - gehan[1:10, ] # take first 10 patients

pred_leuk - survfit(leuk.cox, newdata=leuk_new)

quantile(pred_leuk, 0.5)$quantile



### alternative using rms

leuk.cox.rms -cph(Surv(time, cens) ~ treat + factor(pair), data = gehan,
surv = T)

med - Quantile(leuk.cox.rms)

Predict(leuk.cox.rms, data = leuk_new, fun=function(x)med(lp=x))

Error in Predict(leuk.cox.rms, data = leuk_new, fun = function(x) med(lp =
x)) :

  predictors(s) not in model: data


Thank you for your help.

Best,

Lars.

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


Re: [R] Median expected survival

2014-07-10 Thread Marco Barbàra
Hi, Lars.

I don't understand well your question. why don't you simply type

 pred_leuk

Call: survfit(formula = leuk.cox, newdata = leuk_new)

   records n.max n.start events median 0.95LCL 0.95UCL
1   4242  42 30  1   1  23
2   4242  42 30  7   5  NA
3   4242  42 30 15  10  NA
4   4242  42 30 NA  NA  NA
5   4242  42 30  8   5  NA
6   4242  42 30 23  22  NA
7   4242  42 30  8   6  NA
8   4242  42 30 NA  22  NA
9   4242  42 30  6   4  NA
10  4242  42 30 23  17  NA

Yes, the quantile method returns the correct medians. The NAs usually
appear when the unit belongs to a category for which median survival
time has not yet been reached, so there is no way for the model to
estimate the median time. You can see the expected survival curve with
plot(predl_leuk)

__
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] function completing properly

2014-07-10 Thread Jim Lemon
On Wed, 9 Jul 2014 04:47:39 PM Janet Choate wrote:
 Hi R community,
 i created a function (mkdate) as follows:
 
 mkdate = function(x) {
 x$date = as.Date(paste(x$year, x$month, x$day, sep=-))
 x$wy = ifelse(x$month =10, x$year+1, x$year)
 x$yd = as.integer(format(as.Date(x$date), format=%j))
 x$wyd = cal.wyd(x)
 x
 }
 
 the function results in adding the new columns date, wy, yd, and 
wyd to the
 table i apply it to.
 this has always worked in R version 2.14.2.
 however, in R version 3.1.0 - instead of my mkdate function adding 
those
 columns to my existing table, it just overwrites my table and leaves 
me
 with just a list of the last variable created by my mkdate function. so 
i
 end up with just a list of numbers representing wyd, and lose all the 
data
 in my original table.
 
 does anyone know what would now be causing this to occur, and 
what i need
 to do to make my function work properly again?
 
 thank you for any assistance,
 Janet
 
   [[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.
Hi Janet,
It looks to me as though x should be at least a three column list 
containing a year, month and day in numeric format. You then add 
four other fields to it and return the resulting (at least) seven column 
list. What you may have been doing was to pass your entire data 
frame (?) to the function with one or more incomplete rows, 
whereupon the function would calculate the four fields for all the rows 
and fill in the incomplete rows. This is not a very efficient way to do this 
and you should probably consider just passing the new values and 
appending the object returned to your data frame.

Jim

__
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] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Kenn Konstabel
Dear all,

I found an unexpected behaviour when trying to `source` an utf-8 file
on windows 7:

source(http://psych.ut.ee/~nek/R/test-utf8.txt;)

# Rgui.exe reacts:
# R for windows GUI has stopped working. A problem caused the program
to stop working correctly.
# Windows will close the program and notify you if a solution is available.

The same will happen with R.exe (terminal) and R running wihin
Rstudio. (Session and locale info below).

However, a non-utf version of this little script can be `source`d
without problems.

source(http://psych.ut.ee/~nek/R/test.txt;)

Adding the `encoding` argument to `source` helps a little:

source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=utf-8)
#  unsure about the spelling of utf-8 so I also tried UTF8, utf8, and UTF-8
# ... with the same result in all cases

R doesn't crash any more but gives the following error:

# Error in source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding
= utf-8) :
#   http://psych.ut.ee/~nek/R/test-utf8.txt:2:0: unexpected end of input
# 1: ?
#^
# In addition: Warning message:
# In readLines(file, warn = FALSE) :
#  invalid input found on input connection
'http://psych.ut.ee/~nek/R/test-utf8.txt'

I thought maybe that's because what notepad told me is UTF-8 is
actually something else ... so I did two more experiments.

source(http://psych.ut.ee/~nek/R/test2.R;)
# this was created on a linux machine with leafpad, and saved as utf-8 text
# it can be source´d on windows

source(http://psych.ut.ee/~nek/R/test3.R;)
# the same as previous but o's in file were replaced by ö's
# can be source'd on windows but the ö character is shown as ƶ
# except if you add encoding=utf-8 - then, as expected, it works as expected

So in sum, I can create plain text (saved with utf-8 encoding) files
on windows that cannot be sourced to R on windows, or will crash R
(depending on how you source them). The same files can be sourced on
linux without problems. Part of the problem is obviously in windows
but maybe R shouldn't at least crash.

Session info:

 R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Estonian_Estonia.1257  LC_CTYPE=Estonian_Estonia.1257
[3] LC_MONETARY=Estonian_Estonia.1257 LC_NUMERIC=C
[5] LC_TIME=Estonian_Estonia.1257

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

loaded via a namespace (and not attached):
[1] tools_3.0.2


OS: Windows 7

Linux Mint Debian Edition and R 3.0.2 on the other machine (where
everything worked).

Context:

I was trying to find out how to make files that could be source'd on
both windows and linux. This is partly solved so I have no specific
question other than is this a bug in windows version? but any
comments on the general topic would be appreciated too.

Best regards,

Kenn


Kenn Konstabel
Research fellow
Department of chronic diseases
National Institute of Health Development
Hiiu 42
Tallinn
Estonia

__
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] Information about font

2014-07-10 Thread Sébastien Bihorel
Hi David,

Thank you for your response.

I use png devices to create my plots. Looking at ?pdfFonts and ?Type1Font,
I believe these fonts only apply to pdf devices. Additionally, ?grid::gpar
and ?png are not specific about default font options.

Any suggestions?

Sebastien



On Thu, Jul 10, 2014 at 12:21 AM, David Winsemius dwinsem...@comcast.net
wrote:


 On Jul 9, 2014, at 7:47 PM, Sébastien Bihorel wrote:

  Hi,
 
  I have this set of R scripts which are ran on a linux box and create
 plots
  with the lattice package. I do not specify any custom font family, so I
  believe that whatever is the default font on my system is used in the
 plot.
  1- how can I know which is the default font used in my plots?
  2- is this font specific to R or can it be used by external tools?
  3- if this font can be used by external tools, how can I know the
 location
  of this font on my system?

 Fonts are specific to the graphical device being used. You have not
 specified what device you are using.

 ?Devices

 The fonts are provided by your OS setup.

 ?pdfFonts
 ?Type1Font
 ?grid::gpar

 
  Thank you in advance for your help
 
  Sebastien
 
[[alternative HTML version deleted]]


 Still having trouble understanding your mail client?

 --
 David Winsemius
 Alameda, CA, USA



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


Re: [R] Information about font

2014-07-10 Thread Sébastien Bihorel
Correction

The warnings section in ?png indicate that Helvetica is the default font.
Now I need to verify if this is true for my plot and find out where this
font is located on my system


On Thu, Jul 10, 2014 at 8:54 AM, Sébastien Bihorel pomc...@free.fr wrote:

 Hi David,

 Thank you for your response.

 I use png devices to create my plots. Looking at ?pdfFonts and ?Type1Font,
 I believe these fonts only apply to pdf devices. Additionally, ?grid::gpar
 and ?png are not specific about default font options.

 Any suggestions?

 Sebastien



 On Thu, Jul 10, 2014 at 12:21 AM, David Winsemius dwinsem...@comcast.net
 wrote:


 On Jul 9, 2014, at 7:47 PM, Sébastien Bihorel wrote:

  Hi,
 
  I have this set of R scripts which are ran on a linux box and create
 plots
  with the lattice package. I do not specify any custom font family, so I
  believe that whatever is the default font on my system is used in the
 plot.
  1- how can I know which is the default font used in my plots?
  2- is this font specific to R or can it be used by external tools?
  3- if this font can be used by external tools, how can I know the
 location
  of this font on my system?

 Fonts are specific to the graphical device being used. You have not
 specified what device you are using.

 ?Devices

 The fonts are provided by your OS setup.

 ?pdfFonts
 ?Type1Font
 ?grid::gpar

 
  Thank you in advance for your help
 
  Sebastien
 
[[alternative HTML version deleted]]


 Still having trouble understanding your mail client?

 --
 David Winsemius
 Alameda, CA, USA




[[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] find remove sequences of at least N values for a specific value

2014-07-10 Thread jeff6868
Hi everybody,

I have a small problem in a function, about removing short sequences of
identical numeric values.

For the example, we can consider this data, containing only some 0 and
1:

test - data.frame(x=c(0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1))

The aim of my purpose here is simply to remove each sequence of 1 with a
length shorter than 5, and to keep sequences of 1 which are bigger than 5.
So my final data should look like this:

final - data.frame(x=c(0,0,NA,NA,NA,0,0,0,0,1,1,1,1,1,1,1,1))

For the moment, I have this function:

foo - function(X,N){
  tab - table(X[X==1])
  under.n - as.numeric(names(tab)[tabN]) 
  ind - X %in% under.n
  Ind.sup - which(ind)
  X - ifelse(ind,NA,X)
}

test$x - apply(as.data.frame(test$x),2,function(x) foo(x,5))

The problem is that the function doesn't consider each sequence separately,
but only one sequence. I think that adding rle() instead of table() in my
function should to the trick, but it doesn't work yet. 
Does someone have an idea about fixing this problem?





--
View this message in context: 
http://r.789695.n4.nabble.com/find-remove-sequences-of-at-least-N-values-for-a-specific-value-tp4693810.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Error in installing package raccumulo for R version 3.1.0

2014-07-10 Thread madhvi.gupta
Dear sir,

I am a beginner in R and I am having problem in installing raccumulo 
package.On trying to install it on RStudio from cran repository it gives 
error:
*Warning in install.packages :**
**  package 'raccumulo' is not available (for R version 3.1.0)**

*On installing it from github following a procedure give in the link 
https://github.com/DataTacticsCorp/raccumulo it gives the following errors:
*
* installing to library '/usr/local/lib/R/site-library'
ERROR: failed to lock directory '/usr/local/lib/R/site-library' for 
modifying
Try removing '/usr/local/lib/R/site-library/00LOCK-package'

*After removing the lock package it gives error:

*raccumulo.cpp:14:39: fatal error: protocol/TCompactProtocol.h: No such 
file or directory**
**compilation terminated.**
**make: *** [raccumulo.o] Error 1**
**ERROR: compilation failed for package 'raccumulo'**
*** removing '/usr/local/lib/R/site-library/raccumulo'**
**Error in setwd(startdir) : cannot change working directory**
**Error in setwd(startdir) : cannot change working directory**
**Execution halted**
**sh: 0: getcwd() failed: No such file or directory*

I shal be very thankful for ur any help and an early rply would be 
appreciated.
Thanks and Regards,
Madhvi Gupta

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


Re: [R] Preserving topology when simplifying Spatial Polygons

2014-07-10 Thread Marcus Schwemmle
Have you got any further with this? I have the same problem...



On Wednesday, 4 June 2014 22:17:20 UTC+2, Will Leahy wrote:

 I'm trying to simplify a group of adjacent polygons without gaps and line 
 overlaps forming between them. Ideally I'd like results similar to what 
 mapshaper produces. I've tried using gSimplify() (from rGEOS), 
 thinnedSpatialPoly() (from maptools), and dp() (from shapefiles) but 
 haven't been able to get good results. The first two have a 
 topologyPreserve argument but it only applies to single polygons. Are 
 there any other tools / methods for line simplification that I might try? 
 Thanks 

 [[alternative HTML version deleted]] 

 __ 
 r-h...@r-project.org javascript: 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-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] Survival Analysis with an Historical Control

2014-07-10 Thread Therneau, Terry M., Ph.D.

You are asking for a one sample test.  Using your own data:

connection - textConnection(
GD2  1   8 12  GD2  3 -12 10  GD2  6 -52  7
GD2  7  28 10  GD2  8  44  6  GD2 10  14  8
GD2 12   3  8  GD2 14 -52  9  GD2 15  35 11
GD2 18   6 13  GD2 20  12  7  GD2 23  -7 13
GD2 24 -52  9  GD2 26 -52 12  GD2 28  36 13
GD2 31 -52  8  GD2 33   9 10  GD2 34 -11 16
GD2 36 -52  6  GD2 39  15 14  GD2 40  13 13
GD2 42  21 13  GD2 44 -24 16  GD2 46 -52 13
GD2 48  28  9  GD2  2  15  9  GD2  4 -44 10
GD2  5  -2 12  GD2  9   8  7  GD2 11  12  7
GD2 13 -52  7  GD2 16  21  7  GD2 17  19 11
GD2 19   6 16  GD2 21  10 16  GD2 22 -15  6
GD2 25   4 15  GD2 27  -9  9  GD2 29  27 10
GD2 30   1 17  GD2 32  12  8  GD2 35  20  8
GD2 37 -32  8  GD2 38  15  8  GD2 41   5 14
GD2 43  35 13  GD2 45  28  9  GD2 47   6 15
)

hsv - data.frame(scan(connection, list(vac=, pat=0, wks=0, x=0)))
hsv - transform(hsv, status= (wks 0), wks = abs(wks))

fit1 - survreg(Surv(wks, status) ~ 1, data=hsv, dist='exponential')
temp - predict(fit1, type='quantile', p=.5, se=TRUE)

c(median= temp$fit[1], std= temp$se[1])
  medianstd
24.32723  4.36930

--
The predict function gives the predicted median survival and standard deviation for each 
observation in the data set.  Since this was a mean only model all n of them are the same 
and I printed only the first.
For prediction they make the assumption that the std error for my future study will be the 
same as the std from this one, you want the future 95% CI to not include the value of 16, 
so the future mean will need to be at least 16 + 1.96* 4.369.


A nonparmetric version of the argument would be


fit2 - survfit(Surv(wks, status) ~ 1, data=hsv)
print(fit2)

records   n.max n.start  events  median 0.95LCL 0.95UCL
 48  48  48  31  21  15  35

Then make the argument that in our future study, the 95% CI will stretch 6 units to the 
left of the median, just like it did here.  This argument is a bit more tenuous though. 
The exponential CI width depends on the total number of events and total follow-up time, 
and we can guess that the new study will be similar.  The Kaplan-Meier CI also depends on 
the spacing of the deaths, which is less likely to replicate.


Notes:
 1. Use summary(fit2)$table to extract the CI values.  In R the print functions don't 
allow you to grab what was printed, summary normally does.
 2. For the exponential we could work out the formula in closed form -- a good homework 
exercise for grad students perhaps but not an exciting way to spend my own afternoon.  An 
advantage of the above approach is that we can easily use a more realistic model like the 
weibull.
 3. I've never liked extracting out the Surv(t,s) part of a formula as a separate 
statement on another line.  If I ever need to read this code again, or even just the 
printout from the run, keeping it all together gives much better documentation.
 4. Future calculations for survival data, of any form, are always tenuous since they 
depend critically on the total number of events that will be in the future study.  We can 
legislate the total enrollment and follow-up time for that future study, but the number of 
events is never better than a guess.  Paraphrasing a motto found on the door of a well 
respected investigator I worked with 30 years ago (because I don't remember it exaclty):


  The incidence of the condition under consideration and its subsequent death rate will 
both drop by 1/2 at the commencement of a study, and will not return to their former 
values until the study finishes or the PI retires.



Terry T.

---

On 07/10/2014 05:00 AM, r-help-requ...@r-project.org wrote:

Hello All,

I'm trying to figure out how to perform a survival analysis with an historical 
control. I've spent some time looking online and in my boooks but haven't found 
much showing how to do this. Was wondering if there is a R package that can do 
it, or if there are resources somewhere that show the actual steps one takes, 
or if some knowledgeable person might be willing to share some code.

Here is a statement that describes the sort of analyis I'm being asked to do.

A one-sample parametric test assuming an exponential form of survival was used 
to test the hypothesis that the treatment produces a median PFS no greater than 
the historical control PFS of 16 weeks.  A sample median PFS greater than 20.57 
weeks would fall beyond the critical value associated with the null hypothesis, 
and would be considered statistically significant at alpha = .05, 1 tailed.

My understanding is that the cutoff of 20.57 weeks was obtained using an online 
calculator that can be found at:

http://www.swogstat.org/stat/public/one_survival.htm

Thus far, I've been unable to determine what values were plugged into the 
calculator to get the cutoff.

There's another calculator for a nonparamertric test that can be found at:


Re: [R] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Kenn Konstabel
Wow. Thanks a lot!

source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=UTF-8-BOM)
# works correctly on my Windows 7 machine
# (and without encoding argument it still crashes R)

Kenn

On Thu, Jul 10, 2014 at 4:33 PM, John McKown
john.archie.mck...@gmail.com wrote:
 On Thu, Jul 10, 2014 at 7:18 AM, Kenn Konstabel lebats...@gmail.com wrote:
 Dear all,

 I found an unexpected behaviour when trying to `source` an utf-8 file
 on windows 7:

 source(http://psych.ut.ee/~nek/R/test-utf8.txt;)

 # Rgui.exe reacts:
 # R for windows GUI has stopped working. A problem caused the program
 to stop working correctly.
 # Windows will close the program and notify you if a solution is available.

 The same will happen with R.exe (terminal) and R running wihin
 Rstudio. (Session and locale info below).

 However, a non-utf version of this little script can be `source`d
 without problems.

 source(http://psych.ut.ee/~nek/R/test.txt;)

 Adding the `encoding` argument to `source` helps a little:

 source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=utf-8)
 #  unsure about the spelling of utf-8 so I also tried UTF8, utf8, and UTF-8
 # ... with the same result in all cases

 R doesn't crash any more but gives the following error:

 # Error in source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding
 = utf-8) :
 #   http://psych.ut.ee/~nek/R/test-utf8.txt:2:0: unexpected end of input
 # 1: ?
 #^
 # In addition: Warning message:
 # In readLines(file, warn = FALSE) :
 #  invalid input found on input connection
 'http://psych.ut.ee/~nek/R/test-utf8.txt'

 I just tried that. On Windows XP/Pro,  R 3.1.0 didn't fail, but did
 get the error you mention later. I used wget to actually download
 the file mentioned (on Linux). I think that the problem _may_ be that
 the file starts with a BOM (Byte Order Mark), which is 0xef, 0xbb,
 0xef . This is supposed to tell us that this is UTF-8.

 BOM: http://en.wikipedia.org/wiki/Byte_order_mark

 I get an identical error with R 3.1.0 on both Windows XP/Pro and Linux
 Fedora 20. The problem is that the R readLines() apparently does not
 like the leading BOM. It reads it as data. Most other Linux and
 Windows applications _do_ understand the BOM and so, when you use
 them, they work properly. And, normally, when you then save the file,
 the software does not write the BOM at the start. So it works on the
 saved version of the file.

 Being the curious sort, I decided to look at the source to R. In
 particular in ~/R/src/main/connections.c I saw where it did support
 the reading of BOMs. But there is a special way to do it! Which I
 cannot find in the documentation.

 source(http://psych.ut.ee/~nek/R/test-utf8.txt,encoding=UTF-8-BOM;);

 I tried the above AND IT WORKED properly!

 I simply adore having source code.



 I thought maybe that's because what notepad told me is UTF-8 is
 actually something else ... so I did two more experiments.

 source(http://psych.ut.ee/~nek/R/test2.R;)
 # this was created on a linux machine with leafpad, and saved as utf-8 text
 # it can be source´d on windows

 source(http://psych.ut.ee/~nek/R/test3.R;)
 # the same as previous but o's in file were replaced by ö's
 # can be source'd on windows but the ö character is shown as ƶ
 # except if you add encoding=utf-8 - then, as expected, it works as 
 expected

 So in sum, I can create plain text (saved with utf-8 encoding) files
 on windows that cannot be sourced to R on windows, or will crash R
 (depending on how you source them). The same files can be sourced on
 linux without problems. Part of the problem is obviously in windows
 but maybe R shouldn't at least crash.

 Session info:

  R version 3.0.2 (2013-09-25)
 Platform: i386-w64-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=Estonian_Estonia.1257  LC_CTYPE=Estonian_Estonia.1257
 [3] LC_MONETARY=Estonian_Estonia.1257 LC_NUMERIC=C
 [5] LC_TIME=Estonian_Estonia.1257

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

 loaded via a namespace (and not attached):
 [1] tools_3.0.2


 OS: Windows 7

 Linux Mint Debian Edition and R 3.0.2 on the other machine (where
 everything worked).

 Context:

 I was trying to find out how to make files that could be source'd on
 both windows and linux. This is partly solved so I have no specific
 question other than is this a bug in windows version? but any
 comments on the general topic would be appreciated too.

 Best regards,

 Kenn


 Kenn Konstabel
 Research fellow
 Department of chronic diseases
 National Institute of Health Development
 Hiiu 42
 Tallinn
 Estonia

 --
 There is nothing more pleasant than traveling and meeting new people!
 Genghis Khan

 Maranatha! 
 John McKown

__
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] Cansisc: Error in eigen(eHe, symmetric = TRUE)

2014-07-10 Thread David L Carlson
In particular, look at the vegan Vignette, Introduction to Ordination in 
vegan, particularly section 4 on constrained ordination which describes three 
approaches that seem relevant to your problem.

http://cran.r-project.org/web/packages/vegan/vignettes/intro-vegan.pdf

David Carlson

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Michael Friendly
Sent: Thursday, July 10, 2014 3:22 AM
To: Maria Judith Carmona H
Cc: r-help@r-project.org; John Fox
Subject: Re: [R] Cansisc: Error in eigen(eHe, symmetric = TRUE)

Maria

The variables 
Araceae,Begoniaceae,Bromeliaceae,Clusiaceae,Cyclanthaceae,Ericaceae,Gesneriaceae,
 
Melastomataceae,Orchidaceae,Piperaceae,Pteridophyta
are frequencies (abundances?) of which most are 0 and this is not 
appropriate
as multivariate normal data.

There is probably a version of canonical analysis that takes such 
variables into account,
but I don't know specifically.  Have you looked at the vegan package and 
its references?

HTH
-Michael



On 10/07/2014 12:54 AM, Maria Judith Carmona H wrote:
 Dear John,

 I am including abundance values ​​in my data set so obviously I have 
 zero abundances.
 The problem is that if plot only the factors (biomasa, altdosel, 
 altsoto, cobertura, riqarb, elevacion, temperatura, precipitacion) I 
 get the graphic, the same happen when I included only the families, 
 but I want to see the effect of all these factors+families on this 
 plot . In fact I included only certain families:

 prueba4 - 
 lm(cbind(biomasa,altdosel,altsoto,cobertura,riqarb,elevacion,temperatura,precipitacion,
 Araceae,Begoniaceae,Bromeliaceae,Clusiaceae,Cyclanthaceae,Ericaceae,Gesneriaceae,
 Melastomataceae,Orchidaceae,Piperaceae,Pteridophyta) ~ sitio, 
 data=bosques.p)
 canprueba2 - candisc(prueba2, term=sitio, data=bosques.p, ndim=1)
 Error in eigen (EHD, symmetric = TRUE): infinite or missing values ​​ 
 in 'x'
 In addition: Warning message:
 In sqrt (wmd): NaNs produced

 You see I get the same error.

 Best regards,
 Judith


 On Wed, Jul 9, 2014 at 5:30 PM, John Fox j...@mcmaster.ca 
 mailto:j...@mcmaster.ca wrote:

 Dear Maria Judith Carmona Higuita,

 Since you didn't include enough information (such as your access
 to your data) to reproduce the error, one can only guess. My
 guess: you have fewer observations in your data set than response
 variables on the LHS of the multivariate linear model.

 I hope this helps,
  John

 
 John Fox, Professor
 McMaster University
 Hamilton, Ontario, Canada
 http://socserv.mcmaster.ca/jfox/

 On Wed, 9 Jul 2014 11:36:35 -0500
  Maria Judith Carmona H juditycarm...@gmail.com
 mailto:juditycarm...@gmail.com wrote:
  Hi,
 
  I have a problem using the function Candisc from Candisc Package.
 
  bosques1-read.csv(bosques1.csv,header=TRUE,encoding=latin1)
  bosques1-na.exclude(bosques1)
  attach(bosques1)
 
  #Modelo de regresión
  mod -
 
 
 lm(cbind(biomasa,altdosel,altsoto,cobertura,riqarb,elevacion,temperatura,precipitacion,
  Acanthaceae, Apocinaceae, Araceae, Araliaceae,
 Arecaceae,
  Aspleniaceae, Begoniaceae,
  Blechnaceae, Bromeliaceae, Clusiaceae,
 Cyclanthaceae,
  Davalliaceae, Denstaedtiaceae,
  Dryopteridaceae, Ericaceae, Gesneriaceae,
 Hymenophyllaceae,
  indet., Lauraceae, Lomariopsidaceae, Lycopodiaceae, Melastomataceae,
  Moraceae, Myrsinaceae, Ophioglossaceae,
  Orchidaceae, Peperomia, Piperaceae, Poaceae,
 Polypodiaceae,
  Primulaceae, Pteridaceae,
  Pteridophyta.taxa, Rubiaceae, Vittariaceae) ~ sitio,
  data=bosques1)
  summary(mod)
 
  #Gráfico 1
  can - candisc(mod, term=sitio,data=bosques1,ndim=1,eig=T)
  ### The error happens here, so I can not run the plot.
  plot(can,titles.1d = c(Puntuación canónica, Estructura))
  summary(can, means = FALSE, scores = TRUE, coef = c(std),
 digits = 2)
 
  The error is:
  Error in eigen(eHe, symmetric = TRUE) : infinite or missing
 values in 'x'
  In addition: Warning message:
  In sqrt(wmd) : NaNs produced
 
  Please help!
 
  --
  Maria Judith Carmona Higuita.
  Estudiante de Biología - Universidad de Antioquia
  Medellín - Colombia
 
  La felicidad ocurre cuando encajas en tu vida, cuando encajas
  tan armónicamente que cualquier cosa que hagas es una alegría
 para ti. De
  repente lo sabrás y la meditación te seguirá. Si amas el trabajo
 que haces,
  si amas la manera como vives, entonces ya estás meditando y nada
 puede
  distraerte. Osho
 
[[alternative HTML version deleted]]
 







 -- 
 Maria Judith Carmona Higuita.
 Estudiante de Biología - Universidad de Antioquia
 

Re: [R] function completing properly

2014-07-10 Thread PIKAL Petr
Hi

Works for me after I commented uknown function cal.wyd

 version
   _
platform   i386-w64-mingw32
arch   i386
os mingw32
system i386, mingw32
status Under development (unstable)
major  3
minor  1.0
year   2013
month  12
day19
svn rev64488
language   R
version.string R Under development (unstable) (2013-12-19 r64488)
nickname   Unsuffered Consequences


 mkdate = function(x) {
+ x$date = as.Date(paste(x$year, x$month, x$day, sep=-))
+ x$wy = ifelse(x$month =10, x$year+1, x$year)
+ x$yd = as.integer(format(as.Date(x$date), format=%j))
+ #x$wyd = cal.wyd(x)
+ x
+ }

 test-data.frame(year=2000, month=10, day=5)
 test
  year month day
1 200010   5
 mkdate(test)
  year month day   date   wy  yd
1 200010   5 2000-10-05 2001 279
 test-mkdate(test)
 test
  year month day   date   wy  yd
1 200010   5 2000-10-05 2001 279


Regards
Petr


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Janet Choate
 Sent: Thursday, July 10, 2014 1:48 AM
 To: r-help@r-project.org
 Subject: [R] function completing properly

 Hi R community,
 i created a function (mkdate) as follows:

 mkdate = function(x) {
 x$date = as.Date(paste(x$year, x$month, x$day, sep=-))
 x$wy = ifelse(x$month =10, x$year+1, x$year)
 x$yd = as.integer(format(as.Date(x$date), format=%j))
 x$wyd = cal.wyd(x)
 x
 }

 the function results in adding the new columns date, wy, yd, and wyd to
 the
 table i apply it to.
 this has always worked in R version 2.14.2.
 however, in R version 3.1.0 - instead of my mkdate function adding
 those
 columns to my existing table, it just overwrites my table and leaves me
 with just a list of the last variable created by my mkdate function. so
 i
 end up with just a list of numbers representing wyd, and lose all the
 data
 in my original table.

 does anyone know what would now be causing this to occur, and what i
 need
 to do to make my function work properly again?

 thank you for any assistance,
 Janet

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


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail 

Re: [R] Decision Tree

2014-07-10 Thread Adams, Jean
The function fancyRpartPlot() is actually in the rattle package, and it is
a wrapper for the prp() function in the rpart.plot package.  If you look at
the help for prp(), you should be able to see how to change the color.

library(rpart.plot)
?prp

Jean



On Thu, Jul 10, 2014 at 12:34 AM, Abhinaba Roy abhinabaro...@gmail.com
wrote:

 Hi R-helpers,

 Is it possible to change the color of the boxes when plotting decision
 trees using 'fancyRpartPlot()' from rpart.plot package ?

 --
 Regards,
 Abhinaba Roy

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


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


Re: [R] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Duncan Murdoch

On 10/07/2014 9:53 AM, Kenn Konstabel wrote:

Wow. Thanks a lot!

source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=UTF-8-BOM)
# works correctly on my Windows 7 machine
# (and without encoding argument it still crashes R)

Kenn

On Thu, Jul 10, 2014 at 4:33 PM, John McKown
john.archie.mck...@gmail.com wrote:
 On Thu, Jul 10, 2014 at 7:18 AM, Kenn Konstabel lebats...@gmail.com wrote:
 Dear all,

 I found an unexpected behaviour when trying to `source` an utf-8 file
 on windows 7:

 source(http://psych.ut.ee/~nek/R/test-utf8.txt;)

 # Rgui.exe reacts:
 # R for windows GUI has stopped working. A problem caused the program
 to stop working correctly.
 # Windows will close the program and notify you if a solution is available.

 The same will happen with R.exe (terminal) and R running wihin
 Rstudio. (Session and locale info below).

 However, a non-utf version of this little script can be `source`d
 without problems.

 source(http://psych.ut.ee/~nek/R/test.txt;)

 Adding the `encoding` argument to `source` helps a little:

 source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=utf-8)
 #  unsure about the spelling of utf-8 so I also tried UTF8, utf8, and UTF-8
 # ... with the same result in all cases

 R doesn't crash any more but gives the following error:

 # Error in source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding
 = utf-8) :
 #   http://psych.ut.ee/~nek/R/test-utf8.txt:2:0: unexpected end of input
 # 1: ?
 #^
 # In addition: Warning message:
 # In readLines(file, warn = FALSE) :
 #  invalid input found on input connection
 'http://psych.ut.ee/~nek/R/test-utf8.txt'

 I just tried that. On Windows XP/Pro,  R 3.1.0 didn't fail, but did
 get the error you mention later. I used wget to actually download
 the file mentioned (on Linux). I think that the problem _may_ be that
 the file starts with a BOM (Byte Order Mark), which is 0xef, 0xbb,
 0xef . This is supposed to tell us that this is UTF-8.

 BOM: http://en.wikipedia.org/wiki/Byte_order_mark

 I get an identical error with R 3.1.0 on both Windows XP/Pro and Linux
 Fedora 20. The problem is that the R readLines() apparently does not
 like the leading BOM. It reads it as data. Most other Linux and
 Windows applications _do_ understand the BOM and so, when you use
 them, they work properly. And, normally, when you then save the file,
 the software does not write the BOM at the start. So it works on the
 saved version of the file.

 Being the curious sort, I decided to look at the source to R. In
 particular in ~/R/src/main/connections.c I saw where it did support
 the reading of BOMs. But there is a special way to do it! Which I
 cannot find in the documentation.

 source(http://psych.ut.ee/~nek/R/test-utf8.txt,encoding=UTF-8-BOM;);

 I tried the above AND IT WORKED properly!

 I simply adore having source code.


Searching the source for the string UTF-8-BOM finds it mentioned in 
the docs in 3 places:  in the NEWS file,

in the R Data Import/Export manual, and in the ?connections help page.

Duncan Murdoch





 I thought maybe that's because what notepad told me is UTF-8 is
 actually something else ... so I did two more experiments.

 source(http://psych.ut.ee/~nek/R/test2.R;)
 # this was created on a linux machine with leafpad, and saved as utf-8 text
 # it can be source´d on windows

 source(http://psych.ut.ee/~nek/R/test3.R;)
 # the same as previous but o's in file were replaced by ö's
 # can be source'd on windows but the ö character is shown as ƶ
 # except if you add encoding=utf-8 - then, as expected, it works as 
expected

 So in sum, I can create plain text (saved with utf-8 encoding) files
 on windows that cannot be sourced to R on windows, or will crash R
 (depending on how you source them). The same files can be sourced on
 linux without problems. Part of the problem is obviously in windows
 but maybe R shouldn't at least crash.

 Session info:

  R version 3.0.2 (2013-09-25)
 Platform: i386-w64-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=Estonian_Estonia.1257  LC_CTYPE=Estonian_Estonia.1257
 [3] LC_MONETARY=Estonian_Estonia.1257 LC_NUMERIC=C
 [5] LC_TIME=Estonian_Estonia.1257

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

 loaded via a namespace (and not attached):
 [1] tools_3.0.2


 OS: Windows 7

 Linux Mint Debian Edition and R 3.0.2 on the other machine (where
 everything worked).

 Context:

 I was trying to find out how to make files that could be source'd on
 both windows and linux. This is partly solved so I have no specific
 question other than is this a bug in windows version? but any
 comments on the general topic would be appreciated too.

 Best regards,

 Kenn


 Kenn Konstabel
 Research fellow
 Department of chronic diseases
 National Institute of Health Development
 Hiiu 42
 Tallinn
 Estonia

 --
 There is nothing more pleasant than traveling and meeting new people!
 Genghis Khan

 Maranatha! 
 John McKown


[R] list of valid R encodings.in source(...,encoding=)

2014-07-10 Thread John McKown
This question was spawned by another thread entitled R on Windows
crashes when source'ing UTF-8 file.

The solution to that problem was to use the _proper_ encoding=
parameter of the source() function. But where are they documented? Or
how do I find them in R itself? I ask because the proper encoding to
solve the problem was UTF-8-BOM. I got this by reading the source
code to main/connnections.c . Not where I expect most people to go.

I found iconvlist(). But it does not list UTF-8-BOM, only UTF8 and
UTF-8. I got no useful response to ??BOM from the R prompt.

My normal locale is C on Linux. If I use encoding=UTF-8 in the
source() line, it fails because the BOM at the start is intepreted as
data to be processed. If I use UTF-8-BOM instead, it succeeds. It also
succeeds if I do Sys.setlocale(LC_ALL,en_US.utf8).

I admit that I don't understand all (or even much) of the ins-and-outs
of i10n, or code pages. But the UTF-8-BOM is just weird to me; and
confusing since it is not documented anywhere I can find.

-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! 
John McKown

__
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] Cansisc: Error in eigen(eHe, symmetric = TRUE)

2014-07-10 Thread Maria Judith Carmona H
Hello John, Michael and David,

I will review Vegan Package. I am very thankful with your help.

Best,
Judith


On Thu, Jul 10, 2014 at 9:04 AM, David L Carlson dcarl...@tamu.edu wrote:

 In particular, look at the vegan Vignette, Introduction to Ordination in
 vegan, particularly section 4 on constrained ordination which describes
 three approaches that seem relevant to your problem.

 http://cran.r-project.org/web/packages/vegan/vignettes/intro-vegan.pdf

 David Carlson

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Michael Friendly
 Sent: Thursday, July 10, 2014 3:22 AM
 To: Maria Judith Carmona H
 Cc: r-help@r-project.org; John Fox
 Subject: Re: [R] Cansisc: Error in eigen(eHe, symmetric = TRUE)

 Maria

 The variables

 Araceae,Begoniaceae,Bromeliaceae,Clusiaceae,Cyclanthaceae,Ericaceae,Gesneriaceae,
 Melastomataceae,Orchidaceae,Piperaceae,Pteridophyta
 are frequencies (abundances?) of which most are 0 and this is not
 appropriate
 as multivariate normal data.

 There is probably a version of canonical analysis that takes such
 variables into account,
 but I don't know specifically.  Have you looked at the vegan package and
 its references?

 HTH
 -Michael



 On 10/07/2014 12:54 AM, Maria Judith Carmona H wrote:
  Dear John,
 
  I am including abundance values ​​in my data set so obviously I have
  zero abundances.
  The problem is that if plot only the factors (biomasa, altdosel,
  altsoto, cobertura, riqarb, elevacion, temperatura, precipitacion) I
  get the graphic, the same happen when I included only the families,
  but I want to see the effect of all these factors+families on this
  plot . In fact I included only certain families:
 
  prueba4 -
 
 lm(cbind(biomasa,altdosel,altsoto,cobertura,riqarb,elevacion,temperatura,precipitacion,
 
 Araceae,Begoniaceae,Bromeliaceae,Clusiaceae,Cyclanthaceae,Ericaceae,Gesneriaceae,
  Melastomataceae,Orchidaceae,Piperaceae,Pteridophyta) ~ sitio,
  data=bosques.p)
  canprueba2 - candisc(prueba2, term=sitio, data=bosques.p, ndim=1)
  Error in eigen (EHD, symmetric = TRUE): infinite or missing values ​​
  in 'x'
  In addition: Warning message:
  In sqrt (wmd): NaNs produced
 
  You see I get the same error.
 
  Best regards,
  Judith
 
 
  On Wed, Jul 9, 2014 at 5:30 PM, John Fox j...@mcmaster.ca
  mailto:j...@mcmaster.ca wrote:
 
  Dear Maria Judith Carmona Higuita,
 
  Since you didn't include enough information (such as your access
  to your data) to reproduce the error, one can only guess. My
  guess: you have fewer observations in your data set than response
  variables on the LHS of the multivariate linear model.
 
  I hope this helps,
   John
 
  
  John Fox, Professor
  McMaster University
  Hamilton, Ontario, Canada
  http://socserv.mcmaster.ca/jfox/
 
  On Wed, 9 Jul 2014 11:36:35 -0500
   Maria Judith Carmona H juditycarm...@gmail.com
  mailto:juditycarm...@gmail.com wrote:
   Hi,
  
   I have a problem using the function Candisc from Candisc Package.
  
   bosques1-read.csv(bosques1.csv,header=TRUE,encoding=latin1)
   bosques1-na.exclude(bosques1)
   attach(bosques1)
  
   #Modelo de regresión
   mod -
  
 
 lm(cbind(biomasa,altdosel,altsoto,cobertura,riqarb,elevacion,temperatura,precipitacion,
   Acanthaceae, Apocinaceae, Araceae, Araliaceae,
  Arecaceae,
   Aspleniaceae, Begoniaceae,
   Blechnaceae, Bromeliaceae, Clusiaceae,
  Cyclanthaceae,
   Davalliaceae, Denstaedtiaceae,
   Dryopteridaceae, Ericaceae, Gesneriaceae,
  Hymenophyllaceae,
   indet., Lauraceae, Lomariopsidaceae, Lycopodiaceae,
 Melastomataceae,
   Moraceae, Myrsinaceae, Ophioglossaceae,
   Orchidaceae, Peperomia, Piperaceae, Poaceae,
  Polypodiaceae,
   Primulaceae, Pteridaceae,
   Pteridophyta.taxa, Rubiaceae, Vittariaceae) ~
 sitio,
   data=bosques1)
   summary(mod)
  
   #Gráfico 1
   can - candisc(mod, term=sitio,data=bosques1,ndim=1,eig=T)
   ### The error happens here, so I can not run the plot.
   plot(can,titles.1d = c(Puntuación canónica, Estructura))
   summary(can, means = FALSE, scores = TRUE, coef = c(std),
  digits = 2)
  
   The error is:
   Error in eigen(eHe, symmetric = TRUE) : infinite or missing
  values in 'x'
   In addition: Warning message:
   In sqrt(wmd) : NaNs produced
  
   Please help!
  
   --
   Maria Judith Carmona Higuita.
   Estudiante de Biología - Universidad de Antioquia
   Medellín - Colombia
  
   La felicidad ocurre cuando encajas en tu vida, cuando encajas
   tan armónicamente que cualquier cosa que hagas es una alegría
  para ti. De
   repente lo sabrás y la 

Re: [R] find remove sequences of at least N values for a specific value

2014-07-10 Thread William Dunlap
Here is one way to use rle() to solve the problem:

  shortRunsOfOnesToNAs - function(x, n) {
  r - rle(x)
  r$values[r$values==1  r$lengths  n] - NA
  rep(r$values, r$lengths)
  }
E.g.,
  input - c(0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1)
  result - shortRunsOfOnesToNAs(input, 5)
  desiredResult - c(0,0,NA,NA,NA,0,0,0,0,1,1,1,1,1,1,1,1)
  all.equal(desiredResult, result) # TRUE

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jul 10, 2014 at 5:34 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr
 wrote:

 Hi everybody,

 I have a small problem in a function, about removing short sequences of
 identical numeric values.

 For the example, we can consider this data, containing only some 0 and
 1:

 test - data.frame(x=c(0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1))

 The aim of my purpose here is simply to remove each sequence of 1 with a
 length shorter than 5, and to keep sequences of 1 which are bigger than
 5.
 So my final data should look like this:

 final - data.frame(x=c(0,0,NA,NA,NA,0,0,0,0,1,1,1,1,1,1,1,1))

 For the moment, I have this function:

 foo - function(X,N){
   tab - table(X[X==1])
   under.n - as.numeric(names(tab)[tabN])
   ind - X %in% under.n
   Ind.sup - which(ind)
   X - ifelse(ind,NA,X)
 }

 test$x - apply(as.data.frame(test$x),2,function(x) foo(x,5))

 The problem is that the function doesn't consider each sequence separately,
 but only one sequence. I think that adding rle() instead of table() in my
 function should to the trick, but it doesn't work yet.
 Does someone have an idea about fixing this problem?





 --
 View this message in context:
 http://r.789695.n4.nabble.com/find-remove-sequences-of-at-least-N-values-for-a-specific-value-tp4693810.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Survival Analysis with an Historical Control

2014-07-10 Thread Paul Miller
Hi Dr. Therneau,

Thanks for your response. This is very helpful.

My historical control value is 16 weeks. I've been having some trouble though 
determining how this value was obtained. Are you able to indicate how people 
normally go about determining a value for the historical control? Or do you 
have an view on how it ought to be done? 

It does seem like selecting an appropriate value is extremely important. 
Otherwise the results obtained from the analysis are likely to be nonsense. 

Thanks,

Paul


On Thu, 7/10/14, Therneau, Terry M., Ph.D. thern...@mayo.edu wrote:

 Subject: Re: Survival Analysis with an Historical Control
 To: r-help@r-project.org, Andrews, Chris chri...@med.umich.edu, pjmill
 Received: Thursday, July 10, 2014, 8:52 AM

 You are asking for a one sample
 test.  Using your own data:

 connection - textConnection(
 GD2  1   8 12  GD2  3 -12
 10  GD2  6 -52  7
 GD2  7  28 10  GD2  8  44 
 6  GD2 10  14  8
 GD2 12   3  8  GD2 14 -52 
 9  GD2 15  35 11
 GD2 18   6 13  GD2 20  12 
 7  GD2 23  -7 13
 GD2 24 -52  9  GD2 26 -52 12  GD2 28  36
 13
 GD2 31 -52  8  GD2 33   9 10 
 GD2 34 -11 16
 GD2 36 -52  6  GD2 39  15 14  GD2
 40  13 13
 GD2 42  21 13  GD2 44 -24 16  GD2 46 -52 13
 GD2 48  28  9  GD2  2  15 
 9  GD2  4 -44 10
 GD2  5  -2 12  GD2 
 9   8  7  GD2 11  12  7
 GD2 13 -52  7  GD2 16  21  7  GD2
 17  19 11
 GD2 19   6 16  GD2 21  10 16 
 GD2 22 -15  6
 GD2 25   4 15  GD2 27  -9 
 9  GD2 29  27 10
 GD2 30   1 17  GD2 32  12 
 8  GD2 35  20  8
 GD2 37 -32  8  GD2 38  15  8  GD2
 41   5 14
 GD2 43  35 13  GD2 45  28  9  GD2
 47   6 15
 )

 hsv - data.frame(scan(connection, list(vac=, pat=0,
 wks=0, x=0)))
 hsv - transform(hsv, status= (wks 0), wks =
 abs(wks))

 fit1 - survreg(Surv(wks, status) ~ 1, data=hsv,
 dist='exponential')
 temp - predict(fit1, type='quantile', p=.5, se=TRUE)

 c(median= temp$fit[1], std= temp$se[1])
    median    std
 24.32723  4.36930

 --
 The predict function gives the predicted median survival and
 standard deviation for each 
 observation in the data set.  Since this was a mean
 only model all n of them are the same 
 and I printed only the first.
 For prediction they make the assumption that the std error
 for my future study will be the 
 same as the std from this one, you want the future 95% CI to
 not include the value of 16, 
 so the future mean will need to be at least 16 + 1.96*
 4.369.

 A nonparmetric version of the argument would be

  fit2 - survfit(Surv(wks, status) ~ 1, data=hsv)
  print(fit2)
 records   n.max n.start  events 
 median 0.95LCL 0.95UCL
       48      48   
   48      31     
 21      15      35

 Then make the argument that in our future study, the 95% CI
 will stretch 6 units to the 
 left of the median, just like it did here.  This
 argument is a bit more tenuous though. 
 The exponential CI width depends on the total number of
 events and total follow-up time, 
 and we can guess that the new study will be similar. 
 The Kaplan-Meier CI also depends on 
 the spacing of the deaths, which is less likely to
 replicate.

 Notes:
   1. Use summary(fit2)$table to extract the CI
 values.  In R the print functions don't 
 allow you to grab what was printed, summary normally
 does.
   2. For the exponential we could work out the formula
 in closed form -- a good homework 
 exercise for grad students perhaps but not an exciting way
 to spend my own afternoon.  An 
 advantage of the above approach is that we can easily use a
 more realistic model like the 
 weibull.
   3. I've never liked extracting out the Surv(t,s)
 part of a formula as a separate 
 statement on another line.  If I ever need to read this
 code again, or even just the 
 printout from the run, keeping it all together gives much
 better documentation.
   4. Future calculations for survival data, of any
 form, are always tenuous since they 
 depend critically on the total number of events that will be
 in the future study.  We can 
 legislate the total enrollment and follow-up time for that
 future study, but the number of 
 events is never better than a guess.  Paraphrasing a
 motto found on the door of a well 
 respected investigator I worked with 30 years ago (because I
 don't remember it exaclty):

    The incidence of the condition under
 consideration and its subsequent death rate will 
 both drop by 1/2 at the commencement of a study, and will
 not return to their former 
 values until the study finishes or the PI retires.


 Terry T.

 ---

 On 07/10/2014 05:00 AM, r-help-requ...@r-project.org
 wrote:
  Hello All,
 
  I'm trying to figure out how to perform a survival
 analysis with an historical control. I've spent some time
 looking online and in my boooks but haven't found much
 showing how to do this. Was wondering if there is a R
 package that can do it, or if there are resources somewhere
 that show the actual steps one takes, or if some
 

[R] table over a matrix dimension...

2014-07-10 Thread Jonathan Greenberg
R-helpers:

I'm trying to determine the frequency of characters for a matrix
applied to a single dimension, and generate a matrix as an output.
I've come up with a solution, but it appears inelegant -- I was
wondering if there is an easier way to accomplish this task:

# Create a matrix of factors (characters):
random_characters=matrix(sample(letters[1:4],1000,replace=TRUE),100,10)

# Applying with the table() function doesn't work properly, because not all rows
# have ALL of the factors, so I get a list output:
apply(random_characters,1,table)

# Hacked solution:
unique_values = letters[1:4]

countsmatrix - t(apply(random_characters,1,function(x,unique_values)
{
counts=vector(length=length(unique_values))
for(i in seq(unique_values))
{
counts[i] = sum(x==unique_values[i])
}
return(counts)
},
unique_values=unique_values
))

# Gets me the output I want but requires two nested loops (apply and
for() ), so
# not efficient for very large datasets.

###

Is there a more elegant solution to this?

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

__
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] table over a matrix dimension...

2014-07-10 Thread Marc Schwartz

On Jul 10, 2014, at 12:03 PM, Jonathan Greenberg j...@illinois.edu wrote:

 R-helpers:
 
 I'm trying to determine the frequency of characters for a matrix
 applied to a single dimension, and generate a matrix as an output.
 I've come up with a solution, but it appears inelegant -- I was
 wondering if there is an easier way to accomplish this task:
 
 # Create a matrix of factors (characters):
 random_characters=matrix(sample(letters[1:4],1000,replace=TRUE),100,10)
 
 # Applying with the table() function doesn't work properly, because not all 
 rows
 # have ALL of the factors, so I get a list output:
 apply(random_characters,1,table)
 
 # Hacked solution:
 unique_values = letters[1:4]
 
 countsmatrix - t(apply(random_characters,1,function(x,unique_values)
 {
 counts=vector(length=length(unique_values))
 for(i in seq(unique_values))
 {
 counts[i] = sum(x==unique_values[i])
 }
 return(counts)
 },
 unique_values=unique_values
 ))
 
 # Gets me the output I want but requires two nested loops (apply and
 for() ), so
 # not efficient for very large datasets.
 
 ###
 
 Is there a more elegant solution to this?
 
 --j
 


If I am correctly understanding your issue, you simply need to coerce the input 
to table() to a factor with a common set of levels, since the matrix will be 
'character' by default:


set.seed(1)
random_characters - matrix(sample(factor(letters[1:4]), 1000, replace = TRUE), 
100, 10)

 random_characters 
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,] b  c  b  c  c  c  d  d  d  d  
  [2,] b  b  a  a  a  c  d  d  a  d  
  [3,] c  b  c  b  d  c  a  d  d  b  
  [4,] d  d  b  b  d  c  c  c  c  a  
  [5,] a  c  a  b  d  b  d  c  b  a  
  [6,] d  a  c  d  c  d  d  a  c  a  
  [7,] d  a  c  a  b  b  b  b  b  a  
  [8,] c  b  a  d  d  d  b  c  d  a  
  [9,] c  d  b  a  a  d  d  d  b  a  
 [10,] a  c  c  b  d  c  a  c  a  a  
 [11,] a  d  d  a  d  d  d  c  b  c  
 [12,] a  c  a  a  b  b  b  b  b  d  
 [13,] c  b  d  d  c  a  c  a  b  c  
 [14,] b  b  d  c  d  c  c  d  d  a  
 [15,] d  a  d  b  c  c  c  b  b  a  
 [16,] b  a  b  b  b  a  b  b  c  b  
 [17,] c  c  c  a  b  c  a  a  d  a  
 [18,] d  a  d  b  b  c  b  a  d  c 
 ...


RES - t(apply(random_characters, 1, 
   function(x) table(factor(x, levels = letters[1:4]

 RES
   a b c d
  [1,] 0 2 4 4
  [2,] 4 2 1 3
  [3,] 1 3 3 3
  [4,] 1 2 4 3
  [5,] 3 3 2 2
  [6,] 3 0 3 4
  [7,] 3 5 1 1
  [8,] 2 2 2 4
  [9,] 3 2 1 4
 [10,] 4 1 4 1
 [11,] 2 1 2 5
 [12,] 3 5 1 1
 [13,] 2 2 4 2
 [14,] 1 2 3 4
 [15,] 2 3 3 2
 [16,] 2 7 1 0
 [17,] 4 1 4 1
 [18,] 2 3 2 3
 ...



Regards,

Marc Schwartz

__
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] table over a matrix dimension...

2014-07-10 Thread William Dunlap
You can make make a factor with a common set of levels out of each slice of
the matrix so all the tables are the same size:

f - function (charMatrix, levels = unique(sort(as.vector(charMatrix
{
apply(charMatrix, 1, function(x) table(factor(x, levels = levels)))
}
used as
 m - cbind(c(A,A,A), c(B, A, A))
 f(m)
  [,1] [,2] [,3]
A122
B100



Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jul 10, 2014 at 10:03 AM, Jonathan Greenberg j...@illinois.edu
wrote:

 R-helpers:

 I'm trying to determine the frequency of characters for a matrix
 applied to a single dimension, and generate a matrix as an output.
 I've come up with a solution, but it appears inelegant -- I was
 wondering if there is an easier way to accomplish this task:

 # Create a matrix of factors (characters):
 random_characters=matrix(sample(letters[1:4],1000,replace=TRUE),100,10)

 # Applying with the table() function doesn't work properly, because not
 all rows
 # have ALL of the factors, so I get a list output:
 apply(random_characters,1,table)

 # Hacked solution:
 unique_values = letters[1:4]

 countsmatrix - t(apply(random_characters,1,function(x,unique_values)
 {
 counts=vector(length=length(unique_values))
 for(i in seq(unique_values))
 {
 counts[i] = sum(x==unique_values[i])
 }
 return(counts)
 },
 unique_values=unique_values
 ))

 # Gets me the output I want but requires two nested loops (apply and
 for() ), so
 # not efficient for very large datasets.

 ###

 Is there a more elegant solution to this?

 --j

 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 259 Computing Applications Building, MC-150
 605 East Springfield Avenue
 Champaign, IL  61820-6371
 Phone: 217-300-1924
 http://www.geog.illinois.edu/~jgrn/
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

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


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

2014-07-10 Thread atramon
I'm trying to determine the number of factors to extract for a factor
analysis, but am having trouble with the nS/nScree function.  I did this
successfully earlier today but with the wrong matrix/dataframe, and for some
reason it won't work with the corrected one even though I've entered the
same call.

attmott is the matrix:

attmott-read.table(file.choose(), header=F, sep=,,)
 attmott-as.matrix(attmott)
 dim(attmott)
[1] 18 41
 ev-eigen(cor(attmott))
 ap-parallel(subject=ncol(attmott), var=nrow(attmott), rep=100, cent=.05)
 nS-nScree(x=ev$values, aparallel=ap$eigen$qevpea)
Error in while ((cond1 == TRUE)  (cond2 == TRUE)  (i  nk)) { : 
  missing value where TRUE/FALSE needed


I'm not sure what this error message means...  I tried entering
nS-nScree(x=ev$values, cor=TRUE, aparallel=ap$eigen$qevpea) but that did
not help, nor did replacing all the 0's with NA.


Any help would be greatly appreciated!



--
View this message in context: 
http://r.789695.n4.nabble.com/nScree-tp4693815.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Survival Analysis with an Historical Control

2014-07-10 Thread Paul Miller

Hi Chris,

Thanks for pointing out the use of View page source. Very helpful to know.

Do you happen to know anything about how to perform the analysis itself? I 
haven't been able to find anything confirming that the approach described in my 
original email (below) is correct. 

Thanks,

Paul


On Wed, 7/9/14, Andrews, Chris chri...@med.umich.edu wrote:

 Subject: RE: [R] Survival Analysis with an Historical Control

r-project.org
 Received: Wednesday, July 9, 2014, 11:26 AM

 The code is actually
 available at the websites you provide.  Try View page
 source in your browser.  The most cryptic code
 isn't needed because the math functions (e.g, incomplete
 gamma function) are available in R.


 -Original Message-


 Sent: Tuesday, July 08, 2014 12:00 PM
 To: r-help@r-project.org
 Subject: [R] Survival Analysis with an
 Historical Control

 Hello
 All,

 I'm trying to
 figure out how to perform a survival analysis with an
 historical control. I've spent some time looking online
 and in my boooks but haven't found much showing how to
 do this. Was wondering if there is a R package that can do
 it, or if there are resources somewhere that show the actual
 steps one takes, or if some knowledgeable person might be
 willing to share some code. 

 Here is a statement that describes the sort of
 analyis I'm being asked to do.

 A one-sample parametric test assuming an
 exponential form of survival was used to test the hypothesis
 that the treatment produces a median PFS no greater than the
 historical control PFS of 16 weeks.  A sample median PFS
 greater than 20.57 weeks would fall beyond the critical
 value associated with the null hypothesis, and would be
 considered statistically significant at alpha = .05, 1
 tailed.  

 My understanding
 is that the cutoff of 20.57 weeks was obtained using an
 online calculator that can be found at:

 http://www.swogstat.org/stat/public/one_survival.htm

 Thus far, I've been unable
 to determine what values were plugged into the calculator to
 get the cutoff.

 There's
 another calculator for a nonparamertric test that can be
 found at:

 http://www.swogstat.org/stat/public/one_nonparametric_survival.htm

 It would be nice to try doing
 this using both a parameteric and a non-parametric model.

 So my first question would be
 whether the approach outlined above is valid or if the
 analysis should be done some other way. If the basic idea is
 correct, is it relatively easy (for a Terry Therneau type
 genius) to implement the whole thing using R? The calculator
 is a great tool, but, if reasonable, it would be nice to be
 able to look at some code to see how the numbers actually
 get produced.

 Below are
 some sample survival data and code in case this proves
 helpful.

 Thanks,

 Paul

 ###
  Example Data: GD2 Vaccine 
 ###

 connection -
 textConnection(
 GD2  1   8
 12  GD2  3 -12 10  GD2  6 -52  7
 GD2 
 7  28 10  GD2  8  44  6  GD2 10  14  8
 GD2 12   3  8  GD2 14 -52  9 
 GD2 15  35 11
 GD2 18   6 13 
 GD2 20  12  7  GD2 23  -7 13
 GD2 24
 -52  9  GD2 26 -52 12  GD2 28  36 13
 GD2
 31 -52  8  GD2 33   9 10  GD2 34 -11 16
 GD2 36 -52  6  GD2 39  15 14  GD2 40  13
 13
 GD2 42  21 13  GD2 44 -24 16  GD2 46
 -52 13
 GD2 48  28  9  GD2  2  15  9 
 GD2  4 -44 10
 GD2  5  -2 12  GD2 
 9   8  7  GD2 11  12  7
 GD2
 13 -52  7  GD2 16  21  7  GD2 17  19 11
 GD2 19   6 16  GD2 21  10 16  GD2
 22 -15  6
 GD2 25   4 15  GD2
 27  -9  9  GD2 29  27 10
 GD2
 30   1 17  GD2 32  12  8  GD2 35  20  8
 GD2 37 -32  8  GD2 38  15  8  GD2
 41   5 14
 GD2 43  35 13  GD2
 45  28  9  GD2 47   6 15
 )

 hsv
 - data.frame(scan(connection, list(VAC=,
 PAT=0, WKS=0, X=0)))
 hsv -
 transform(hsv, CENS=ifelse(WKS  1, 1, 0),
 WKS=abs(WKS))
 head(hsv)

 require(survival)

 survObj - Surv(hsv$WKS,
 hsv$CENS==0) ~ 1

 km -
 survfit(survObj, type=c(kaplan-meier))
 print(km)

 paraExp - survreg(survObj,
 dist=exponential)
 print(paraExp)


 **
 Electronic Mail is not secure, may not be read
 every day, and should not be used for urgent or sensitive
 issues 

__
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] Installing RMySQL on Debian

2014-07-10 Thread Federico Razzoli
Hello. I am trying to install RMySQL. My Os is Debian and I have MariaDB
installed from the tar package (not deb). After downloading RMySQL, I ran
the following commands, and I see DONE. Hoewever, I don't think that the
package is installed, because the dbConnect() function cannot be found.
Probably I'm not passing R the correct paths, but then what paths should I
pass?


root@this:/tmp# export PKG_CPPFLAGS=-I/usr/local/mysql/include/mysql
root@this:/tmp# export PKG_LIBS=-L/usr/local/mysql/lib -lmysqlclient
root@this:/tmp# R CMD INSTALL /tmp/RMySQL_0.9-3.tar.gz
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for compress in -lz... yes
checking for getopt_long in -lc... yes
checking for mysql_init in -lmysqlclient... no
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG
-I/usr/local/mysql/include/mysql -fpic  -O2 -pipe -g  -c RS-DBI.c -o
RS-DBI.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG
-I/usr/local/mysql/include/mysql -fpic  -O2 -pipe -g  -c RS-MySQL.c -o
RS-MySQL.o
gcc -std=gnu99 -shared -o RMySQL.so RS-DBI.o RS-MySQL.o
-L/usr/local/mysql/lib -lmysqlclient -lz -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/RMySQL/libs
** R
** inst
** preparing package for lazy loading
Creating a generic function for ‘format’ from package ‘base’ in package
‘RMySQL’
Creating a generic function for ‘print’ from package ‘base’ in package
‘RMySQL’
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded

* DONE (RMySQL)


Thank you in advance
Federico

__
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] Installing RMySQL on Debian

2014-07-10 Thread Sarah Goslee
Hi,

On Thu, Jul 10, 2014 at 3:34 PM, Federico Razzoli san...@riseup.net wrote:
 Hello. I am trying to install RMySQL. My Os is Debian and I have MariaDB
 installed from the tar package (not deb). After downloading RMySQL, I ran
 the following commands, and I see DONE. Hoewever, I don't think that the
 package is installed, because the dbConnect() function cannot be found.
 Probably I'm not passing R the correct paths, but then what paths should I
 pass?

Just to check, are you loading the package using

library(RMySQL)

before trying to use it?

If so, is it giving you any errors?

Sarah



 root@this:/tmp# export PKG_CPPFLAGS=-I/usr/local/mysql/include/mysql
 root@this:/tmp# export PKG_LIBS=-L/usr/local/mysql/lib -lmysqlclient
 root@this:/tmp# R CMD INSTALL /tmp/RMySQL_0.9-3.tar.gz
 * installing to library ‘/usr/local/lib/R/site-library’
 * installing *source* package ‘RMySQL’ ...
 ** package ‘RMySQL’ successfully unpacked and MD5 sums checked
 checking for gcc... gcc
 checking for C compiler default output file name... a.out
 checking whether the C compiler works... yes
 checking whether we are cross compiling... no
 checking for suffix of executables...
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether gcc accepts -g... yes
 checking for gcc option to accept ANSI C... none needed
 checking how to run the C preprocessor... gcc -E
 checking for compress in -lz... yes
 checking for getopt_long in -lc... yes
 checking for mysql_init in -lmysqlclient... no
 checking for egrep... grep -E
 checking for ANSI C header files... yes
 checking for sys/types.h... yes
 checking for sys/stat.h... yes
 checking for stdlib.h... yes
 checking for string.h... yes
 checking for memory.h... yes
 checking for strings.h... yes
 checking for inttypes.h... yes
 checking for stdint.h... yes
 checking for unistd.h... yes
 checking mysql.h usability... no
 checking mysql.h presence... no
 checking for mysql.h... no
 configure: creating ./config.status
 config.status: creating src/Makevars
 ** libs
 gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG
 -I/usr/local/mysql/include/mysql -fpic  -O2 -pipe -g  -c RS-DBI.c -o
 RS-DBI.o
 gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG
 -I/usr/local/mysql/include/mysql -fpic  -O2 -pipe -g  -c RS-MySQL.c -o
 RS-MySQL.o
 gcc -std=gnu99 -shared -o RMySQL.so RS-DBI.o RS-MySQL.o
 -L/usr/local/mysql/lib -lmysqlclient -lz -L/usr/lib/R/lib -lR
 installing to /usr/local/lib/R/site-library/RMySQL/libs
 ** R
 ** inst
 ** preparing package for lazy loading
 Creating a generic function for ‘format’ from package ‘base’ in package
 ‘RMySQL’
 Creating a generic function for ‘print’ from package ‘base’ in package
 ‘RMySQL’
 ** help
 *** installing help indices
 ** building package indices
 ** installing vignettes
 ** testing if installed package can be loaded

 * DONE (RMySQL)


 Thank you in advance
 Federico



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] Installing RMySQL on Debian

2014-07-10 Thread Federico Razzoli
 Just to check, are you loading the package using

 library(RMySQL)

 before trying to use it?

 If so, is it giving you any errors?

Hi,
It was my first attempt, but since it didn't work I tried the other
suggested method. By the way, here is what I get:


 install.packages(RMySQL)
Installing package(s) into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
provo con l'URL
'http://cran.mirror.garr.it/mirrors/CRAN/src/contrib/RMySQL_0.9-3.tar.gz'
Content type 'text/plain' length 165363 bytes (161 Kb)
URL aperto
==
downloaded 161 Kb

* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for compress in -lz... yes
checking for getopt_long in -lc... yes
checking for mysql_init in -lmysqlclient... no
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking /usr/local/include/mysql/mysql.h usability... no
checking /usr/local/include/mysql/mysql.h presence... no
checking for /usr/local/include/mysql/mysql.h... no
checking /usr/include/mysql/mysql.h usability... no
checking /usr/include/mysql/mysql.h presence... no
checking for /usr/include/mysql/mysql.h... no
checking /usr/local/mysql/include/mysql/mysql.h usability... yes
checking /usr/local/mysql/include/mysql/mysql.h presence... yes
checking for /usr/local/mysql/include/mysql/mysql.h... yes

Configuration error:
  could not find the MySQL installation include and/or library
  directories.  Manually specify the location of the MySQL
  libraries and the header files and re-run R CMD INSTALL.

INSTRUCTIONS:

1. Define and export the 2 shell variables PKG_CPPFLAGS and
   PKG_LIBS to include the directory for header files (*.h)
   and libraries, for example (using Bourne shell syntax):

  export PKG_CPPFLAGS=-IMySQL-include-dir
  export PKG_LIBS=-LMySQL-lib-dir -lmysqlclient

   Re-run the R INSTALL command:

  R CMD INSTALL RMySQL_version.tar.gz

2. Alternatively, you may pass the configure arguments
  --with-mysql-dir=base-dir (distribution directory)
   or
  --with-mysql-inc=base-inc (where MySQL header files reside)
  --with-mysql-lib=base-lib (where MySQL libraries reside)
   in the call to R INSTALL --configure-args='...'

   R CMD INSTALL --configure-args='--with-mysql-dir=DIR'
RMySQL_version.tar.gz

ERROR: configuration failed for package ‘RMySQL’
* removing ‘/usr/local/lib/R/site-library/RMySQL’
* restoring previous ‘/usr/local/lib/R/site-library/RMySQL’

The downloaded source packages are in
‘/tmp/RtmpaJ2WeK/downloaded_packages’
Warning message:
In install.packages(RMySQL) :
  installation of package ‘RMySQL’ had non-zero exit status


Federico

__
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] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Kenn Konstabel
I confirm that the original problem doesn't happen in R 3.1.1. in
Windows (XP, this time). That is,

source(http://psych.ut.ee/~R/test-utf8.txt;)

.. no longer crashes R but gives a sensible (i.e., understandable,
after this discussion) error.
... and adding encoding=UTF-8-BOM reads in the file correctly.



On Thu, Jul 10, 2014 at 5:50 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 10/07/2014 9:53 AM, Kenn Konstabel wrote:

 Wow. Thanks a lot!

 source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=UTF-8-BOM)
 # works correctly on my Windows 7 machine
 # (and without encoding argument it still crashes R)

 Kenn

 On Thu, Jul 10, 2014 at 4:33 PM, John McKown
 john.archie.mck...@gmail.com wrote:
  On Thu, Jul 10, 2014 at 7:18 AM, Kenn Konstabel lebats...@gmail.com
  wrote:
  Dear all,
 
  I found an unexpected behaviour when trying to `source` an utf-8 file
  on windows 7:
 
  source(http://psych.ut.ee/~nek/R/test-utf8.txt;)
 
  # Rgui.exe reacts:
  # R for windows GUI has stopped working. A problem caused the program
  to stop working correctly.
  # Windows will close the program and notify you if a solution is
  available.
 
  The same will happen with R.exe (terminal) and R running wihin
  Rstudio. (Session and locale info below).
 
  However, a non-utf version of this little script can be `source`d
  without problems.
 
  source(http://psych.ut.ee/~nek/R/test.txt;)
 
  Adding the `encoding` argument to `source` helps a little:
 
  source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding=utf-8)
  #  unsure about the spelling of utf-8 so I also tried UTF8, utf8, and
  UTF-8
  # ... with the same result in all cases
 
  R doesn't crash any more but gives the following error:
 
  # Error in source(http://psych.ut.ee/~nek/R/test-utf8.txt;, encoding
  = utf-8) :
  #   http://psych.ut.ee/~nek/R/test-utf8.txt:2:0: unexpected end of
  input
  # 1: ?
  #^
  # In addition: Warning message:
  # In readLines(file, warn = FALSE) :
  #  invalid input found on input connection
  'http://psych.ut.ee/~nek/R/test-utf8.txt'
 
  I just tried that. On Windows XP/Pro,  R 3.1.0 didn't fail, but did
  get the error you mention later. I used wget to actually download
  the file mentioned (on Linux). I think that the problem _may_ be that
  the file starts with a BOM (Byte Order Mark), which is 0xef, 0xbb,
  0xef . This is supposed to tell us that this is UTF-8.
 
  BOM: http://en.wikipedia.org/wiki/Byte_order_mark
 
  I get an identical error with R 3.1.0 on both Windows XP/Pro and Linux
  Fedora 20. The problem is that the R readLines() apparently does not
  like the leading BOM. It reads it as data. Most other Linux and
  Windows applications _do_ understand the BOM and so, when you use
  them, they work properly. And, normally, when you then save the file,
  the software does not write the BOM at the start. So it works on the
  saved version of the file.
 
  Being the curious sort, I decided to look at the source to R. In
  particular in ~/R/src/main/connections.c I saw where it did support
  the reading of BOMs. But there is a special way to do it! Which I
  cannot find in the documentation.
 
  source(http://psych.ut.ee/~nek/R/test-utf8.txt,encoding=UTF-8-BOM;);
 
  I tried the above AND IT WORKED properly!
 
  I simply adore having source code.


 Searching the source for the string UTF-8-BOM finds it mentioned in the
 docs in 3 places:  in the NEWS file,
 in the R Data Import/Export manual, and in the ?connections help page.

 Duncan Murdoch

 
 
 
  I thought maybe that's because what notepad told me is UTF-8 is
  actually something else ... so I did two more experiments.
 
  source(http://psych.ut.ee/~nek/R/test2.R;)
  # this was created on a linux machine with leafpad, and saved as utf-8
  text
  # it can be source´d on windows
 
  source(http://psych.ut.ee/~nek/R/test3.R;)
  # the same as previous but o's in file were replaced by ö's
  # can be source'd on windows but the ö character is shown as ƶ
  # except if you add encoding=utf-8 - then, as expected, it works as
  expected
 
  So in sum, I can create plain text (saved with utf-8 encoding) files
  on windows that cannot be sourced to R on windows, or will crash R
  (depending on how you source them). The same files can be sourced on
  linux without problems. Part of the problem is obviously in windows
  but maybe R shouldn't at least crash.
 
  Session info:
 
   R version 3.0.2 (2013-09-25)
  Platform: i386-w64-mingw32/i386 (32-bit)
 
  locale:
  [1] LC_COLLATE=Estonian_Estonia.1257  LC_CTYPE=Estonian_Estonia.1257
  [3] LC_MONETARY=Estonian_Estonia.1257 LC_NUMERIC=C
  [5] LC_TIME=Estonian_Estonia.1257
 
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
 
  loaded via a namespace (and not attached):
  [1] tools_3.0.2
 
 
  OS: Windows 7
 
  Linux Mint Debian Edition and R 3.0.2 on the other machine (where
  everything worked).
 
  Context:
 
  I was trying to find out how to make files that could be 

Re: [R] R Studio v3.0.3 for Windows 32bits is too slow

2014-07-10 Thread Phan, Truong Q
Hi All,

Thanks for all comments/suggestions.
I would like to clarify a few things for some of your questions/doubts.

1) Matt Peeples' K-Clusters R scripts has covered some of pre-requisite steps 
for the K-Clusters algorithm. 
   I would recommend for those who has not done K-Clusters to read it.
a) Convert count data to percent
b) Allow to use Z-score standardize data when variables differ greatly 
in range or standard deviation or are not directly comparable measures

2) K-Clusters algorithm can handle well for the dataset which has less than 
5000 features.

3) Our original dataset has more than 9000 parameters which I have been using 
Hadoop MapReduce streaming via Python to reduce them down to around 2000 
parameter and then I use R to further cleansing data down to 1426 parameters.

4) I have been trying to use Mahout and Cloudera's Oryx tools but the 
integration of different tools perform tasks: Prepare data, Build models, Cross 
Validating models, Test models and Present data product are far too complicate 
for this small POC.

Thanks and Regards,
Truong Phan


P    + 61 2 8576 5771
M   + 61 4 1463 7424
E    troung.p...@team.telstra.com
W  www.telstra.com


-Original Message-
From: peter dalgaard [mailto:pda...@gmail.com] 
Sent: Thursday, 10 July 2014 10:08 AM
To: Jeff Newmiller
Cc: Bert Gunter; Phan, Truong Q; r-help@r-project.org
Subject: Re: [R] R Studio v3.0.3 for Windows 32bits is too slow

Grumpy today, Jeff?

For the concrete issue, I'd conjecture that the base problem is that there are 
way too many columns in the data and that the nature of the method is not 
properly understood. It is not obvious that k-means clustering based on 
Euclidean distance makes sense in 1426-dimensional space. It is quite possible 
that the data set not even consists of columns measured in the same units. Even 
if it does fit the problem, it is a quite computationally intensive. Some sort 
of feature extraction or data reduction technique is likely to be required.

So basically, further study of the methodology, or contact with a machine 
learning expert (which I am not) seems advisable.

-pd  


On 09 Jul 2014, at 18:24 , Jeff Newmiller jdnew...@dcn.davis.ca.us wrote:

 Grumpy today, Bert?
 
 While it is a fact that RStudio is a separate tool from R, it is clear from 
 the question that the OP is interested in capabilities that R is providing 
 and he simply cannot tell the difference.
 
 OP:
 
 1) Better is a word that leads to pointless arguments. You will have to be 
 the judge of what works for you. I caution you that Open Source tools almost 
 always achieve success by interoperating with other OS tools, and much of the 
 success you have already obtained is the result of many contributions, of 
 which R and its contributed packages deserve the lion's share of credit. 
 RStudio is a very convenient editor that makes using R and LaTeX and Markdown 
 and version control easier, but it is unlikely that either the blame for your 
 dissatisfaction or the credit for your success should be attributed to 
 RStudio.
 
 I have successfully used all sorts of plain text editors and command line 
 interfaces with R, and if you plan to scale up your projects then you will 
 likely want to be very clear on this distinction between editors and 
 computing tools so you can distribute your work on multiple parallel servers 
 (where editors may not necessarily even be helpful) even if you choose to use 
 RStudio as your controlling environment for launching such tasks.
 
 2) and 3) I know that R has contributed packages that can manage Hadoop data 
 processing, but I have no personal experience with them. Google is your 
 friend... especially if you keep in mind that these tools are not all found 
 in one monolithic package.
 
 For future reference: this is a plain text mailing list, so please adjust 
 your mail client appropriately when sending to this list. Also, there are 
 considerable resources mentioned in the Posting Guide that you should be 
 aware of... see the link below.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  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 July 9, 2014 7:10:00 AM PDT, Bert Gunter gunter.ber...@gene.com wrote:
 RStudio is a separate product with its own support. Post there, not 
 here.
 
 -- Bert
 
 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374
 
 Data is not information. Information is not knowledge. And knowledge 
 is certainly not wisdom.
 Clifford Stoll
 
 
 
 
 

Re: [R] quantmod: How could I change the name in chartSeries

2014-07-10 Thread Duncan Mackay
Hi

I have not used quantmod before  so I got the

stock.name - getSymbols(stock.code, from = 2010-01-01,
 to = Sys.Date(), src = 
yahoo, auto.assign=FALSE)
   chartSeries(stock.name, theme = theme.white,
   # subset = 'last 12 months',
   TA = addVo(); addSMA(); addEnvelope();
   addMACD(); addMomentum(); addROC();
   addBBands())
and 
str(stock.name)

on it to see its structure

If you require  the ^ before the stock.code insert

name = sub(\\..*$,,attributes(stock.name)$dimnames[[2]][1]),
otherwise 
name = stock.code

eg

chartSeries(stock.name,
   theme = theme.white,
   name =
sub(\\..*$,,attributes(stock.name)$dimnames[[2]][1]),
   # subset = 'last 12 months',
   TA = addVo(); addSMA(); addEnvelope(); addMACD();
addMomentum(); addROC(); addBBands())
   addLines(v = which(stock.name[,4] == max(stock.name[,4])),
   col = gray)

If this is not what you want it will be somewhere in the stock.name and
?chartSeries

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of William
Sent: Thursday, 10 July 2014 14:00
To: r-help@r-project.org
Subject: [R] quantmod: How could I change the name in chartSeries

hi, guys,

I am just a beginner to the excellent R package, quantmod. I quite don't 
know how to change the y-axis name in the chartSeries function. 
Actually, I want to write some sort of the following function, by which 
I could use just one code  sentence  to complete the financial analysis.

The following function is designed to provide some aspects of the 
SP500. And now I want to change the stock.name on the y-axis as 
SP500. Is there anyway to realize this?

THX

 William


#
stock.price - function(stock.name, stock.code){
    Loading..
   library(zoo)
   library(xts)
   library(TTR)
   library(Defaults)
   library(quantmod)
#---
---
   ## Theme: white
   theme.white - chartTheme(white)
   names(theme.white)
   theme.white$bg.col - white
   theme.white$up.col - red
   theme.white$dn.col - green
#---
---
    main function
   stock.name - getSymbols(stock.code, from = 2010-01-01,
 to = Sys.Date(), src = 
yahoo, auto.assign=FALSE)
   chartSeries(stock.name, theme = theme.white,
   # subset = 'last 12 months',
   TA = addVo(); addSMA(); addEnvelope();
   addMACD(); addMomentum(); addROC();
   addBBands())
   addLines(v = which(stock.name[,4] == max(stock.name[,4])),
col = gray)
}
#
stock.price(SP500, ^GSPC)

__
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-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] linearHypothesis() ERROR-Message

2014-07-10 Thread John Fox
Dear Katharina,

There's no specific method for linearHypothesis() for objects produced by 
plm(), but as you say, the default method seems to work. For example, following 
example(plm):

-- snip ---

 linearHypothesis(zz, names(coef(zz)), test=F)
Linear hypothesis test

Hypothesis:
log(pcap) = 0
log(pc) = 0
log(emp) = 0
unemp = 0

Model 1: restricted model
Model 2: log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp

  Res.Df Df  FPr(F)
1768
2764  4 3064.8  2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

--- snip -

The error message seems reasonably self-explanatory, and given the hypothesis 
that you're testing -- that all coefficients are 0 -- it suggests that the 
covariance matrix of the coefficients is numerically singular. You can check 
that, e.g., by examining the eigenstructure of vcov(fixed.interest3). 

I agree that's curious given that plm() doesn't complain. Are you able to get 
coefficient standard errors in summary(fixed.interest3)?

Without your data, it's not possible to say more, and you could make the 
problem reproducible by supplying the data. In any event, I've just returned 
from several weeks out of town and wouldn't be able to look at your data for a 
few days.

I hope this helps,
 John

On Thu, 10 Jul 2014 12:04:46 +0200
 Katharina Mersmann kmers...@smail.uni-koeln.de wrote:
 Dear Community,
 
 unfortunately I can´t give you an reproducable example, because I really do
 not understand why this messages pops up.
 
 I estimate an Fixed Effects Modell, controlling for HAC, because F-statistic
 changes, I want to compute it, for the other model-specifications it works,
 
 But for this special one I get the following error: 
 
  
 
  fixed.interest3-plm(CSmean~ numfull_FCRlong_adj+exp(numfull_FCRlong_adj),
 
 +  data=data.plm,index = c(countrynr,quartal),
 model=within)
 
  ###F-Test
 
  coefs - names(coef(fixed.interest3))
 
  linearHypothesis(fixed.interest3,coefs,test=F, vcov=function(x)
 vcovHC(x, method = arellano)) 
 
 Fehler in solve.default(L %*% V %*% t(L)) : 
 
   System ist für den Rechner singulär: reziproke Konditionszahl =
 1.37842e-19  „system is computationally singular reciprocal condition
 number”
 
  drop(coefs)
 
 [1] numfull_FCRlong_adj exp(numfull_FCRlong_adj)
 
  
 
  
 
 Is something wrong in the code. Or is it because of the model?
 
  
 
  
 
 Thanks in advance and a really nice day
 
 Katie
 
 
   [[alternative HTML version deleted]]
 


John Fox, Professor
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

__
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] Installing RStudio for ARM architecture

2014-07-10 Thread Chris Feigl
I'm trying to get RStudio (Desktop) up and running on a Samsung XE303C12.
 It has a duel-core ARM processor.

- Installed R using Ubuntu Software Centre.

- Downloaded source code  in the form of
'rstudio-rstudio-v0.98.952-0-g47edc6d.tar.gz' from
rstudio.com/products/rstudio/download and unpacked it.

- Based on the install-dependencies-debian script:

[[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] Porting GHC neccessary to install RStudio on ARM/Linux?

2014-07-10 Thread Chris Feigl
I'm trying to get RStudio (Desktop) up and running on a Samsung XE303C12
running Ubuntu 14.04.  This machine has a duel-core ARM processor inside.
 This is the process I have followed so far.

- Installed R using the Ubuntu Software Centre.

- Downloaded RStudio source code in the form of
'rstudio-rstudio-v0.98.952-0-g47edc6d.tar.gz' from
rstudio.com/products/rstudio/download and unpacked it.

- While installing the common dependencies, I run the following script:

#!/bin/bash

#
# install-pandoc
#
# Copyright (C) 2009-12 by RStudio, Inc.
#
# Unless you have received this program directly from RStudio pursuant
# to the terms of a commercial license agreement with RStudio, then
# this program is licensed to you under the terms of version 3 of the
# GNU Affero General Public License. This program is distributed WITHOUT
# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
#
#

set -e

# install dir
INSTALL_DIR=`pwd`

# determine platform
PLATFORM=`uname`

# use curl or wget as appropriate
download()
{
  if [ $PLATFORM == Darwin ]
  then
curl -L https://s3.amazonaws.com/rstudio-buildtools/$1  $1
  else
wget https://s3.amazonaws.com/rstudio-buildtools/$1 -O $1
  fi
}

# get pandoc
PANDOC_VERSION=1.12.3
PANDOC_DIR=pandoc/$PANDOC_VERSION
if [ -d $PANDOC_DIR ]
then
   echo pandoc ${PANDOC_VERSION} already installed
else
   PANDOC_NAME=pandoc-${PANDOC_VERSION}
   PANDOC_ZIP=${PANDOC_NAME}.zip
   download $PANDOC_ZIP
   unzip -q $PANDOC_ZIP
   mkdir -p ${PANDOC_DIR}
   if [ $PLATFORM == Darwin ]
   then
  cp ${PANDOC_NAME}/mac/pandoc* ${PANDOC_DIR}
   else
  # copy binaries for appropriate distro/arch. debian and fedora
  # use the fully static debian binaries (so we don't run into
  # problems with libgmp.so.3 being missing on later versions
  # of fedora. rhel 5 and 6 use the rpm binaries
  if [[ -x /usr/bin/dpkg ]] || [[ -f /etc/fedora-release ]]; then
BINARY_TYPE=debian
  else
BINARY_TYPE=rpm
  fi
  ARCH=`uname -m`
  cp ${PANDOC_NAME}/linux/${BINARY_TYPE}/${ARCH}/pandoc* ${PANDOC_DIR}
   fi
   rm $PANDOC_ZIP
   rm -rf $PANDOC_NAME
fi

# back to install dir
cd $INSTALL_DIR




- I get back:
2014-07-11 08:51:07 (72.7 KB/s) - ‘pandoc-1.12.3.zip’ saved
[97002741/97002741]

cp: cannot stat ‘pandoc-1.12.3/linux/debian/armv7l/pandoc*’: No such file
or directory

- On inspection I find there is no directory
pandoc-1.12.3/linux/debian/arm7l
  (not surprising)

- Went to this site 'http://johnmacfarlane.net/pandoc/installing.html' to
learn more about installing pandoc.  Find out I need to install the Haskell
platform.

- From this site 'http://www.haskell.org/platform/linux.html' learn that I
need to install GHC 7.6.3 prior to building the Haskell platform.

- Under 'Source Distribution' reads

The source distribution needs an installed GHC (version 7.0 at least). If
your platform isn't currently supported with a binary distribution, then
you'll need to consult the section on Porting GHC
http://hackage.haskell.org/trac/ghc/wiki/Building/Porting in the Building
Guide.

Since this is all pretty new to me, I would like to seek clarification
before I decide whether or not to go further down this (rocky) path.

Am I required to port GHC across to ARM/Linux in order to install RStudio
on my machine?

Kind regards,
Chris

[[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] Build and install of Rstudio on ARMv7/Linux freezes

2014-07-10 Thread Chris Feigl
I have been trying to build RStudio (Desktop) from the source code in
'rstudio-rstudio-v0.98.952-0-g47edc6d.tar.gz' on a machine running Ubuntu
14.04 with an ARMv7 processor.

I have successfully installed all the dependencies, except for Pandoc (I
think).

I configured the build environment in accordance with the instructions in
the INSTALL file, using the command:
'cmake ~/rstudio-rstudio-47edc6d -DRSTUDIO_TARGET=Desktop'
in the directory ~/rstudio-rstudio-47edc6d/build

This finishes with:

-- Configuring done
-- Generating done
-- Build files have been written to:
/home/chrisfeigl/rstudio-rstudio-47edc6d/build
$


I then run 'make install' from '~/rstudio-rstudio-47edc6d/build' with the
following result:

Scanning dependencies of target gwt_build
Buildfile: /home/chrisfeigl/rstudio-rstudio-47edc6d/src/gwt/build.xml

ext:


This is all I get.

Can anyone please offer any suggestions as to why the installation might
have frozen?

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


Re: [R] Decision Tree

2014-07-10 Thread Abhinaba Roy
Hi Jean,

I'd looked at the help for 'prp' but couldn't find the argument for
changing box colours. Am I missing something?


On Thu, Jul 10, 2014 at 8:01 PM, Adams, Jean jvad...@usgs.gov wrote:

 The function fancyRpartPlot() is actually in the rattle package, and it is
 a wrapper for the prp() function in the rpart.plot package.  If you look at
 the help for prp(), you should be able to see how to change the color.

 library(rpart.plot)
 ?prp

 Jean



 On Thu, Jul 10, 2014 at 12:34 AM, Abhinaba Roy abhinabaro...@gmail.com
 wrote:

 Hi R-helpers,

 Is it possible to change the color of the boxes when plotting decision
 trees using 'fancyRpartPlot()' from rpart.plot package ?

 --
 Regards,
 Abhinaba Roy

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





-- 
Regards,
Abhinaba Roy

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


Re: [R-es] bucle

2014-07-10 Thread Isidro Hidalgo
Probablemente tienes un caso en el que ninguna de las 11 condiciones se
cumple... Fíjate con los datos simulados, hay 1686 casos fuera de las
condiciones que defines:

set.seed(12345)
rango_inr1 = ceiling(runif(3738,0,11))
inr = runif(3738,2,4)
n=3738
cinr = rep(NA, 3738)
for (i in 1:n)
{
 if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3))
  cinr[i]-1
 if (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5))
  cinr[i]-2
 if (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9))
  cinr[i]-3
 if (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5))
  cinr[i]-4
 if (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25))
  cinr[i]-5
 if (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5))
  cinr[i]-6
 if (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4))
  cinr[i]-7
 if (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6))
  cinr[i]-8
 if (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5))
  cinr[i]-9
 if (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8))
  cinr[i]-10
 if (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4))
  cinr[i]-11
}
table(cinr)
sum(is.na(cinr))

Un saludo.

Isidro Hidalgo Arellano
Observatorio Regional de Empleo
Consejería de Empleo y Economía
http://www.jccm.es


 -Mensaje original-
 De: r-help-es-boun...@r-project.org [mailto:r-help-es-bounces@r-
 project.org] En nombre de juan(uned)
 Enviado el: jueves, 10 de julio de 2014 8:59
 Para: r-help-es@r-project.org
 Asunto: [R-es] bucle

 Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero
 que no encuentro sentido. Tengo un bucle con el siguiente código:

 for (i in 1:n)
 {
 if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1 if
 (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2 if
 (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3 if
 (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4 if
 (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5 if
 (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6 if
 (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7 if
 (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8 if
 (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9 if
 (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10 if
 (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11 }

 donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la
 variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He
 comprobado los casos de rango_inr1 y de inr y son 3738.
 ¿Qué estoy haciendo mal?.

 Un cordial saludo,

 Juan

 --
 Juan Antonio Gil Pascual
 Profesor de Metodología de la Investigación Cuantitativa
 correo: j...@edu.uned.es
 web: www.uned.es/personal/jgil

 Dpto. MIDE
 Facultad de Educación
 c/Juan del Rosal, 14 desp. 2.72
 28040 Madrid
 Tel‚f. 91 3987279
 Fax. 91 3987288

 ___
 R-help-es mailing list
 R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] bucle

2014-07-10 Thread Eva Prieto Castro
Hola, Juan:

Eso sólo es posible si exactamente para uno de los valores de i no se cumple 
ninguna de las condiciones, con lo cual no llegas a incorporar valor en cinr.

Puedes utilizar if else de modo que te emita un mensaje informando del i que 
no supera ninguno de los if.

Un saludo.
Eva


El Jueves 10 de julio de 2014 8:58, juan(uned) j...@edu.uned.es escribió:
 


Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero 
que no encuentro sentido. Tengo un bucle con el siguiente código:

for (i in 1:n)
{
if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1
if (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2
if (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3
if (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4
if (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5
if (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6
if (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7
if (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8
if (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9
if (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10
if (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11
}

donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la 
variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He 
comprobado los casos de rango_inr1 y de inr y son 3738.
¿Qué estoy haciendo mal?.

Un cordial saludo,

Juan

-- 
Juan Antonio Gil Pascual
Profesor de Metodología de la Investigación Cuantitativa
correo: j...@edu.uned.es
web: www.uned.es/personal/jgil

Dpto. MIDE
Facultad de Educación
c/Juan del Rosal, 14 desp. 2.72
28040 Madrid
Tel‚f. 91 3987279
Fax. 91 3987288

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] bucle

2014-07-10 Thread Eva Prieto Castro


Juan,

Prueba a utilizar for (i in 0:(n-1))

A lo mejor sólo estás comprobando los (n-1) casos.

Eva


El Jueves 10 de julio de 2014 9:37, Eva Prieto Castro evapcas...@yahoo.es 
escribió:
 


Hola, Juan:

Eso sólo es posible si exactamente para uno de los valores de i no se cumple 
ninguna de las condiciones, con lo cual no llegas a incorporar valor en cinr.

Puedes utilizar if else de modo que te emita un mensaje informando del i que 
no supera ninguno de los if.

Un saludo.
Eva


El Jueves 10 de julio de 2014 8:58, juan(uned) j...@edu.uned.es escribió:
 


Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero 
que no encuentro sentido. Tengo un bucle con el siguiente código:

for (i in 1:n)
{
if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1
if (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2
if (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3
if (rango_inr1[i]==4
  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4
if (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5
if (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6
if (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7
if (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8
if (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9
if (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10
if (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11
}

donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la 
variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He 
comprobado los casos de rango_inr1 y de inr y son 3738.
¿Qué estoy haciendo mal?.

Un cordial saludo,

Juan

-- 
Juan Antonio Gil
 Pascual
Profesor de Metodología de la Investigación Cuantitativa
correo: j...@edu.uned.es
web: www.uned.es/personal/jgil

Dpto. MIDE
Facultad de Educación
c/Juan del Rosal, 14 desp. 2.72
28040 Madrid
Tel‚f. 91 3987279
Fax. 91 3987288

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] bucle

2014-07-10 Thread Isidro Hidalgo
De todas formas, es mejor (y más rápido) no usar un bucle y asignar
directamente:

cinr = rep(NA, 3738)
cinr[rango_inr1==1  (inr= 2  inr= 3)] - 1
cinr[rango_inr1==2  (inr= 2.5  inr= 3.5)] - 2
cinr[rango_inr1==3  (inr= 2  inr= 2.9)] - 3
cinr[rango_inr1==4  (inr= 2.25  inr= 3.5)] - 4
cinr[rango_inr1==5  (inr= 2.2  inr= 3.25)] - 5
cinr[rango_inr1==6  (inr= 2  inr= 3.5)] - 6
cinr[rango_inr1==7  (inr= 2  inr= 4)] - 7
cinr[rango_inr1==8  (inr= 2  inr= 2.6)] - 8
cinr[rango_inr1==9  (inr= 2  inr= 2.5)] - 9
cinr[rango_inr1==10  (inr= 2  inr= 2.8)] - 10
cinr[rango_inr1==11  (inr= 2.5  inr= 4)] - 11)

Un saludo.

Isidro Hidalgo Arellano
Observatorio Regional de Empleo
Consejería de Empleo y Economía
http://www.jccm.es




 -Mensaje original-
 De: r-help-es-boun...@r-project.org [mailto:r-help-es-bounces@r-
 project.org] En nombre de juan(uned)
 Enviado el: jueves, 10 de julio de 2014 8:59
 Para: r-help-es@r-project.org
 Asunto: [R-es] bucle

 Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero
 que no encuentro sentido. Tengo un bucle con el siguiente código:

 for (i in 1:n)
 {
 if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1 if
 (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2 if
 (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3 if
 (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4 if
 (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5 if
 (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6 if
 (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7 if
 (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8 if
 (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9 if
 (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10 if
 (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11 }

 donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la
 variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He
 comprobado los casos de rango_inr1 y de inr y son 3738.
 ¿Qué estoy haciendo mal?.

 Un cordial saludo,

 Juan

 --
 Juan Antonio Gil Pascual
 Profesor de Metodología de la Investigación Cuantitativa
 correo: j...@edu.uned.es
 web: www.uned.es/personal/jgil

 Dpto. MIDE
 Facultad de Educación
 c/Juan del Rosal, 14 desp. 2.72
 28040 Madrid
 Tel‚f. 91 3987279
 Fax. 91 3987288

 ___
 R-help-es mailing list
 R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] bucle

2014-07-10 Thread Jorge I Velez
Hola Juan Antonio,

Has pensado considerar una aproximacion diferente?  De ser asi, explora
?cut y
?car:::recode.

Saludos,
Jorge.-



2014-07-10 16:58 GMT+10:00 juan(uned) j...@edu.uned.es:

 Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero que
 no encuentro sentido. Tengo un bucle con el siguiente código:

 for (i in 1:n)
 {
 if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1
 if (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2
 if (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3
 if (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4
 if (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5
 if (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6
 if (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7
 if (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8
 if (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9
 if (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10
 if (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11
 }

 donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la
 variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He
 comprobado los casos de rango_inr1 y de inr y son 3738.
 ¿Qué estoy haciendo mal?.

 Un cordial saludo,

 Juan

 --
 Juan Antonio Gil Pascual
 Profesor de Metodología de la Investigación Cuantitativa
 correo: j...@edu.uned.es
 web: www.uned.es/personal/jgil

 Dpto. MIDE
 Facultad de Educación
 c/Juan del Rosal, 14 desp. 2.72
 28040 Madrid
 Tel'f. 91 3987279
 Fax. 91 3987288

 ___
 R-help-es mailing list
 R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] bucle

2014-07-10 Thread juan(uned)
Eva muchas gracias por la contestación pero hay muchos casos que no 
cumplen la condición y cinr toma el valor NA porque inr toma valores 
fuera de los intervalos que pongo pero rango_inr1 siempre toma uno de 
los 11 valores, además sum(table(rango_inr1)) es 3738. Podías concretar 
la opción que comentas de ifelse().
Muchas gracias a Jorge y a Isidro. Probaré la alternativa de Isidro.

Un cordial saludo,

Juan

El 10/07/2014 9:37, Eva Prieto Castro escribió:
 Hola, Juan:

 Eso sólo es posible si exactamente para uno de los valores de i no se 
 cumple ninguna de las condiciones, con lo cual no llegas a incorporar 
 valor en cinr.

 Puedes utilizar if else de modo que te emita un mensaje informando del 
 i que no supera ninguno de los if.

 Un saludo.
 Eva


 El Jueves 10 de julio de 2014 8:58, juan(uned) j...@edu.uned.es 
 escribió:


 Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero
 que no encuentro sentido. Tengo un bucle con el siguiente código:

 for (i in 1:n)
 {
 if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1
 if (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2
 if (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3
 if (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4
 if (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5
 if (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6
 if (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7
 if (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8
 if (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9
 if (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10
 if (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11
 }

 donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la
 variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He
 comprobado los casos de rango_inr1 y de inr y son 3738.
 ¿Qué estoy haciendo mal?.

 Un cordial saludo,

 Juan

 -- 
 Juan Antonio Gil Pascual
 Profesor de Metodología de la Investigación Cuantitativa
 correo: j...@edu.uned.es mailto:j...@edu.uned.es
 web: www.uned.es/personal/jgil

 Dpto. MIDE
 Facultad de Educación
 c/Juan del Rosal, 14 desp. 2.72
 28040 Madrid
 Tel‚f. 91 3987279
 Fax. 91 3987288

 ___
 R-help-es mailing list
 R-help-es@r-project.org mailto:R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es


-- 
Juan Antonio Gil Pascual
Profesor de Metodología de la Investigación Cuantitativa
correo: j...@edu.uned.es
web: www.uned.es/personal/jgil

Dpto. MIDE
Facultad de Educación
c/Juan del Rosal, 14 desp. 2.72
28040 Madrid
Tel‚f. 91 3987279
Fax. 91 3987288


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] bucle

2014-07-10 Thread Jose Luis Cañadas Reche
Hola.

La alternativa de Isidro es la que yo uso normalmente en este tipo de 
cosas. Si algún caso que no cumpla ninguna de las condiciones te quedará 
con cinr=NA.

Saludos

El 10/07/14 17:10, juan(uned) escribió:
 Eva muchas gracias por la contestación pero hay muchos casos que no
 cumplen la condición y cinr toma el valor NA porque inr toma valores
 fuera de los intervalos que pongo pero rango_inr1 siempre toma uno de
 los 11 valores, además sum(table(rango_inr1)) es 3738. Podías concretar
 la opción que comentas de ifelse().
 Muchas gracias a Jorge y a Isidro. Probaré la alternativa de Isidro.

 Un cordial saludo,

 Juan

 El 10/07/2014 9:37, Eva Prieto Castro escribió:
 Hola, Juan:

 Eso sólo es posible si exactamente para uno de los valores de i no se
 cumple ninguna de las condiciones, con lo cual no llegas a incorporar
 valor en cinr.

 Puedes utilizar if else de modo que te emita un mensaje informando del
 i que no supera ninguno de los if.

 Un saludo.
 Eva


 El Jueves 10 de julio de 2014 8:58, juan(uned) j...@edu.uned.es
 escribió:


 Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero
 que no encuentro sentido. Tengo un bucle con el siguiente código:

 for (i in 1:n)
 {
 if (rango_inr1[i]==1  (inr[i]= 2  inr[i]= 3)) cinr[i]-1
 if (rango_inr1[i]==2  (inr[i]= 2.5  inr[i]= 3.5)) cinr[i]-2
 if (rango_inr1[i]==3  (inr[i]= 2  inr[i]= 2.9)) cinr[i]-3
 if (rango_inr1[i]==4  (inr[i]= 2.25  inr[i]= 3.5)) cinr[i]-4
 if (rango_inr1[i]==5  (inr[i]= 2.2  inr[i]= 3.25)) cinr[i]-5
 if (rango_inr1[i]==6  (inr[i]= 2  inr[i]= 3.5)) cinr[i]-6
 if (rango_inr1[i]==7  (inr[i]= 2  inr[i]= 4)) cinr[i]-7
 if (rango_inr1[i]==8  (inr[i]= 2  inr[i]= 2.6)) cinr[i]-8
 if (rango_inr1[i]==9  (inr[i]= 2  inr[i]= 2.5)) cinr[i]-9
 if (rango_inr1[i]==10  (inr[i]= 2  inr[i]=2.8)) cinr[i]-10
 if (rango_inr1[i]==11  (inr[i]= 2.5  inr[i]= 4)) cinr[i]-11
 }

 donde n vale 3738 e i naturalmente 3738. Pues bien, resulta que la
 variable creada cinr tiene 3737 casos. ¿Qué puede estar ocurriendo?. He
 comprobado los casos de rango_inr1 y de inr y son 3738.
 ¿Qué estoy haciendo mal?.

 Un cordial saludo,

 Juan

 -- 
 Juan Antonio Gil Pascual
 Profesor de Metodología de la Investigación Cuantitativa
 correo: j...@edu.uned.es mailto:j...@edu.uned.es
 web: www.uned.es/personal/jgil

 Dpto. MIDE
 Facultad de Educación
 c/Juan del Rosal, 14 desp. 2.72
 28040 Madrid
 Tel,f. 91 3987279
 Fax. 91 3987288

 ___
 R-help-es mailing list
 R-help-es@r-project.org mailto:R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es



 ___
 R-help-es mailing list
 R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es