Re: [R] Compressing code help in a loop

2014-11-12 Thread PIKAL Petr
Hi

slightly more general if first number is quarter and last two are year

 index - c(406, 107, 207, 307, 407, 108, 208, 308, 408, 109, 209, 309, 409,
+ 110, 210, 310, 410, 111, 211)

year-substr(as.character(index), 2,3)
qrt-substr(as.character(index), 1,1)
as.numeric(factor(paste(year, qrt, sep=-)))
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19

qyTOindex - function(x) {

year - substr(as.character(x), 2,3)
qrt - substr(as.character(x), 1,1)
result -as.numeric(factor(paste(year, qrt, sep=-)))
}

qyTOindex(p_int$p_made)

Regards

Petr

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Wush Wu
 Sent: Monday, November 10, 2014 2:30 PM
 To: Francesca
 Cc: R help
 Subject: Re: [R] Compressing code help in a loop

 Dear Francesca,

 Is this what you want?

 ```r
 index - c(406, 107, 207, 307, 407, 108, 208, 308, 408, 109, 209, 309,
 409,
 110, 210, 310, 410, 111, 211)
 p_m - match( p_int$p_made, index)
 dim(p_m) - c(dim(p_int)[1],1)
 ```

 Best,
 Wush
 PhD Student Graduate Institute of Electrical Engineering, National
 Taiwan
 University



 2014-11-10 20:14 GMT+08:00 Francesca francesca.panco...@gmail.com:

  Dear Contributors
 
  I have a problem with a loop.
 
  I needed to create a variable that takes values 1,2.. to 19
 corresponding
  to the value of a variable in a data.frame whose name is p_int$p_made
 and
 
  which takes values from 406  to 211.
 
  The problem is that this values come ordered in the wrong way when I
 try to
  compress the loop as the system reads
 
 
  107,111,207,211,311,406,407,408,409,410,411,
 
 
  while they correspond to quarters-years so they should be ordered as
 
 
  406-107-207-307-407…
 
  the only solution I found was really silly. It is the following.
 
 
 
 
  p_m-matrix(0,dim(p_int)[1],1)
 
  for (i in 1:length(p_int$p_made)){
 
if (p_int$p_made[i]==406) p_m[i]-1 else
 
  if (p_int$p_made[i]==107) p_m[i]-2 else
 
if (p_int$p_made[i]==207) p_m[i]-3 else
 
  if (p_int$p_made[i]==307) p_m[i]-4 else
 
if (p_int$p_made[i]==407) p_m[i]-5 else
 
  if (p_int$p_made[i]==108) p_m[i]-6 else
 
if (p_int$p_made[i]==208) p_m[i]-7 else
 
  if (p_int$p_made[i]==308) p_m[i]-8 else
 
if (p_int$p_made[i]==408) p_m[i]-9 else
 
  if (p_int$p_made[i]==109) p_m[i]-10 else
 
if (p_int$p_made[i]==209) p_m[i]-11 else
 
  if (p_int$p_made[i]==309) p_m[i]-12 else
 
if (p_int$p_made[i]==409) p_m[i]-13 else
 
  if (p_int$p_made[i]==110) p_m[i]-14 else
 
if (p_int$p_made[i]==210) p_m[i]-15
 else
 
  if (p_int$p_made[i]==310) p_m[i]-16
 else
 
if (p_int$p_made[i]==410) p_m[i]-
 17 else
 
  if (p_int$p_made[i]==111)
 p_m[i]-18
  else
 
if (p_int$p_made[i]==211)
 p_m[i]-19
 
  }
 
  Can anyone help to find something more efficient?
 
 
  Thanks in advance.
 
 
  Francesca
 
  --
 
  Francesca
 
  --
  Francesca Pancotto
  Associate Professor
  University of Modena and Reggio Emilia
  Viale A. Allegri, 9
  40121 Reggio Emilia
  Office: +39 0522 523264
  Web: https://sites.google.com/site/francescapancotto/
  --
 
  [[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.


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 

[R] factor levels numeric values

2014-11-12 Thread David Studer
Hi everybody,

I have another question (to which I could not find an answer in my r-books.
I am sure, it's not a great issue, but I simply lack of a good idea how to
solve this:

One of my variables gets imported as a factor instead of a numeric variable.
Now I have a...
 Factor w/ 63 levels 0,0.02,0.03,..: 1 NA NA 1 NA NA 1 1 53 10 ...

How can I transform these factor levels into actual values?

Thank you very much for any help!
David

[[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] factor levels numeric values

2014-11-12 Thread Gerrit Eichner

Hello, David,

take a look at the beginning of the Warning section of ?factor.

 Hth  --  Gerrit


Hi everybody,

I have another question (to which I could not find an answer in my r-books.
I am sure, it's not a great issue, but I simply lack of a good idea how to
solve this:

One of my variables gets imported as a factor instead of a numeric variable.
Now I have a...
Factor w/ 63 levels 0,0.02,0.03,..: 1 NA NA 1 NA NA 1 1 53 10 ...

How can I transform these factor levels into actual values?

Thank you very much for any help!
David

[[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-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] Submodel selection using dredge and gam (mgcv)

2014-11-12 Thread Arnaud Mosnier
Hi Kamil,

Thanks for your answer. In fact, I already tried something with operators
in such a way you advise, but it seems more complicated due to the use of
the s() and ti() operators.

Can you provide a solution for the following example ?

library(mgcv)
set.seed(2)
dat - gamSim(1,n=400,dist=normal,scale=2)

bt - gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method=ML)

library(MuMIn)

# this does not work
dredge(bt, subset = (!(x0,x1) | (x0  x1)))
dredge(bt, subset = (!ti(x0,x1) | (s(x0)  s(x1

Cheers,

Arnaud


2014-11-11 4:11 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl:

 Hi Arnaud,
 your question has in fact nothing to do with gam or model selection. What
 you are asking is: what is the logical expression that yields True when AB
 is False or both A and B are True. Now replace the words with operators
 (!AB | (A  B)) and voilà.

 See also:
 help(Logic, base)
 fortunes::fortune(350)

 best,
 kamil



 On 2014-11-10 21:26, Arnaud Mosnier wrote:

 Hi,

 I want to use dredge to test several gam submodels including interactions.
 I tried to find a way in order to keep models with interaction only if
 the single variables occurring in the interaction are also included.

 i.e.: for
   y~s(x0)+s(x1)+ti(x0, x1)

 I want to keep
 y ~ s(x0)
 y ~ s(x1)
 y ~ s(x0) + s(x1)
 y ~ s(x0) + s(x1) + ti(x0,x1)

 and I want to remove

 y ~ s(x0) + ti(x0,x1)
 y ~ s(x1) + ti(x0,x1)
 y ~ ti(x0,x1)


 I know that I should use the subset option of the dredge function.
 However, I can not find the correct matrix / expression to obtain what I
 need !


 Here a small example.

 

 # Create some data (use mgcv example)
 library(mgcv)
 set.seed(2)
 dat - gamSim(1,n=400,dist=normal,scale=2)

 # Create the global gam model
 # Here a model with interaction. Note the use of ti()
 bt - gam(y~s(x0)+s(x1)+s(x2)+s(x3)+ti(x1,x2), data=dat,method=ML)

 # Use dredge to test sub-models
 library(MuMIn)
 print(modstab - dredge(bt))

 # Here the 11th model include the interaction but do not include the
 single variables x1 and x2
 # ... I want to avoid that kind of model.
 get.models(modstab, subset = 11)

 


 Any help would be appreciated !

 Arnaud




[[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] factor levels numeric values

2014-11-12 Thread David L Carlson
Also look at the Frequently Asked Questions document that comes with your R 
installation:

7.10 How do I convert factors to numeric?

It may happen that when reading numeric data into R (usually, when reading in a 
file), they come in as factors. If f is such a factor object, you can use

as.numeric(as.character(f))

to get the numbers back. More efficient, but harder to remember, is

as.numeric(levels(f))[as.integer(f)]

In any case, do not call as.numeric() or their likes directly for the task at 
hand (as as.numeric() or unclass() give the internal codes).

-
David L Carlson
Department of Anthropology
Texas AM University
College Station, TX 77840-4352

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Gerrit Eichner
Sent: Wednesday, November 12, 2014 8:06 AM
To: David Studer
Cc: r-help@r-project.org
Subject: Re: [R] factor levels  numeric values

Hello, David,

take a look at the beginning of the Warning section of ?factor.

  Hth  --  Gerrit

 Hi everybody,

 I have another question (to which I could not find an answer in my r-books.
 I am sure, it's not a great issue, but I simply lack of a good idea how to
 solve this:

 One of my variables gets imported as a factor instead of a numeric variable.
 Now I have a...
 Factor w/ 63 levels 0,0.02,0.03,..: 1 NA NA 1 NA NA 1 1 53 10 ...

 How can I transform these factor levels into actual values?

 Thank you very much for any help!
 David

   [[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-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] R memory issues

2014-11-12 Thread ce
you may try to increase virtual memory :

http://windows.microsoft.com/en-us/windows/change-virtual-memory-size#1TC=windows-7

-Original Message-
From: eliza botto [eliza_bo...@hotmail.com]
Date: 11/11/2014 02:35 PM
To: r-help@r-project.org r-help@r-project.org
Subject: [R] R memory issues

Dear useRs,
I have this funny thing going on with me since morning. I am 32 bit window 7 
system with 4 GB RAM(2.95 usable). I tried to run a code on it but when I tried 
to convert dataframe to matrix by using the following code
mat-matrix(as.numeric(unlist(SFI)),nrow=nrow(SFI))
*where SFI is my dataframe.
an error came up, Error: cannot allocate vector of size 237.3 Mb
I tried to increase memory by using memory.limit(2500) but to no effect. 
Kindly help me out on it as you always do.
Thanks,
Eliza 
[[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-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] factor levels numeric values

2014-11-12 Thread Ivan Calandra
I have not completely followed the discussion, so excuse me if it was 
already pointed out.
If numeric data are read as factors, this means that there are not only 
numeric data in the column. It could be an empty space somewhere, or 
some character that should be NA, or...
I think it is worth spending some time searching for the typo so that 
the file will be read correctly in R.


HTH,
Ivan

--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENA² - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra

Le 12/11/14 15:56, David L Carlson a écrit :

Also look at the Frequently Asked Questions document that comes with your R 
installation:

7.10 How do I convert factors to numeric?

It may happen that when reading numeric data into R (usually, when reading in a 
file), they come in as factors. If f is such a factor object, you can use

as.numeric(as.character(f))

to get the numbers back. More efficient, but harder to remember, is

as.numeric(levels(f))[as.integer(f)]

In any case, do not call as.numeric() or their likes directly for the task at 
hand (as as.numeric() or unclass() give the internal codes).

-
David L Carlson
Department of Anthropology
Texas AM University
College Station, TX 77840-4352

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Gerrit Eichner
Sent: Wednesday, November 12, 2014 8:06 AM
To: David Studer
Cc: r-help@r-project.org
Subject: Re: [R] factor levels  numeric values

Hello, David,

take a look at the beginning of the Warning section of ?factor.

   Hth  --  Gerrit


Hi everybody,

I have another question (to which I could not find an answer in my r-books.
I am sure, it's not a great issue, but I simply lack of a good idea how to
solve this:

One of my variables gets imported as a factor instead of a numeric variable.
Now I have a...
Factor w/ 63 levels 0,0.02,0.03,..: 1 NA NA 1 NA NA 1 1 53 10 ...

How can I transform these factor levels into actual values?

Thank you very much for any help!
David

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



__
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] Compilation error: Rcpp and related packages - record-gcc-switches missing

2014-11-12 Thread Antti Simola
Hello,

I encountered problem with Linux machine (openSUSE, 3.1.1. version of R)
while I tried to update the packages with update.packages(). Rcpp,
RcppArmadillo and RcppEigen refused to compile because record-gcc-swtiches
was missing. I don't know much about compiling and such so I didn't get any
further with the problem. Enquiries to Rcpp and openSUSE experts have not
solved my problem. What I learned was that -frecord-gcc-switches might be
mispelled somewhere. That information did not help me to find solution. If
anyone could help with this problem I would we very thankful. See the log
and SessionInfo() below for more detail:

Rcpp :
Version 0.11.2 installed in /home/antti/R/x86_64-suse-linux-gnu-library/3.1
Version 0.11.3 available at http://ftp.eenet.ee/pub/cran
Update (y/N/c)? y
RcppArmadillo :
Version 0.4.320.0 installed in
/home/antti/R/x86_64-suse-linux-gnu-library/3.1
Version 0.4.450.1.0 available at http://ftp.eenet.ee/pub/cran
Update (y/N/c)? y
RcppEigen :
Version 0.3.2.1.2 installed in
/home/antti/R/x86_64-suse-linux-gnu-library/3.1
Version 0.3.2.2.0 available at http://ftp.eenet.ee/pub/cran
Update (y/N/c)? y
trying URL 'http://ftp.eenet.ee/pub/cran/src/con..._0.11.3.tar.gz
http://ftp.eenet.ee/pub/cran/src/contrib/Rcpp_0.11.3.tar.gz'
Content type 'application/x-tar' length 2169583 bytes (2.1 Mb)
opened URL
==
downloaded 2.1 Mb

trying URL 'http://ftp.eenet.ee/pub/cran/src/con...450.1.0.tar.gz
http://ftp.eenet.ee/pub/cran/src/contrib/RcppArmadillo_0.4.450.1.0.tar.gz'
Content type 'application/x-tar' length 931597 bytes (909 Kb)
opened URL
==
downloaded 909 Kb

trying URL 'http://ftp.eenet.ee/pub/cran/src/con...3.2.2.0.tar.gz
http://ftp.eenet.ee/pub/cran/src/contrib/RcppEigen_0.3.2.2.0.tar.gz'
Content type 'application/x-tar' length 1216536 bytes (1.2 Mb)
opened URL
==
downloaded 1.2 Mb

* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/lib64/R/include -I../inst/include/ -I/usr/local/include -fpic
-fmessage-length=0 record-gcc-switches -fstack-protector -O3 -Wall
-D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -c
Date.cpp -o Date.o
g++: error: record-gcc-switches: No such file or directory
make: *** [Date.o] Error 1
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/home/antti/R/x86_64-suse-linux-gnu-library/3.1/Rcpp’
* restoring previous ‘/home/antti/R/x86_64-suse-linux-gnu-library/3.1/Rcpp’
* installing *source* package ‘RcppArmadillo’ ...
** package ‘RcppArmadillo’ successfully unpacked and MD5 sums checked
* checking LAPACK_LIBS: divide-and-conquer complex SVD available via
R-supplied LAPACK
** libs
g++ -I/usr/lib64/R/include -I/usr/local/include
-I/home/antti/R/x86_64-suse-linux-gnu-library/3.1/Rcpp/include
-I../inst/include -fpic -fmessage-length=0 record-gcc-switches
-fstack-protector -O3 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables
-fasynchronous-unwind-tables -c RcppArmadillo.cpp -o RcppArmadillo.o
g++: error: record-gcc-switches: No such file or directory
make: *** [RcppArmadillo.o] Error 1
ERROR: compilation failed for package ‘RcppArmadillo’
* removing ‘/home/antti/R/x86_64-suse-linux-gnu-library/3.1/RcppArmadillo’
* restoring previous
‘/home/antti/R/x86_64-suse-linux-gnu-library/3.1/RcppArmadillo’
* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/lib64/R/include -I/usr/local/include
-I/home/antti/R/x86_64-suse-linux-gnu-library/3.1/Rcpp/include
-I../inst/include -fpic -fmessage-length=0 record-gcc-switches
-fstack-protector -O3 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables
-fasynchronous-unwind-tables -c RcppEigen.cpp -o RcppEigen.o
g++: error: record-gcc-switches: No such file or directory
make: *** [RcppEigen.o] Error 1
ERROR: compilation failed for package ‘RcppEigen’
* removing ‘/home/antti/R/x86_64-suse-linux-gnu-library/3.1/RcppEigen’
* restoring previous
‘/home/antti/R/x86_64-suse-linux-gnu-library/3.1/RcppEigen’

The downloaded source packages are in
‘/tmp/Rtmpnx5dfE/downloaded_packages’
Warning messages:
1: In install.packages(update[instlib == l, Package], l, contriburl =
contriburl, :
installation of package ‘Rcpp’ had non-zero exit status
2: In install.packages(update[instlib == l, Package], l, contriburl =
contriburl, :
installation of package ‘RcppArmadillo’ had non-zero exit status
3: In install.packages(update[instlib == l, Package], l, contriburl =
contriburl, :
installation of package ‘RcppEigen’ had non-zero exit status
 sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-suse-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 

Re: [R] factor levels numeric values

2014-11-12 Thread Jeff Newmiller
Another approach is to re-import your data using options that do not put the 
data into a factor in the first place.  For example you can use the colClasses 
parameter in the read.table family of functions to specify numeric for that 
column. If you need to give special handling to that column anyway (using 
strong functions) then you can use the stringsAsFactors=FALSE or as.is=TRUE 
parameter settings and avoid the as.character() band-aid in your code.
---
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 November 12, 2014 6:56:11 AM PST, David L Carlson dcarl...@tamu.edu wrote:
Also look at the Frequently Asked Questions document that comes with
your R installation:

7.10 How do I convert factors to numeric?

It may happen that when reading numeric data into R (usually, when
reading in a file), they come in as factors. If f is such a factor
object, you can use

as.numeric(as.character(f))

to get the numbers back. More efficient, but harder to remember, is

as.numeric(levels(f))[as.integer(f)]

In any case, do not call as.numeric() or their likes directly for the
task at hand (as as.numeric() or unclass() give the internal codes).

-
David L Carlson
Department of Anthropology
Texas AM University
College Station, TX 77840-4352

-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Gerrit Eichner
Sent: Wednesday, November 12, 2014 8:06 AM
To: David Studer
Cc: r-help@r-project.org
Subject: Re: [R] factor levels  numeric values

Hello, David,

take a look at the beginning of the Warning section of ?factor.

  Hth  --  Gerrit

 Hi everybody,

 I have another question (to which I could not find an answer in my
r-books.
 I am sure, it's not a great issue, but I simply lack of a good idea
how to
 solve this:

 One of my variables gets imported as a factor instead of a numeric
variable.
 Now I have a...
 Factor w/ 63 levels 0,0.02,0.03,..: 1 NA NA 1 NA NA 1 1 53 10
...

 How can I transform these factor levels into actual values?

 Thank you very much for any help!
 David

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

__
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 memory issues

2014-11-12 Thread Prof Brian Ripley

On 12/11/2014 15:18, ce wrote:

you may try to increase virtual memory :

http://windows.microsoft.com/en-us/windows/change-virtual-memory-size#1TC=windows-7


That is a very low plausibility for the error.  See the discussion in 
the FAQ: 
http://cran.r-project.org/bin/windows/base/rw-FAQ.html#There-seems-to-be-a-limit-on-the-memory-it-uses_0021 
and the discussion of fragmentation in ?Memory-limits .


As others have said: get a 64-bit OS -- the only 32-bit one I have seen 
for several years now is on an old Windows sub-notebook with an Atom CPU.




-Original Message-
From: eliza botto [eliza_bo...@hotmail.com]
Date: 11/11/2014 02:35 PM
To: r-help@r-project.org r-help@r-project.org
Subject: [R] R memory issues

Dear useRs,
I have this funny thing going on with me since morning. I am 32 bit window 7 
system with 4 GB RAM(2.95 usable). I tried to run a code on it but when I tried 
to convert dataframe to matrix by using the following code
mat-matrix(as.numeric(unlist(SFI)),nrow=nrow(SFI))
*where SFI is my dataframe.
an error came up, Error: cannot allocate vector of size 237.3 Mb
I tried to increase memory by using memory.limit(2500) but to no effect.
Kindly help me out on it as you always do.
Thanks,
Eliza   
[[alternative HTML version deleted]]




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK

__
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] tapply error svyby function survey package

2014-11-12 Thread Martin Canon
Hi.


I'm trying to calculate the weighted mean score of a quality of life
measure (ovt) in patients with irritable bowel syndrome by their
marital status (d7).

This is a summary of the structure of the dataset:

 str(sii.tesis)
'data.frame':1063 obs. of  75 variables:
 $ id : int  51 52 53 54 55 56 57 58 59 60 ...
 $ stratum: Factor w/ 6 levels MEst,MAcad,..: 1 4 NA 4 4 1 6 NA 4 4 ...
 $ expfc  : num  22.8 17.1 NA 17.1 17.1 ...
 $ d6 : Factor w/ 3 levels Estudiante,Profesor,..: 1 1 NA
1 1 1 3 NA 1 1 ...
 $ d7 : Factor w/ 6 levels Soltero,Casado,..: 1 1 NA 1 1 1
1 NA 1 1 ...
 $ d7c: Factor w/ 2 levels No estable,Estable: 1 1 NA 1 1
1 1 NA 1 1 ...
 $ s1cm   : Factor w/ 2 levels No,Si: 1 2 NA 1 1 1 2 NA 1 1 ...
 $ ovt: num  NA 93.4 NA NA NA ...

I declared the sampling design:

 sii.design - svydesign(
  id = ~1,
  strata = ~stratum,
  weights = ~expfc,
  data = subset(sii.tesis, !is.na(stratum)))

Then I tried to get the result:

 svyby(~ovt, ~d7, sii.design, svymean, na.rm = TRUE, level = 0.95)

but i get the error:

Error in tapply(1:NROW(x), list(factor(strata)), function(index) { :
  arguments must have same length


The length of both variables is the same. If the variable ovt exists,
there is a d7 match in the data frame.

I try the same thing using another variable instead - role (d6) -
and it works.

 svyby(~ovt, ~d6, sii.design, svymean, na.rm = TRUE, level = 0.95)
   d6  ovt   se
Estudiante Estudiante 71.01805 1.370569
Profesor Profesor 72.30923 6.518378
Administrativo Administrativo 75.69102 3.715050

If I use the recategorized d7 variable (d7c,  two levels only) it works too:

 svyby(~ovt, ~d7c, sii.design, svymean, na.rm = TRUE, level = 0.95)
  d7c  ovt  se
No estable No estable 70.92344 1.37460
Estable   Estable 74.53719 4.16954


What could be the problem?


Regards.


Martin Canon
Colombia, South America

__
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] tapply error svyby function survey package

2014-11-12 Thread Anthony Damico
try resetting your levels?  if that doesn't work, please dput() an example
data set that we can test with :) thanks!

sii.design - update( sii.design , d6 = factor( d6 ) )






On Wed, Nov 12, 2014 at 7:59 AM, Martin Canon martin.ca...@gmail.com
wrote:

 Hi.


 I'm trying to calculate the weighted mean score of a quality of life
 measure (ovt) in patients with irritable bowel syndrome by their
 marital status (d7).

 This is a summary of the structure of the dataset:

  str(sii.tesis)
 'data.frame':1063 obs. of  75 variables:
  $ id : int  51 52 53 54 55 56 57 58 59 60 ...
  $ stratum: Factor w/ 6 levels MEst,MAcad,..: 1 4 NA 4 4 1 6 NA 4
 4 ...
  $ expfc  : num  22.8 17.1 NA 17.1 17.1 ...
  $ d6 : Factor w/ 3 levels Estudiante,Profesor,..: 1 1 NA
 1 1 1 3 NA 1 1 ...
  $ d7 : Factor w/ 6 levels Soltero,Casado,..: 1 1 NA 1 1 1
 1 NA 1 1 ...
  $ d7c: Factor w/ 2 levels No estable,Estable: 1 1 NA 1 1
 1 1 NA 1 1 ...
  $ s1cm   : Factor w/ 2 levels No,Si: 1 2 NA 1 1 1 2 NA 1 1 ...
  $ ovt: num  NA 93.4 NA NA NA ...

 I declared the sampling design:

  sii.design - svydesign(
   id = ~1,
   strata = ~stratum,
   weights = ~expfc,
   data = subset(sii.tesis, !is.na(stratum)))

 Then I tried to get the result:

  svyby(~ovt, ~d7, sii.design, svymean, na.rm = TRUE, level = 0.95)

 but i get the error:

 Error in tapply(1:NROW(x), list(factor(strata)), function(index) { :
   arguments must have same length


 The length of both variables is the same. If the variable ovt exists,
 there is a d7 match in the data frame.

 I try the same thing using another variable instead - role (d6) -
 and it works.

  svyby(~ovt, ~d6, sii.design, svymean, na.rm = TRUE, level = 0.95)
d6  ovt   se
 Estudiante Estudiante 71.01805 1.370569
 Profesor Profesor 72.30923 6.518378
 Administrativo Administrativo 75.69102 3.715050

 If I use the recategorized d7 variable (d7c,  two levels only) it works
 too:

  svyby(~ovt, ~d7c, sii.design, svymean, na.rm = TRUE, level = 0.95)
   d7c  ovt  se
 No estable No estable 70.92344 1.37460
 Estable   Estable 74.53719 4.16954


 What could be the problem?


 Regards.


 Martin Canon
 Colombia, South America

 __
 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] Submodel selection using dredge and gam (mgcv)

2014-11-12 Thread Kamil Bartoń

Hi Arnaud,
please read ?dredge - Details - Subsetting, where this is explained.


On 2014-11-12 15:19, Arnaud Mosnier wrote:

Hi Kamil,

Thanks for your answer. In fact, I already tried something with
operators in such a way you advise, but it seems more complicated due to
the use of the s() and ti() operators.

Can you provide a solution for the following example ?

library(mgcv)
set.seed(2)
dat - gamSim(1,n=400,dist=normal,scale=2)

bt - gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method=ML)

library(MuMIn)

# this does not work
dredge(bt, subset = (!(x0,x1) | (x0  x1)))
dredge(bt, subset = (!ti(x0,x1) | (s(x0)  s(x1

Cheers,

Arnaud


2014-11-11 4:11 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl
mailto:kamil.bar...@o2.pl:

Hi Arnaud,
your question has in fact nothing to do with gam or model selection.
What you are asking is: what is the logical expression that yields
True when AB is False or both A and B are True. Now replace the
words with operators (!AB | (A  B)) and voilà.

See also:
help(Logic, base)
fortunes::fortune(350)

best,
kamil



On 2014-11-10 21:26, Arnaud Mosnier wrote:

Hi,

I want to use dredge to test several gam submodels including
interactions.
I tried to find a way in order to keep models with interaction
only if
the single variables occurring in the interaction are also included.

i.e.: for
   y~s(x0)+s(x1)+ti(x0, x1)

I want to keep
y ~ s(x0)
y ~ s(x1)
y ~ s(x0) + s(x1)
y ~ s(x0) + s(x1) + ti(x0,x1)

and I want to remove

y ~ s(x0) + ti(x0,x1)
y ~ s(x1) + ti(x0,x1)
y ~ ti(x0,x1)


I know that I should use the subset option of the dredge function.
However, I can not find the correct matrix / expression to
obtain what I
need !


Here a small example.



# Create some data (use mgcv example)
library(mgcv)
set.seed(2)
dat - gamSim(1,n=400,dist=normal,__scale=2)

# Create the global gam model
# Here a model with interaction. Note the use of ti()
bt - gam(y~s(x0)+s(x1)+s(x2)+s(x3)+__ti(x1,x2),
data=dat,method=ML)

# Use dredge to test sub-models
library(MuMIn)
print(modstab - dredge(bt))

# Here the 11th model include the interaction but do not include the
single variables x1 and x2
# ... I want to avoid that kind of model.
get.models(modstab, subset = 11)




Any help would be appreciated !

Arnaud





__
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] tapply error svyby function survey package

2014-11-12 Thread Anthony Damico
hi martin, sending the first 25 rows does not help if it does not re-create
the problem..  when i run the data you have provided, i do not encounter
your problem (see below).  someone else may be able to guess the issue, but
this would be a lot easier to solve if you can create a minimal
reproducible example

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example


sii.tesis -
structure(list(id = c(51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
73L, 74L, 75L, 76L), stratum = structure(c(1L, 4L, NA, 4L, 4L,
1L, 6L, NA, 4L, 4L, 1L, 1L, 1L, 6L, 6L, 3L, 3L, 6L, NA, 1L, 1L,
6L, 4L, 3L, 6L), .Label = c(MEst, MAcad, MAdm, FEst,
FAcad, FAdm), class = factor), expfc = c(22.8195266723633,
17.0644626617432, NA, 17.0644626617432, 17.0644626617432, 22.8195266723633,
5.1702127456665, NA, 17.0644626617432, 17.0644626617432, 22.8195266723633,
22.8195266723633, 22.8195266723633, 5.1702127456665, 5.1702127456665,
6.24137926101685, 6.24137926101685, 5.1702127456665, NA, 22.8195266723633,
22.8195266723633, 5.1702127456665, 17.0644626617432, 6.24137926101685,
5.1702127456665), d7 = structure(c(1L, 1L, NA, 1L, 1L, 1L, 1L,
NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, NA, 1L, 1L, 6L, 1L,
6L, 6L), .Label = c(Soltero, Casado, Separado, Divorciado,
Viudo, Union libre), class = factor), ovt = c(NA, 93.3823547363281,
NA, NA, NA, NA, 83.8235321044922, NA, NA, NA, NA, NA, NA, NA,
79.4117660522461, NA, NA, 19.1176471710205, NA, NA, NA, 85.2941207885742,
NA, NA, NA)), .Names = c(id, stratum, expfc, d7, ovt
), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25), class = data.frame)

 sii.design - svydesign(
  id = ~1,
  strata = ~stratum,
  weights = ~expfc,
  data = subset(sii.tesis, !is.na(stratum)))

svyby(~ovt, ~d7, sii.design, svymean, na.rm = TRUE, level = 0.95)


# works fine---
 svyby(~ovt, ~d7, sii.design, svymean, na.rm = TRUE, level = 0.95)
 d7  ovt   se
Soltero Soltero 88.94329 3.333485
Casado   Casado 19.11765 0.00
Union libre Union libre 85.29412 0.00






On Wed, Nov 12, 2014 at 5:25 PM, Martin Canon martin.ca...@gmail.com
wrote:

 Anthony, thanks for your reply.

 Resetting the levels didn't work.

 These are the first 25 rows of the dataset:

 structure(list(id = c(51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
 73L, 74L, 75L, 76L), stratum = structure(c(1L, 4L, NA, 4L, 4L,
 1L, 6L, NA, 4L, 4L, 1L, 1L, 1L, 6L, 6L, 3L, 3L, 6L, NA, 1L, 1L,
 6L, 4L, 3L, 6L), .Label = c(MEst, MAcad, MAdm, FEst,
 FAcad, FAdm), class = factor), expfc = c(22.8195266723633,
 17.0644626617432, NA, 17.0644626617432, 17.0644626617432, 22.8195266723633,
 5.1702127456665, NA, 17.0644626617432, 17.0644626617432, 22.8195266723633,
 22.8195266723633, 22.8195266723633, 5.1702127456665, 5.1702127456665,
 6.24137926101685, 6.24137926101685, 5.1702127456665, NA, 22.8195266723633,
 22.8195266723633, 5.1702127456665, 17.0644626617432, 6.24137926101685,
 5.1702127456665), d7 = structure(c(1L, 1L, NA, 1L, 1L, 1L, 1L,
 NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, NA, 1L, 1L, 6L, 1L,
 6L, 6L), .Label = c(Soltero, Casado, Separado, Divorciado,
 Viudo, Union libre), class = factor), ovt = c(NA, 93.3823547363281,
 NA, NA, NA, NA, 83.8235321044922, NA, NA, NA, NA, NA, NA, NA,
 79.4117660522461, NA, NA, 19.1176471710205, NA, NA, NA, 85.2941207885742,
 NA, NA, NA)), .Names = c(id, stratum, expfc, d7, ovt
 ), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9,
 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
 21, 22, 23, 24, 25), class = data.frame)

 Regards.

 Martin

 On Wed, Nov 12, 2014 at 1:39 PM, Anthony Damico ajdam...@gmail.com
 wrote:
  try resetting your levels?  if that doesn't work, please dput() an
 example
  data set that we can test with :) thanks!
 
  sii.design - update( sii.design , d6 = factor( d6 ) )
 
 
 
 
 
 
  On Wed, Nov 12, 2014 at 7:59 AM, Martin Canon martin.ca...@gmail.com
  wrote:
 
  Hi.
 
 
  I'm trying to calculate the weighted mean score of a quality of life
  measure (ovt) in patients with irritable bowel syndrome by their
  marital status (d7).
 
  This is a summary of the structure of the dataset:
 
   str(sii.tesis)
  'data.frame':1063 obs. of  75 variables:
   $ id : int  51 52 53 54 55 56 57 58 59 60 ...
   $ stratum: Factor w/ 6 levels MEst,MAcad,..: 1 4 NA 4 4 1 6 NA
 4
  4 ...
   $ expfc  : num  22.8 17.1 NA 17.1 17.1 ...
   $ d6 : Factor w/ 3 levels Estudiante,Profesor,..: 1 1 NA
  1 1 1 3 NA 1 1 ...
   $ d7 : Factor w/ 6 levels Soltero,Casado,..: 1 1 NA 1 1 1
  1 NA 1 1 ...
   $ d7c: Factor w/ 2 levels No estable,Estable: 1 1 NA 1 1
  1 1 NA 1 1 ...
   $ s1cm   : Factor w/ 2 levels No,Si: 1 2 NA 1 1 1 2 NA 1 1 ...
   $ ovt: num  NA 93.4 NA NA NA ...
 
  I declared the sampling design:
 
   sii.design - svydesign(
id = ~1,
strata = 

Re: [R] Is it possible to define another kind of NA

2014-11-12 Thread MacQueen, Don
Along the lines of what Bert Gunter said, the ideal way to represent LDL
results depends on the functions used later to analyze them. I deal with
such data on a daily basis and have never found it necessary to
incorporate that information in the same variable as the results. What
would you do if data were censored at both ends, both low and high?

Anyway, the functions I use mostly incorporate that information in a
second variable, a ³detection indicator² variable, and that¹s what I do.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/9/14, 10:07 AM, Marc Girondot marc_...@yahoo.fr wrote:

Dear member list,

In many experimental sciences, there is a lower detection limit (LDL)
when a dosage of a product is done. Then some samples are evaluated to
be below this limit.
I search for the best way to indicate in a data.frame that some values
are such LDL. Ideally, an equivalent of NA would be the best.
Until now I manage by indicating all the column in characters.
So the question is: is it possible to define a value that could be named
LDL and that could take place in vectors or data.frame such as:
v - c(0.2, 0.28, LDL, 0.9) is the same way that NA can be used.
with of course a function is.ldl(v) that would return F F T F

Thanks a lot for any direction to solve this

Marc

__
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] Synthestic Control Methods for Causal Inference

2014-11-12 Thread Peter Maclean
I am interested in conducting causal inference using synthetic control method 
using R where there are multiple treated units/regions. The current synth 
package allows only one treated unit to be compared to other (several) 
synthetic units. In my case, I have 5 treated units and 35 untreated units. Is 
there any package I have missed? I am currently doing a sequential analysis 
comparing each treated unit to the 35 untreated units. I would like to get a 
composite result. Any help will be appreciated.
 
Sincerely,

Peter Maclean
Department of Economics
UDSM

__
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] Submodel selection using dredge and gam (mgcv)

2014-11-12 Thread Arnaud Mosnier
Argh ! Ok ... my fault ... the use of back-ticks was the solution !!!
Thanks,

Arnaud

2014-11-12 14:19 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl:

 Hi Arnaud,
 please read ?dredge - Details - Subsetting, where this is explained.


 On 2014-11-12 15:19, Arnaud Mosnier wrote:

 Hi Kamil,

 Thanks for your answer. In fact, I already tried something with
 operators in such a way you advise, but it seems more complicated due to
 the use of the s() and ti() operators.

 Can you provide a solution for the following example ?

 library(mgcv)
 set.seed(2)
 dat - gamSim(1,n=400,dist=normal,scale=2)

 bt - gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method=ML)

 library(MuMIn)

 # this does not work
 dredge(bt, subset = (!(x0,x1) | (x0  x1)))
 dredge(bt, subset = (!ti(x0,x1) | (s(x0)  s(x1

 Cheers,

 Arnaud


 2014-11-11 4:11 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl
 mailto:kamil.bar...@o2.pl:


 Hi Arnaud,
 your question has in fact nothing to do with gam or model selection.
 What you are asking is: what is the logical expression that yields
 True when AB is False or both A and B are True. Now replace the
 words with operators (!AB | (A  B)) and voilà.

 See also:
 help(Logic, base)
 fortunes::fortune(350)

 best,
 kamil



 On 2014-11-10 21:26, Arnaud Mosnier wrote:

 Hi,

 I want to use dredge to test several gam submodels including
 interactions.
 I tried to find a way in order to keep models with interaction
 only if
 the single variables occurring in the interaction are also
 included.

 i.e.: for
y~s(x0)+s(x1)+ti(x0, x1)

 I want to keep
 y ~ s(x0)
 y ~ s(x1)
 y ~ s(x0) + s(x1)
 y ~ s(x0) + s(x1) + ti(x0,x1)

 and I want to remove

 y ~ s(x0) + ti(x0,x1)
 y ~ s(x1) + ti(x0,x1)
 y ~ ti(x0,x1)


 I know that I should use the subset option of the dredge
 function.
 However, I can not find the correct matrix / expression to
 obtain what I
 need !


 Here a small example.

 

 # Create some data (use mgcv example)
 library(mgcv)
 set.seed(2)
 dat - gamSim(1,n=400,dist=normal,__scale=2)

 # Create the global gam model
 # Here a model with interaction. Note the use of ti()
 bt - gam(y~s(x0)+s(x1)+s(x2)+s(x3)+__ti(x1,x2),
 data=dat,method=ML)

 # Use dredge to test sub-models
 library(MuMIn)
 print(modstab - dredge(bt))

 # Here the 11th model include the interaction but do not include
 the
 single variables x1 and x2
 # ... I want to avoid that kind of model.
 get.models(modstab, subset = 11)

 


 Any help would be appreciated !

 Arnaud






[[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] tapply error svyby function survey package

2014-11-12 Thread Martin Canon
Anthony, thanks for your reply.

Resetting the levels didn't work.

These are the first 25 rows of the dataset:

structure(list(id = c(51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
73L, 74L, 75L, 76L), stratum = structure(c(1L, 4L, NA, 4L, 4L,
1L, 6L, NA, 4L, 4L, 1L, 1L, 1L, 6L, 6L, 3L, 3L, 6L, NA, 1L, 1L,
6L, 4L, 3L, 6L), .Label = c(MEst, MAcad, MAdm, FEst,
FAcad, FAdm), class = factor), expfc = c(22.8195266723633,
17.0644626617432, NA, 17.0644626617432, 17.0644626617432, 22.8195266723633,
5.1702127456665, NA, 17.0644626617432, 17.0644626617432, 22.8195266723633,
22.8195266723633, 22.8195266723633, 5.1702127456665, 5.1702127456665,
6.24137926101685, 6.24137926101685, 5.1702127456665, NA, 22.8195266723633,
22.8195266723633, 5.1702127456665, 17.0644626617432, 6.24137926101685,
5.1702127456665), d7 = structure(c(1L, 1L, NA, 1L, 1L, 1L, 1L,
NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, NA, 1L, 1L, 6L, 1L,
6L, 6L), .Label = c(Soltero, Casado, Separado, Divorciado,
Viudo, Union libre), class = factor), ovt = c(NA, 93.3823547363281,
NA, NA, NA, NA, 83.8235321044922, NA, NA, NA, NA, NA, NA, NA,
79.4117660522461, NA, NA, 19.1176471710205, NA, NA, NA, 85.2941207885742,
NA, NA, NA)), .Names = c(id, stratum, expfc, d7, ovt
), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25), class = data.frame)

Regards.

Martin

On Wed, Nov 12, 2014 at 1:39 PM, Anthony Damico ajdam...@gmail.com wrote:
 try resetting your levels?  if that doesn't work, please dput() an example
 data set that we can test with :) thanks!

 sii.design - update( sii.design , d6 = factor( d6 ) )






 On Wed, Nov 12, 2014 at 7:59 AM, Martin Canon martin.ca...@gmail.com
 wrote:

 Hi.


 I'm trying to calculate the weighted mean score of a quality of life
 measure (ovt) in patients with irritable bowel syndrome by their
 marital status (d7).

 This is a summary of the structure of the dataset:

  str(sii.tesis)
 'data.frame':1063 obs. of  75 variables:
  $ id : int  51 52 53 54 55 56 57 58 59 60 ...
  $ stratum: Factor w/ 6 levels MEst,MAcad,..: 1 4 NA 4 4 1 6 NA 4
 4 ...
  $ expfc  : num  22.8 17.1 NA 17.1 17.1 ...
  $ d6 : Factor w/ 3 levels Estudiante,Profesor,..: 1 1 NA
 1 1 1 3 NA 1 1 ...
  $ d7 : Factor w/ 6 levels Soltero,Casado,..: 1 1 NA 1 1 1
 1 NA 1 1 ...
  $ d7c: Factor w/ 2 levels No estable,Estable: 1 1 NA 1 1
 1 1 NA 1 1 ...
  $ s1cm   : Factor w/ 2 levels No,Si: 1 2 NA 1 1 1 2 NA 1 1 ...
  $ ovt: num  NA 93.4 NA NA NA ...

 I declared the sampling design:

  sii.design - svydesign(
   id = ~1,
   strata = ~stratum,
   weights = ~expfc,
   data = subset(sii.tesis, !is.na(stratum)))

 Then I tried to get the result:

  svyby(~ovt, ~d7, sii.design, svymean, na.rm = TRUE, level = 0.95)

 but i get the error:

 Error in tapply(1:NROW(x), list(factor(strata)), function(index) { :
   arguments must have same length


 The length of both variables is the same. If the variable ovt exists,
 there is a d7 match in the data frame.

 I try the same thing using another variable instead - role (d6) -
 and it works.

  svyby(~ovt, ~d6, sii.design, svymean, na.rm = TRUE, level = 0.95)
d6  ovt   se
 Estudiante Estudiante 71.01805 1.370569
 Profesor Profesor 72.30923 6.518378
 Administrativo Administrativo 75.69102 3.715050

 If I use the recategorized d7 variable (d7c,  two levels only) it works
 too:

  svyby(~ovt, ~d7c, sii.design, svymean, na.rm = TRUE, level = 0.95)
   d7c  ovt  se
 No estable No estable 70.92344 1.37460
 Estable   Estable 74.53719 4.16954


 What could be the problem?


 Regards.


 Martin Canon
 Colombia, South America

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


[R] subset drops S3 classes?

2014-11-12 Thread Murat Tasan
Hi all --- I've stumbled upon some pretty annoying behavior, and I'm
curious how others may have gotten around it.
When using subset(...) on a data frame that contains a custom S3
field, the class is dropped in the result:

 MyClass - function(x) structure(x, class = MyClass)

 df - data.frame(x = 1:10, y = 10:1)
 df$x - MyClass(df$x)
 str(df)
 'data.frame':   10 obs. of  2 variables:
  $ x:Class 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10
  $ y: int  10 9 8 7 6 5 4 3 2 1
 str(subset(df, x %% 2 == 0))
 'data.frame':   5 obs. of  2 variables:
  $ x: int  2 4 6 8 10
  $ y: int  9 7 5 3 1

And so, any generic functions hooked to MyClass suddenly don't work on
the subset results, but do work on the original data frame.
I think I could write a custom as.data.frame.MyClass for all such
classes, but this is annoying, indeed (and I don't know for sure if
that's a robust solution)
Wrapping in I(...) doesn't work, either:

 df - data.frame(x = 1:10, y = 10:1)
 df$x - I(MyClass(df$x))
 str(df)
 'data.frame':   10 obs. of  2 variables:
  $ x:Classes 'AsIs', 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10
  $ y: int  10 9 8 7 6 5 4 3 2 1
 str(subset(df, x %% 2 == 0))
  'data.frame':   5 obs. of  2 variables:
  $ x:Class 'AsIs'  int [1:5] 2 4 6 8 10
  $ y: int  9 7 5 3 1

(note that while 'AsIs' is kept, 'MyClass' has been removed in $x)

Cheers!

-Murat

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


Re: [R] subset drops S3 classes?

2014-11-12 Thread Murat Tasan
And as a follow-up, I implemented a barebones as.data.frame.MyClass(...).
It works when dealing with non-subsetted data frames, but fails upon a
subset(...) call:

 as.data.frame.MyClass - function(x, ...) as.data.frame.vector(x, ...)

This works for a single column, e.g.:

 str(data.frame(MyClass(1:10)))
 'data.frame':   10 obs. of  1 variable:
  $ MyClass.1.10.:Class 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10

But not during a subset:

 str(subset(data.frame(x = MyClass(1:10)), x %% 2 == 0))
'data.frame':   5 obs. of  1 variable:
 $ x: int  2 4 6 8 10

-Murat


On Wed, Nov 12, 2014 at 10:02 PM, Murat Tasan mmu...@gmail.com wrote:
 Hi all --- I've stumbled upon some pretty annoying behavior, and I'm
 curious how others may have gotten around it.
 When using subset(...) on a data frame that contains a custom S3
 field, the class is dropped in the result:

 MyClass - function(x) structure(x, class = MyClass)

 df - data.frame(x = 1:10, y = 10:1)
 df$x - MyClass(df$x)
 str(df)
  'data.frame':   10 obs. of  2 variables:
   $ x:Class 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10
   $ y: int  10 9 8 7 6 5 4 3 2 1
 str(subset(df, x %% 2 == 0))
  'data.frame':   5 obs. of  2 variables:
   $ x: int  2 4 6 8 10
   $ y: int  9 7 5 3 1

 And so, any generic functions hooked to MyClass suddenly don't work on
 the subset results, but do work on the original data frame.
 I think I could write a custom as.data.frame.MyClass for all such
 classes, but this is annoying, indeed (and I don't know for sure if
 that's a robust solution)
 Wrapping in I(...) doesn't work, either:

 df - data.frame(x = 1:10, y = 10:1)
 df$x - I(MyClass(df$x))
 str(df)
  'data.frame':   10 obs. of  2 variables:
   $ x:Classes 'AsIs', 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10
   $ y: int  10 9 8 7 6 5 4 3 2 1
 str(subset(df, x %% 2 == 0))
   'data.frame':   5 obs. of  2 variables:
   $ x:Class 'AsIs'  int [1:5] 2 4 6 8 10
   $ y: int  9 7 5 3 1

 (note that while 'AsIs' is kept, 'MyClass' has been removed in $x)

 Cheers!

 -Murat

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


Re: [R] subset drops S3 classes?

2014-11-12 Thread Murat Tasan
... nd nevermind, figured it out (from the final example on the
Extract.data.frame page):

`[.MyClass` - function(x, i, ...) {
NextMethod([)
mostattributes(RV) - attribute(x)
RV
}

cheers,

-m

On Wed, Nov 12, 2014 at 11:02 PM, Murat Tasan mmu...@gmail.com wrote:
 And as a follow-up, I implemented a barebones as.data.frame.MyClass(...).
 It works when dealing with non-subsetted data frames, but fails upon a
 subset(...) call:

 as.data.frame.MyClass - function(x, ...) as.data.frame.vector(x, ...)

 This works for a single column, e.g.:

 str(data.frame(MyClass(1:10)))
  'data.frame':   10 obs. of  1 variable:
   $ MyClass.1.10.:Class 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10

 But not during a subset:

 str(subset(data.frame(x = MyClass(1:10)), x %% 2 == 0))
 'data.frame':   5 obs. of  1 variable:
  $ x: int  2 4 6 8 10

 -Murat


 On Wed, Nov 12, 2014 at 10:02 PM, Murat Tasan mmu...@gmail.com wrote:
 Hi all --- I've stumbled upon some pretty annoying behavior, and I'm
 curious how others may have gotten around it.
 When using subset(...) on a data frame that contains a custom S3
 field, the class is dropped in the result:

 MyClass - function(x) structure(x, class = MyClass)

 df - data.frame(x = 1:10, y = 10:1)
 df$x - MyClass(df$x)
 str(df)
  'data.frame':   10 obs. of  2 variables:
   $ x:Class 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10
   $ y: int  10 9 8 7 6 5 4 3 2 1
 str(subset(df, x %% 2 == 0))
  'data.frame':   5 obs. of  2 variables:
   $ x: int  2 4 6 8 10
   $ y: int  9 7 5 3 1

 And so, any generic functions hooked to MyClass suddenly don't work on
 the subset results, but do work on the original data frame.
 I think I could write a custom as.data.frame.MyClass for all such
 classes, but this is annoying, indeed (and I don't know for sure if
 that's a robust solution)
 Wrapping in I(...) doesn't work, either:

 df - data.frame(x = 1:10, y = 10:1)
 df$x - I(MyClass(df$x))
 str(df)
  'data.frame':   10 obs. of  2 variables:
   $ x:Classes 'AsIs', 'MyClass'  int [1:10] 1 2 3 4 5 6 7 8 9 10
   $ y: int  10 9 8 7 6 5 4 3 2 1
 str(subset(df, x %% 2 == 0))
   'data.frame':   5 obs. of  2 variables:
   $ x:Class 'AsIs'  int [1:5] 2 4 6 8 10
   $ y: int  9 7 5 3 1

 (note that while 'AsIs' is kept, 'MyClass' has been removed in $x)

 Cheers!

 -Murat

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


[R] problem when using gmailr

2014-11-12 Thread PO SU

Dear expeRts,
Hi, when i using gmailr through Rscript  got the following error :
oauth_listener() needs an interactive environment
But when i using the Rstudio it worked.
Does the function gmail_auth(filepath,full) support the Rscript way ??
I need run it in a windows schdual task. TKS 







--

PO SU
mail: desolato...@163.com 
Majored in Statistics from SJTU
__
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.