[R] Merging RData files

2018-01-16 Thread Steven Yen
I ran two separate hours-long projects. Results of each were saved to 
two separate .RData files.
Content of each includes, among others, the following:

    me    se  t p sig
pc21.age    0.640 0.219  2.918 0.004 ***
pc21.agesq  0.000 0.000    NaN   NaN
pc21.inc    0.903 0.103  8.752 0.000 ***
pc21.incsq  0.000 0.000    NaN   NaN
pc21.sei10  0.451 0.145  3.122 0.002 ***
pc21.sblkprot  -4.334 3.387  1.280 0.201
...

Question: How can I combine/consolidate the two .RData files into one? 
Thank you.





[[alternative HTML version deleted]]

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

Re: [R] Merging RData files

2018-01-16 Thread Steven Yen
Hi all,
This is great. Again, here is what I need. I run two separate jobs (a.R 
and b.R) with results (say regression outputs) going to a.RData and 
b.RData. I like to put all results in one place (where I can retrieve 
them in one place, ab.RData). The following codes do it (I am not sure 
if line 2 is needed but I am happy). Thank you all.

load("a.RData")
save.image("ab.RData")
load("b.RData")
save.image("ab.RData")

On 1/16/2018 7:08 PM, PIKAL Petr wrote:
> Huh.
>
> I may by completely wrong but you cannot do such "merging". .RData files are 
> AFAIK places where all objects from given session are stored.
>
> However you could load each .RData file and save/export result (one object).
>
> BTW, what do you mean exactly by "combine/consolidate"?
>
> And finally, post your questions in plain text not html, otherwise they can 
> be mangled.
>
> Cheers
> Petr
>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Steven Yen
>> Sent: Tuesday, January 16, 2018 9:44 AM
>> To: r-help@r-project.org
>> Subject: [R] Merging RData files
>>
>> I ran two separate hours-long projects. Results of each were saved to two
>> separate .RData files.
>> Content of each includes, among others, the following:
>>
>>  mese  t p sig pc21.age0.640 0.219  
>> 2.918 0.004 ***
>> pc21.agesq  0.000 0.000NaN   NaN pc21.inc0.903 0.103  8.752 
>> 0.000
>> *** pc21.incsq  0.000 0.000NaN   NaN
>> pc21.sei10  0.451 0.145  3.122 0.002 *** pc21.sblkprot  -4.334 3.387  
>> 1.280
>> 0.201 ...
>>
>> Question: How can I combine/consolidate the two .RData files into one?
>> Thank you.
>>
>>
>>
>>
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> 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 sen

Re: [R] Merging RData files

2018-01-16 Thread Steven Yen
Understood. In my case, a.RData and b.RData contain identical 
variables/data, plus simulation outputs from separate runs. The codes 
deliver what I need. Good to know the three lines work. Thank you.

On 1/16/2018 8:06 PM, Duncan Murdoch wrote:
> On 16/01/2018 6:33 AM, Steven Yen wrote:
>> Hi all,
>> This is great. Again, here is what I need. I run two separate jobs (a.R
>> and b.R) with results (say regression outputs) going to a.RData and
>> b.RData. I like to put all results in one place (where I can retrieve
>> them in one place, ab.RData). The following codes do it (I am not sure
>> if line 2 is needed but I am happy). Thank you all.
>>
>> load("a.RData")
>> save.image("ab.RData")
>> load("b.RData")
>> save.image("ab.RData")
>
> That's the same as
>
> load("a.RData")
> load("b.RData")
> save.image("ab.RData")
>
> because the second saved image overwrites the first one.  It'll be 
> okay if all the variable names are different in a.RData and b.RData, 
> but will lose values from a.RData if any of them have the same names 
> as objects in b.RData.  See the link I posted earlier to avoid this.
>
> Duncan Murdoch
>
>>
>> On 1/16/2018 7:08 PM, PIKAL Petr wrote:
>>> Huh.
>>>
>>> I may by completely wrong but you cannot do such "merging". .RData 
>>> files are AFAIK places where all objects from given session are stored.
>>>
>>> However you could load each .RData file and save/export result (one 
>>> object).
>>>
>>> BTW, what do you mean exactly by "combine/consolidate"?
>>>
>>> And finally, post your questions in plain text not html, otherwise 
>>> they can be mangled.
>>>
>>> Cheers
>>> Petr
>>>
>>>> -Original Message-
>>>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of 
>>>> Steven Yen
>>>> Sent: Tuesday, January 16, 2018 9:44 AM
>>>> To: r-help@r-project.org
>>>> Subject: [R] Merging RData files
>>>>
>>>> I ran two separate hours-long projects. Results of each were saved 
>>>> to two
>>>> separate .RData files.
>>>> Content of each includes, among others, the following:
>>>>
>>>>   me    se  t p sig pc21.age    
>>>> 0.640 0.219  2.918 0.004 ***
>>>> pc21.agesq  0.000 0.000    NaN   NaN pc21.inc 0.903 0.103  
>>>> 8.752 0.000
>>>> *** pc21.incsq  0.000 0.000    NaN   NaN
>>>> pc21.sei10  0.451 0.145  3.122 0.002 *** pc21.sblkprot -4.334 
>>>> 3.387  1.280
>>>> 0.201 ...
>>>>
>>>> Question: How can I combine/consolidate the two .RData files into one?
>>>> Thank you.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>     [[alternative HTML version deleted]]
>>>>
>>>> __
>>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide 
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> 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

[R] Problem saving .RData file with save.image

2018-01-26 Thread Steven Yen
I am running R-3.0.3 on RStudio 1.1.183. I have recently gotten the following 
error message while saving an .RData file with the save.image command. I have 
not had this problem until recently. Help appreciated.

===
Error in save.image("bope1a.RData") :
   image could not be renamed and is left in bope1a.RDataTmp


[[alternative HTML version deleted]]

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


[R] Documenting R package with Rd file

2018-03-14 Thread Steven Yen
I have trouble documenting an R package. In my .Rd file (sixth line below), I 
have
uhat<-m%*%y

but when the package is built (successfully), the matrix multiplication part 
does not show up in the documentation. The line become (missing %*% y)

uhat<-m

===

\examples{
x<-c(1,2,3,4,5)
y<-c(1,1,2,2,4)
x<-cbind(1,x)
m<-mmat(x)
uhat<-m%*%y
dstat(uhat)
}

  --
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Problem building binary data into library file

2018-04-26 Thread Steven Yen
I build binary data files into a library by placing the .rda files at the 
proper \data sub-folder before building the library with the following 
procedure:
1. File -> Open project
2. Build -> Build binary packages.
This has worked up to 3 .rda files.

Now, I add another .rda file to the folder. I received a very strange, 
seemingly unrelated warning message that says:

Warning: object '.Random.seed' is created by more than one data call

The weird thing about this is, repeating the procedure, I sometime can access 
the data file from the library (i.e., by data(filename)), other time I cannot 
access the data file. The data file is big but not so big (571 KB).

Any clues? Why am I getting that warning message?


==
Below is a log with more details.

==> Rcmd.exe INSTALL --build --preclean yenlib3

* installing to library 'C:/Users/syen01/Documents/R/win-library/3.4'
* installing *source* package 'yenlib3' ...
** R
** data
*** moving datasets to lazyload DB
Warning: object '.Random.seed' is created by more than one data call
** preparing package for lazy loading
** help
*** installing help indices
   converting help for package 'yenlib3'
 finding HTML links ... done
 aidshtml
 all.variables   html
  (truncated)
 ate.boprobitE   html
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* MD5 sums
packaged installation of 'yenlib3' as yenlib3_1.1.0.zip
* DONE (yenlib3)
In R CMD INSTALL
Binary package written to Y:/


[[alternative HTML version deleted]]

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


[R] Package installation

2018-07-09 Thread Steven Yen
I have had trouble installing packages (e.g., car, aod) in some 
computers (such as computers in the student lab) but no problem in my 
own laptop.
Installation typically goes through, but after I got out and back in R 
(and RStudios), the error message says "packages xxx not available". 
That is, earlier installation of the packages did not stay (despite the 
successful installation message).
I went back as far as R3.0.3 and there is no problem.
Does this tell anyone what may be going on? Thanks.

-- 
st...@ntu.edu.tw  (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Matrix multiplication

2017-06-07 Thread Steven Yen
I need to have all elements of a matrix multiplied by a weight before 
being post-multiplied by itself, as shown in the forst block of codes 
below. I can also multiply the matrix by the square root of the weight 
and then take the outer product.

Actually, what I need is this. Denote each row of the matrix by a row 
vector as xi and each element of the weighting vector as wi. Then, I 
need the sum of wi * t(xi) %*% xi over i.

Any suggestion for a compact approach would be appreciated.

set.seed(76543211)
w<-1:10; w
a<-matrix(rpois(20,2),nrow=10); a
b<-a
a<-w*a
t(a)%*%b

set.seed(76543211)
a<-matrix(rpois(20,2),nrow=10); a
a<-sqrt(w)*a; a
t(a)%*%a




On 1/4/2017 5:41 PM, Steven Yen wrote:
> I need help with gls{nlme}.
> Specifically, I am estimating an equation with AR(1) using 
> maximum-likelihood. I am not understanding the correlationoption 
> below. Help appreciated.
>
> ===
> library(nlme)
> eq1<-log(chnimp)~log(chempi)+log(gas)+log(rtwex)+befile6+
>  affile6+afdec6
> reg1<-gls(eq1,data=mydata,correlation=corAR1(),method="ML",verbose=T)
>

[[alternative HTML version deleted]]

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


Re: [R] Matrix multiplication

2017-06-07 Thread Steven Yen
OK Thanks. Your response made me think. Here (the last line) is what I need:

set.seed(76543211)
w<-1:10; w
a<-matrix(rpois(20,2),nrow=10); a
t(w*a)%*%a

On 6/8/2017 12:09 PM, Jeff Newmiller wrote:
> Is this a question? You seem to have three possible calculations, have 
> already implemented two of them (?) and it is unclear (to me) what you think 
> the right answer for any of them is supposed to be.
> -- Sent from my phone. Please excuse my brevity. On June 7, 2017 
> 8:50:55 PM PDT, Steven Yen  wrote:
>> I need to have all elements of a matrix multiplied by a weight before
>> being post-multiplied by itself, as shown in the forst block of codes
>> below. I can also multiply the matrix by the square root of the weight
>> and then take the outer product.
>>
>> Actually, what I need is this. Denote each row of the matrix by a row
>> vector as xi and each element of the weighting vector as wi. Then, I
>> need the sum of wi * t(xi) %*% xi over i.
>>
>> Any suggestion for a compact approach would be appreciated.
>>
>> set.seed(76543211)
>> w<-1:10; w
>> a<-matrix(rpois(20,2),nrow=10); a
>> b<-a
>> a<-w*a
>> t(a)%*%b
>>
>> set.seed(76543211)
>> a<-matrix(rpois(20,2),nrow=10); a
>> a<-sqrt(w)*a; a
>> t(a)%*%a


[[alternative HTML version deleted]]

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


[R] Grep command

2016-05-19 Thread Steven Yen
What is a good way to grep multiple strings (say in a vector)? In the 
following, I grep ants, cats, and fox separately and concatenate them, 
is there a way to grep the trio in one action? Thanks.

all<-c("ants","birds","cats","dogs","elks","fox"); all
[1] "ants"  "birds" "cats"  "dogs"  "elks"  "fox"
some<-c("ants","cats","fox"); some
[1] "ants" "cats" "fox"
j<-c(
   grep(some[1],all,value=F),
   grep(some[2],all,value=F),
   grep(some[3],all,value=F)); j; all[j]
[1] 1 3 6
[1] "ants" "cats" "fox"


[[alternative HTML version deleted]]

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


[R] Element-by-element multiplication

2016-05-22 Thread Steven Yen
Dear R users:

 > # p is a vector if length 10
 > # a is a vector if length 3
 > # I like to create a matrix with
 > # the first  column being p multiplied by a[1]
 > # the second column being p multiplied by a[2]
 > # the third  column being p multiplied by a[3]
 > # The following would do that:
 >
 > a<-c(10,100,1000); a
[1]   10  100 1000
 > p<-matrix(1:10,nrow=10); p
   [,1]
  [1,]1
  [2,]2
  [3,]3
  [4,]4
  [5,]5
  [6,]6
  [7,]7
  [8,]8
  [9,]9
[10,]   10
 > cbind(a[1]*p,a[2]*p,a[3]*p)
   [,1] [,2]  [,3]
  [1,]   10  100  1000
  [2,]   20  200  2000
  [3,]   30  300  3000
  [4,]   40  400  4000
  [5,]   50  500  5000
  [6,]   60  600  6000
  [7,]   70  700  7000
  [8,]   80  800  8000
  [9,]   90  900  9000
[10,]  100 1000 1
 >
 > # Gauss does it easily with an element-by-element
 > # multiplicationa.*p
 > # How can I do this in R?
 >


[[alternative HTML version deleted]]

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


[R] Element-by-element operation (adding)

2016-05-22 Thread Steven Yen
Hi all, need help below. Thank you.

 > # Matrix v is 5 x 3
 > # Vector b is of length 3
 > # I like to add b[1] to all element in v[,1]
 > # I like to add b[2] to all element in v[,2]
 > # I like to add b[3] to all element in v[,3]
 > # as follows
 > v<-matrix(0,nrow=5,ncol=3); v
  [,1] [,2] [,3]
[1,]000
[2,]000
[3,]000
[4,]000
[5,]000
 > b<-c(0.1,0.2,0.3)
 > cbind(
+ (b[1]+v[,1]),
+ (b[2]+v[,2]),
+ (b[3]+v[,3]))
  [,1] [,2] [,3]
[1,]  0.1  0.2  0.3
[2,]  0.1  0.2  0.3
[3,]  0.1  0.2  0.3
[4,]  0.1  0.2  0.3
[5,]  0.1  0.2  0.3
 > # I am obviously not using sapply correctly:
 > as.data.frame(sapply(b,"+",v))
 V1  V2  V3
1  0.1 0.2 0.3
2  0.1 0.2 0.3
3  0.1 0.2 0.3
4  0.1 0.2 0.3
5  0.1 0.2 0.3
6  0.1 0.2 0.3
7  0.1 0.2 0.3
8  0.1 0.2 0.3
9  0.1 0.2 0.3
10 0.1 0.2 0.3
11 0.1 0.2 0.3
12 0.1 0.2 0.3
13 0.1 0.2 0.3
14 0.1 0.2 0.3
15 0.1 0.2 0.3


[[alternative HTML version deleted]]

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


[R] read.fortran format

2016-05-27 Thread Steven Yen
Dear fellow R users:
I am reading a data (ascii) file with fortran fixed format, containing 
multiple records. R does not recognize fortran's record break (a slash). 
I tried to do the following but it does not work. Help appreciated.

  60 FORMAT(1X,F6.0,5F8.6/1X,5F8.4,F10.6/1X,2F6.0,3E15.9,F8.0,F5.2,F5.3
  *  /1X,F7.0,2E15.9,F9.4,F5.3)

mydata<-read.fortran("G:/Journals/Disk1/12_restat_95/estimate/GROUPD.DAT",
 c("1X","F6.0","5F8.6"/"1X","5F8.4","F10.6"
  /"1X","2F6.0","3E15.9","F8.0","F5.2","F5.3"
  /"1X","F7.0","2E15.9","F9.4","F5.3"),
col.names=c("year","w1","w2","w3","w4","w5","w6","v1","v2","v3",
"v4","v5","v6","z","chyes","chno","ec","vc","cvc",
"pop","ahs","fah","tnh","eq","vq","ups","zm1 "))



[[alternative HTML version deleted]]

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


Re: [R] read.fortran format

2016-05-27 Thread Steven Yen
Thanks John. That helped, but I got a mixed of good thing and bad thing. 
Good is R does not like the scientific number format "3E15.9" but I was 
able to read with alphanumerical format "3A15" (and convert to 
numerical). Bad is R does not like the numbers .1234, .2345 without the 
zeros before the decimal points. My data look like:

   1950. .614350 .026834 .087227 .006821 .180001 .084766

The first variable was read correctly, followed by six 0's.

As the instructions say, this fortran format is approximation at best 
and in this case, a poort approximation.

On 5/27/2016 2:21 PM, John McKown wrote:
> On Fri, May 27, 2016 at 12:56 PM, Steven Yen  <mailto:sye...@gmail.com>>wrote:
>
> Dear fellow R users:
> I am reading a data (ascii) file with fortran fixed format, containing
> multiple records. R does not recognize fortran's record break (a
> slash).
> I tried to do the following but it does not work. Help appreciated.
>
>   60
> FORMAT(1X,F6.0,5F8.6/1X,5F8.4,F10.6/1X,2F6.0,3E15.9,F8.0,F5.2,F5.3
>   *  /1X,F7.0,2E15.9,F9.4,F5.3)
>
> mydata<-read.fortran("G:/Journals/Disk1/12_restat_95/estimate/GROUPD.DAT",
> ​​
>  c("1X","F6.0","5F8.6"/"1X","5F8.4","F10.6"
>   /"1X","2F6.0","3E15.9","F8.0","F5.2","F5.3"
>   /"1X","F7.0","2E15.9","F9.4","F5.3"),
> ​​
> col.names=c("year","w1","w2","w3","w4","w5","w6","v1","v2","v3",
> "v4","v5","v6","z","chyes","chno","ec","vc","cvc",
> "pop","ahs","fah","tnh","eq","vq","ups","zm1 "))
>
>
> ​Did you see this from ?read.fortran
>
> 
>
>  For a single-line record, ‘format’ should be a character vector.
>For a multiline record it should be a list with a character vector
>for each line.
>
> ​
>
> ​I think (not sure) you need:
>
> mydata<-read.frotran("G:/Journals/Disk1/12_restat_95/estimate/GROUPD.DAT",
> list(c("1X","F6.0","5F8.6"),c("1X","5F8.4","F10.6"),c("1X","2F6.0","3E15.9","F8.0","F5.2","F5.3"),c("1X","F7.0","2E15.9","F9.4","F5.3")).
> ​
> col.names=c("year","w1","w2","w3","w4","w5","w6","v1","v2","v3",
> "v4","v5","v6","z","chyes","chno","ec","vc","cvc",
> "pop","ahs","fah","tnh","eq","vq","ups","zm1 "))
>
>
>
>
>
> -- 
> The unfacts, did we have them, are too imprecisely few to warrant our 
> certitude.
>
> Maranatha! <><
> John McKown


[[alternative HTML version deleted]]

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

Re: [R] read.fortran format

2016-05-27 Thread Steven Yen
That's great, John. Your mother told you when you were born? How am I 
supposed to know? Thank you both.
The following format statement did it!! I just change F5.3 to F5, 5F8.4 
to 5F8. I also change 2E15.9 to 2A9, and then use the following 
as.numeric to convert the alphanumerical to numerical. Thank you!!!

mydata<-read.fortran("GROUPC.DAT",
 list(c("1X","F6","5F8"),
  c("1X","5F8","F10"),
  c("1X","2F6","3A15","F8","F5","F5"),
  c("1X","F7","2A15","F9","F5")),
col.names=c("year","w1","w2","w3","w4","w5","v1","v2","v3",
"v4","v5","m","chyes","chno","ec","vc","cvc",
"pop","ahs","fah","tnh","eq","vq","ups","zm1"))
mydata$ec <-as.numeric(mydata$ec)

On 5/27/2016 6:33 PM, William Dunlap wrote:
> It has been a while since I used Fortran formatted input, but the 
> following,
> without dots in the format, works:
>
> > txt <- "1950. .614350 .026834 .087227 .006821 .180001 4.56E-2"
> > print(read.fortran(textConnection(txt), c("f5", "6f8")), digits=10)
> V1  V2   V3   V4   V5   V6 V7
> 1 1950 0.61435 0.026834 0.087227 0.006821 0.180001 0.0456
>
>
> If I recall correctly, a dot in the format pushes the decimal point:
>
> > print(read.fortran(textConnection(txt), c("f5", "6f8.3")),
> digits=10)
> V1 V2 V3 V4V5  V6   V7
> 1 1950 0.00061435 2.6834e-05 8.7227e-05 6.821e-06 0.000180001 4.56e-05
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com <http://tibco.com>
>
> On Fri, May 27, 2016 at 3:15 PM, Steven Yen  <mailto:sye...@gmail.com>> wrote:
>
> Thanks John. That helped, but I got a mixed of good thing and bad
> thing.
> Good is R does not like the scientific number format "3E15.9" but
> I was
> able to read with alphanumerical format "3A15" (and convert to
> numerical). Bad is R does not like the numbers .1234, .2345
> without the
> zeros before the decimal points. My data look like:
>
>1950. .614350 .026834 .087227 .006821 .180001 .084766
>
> The first variable was read correctly, followed by six 0's.
>
> As the instructions say, this fortran format is approximation at best
> and in this case, a poort approximation.
>
> On 5/27/2016 2:21 PM, John McKown wrote:
> > On Fri, May 27, 2016 at 12:56 PM, Steven Yen  <mailto:sye...@gmail.com>
> > <mailto:sye...@gmail.com <mailto:sye...@gmail.com>>>wrote:
> >
> > Dear fellow R users:
> > I am reading a data (ascii) file with fortran fixed format,
> containing
> > multiple records. R does not recognize fortran's record break (a
> > slash).
> > I tried to do the following but it does not work. Help
> appreciated.
> >
> >   60
> >  FORMAT(1X,F6.0,5F8.6/1X,5F8.4,F10.6/1X,2F6.0,3E15.9,F8.0,F5.2,F5.3
> >   *  /1X,F7.0,2E15.9,F9.4,F5.3)
> >
> >
>  
> mydata<-read.fortran("G:/Journals/Disk1/12_restat_95/estimate/GROUPD.DAT",
> > ​​
> >  c("1X","F6.0","5F8.6"/"1X","5F8.4","F10.6"
> >  /"1X","2F6.0","3E15.9","F8.0","F5.2","F5.3"
> >   /"1X","F7.0","2E15.9","F9.4","F5.3"),
> > ​​
> >  col.names=c("year","w1","w2","w3","w4","w5","w6","v1","v2","v3",
> > "v4","v5","v6","z","chyes","chno","ec","vc","cvc",
> > "pop","ahs","fah","tnh","eq","vq","ups","zm1 "))
> >
> >
> > ​Did you see this from ?read.fortran
> >
> > 
> >
> >  For a single-line record, ‘format’ should be a character vector.
> >For a multiline record it should be a list with a character

[R] Reading csv file with missing value

2016-06-24 Thread Steven Yen
I read a csv file (with read.csv) containing missing values (as shown 
below). Is there a convenient way to set these NA into zeros?
Better yet, is there an option to assign zeros to these blank cells in 
reading the csv file? Thank you!

NA  -1  NA  NA  NA   1  NA
NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA  NA
NA  -1  NA  NA  NA  NA  NA



[[alternative HTML version deleted]]

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


[R] t-test for regression estimate

2016-06-28 Thread Steven Yen
test option for linearHypothesis in library(car) include "Chisq" and 
"F". I prefer a simple t-test so that I can retrieve the standard error. 
Any options other than linearHypothesis to test the linear hypothesis 
(with 1 restriction/degree of freedom)?

 > summary(ols1)

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.200130.09199  -2.176   0.0298 *
age  0.040540.01721   2.355   0.0187 *
suburb   0.019110.05838   0.327   0.7435
smcity  -0.299690.19175  -1.563   0.1184
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 > linearHypothesis(ols1,"suburb")
Linear hypothesis test

Hypothesis:
suburb = 0

Model 1: restricted model
Model 2: polideo ~ age + suburb + smcity

   Res.DfRSS Df Sum of Sq  F Pr(>F)
1888 650.10
2887 650.02  1  0.078534 0.1072 0.7435


[[alternative HTML version deleted]]

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

Re: [R] t-test for regression estimate

2016-06-28 Thread Steven Yen
Thanks John. Reason is I am doing linear transformations of many 
coefficients (e.g., bi / scalar). Of course I can uncover the 
t-statistic from the F statistic and then the standard error. Simply 
scaling the estimated coefficients I can also transform the standard 
errors. I have since found deltaMethod from library "car" useful. Its 
just that, if linearHypothesis had provide the standard errors and 
t-statistics then the operation would have been easier, with a one-line 
command for each coefficient. Thank you again.

On 6/28/2016 6:28 PM, Fox, John wrote:
> Dear Steven,
>
> The reason that linearHypothesis() computes a Wald F or chisquare test rather 
> than a t or z test is that the (numerator) df for the linear hypothesis need 
> not be 1.
>
> In your case (as has been pointed out) you can get the coefficient standard 
> error directly from the model summary.
>
> More generally, with some work, you could solve for the the SE for a 1 df 
> linear hypothesis in terms of the value of the linear function of 
> coefficients and the F or chisquare. That said, I'm not sure why you want to 
> do this.
>
> I hope this helps,
>   John
>
> -
> John Fox, Professor
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> Web: socserv.mcmaster.ca/jfox
>
>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Steven Yen
>> Sent: June 28, 2016 9:27 AM
>> To: R-help 
>> Subject: [R] t-test for regression estimate
>>
>> test option for linearHypothesis in library(car) include "Chisq" and "F". I 
>> prefer
>> a simple t-test so that I can retrieve the standard error.
>> Any options other than linearHypothesis to test the linear hypothesis (with 1
>> restriction/degree of freedom)?
>>
>>   > summary(ols1)
>>
>> Coefficients:
>>   Estimate Std. Error t value Pr(>|t|)
>> (Intercept) -0.200130.09199  -2.176   0.0298 *
>> age  0.040540.01721   2.355   0.0187 *
>> suburb   0.019110.05838   0.327   0.7435
>> smcity  -0.299690.19175  -1.563   0.1184
>> ---
>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>
>>   > linearHypothesis(ols1,"suburb")
>> Linear hypothesis test
>>
>> Hypothesis:
>> suburb = 0
>>
>> Model 1: restricted model
>> Model 2: polideo ~ age + suburb + smcity
>>
>> Res.DfRSS Df Sum of Sq  F Pr(>F)
>> 1888 650.10
>> 2887 650.02  1  0.078534 0.1072 0.7435
>>
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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

Re: [R] t-test for regression estimate

2016-06-29 Thread Steven Yen
Thanks John. Yes, by using verbose=T, I get the value of the hypothesis. 
But tell me again, how would I get the variance (standard error)?

On 6/29/2016 11:56 AM, Fox, John wrote:
> Dear Steven,
>
> OK -- that makes sense, and there was also a previous request for 
> linearHypothesis() to return the value of the hypothesis and its covariance 
> matrix. In your case, where there's only 1 numerator df, that would be the 
> value and estimated sampling variance of the hypothesis.
>
> I've now implemented that, using (at least provisionally) attributes in the 
> development version of the car package on R-Forge, which you should be able 
> to install via install.packages("car", repos="http://R-Forge.R-project.org";). 
> Then see ?linearHypothesis for more information.
>
> Best,
>   John
>
>> -Original Message-
>> From: Steven Yen [mailto:sye...@gmail.com]
>> Sent: June 28, 2016 3:44 PM
>> To: Fox, John 
>> Cc: R-help 
>> Subject: Re: [R] t-test for regression estimate
>>
>> Thanks John. Reason is I am doing linear transformations of many coefficients
>> (e.g., bi / scalar). Of course I can uncover the t-statistic from the F 
>> statistic and
>> then the standard error. Simply scaling the estimated coefficients I can also
>> transform the standard errors. I have since found deltaMethod from library
>> "car" useful. Its just that, if linearHypothesis had provide the standard 
>> errors
>> and t-statistics then the operation would have been easier, with a one-line
>> command for each coefficient. Thank you again.
>>
>>
>> On 6/28/2016 6:28 PM, Fox, John wrote:
>>
>>
>>  Dear Steven,
>>
>>  The reason that linearHypothesis() computes a Wald F or chisquare
>> test rather than a t or z test is that the (numerator) df for the linear 
>> hypothesis
>> need not be 1.
>>
>>  In your case (as has been pointed out) you can get the coefficient
>> standard error directly from the model summary.
>>
>>  More generally, with some work, you could solve for the the SE for a 1
>> df linear hypothesis in terms of the value of the linear function of 
>> coefficients
>> and the F or chisquare. That said, I'm not sure why you want to do this.
>>
>>  I hope this helps,
>>   John
>>
>>  -
>>  John Fox, Professor
>>  McMaster University
>>  Hamilton, Ontario
>>  Canada L8S 4M4
>>  Web: socserv.mcmaster.ca/jfox
>>
>>
>>
>>  -Original Message-
>>  From: R-help [mailto:r-help-boun...@r-project.org] On Behalf
>> Of Steven Yen
>>  Sent: June 28, 2016 9:27 AM
>>  To: R-help  <mailto:r-help@r-
>> project.org>
>>  Subject: [R] t-test for regression estimate
>>
>>  test option for linearHypothesis in library(car) include "Chisq"
>> and "F". I prefer
>>  a simple t-test so that I can retrieve the standard error.
>>  Any options other than linearHypothesis to test the linear
>> hypothesis (with 1
>>  restriction/degree of freedom)?
>>
>>   > summary(ols1)
>>
>>  Coefficients:
>>   Estimate Std. Error t value Pr(>|t|)
>>  (Intercept) -0.200130.09199  -2.176   0.0298 *
>>  age  0.040540.01721   2.355   0.0187 *
>>  suburb   0.019110.05838   0.327   0.7435
>>  smcity  -0.299690.19175  -1.563   0.1184
>>  ---
>>  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>
>>   > linearHypothesis(ols1,"suburb")
>>  Linear hypothesis test
>>
>>  Hypothesis:
>>  suburb = 0
>>
>>  Model 1: restricted model
>>  Model 2: polideo ~ age + suburb + smcity
>>
>> Res.DfRSS Df Sum of Sq  F Pr(>F)
>>  1888 650.10
>>  2887 650.02  1  0.078534 0.1072 0.7435
>>
>>
>>  [[alternative HTML version deleted]]
>>
>>  __
>>  R-help@r-project.org <mailto:R-help@r-project.org>  mailing
>> list -- To UNSUBSCRIBE and more, see
>>  https://stat.ethz.ch/mailman/listinfo/r-help
>>  PLEASE do read the posting guide http://www.R-
>> project.org/posting-
>>  guide.html
>>  and provide commented, minimal, self-contained, reproducible
>> code.
>>


[[alternative HTML version deleted]]

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

Re: [R] t-test for regression estimate

2016-06-29 Thread Steven Yen
Also,
Is there a way to get the second command (hypothesis defined with 
externally scalars) below to work? Thanks.

linearHypothesis(U,"0.5*eq1_DQ+0.3*eq2_DQ",verbose=T)
w1<-0.5; w2<-0.3
linearHypothesis(U,"w1*eq1_DQ+w2*eq2_DQ",verbose=T) # does not work

On 6/29/2016 12:38 PM, Steven Yen wrote:
> Thanks John. Yes, by using verbose=T, I get the value of the 
> hypothesis. But tell me again, how would I get the variance (standard 
> error)?
>
> On 6/29/2016 11:56 AM, Fox, John wrote:
>> Dear Steven,
>>
>> OK -- that makes sense, and there was also a previous request for 
>> linearHypothesis() to return the value of the hypothesis and its covariance 
>> matrix. In your case, where there's only 1 numerator df, that would be the 
>> value and estimated sampling variance of the hypothesis.
>>
>> I've now implemented that, using (at least provisionally) attributes in the 
>> development version of the car package on R-Forge, which you should be able 
>> to install via install.packages("car", 
>> repos="http://R-Forge.R-project.org";). Then see ?linearHypothesis for more 
>> information.
>>
>> Best,
>>   John
>>
>>> -Original Message-
>>> From: Steven Yen [mailto:sye...@gmail.com]
>>> Sent: June 28, 2016 3:44 PM
>>> To: Fox, John
>>> Cc: R-help
>>> Subject: Re: [R] t-test for regression estimate
>>>
>>> Thanks John. Reason is I am doing linear transformations of many 
>>> coefficients
>>> (e.g., bi / scalar). Of course I can uncover the t-statistic from the F 
>>> statistic and
>>> then the standard error. Simply scaling the estimated coefficients I can 
>>> also
>>> transform the standard errors. I have since found deltaMethod from library
>>> "car" useful. Its just that, if linearHypothesis had provide the standard 
>>> errors
>>> and t-statistics then the operation would have been easier, with a one-line
>>> command for each coefficient. Thank you again.
>>>
>>>
>>> On 6/28/2016 6:28 PM, Fox, John wrote:
>>>
>>>
>>> Dear Steven,
>>>
>>> The reason that linearHypothesis() computes a Wald F or chisquare
>>> test rather than a t or z test is that the (numerator) df for the linear 
>>> hypothesis
>>> need not be 1.
>>>
>>> In your case (as has been pointed out) you can get the coefficient
>>> standard error directly from the model summary.
>>>
>>> More generally, with some work, you could solve for the the SE for a 1
>>> df linear hypothesis in terms of the value of the linear function of 
>>> coefficients
>>> and the F or chisquare. That said, I'm not sure why you want to do this.
>>>
>>> I hope this helps,
>>>  John
>>>
>>> -
>>> John Fox, Professor
>>> McMaster University
>>> Hamilton, Ontario
>>> Canada L8S 4M4
>>> Web: socserv.mcmaster.ca/jfox
>>>
>>>
>>>
>>> -Original Message-
>>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf
>>> Of Steven Yen
>>> Sent: June 28, 2016 9:27 AM
>>> To: R-help  <mailto:r-help@r- project.org>
>>> Subject: [R] t-test for regression estimate
>>>
>>> test option for linearHypothesis in library(car) include "Chisq"
>>> and "F". I prefer
>>> a simple t-test so that I can retrieve the standard error.
>>> Any options other than linearHypothesis to test the linear
>>> hypothesis (with 1
>>> restriction/degree of freedom)?
>>>
>>>  > summary(ols1)
>>>
>>> Coefficients:
>>>  Estimate Std. Error t value Pr(>|t|)
>>> (Intercept) -0.200130.09199  -2.176   0.0298 *
>>> age  0.040540.01721   2.355   0.0187 *
>>> suburb   0.019110.05838   0.327   0.7435
>>> smcity  -0.299690.19175  -1.563   0.1184
>>> ---
>>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>>
>>>  > linearHypothesis(ols1,"suburb")
>>> Linear hypothesis test
>>>
>>> Hypothesis:
>>>

[R] Column product

2016-07-01 Thread Steven Yen
A is a 5 x 3 matrix and a is a 3-vector. I like to exponentiate A[,1] to 
a[1], A[,2] to a[2], and A[,3] to a[3], and obtain the product of the 
resulting columns, as in line 3.

I also accomplish this with lines 4 and 5. I like to have rowProducts(B) 
but there is not so I came up with something ugly in line 
5--exponentiating the row sums of log. Is there a more elegant way than 
than line 5 or, better yet, lines 4 and 5 together? Thanks.

A<-matrix(1:15,nrow=5,byrow=F); A
a<-c(1,2,3)
(A[,1]^a[1])*(A[,2]^a[2])*(A[,3]^a[3])
B<-t(t(A)^a); B
exp(rowSums(log(B)))

Result:

 > A<-matrix(1:15,nrow=5,byrow=F); A
  [,1] [,2] [,3]
[1,]16   11
[2,]27   12
[3,]38   13
[4,]49   14
[5,]5   10   15
 > a<-c(1,2,3)
 > (A[,1]^a[1])*(A[,2]^a[2])*(A[,3]^a[3])
[1]   47916  169344  421824  889056 1687500
 > B<-t(t(A)^a); B
  [,1] [,2] [,3]
[1,]1   36 1331
[2,]2   49 1728
[3,]3   64 2197
[4,]4   81 2744
[5,]5  100 3375
 > exp(rowSums(log(B)))
[1]   47916  169344  421824  889056 1687500
 >


[[alternative HTML version deleted]]

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


[R] Build command in library(devtools)

2016-07-19 Thread Steven Yen
I recently updated my R and RStudio to the latest version and now the 
binary option in the "build" command in devtools stops working.

I went around and used the binary=F option which worked by I get the 
.tar.gz file instead of the .zip file which I prefer.

Does anyone understand the following error message:

status 127
running 'zip' failed

===
setwd("A:/R/yenlib/"); library(devtools)
#build("yenlib",binary=T) # Thisfailed with an error message
build("yenlib",binary=F) # This works

 > build("yenlib",binary=T)
"C:/PROGRA~1/R/R-33~1.1/bin/x64/R" --no-site-file  \
   --no-environ --no-save --no-restore --quiet CMD INSTALL \
   "A:\R\yenlib\yenlib" --build

* installing to library 
'C:/Users/syen01/AppData/Local/Temp/Rtmp8A7KEw/temp_libpath4074149a528e'
* installing *source* package 'yenlib' ...
** R
** data
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* MD5 sums
Warning: running command '"zip" -r9Xq "A:/R/yenlib/yenlib_16.3.zip" 
yenlib' had status 127
running 'zip' failed
* DONE (yenlib)
[1] "A:/R/yenlib/yenlib_16.3.zip"
 >


[[alternative HTML version deleted]]

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


Re: [R] Build command in library(devtools)

2016-07-19 Thread Steven Yen
Thanks. I found the reason was Rtools does not run under the new version 
of R. I had to go back to as early as R 3.0.2 (September 2013) to make 
Rtools work.
Any idea for a go-around? Thanks.

On 7/19/2016 4:38 PM, John McKown wrote:
> On Tue, Jul 19, 2016 at 3:15 PM, Steven Yen  <mailto:sye...@gmail.com>>wrote:
>
> I recently updated my R and RStudio to the latest version and now the
> binary option in the "build" command in devtools stops working.
>
> I went around and used the binary=F option which worked by I get the
> .tar.gz file instead of the .zip file which I prefer.
>
> Does anyone understand the following error message:
>
> status 127
> running 'zip' failed
>
>
> ​I'm not totally sure, but I think that means that R cannot find the 
> "zip" program in order to run it. ​
>
>
> ===
> setwd("A:/R/yenlib/"); library(devtools)
> #build("yenlib",binary=T) # Thisfailed with an error message
> build("yenlib",binary=F) # This works
>
>  > build("yenlib",binary=T)
> "C:/PROGRA~1/R/R-33~1.1/bin/x64/R" --no-site-file  \
>--no-environ --no-save --no-restore --quiet CMD INSTALL \
>"A:\R\yenlib\yenlib" --build
>
> * installing to library
> 'C:/Users/syen01/AppData/Local/Temp/Rtmp8A7KEw/temp_libpath4074149a528e'
> * installing *source* package 'yenlib' ...
> ** R
> ** data
> ** preparing package for lazy loading
> ** help
> *** installing help indices
> ** building package indices
> ** testing if installed package can be loaded
> *** arch - i386
> *** arch - x64
> * MD5 sums
> Warning: running command '"zip" -r9Xq "A:/R/yenlib/yenlib_16.3.zip"
> yenlib' had status 127
> running 'zip' failed
> * DONE (yenlib)
> [1] "A:/R/yenlib/yenlib_16.3.zip"
>  >
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> -- 
> "Worry was nothing more than paying interest on a loan that a man may 
> never borrow"
>
> From: "Quest for the White Wind" by Alan Black
>
> Maranatha! <><
> John McKown


[[alternative HTML version deleted]]

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

Re: [R] Build command in library(devtools)

2016-07-20 Thread Steven Yen
Here is what I found. I had to go back to as early as R 3.0.3 (March, 
2014) along with Rtools30.exe that works with that version of R, in 
order for devtools to work right. With other/later version of R, I end 
up building a package with
library(devtools); build("yenlib",binary=F)
with no error message but the package does not run correctly; or with
library(devtools); build("yenlib",binary=T)
which deliver an error that says zip command failed (bevtools calls 
Rtools when binary=T).

Updated versions are good, but what's the use if they do not work for a 
situation like this.

Any help/insight would be appreciated.

On 7/20/2016 10:08 AM, Steven Yen wrote:
> On 7/19/2016 4:38 PM, John McKown wrote:
>> On Tue, Jul 19, 2016 at 3:15 PM, Steven Yen > <mailto:sye...@gmail.com>>wrote:
>>
>> I recently updated my R and RStudio to the latest version and
>> now the
>> binary option in the "build" command in devtools stops working.
>>
>> I went around and used the binary=F option which worked by I get
>> the
>> .tar.gz file instead of the .zip file which I prefer.
>>
>> Does anyone understand the following error message:
>>
>> status 127
>> running 'zip' failed
>>
>>
>> ​I'm not totally sure, but I think that means that R cannot find the
>> "zip" program in order to run it. ​


[[alternative HTML version deleted]]

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

[R] Read text file

2015-06-17 Thread Steven Yen
How do I read a block of space-delimited numbers into a column vector 
using the read.table command? Thank you.


--
Steven Yen

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


[R] Call to a function

2015-06-23 Thread Steven Yen

Dear Members
I have a data frame as generated below. I like to be able to call a
function both with a vector and a vector (mydata$v1) in that data frame
(v1). The first call works, but the second does not. Can someone help me
with the second call? Thanks!!

---
mydata<-data.frame(matrix(1:20,ncol=2))
colnames(mydata) <-c("v1","v2")
summary(mydata)

aaa<-function(data,w=w){
  if(is.vector(w)){
out<-mean(w)
  } else {
out<-mean(data[wt])
  }
return(out)
}

aaa(mydata,mydata$v1)
aaa(mydata,"v1")  # want this call to work

---
Printout with error message


mydata<-data.frame(matrix(1:20,ncol=2))
colnames(mydata) <-c("v1","v2")
summary(mydata)

   v1  v2
 Min.   : 1.00   Min.   :11.00
 1st Qu.: 3.25   1st Qu.:13.25
 Median : 5.50   Median :15.50
 Mean   : 5.50   Mean   :15.50
 3rd Qu.: 7.75   3rd Qu.:17.75
 Max.   :10.00   Max.   :20.00


aaa<-function(data,w=w){

+   if(is.vector(w)){
+ out<-mean(w)
+   } else {
+ out<-mean(data[wt])
+   }
+ return(out)
+ }

aaa(mydata,mydata$v1)

[1] 5.5

aaa(mydata,"v1")

[1] NA
Warning message:
In mean.default(w) : argument is not numeric or logical: returning NA




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


Re: [R] Call to a function

2015-06-23 Thread Steven Yen

Thanks! From this I learn the much needed class statement

if (class(wt)=="character") wt <- x[, wt]

which serves my need in a bigger project.

Steven Yen

On 6/23/2015 6:20 PM, boB Rudis wrote:

You can do something like:

aaa <- function(data, w=w) {
   if (class(w) %in% c("integer", "numeric", "double")) {
 out <- mean(w)
   } else {
 out <- mean(data[, w])
   }
   return(out)
}

(there are some typos in your function you may want to double check, too)

On Tue, Jun 23, 2015 at 5:39 PM, Steven Yen  wrote:

mydata<-data.frame(matrix(1:20,ncol=2))
colnames(mydata) <-c("v1","v2")
summary(mydata)

aaa<-function(data,w=w){
   if(is.vector(w)){
 out<-mean(w)
   } else {
 out<-mean(data[wt])
   }
return(out)
}

aaa(mydata,mydata$v1)
aaa(mydata,"v1")  # want this call to work




--
Steven Yen
My e-mail alert:
https://youtu.be/9UwEAruhyhY?list=PLpwR3gb9OGHP1BzgVuO9iIDdogVOijCtO

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


Re: [R] 'class(.) == **' [was 'Call to a function']

2015-06-25 Thread Steven Yen
Thanks to all for the help. I have learned much about "inherit" and 
"class". I like to know about one additional option, and that is to use 
a calling parameter without the quotation marks, similar to the linear 
regression syntax:


lm(data=mydata,weights=wt)

Below is a simple set of codes to calculate weighted means with 
generated data in data frame "mydata". As annotated below, I like the 
following call to work (without the quotations):


wmean(mydata,wt=weight)

Thank you!


mydata<-matrix(1:20,ncol=2)
mydata<-cbind(mydata,runif(10,0,1))
colnames(mydata)<-c("y","x","weight")
mydata<-as.data.frame(mydata)

wmean <- function(data,wt){
  if (inherits(wt,what="character")) wt<-data[,wt]
  wt<-wt/mean(wt)
  Mean<-NULL
  for (i in 1:ncol(data)){
Mean[i] <- sum(data[,i]*wt)/sum(wt)
  }
  list("Mean: ",Mean)
}
wmean(mydata,wt="weight") # This works
wmean(mydata,wt=weight)   # <= Like this to work
reg<-lm(data=mydata,weights=weight) # ? lm

On 6/24/2015 3:20 AM, Martin Maechler wrote:

Steve Taylor 
 on Wed, 24 Jun 2015 00:56:26 + writes:


 > Note that objects can have more than one class, in which case your == 
and %in% might not work as expected.

 > Better to use inherits().

 > cheers,
 > Steve

Yes indeed, as Steve said, really do!

The use of   (class(.) == "")   it is error prone and
against the philosophy of classes (S3 or S4 or ..) in R :

Classes can "extend" other classes or "inherit" from them;
S3 examples in "base R"  are
  - glm() objects which are "glm"
but also inherit from "lm"
  - multivariate time-series are "mts" and "ts"
  - The time-date objects  POSIXt , POSIXct, POSIXlt

==> do work  with  inherits(, , )


We've seen this use of  

  class(.) == ".."(or '!=" or  %in% ...)

in too many places;  though it may work fine in your test cases,
it is wrong to be used in generality e.g. inside a function you
provide for more general use,
and is best  replaced with the use of inherits() / is()
everywhere  "out of principle".

Martin Maechler
ETH Zurich



--
Steven Yen
My e-mail alert:
https://youtu.be/9UwEAruhyhY?list=PLpwR3gb9OGHP1BzgVuO9iIDdogVOijCtO

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


Re: [R] 'class(.) == **' [was 'Call to a function']

2015-06-25 Thread Steven Yen

Thanks Davis. But actually, the line is legitimate:

   if (inherits(wt,what="character")) wt<-data[,wt]

because, coming down with wt being characters, the part wt<-data[,wt] 
then picks up variables data$wt. The call


   wmean(mydata,wt="weight")

actually goes OK. I was hoping to figure out a way to fix the wmean 
routine some how so that I can call with


   wmean(mydata,wt=weight)

Good to know there is a better way to initialize the vector Mean and and 
a better list command. Thank you!


On 6/26/2015 2:39 AM, David Winsemius wrote:


On Jun 25, 2015, at 7:48 PM, Steven Yen wrote:


Thanks to all for the help. I have learned much about "inherit" and "class". I 
like to know about one additional option, and that is to use a calling parameter without the 
quotation marks, similar to the linear regression syntax:

lm(data=mydata,weights=wt)

Below is a simple set of codes to calculate weighted means with generated data in data 
frame "mydata". As annotated below, I like the following call to work (without 
the quotations):

wmean(mydata,wt=weight)


Let's start with the call. If you are to execute this,  then names `mydata` and 
`weight` each must have a value.



Thank you!


mydata<-matrix(1:20,ncol=2)


OK. There is a value having been assigned to `mydata`


mydata<-cbind(mydata,runif(10,0,1))


And now augmented.


colnames(mydata)<-c("y","x","weight")


And a names attribute added for its columns.


mydata<-as.data.frame(mydata)

wmean <- function(data,wt){
  if (inherits(wt,what="character")) wt<-data[,wt]
  wt<-wt/mean(wt)


Here's the problem. If `wt` was of mode "character", then you cannot divide it 
by a number, since the RHS will be evaluated first. You really should read the error 
messages!

Perhaps you meant:

wt <-  data[, wt]/mean(data[ , wt]

But if you did, then it's rather confusing (but possible) to assign the value 
to the same name as the column of the matrix.



  Mean<-NULL


Why do that? If you remove it from the workspace then you cannot assign a value 
using indexed assignment as you apparently intend to do. Should have been

Mean <- numeric( ncol(data) )



  for (i in 1:ncol(data)){
Mean[i] <- sum(data[,i]*wt)/sum(wt)


There is a bit of a confusion here. `wt` started out as a character value. I 
guess you could do this.


  }
  list("Mean: ",Mean)


Wrong syntax for lists. Suspect you want

list(Mean=Mean)



}
wmean(mydata,wt="weight") # This works
wmean(mydata,wt=weight)   # <= Like this to work


So were you planning to execute this first?

weight="weight" #?



--
Steven Yen
My e-mail alert:
https://youtu.be/9UwEAruhyhY?list=PLpwR3gb9OGHP1BzgVuO9iIDdogVOijCtO

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


[R] Judging if a matrix contains any NA

2015-07-26 Thread Steven Yen
How do I judge if a matrix contain any NA or otherwise non-missing, 
non-numerical?
In the following, I would like to deliver ONE logical of TRUE or FALSE, 
rather than a 4 x 4 matrix containing TRUE or FALSE. Thank you.


> a<-matrix(1:16,nrow=4)
> diag(a)<-NA
> a
 [,1] [,2] [,3] [,4]
[1,]   NA59   13
[2,]2   NA   10   14
[3,]37   NA   15
[4,]48   12   NA
> is.na(a)
  [,1]  [,2]  [,3]  [,4]
[1,]  TRUE FALSE FALSE FALSE
[2,] FALSE  TRUE FALSE FALSE
[3,] FALSE FALSE  TRUE FALSE
[4,] FALSE FALSE FALSE  TRUE

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


[R] Element-by-element division

2015-07-27 Thread Steven Yen
I need help with element-by-element division. Below, matrices a and c are
both 5 x 2 and element-by-element division works as (I) expected. What if
matrix is 1 by 2: to divide first column of a by b[1] and second column of
a by b[2]. I had to go around (two ways) to make it work. In Gauss, these
can be dine by a./b and a./c. Any such simple way in R? Thank!

> a<-matrix(1:10,nrow=5); a
 [,1] [,2]
[1,]16
[2,]27
[3,]38
[4,]49
[5,]5   10
> b<-matrix(c(0.5,0.25),nrow=1); b
 [,1] [,2]
[1,]  0.5 0.25
> c<-matrix(rep(c(0.5,0.25),5),nrow=5,byrow=T); c
 [,1] [,2]
[1,]  0.5 0.25
[2,]  0.5 0.25
[3,]  0.5 0.25
[4,]  0.5 0.25
[5,]  0.5 0.25

> one<-a/c; one [,1] [,2]
[1,]2   24
[2,]4   28
[3,]6   32
[4,]8   36
[5,]   10   40


> two<-a/b
Error in a/b : non-conformable arrays
> two<-cbind(a[,1]/b[1],a[,2]/b[2]); two
 [,1] [,2]
[1,]2   24
[2,]4   28
[3,]6   32
[4,]8   36
[5,]   10   40

> b2<-matrix(rep(b,5),nrow=5,byrow=T); b2 [,1] [,2]
[1,]  0.5 0.25
[2,]  0.5 0.25
[3,]  0.5 0.25
[4,]  0.5 0.25
[5,]  0.5 0.25> a/b2 [,1] [,2]
[1,]2   24
[2,]4   28
[3,]6   32
[4,]8   36
[5,]   10   40

[[alternative HTML version deleted]]

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


[R] Splitting lines in R script

2015-08-02 Thread Steven Yen
I have a line containing summation of four components.

# This works OK:
  p<-pbivnorm(bb,dd,tau)+pbivnorm(aa,cc,tau)-
-pbivnorm(aa,dd,tau)-pbivnorm(bb,cc,tau)

# This produces unpredicted results without warning:
  p<-pbivnorm(bb,dd,tau)+pbivnorm(aa,cc,tau)
-pbivnorm(aa,dd,tau)-pbivnorm(bb,cc,tau)

Is there a general rule of thumb for line breaks? Thanks you.

[[alternative HTML version deleted]]

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


[R] Checking if a logical variable exists

2014-12-14 Thread Steven Yen

My obj does not always come with a logical variable defined. So I do

my.foo <- function(obj,df,digits=5){
if (!is.na("obj$spec$Fisher")) Fisher<-obj$spec$Fisher
...
}

This works when "Fisher" is defined in/passed from obj. When it is 
not, I get error:


Error in (!is.na("obj$spec$Fisher")) & Fisher :
  operations are possible only for numeric, logical or complex types

I tried exist(Fisher), missing(Fisher)... to no vail. Any idea? Thanks.

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


Re: [R] Checking if a logical variable exists

2014-12-14 Thread Steven Yen

Thanks. This worked!! :)
Fisher <- ifelse(!("Fisher" %in% names(obj$spec)), FALSE, obj$spec$Fisher)

Steven

At 08:43 AM 12/14/2014, Ben Tupper wrote:

Hi,

Does this work for you?  It simply tests if the name Fisher is found 
among the names of the elements of spec.


obj = list(spec = list)
Fisher <- ifelse(!("Fisher" %in% names(obj$spec)), FALSE, obj$spec$Fisher)

Cheers,
Ben

On Dec 14, 2014, at 8:07 AM, Steven Yen  wrote:

> My obj does not always come with a logical variable defined. So I do
>
> my.foo <- function(obj,df,digits=5){
> if (!is.na("obj$spec$Fisher")) Fisher<-obj$spec$Fisher
> ...
> }
>
> This works when "Fisher" is defined in/passed from obj. When it 
is not, I get error:

>
> Error in (!is.na("obj$spec$Fisher")) & Fisher :
>  operations are possible only for numeric, logical or complex types
>
> I tried exist(Fisher), missing(Fisher)... to no vail. Any idea? Thanks.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org


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


[R] Automating regression

2014-12-22 Thread Steven Yen

How do I specify the type of regression in calling a procedure/
In the following I call the procedure to do a probit regression. Of 
course, I can change "probit" into "lm" in procedure "myreg" to do a 
linear regression.


My question is, how do I automate this (choice of lm or probit) in 
calling "myreg", with a proper input (e.g., model=lm)? Thank you.


---
eq1<-d~sex+age+children
b<-myreg(eq1,data=mydata); summary(b)

myreg<-function(formula,data){
data<-model.frame(formula,data)
reg<-probit(formula,data=data)
return(reg)
}

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


[R] Matrix element-by-element multiplication

2015-01-07 Thread Steven Yen
I like to multiple the first and second column of a 10 x 3 matrix by 
100. The following did not work. I need this in an operation with a 
much larger scale. Any help?


aa<-matrix(1:30,nrow=10,ncol=3); aa
bb<-matrix(c(100,100,1),nrow=1,ncol=3); bb
dim(aa)
dim(bb)
aa*bb

Results:

> aa<-matrix(1:30,nrow=10,ncol=3); aa
  [,1] [,2] [,3]
 [1,]1   11   21
 [2,]2   12   22
 [3,]3   13   23
 [4,]4   14   24
 [5,]5   15   25
 [6,]6   16   26
 [7,]7   17   27
 [8,]8   18   28
 [9,]9   19   29
[10,]   10   20   30
> bb<-matrix(c(100,100,1),nrow=1,ncol=3); bb
 [,1] [,2] [,3]
[1,]  100  1001
> dim(aa)
[1] 10  3
> dim(bb)
[1] 1 3
> aa*bb
Error in aa * bb : non-conformable arrays

>

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


Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Steven Yen
Thank you both. Both John and Peter's suggestions work great!!

At 06:17 PM 1/7/2015, John McKown wrote:
>On Wed, Jan 7, 2015 at 5:05 PM, Steven Yen 
><<mailto:sye...@gmail.com>sye...@gmail.com> wrote:
>I like to multiple the first and second column 
>of a 10 x 3 matrix by 100. The following did not 
>work. I need this in an operation with a much larger scale. Any help?
>
>aa<-matrix(1:30,nrow=10,ncol=3); aa
>bb<-matrix(c(100,100,1),nrow=1,ncol=3); bb
>dim(aa)
>dim(bb)
>aa*bb
>
>Results:
>
> > aa<-matrix(1:30,nrow=10,ncol=3); aa
>�  �  �  [,1] [,2] [,3]
>� [1,]�  �  1�  � 11�  � 21
>� [2,]�  �  2�  � 12�  � 22
>� [3,]�  �  3�  � 13�  � 23
>� [4,]�  �  4�  � 14�  � 24
>� [5,]�  �  5�  � 15�  � 25
>� [6,]�  �  6�  � 16�  � 26
>� [7,]�  �  7�  � 17�  � 27
>� [8,]�  �  8�  � 18�  � 28
>� [9,]�  �  9�  � 19�  � 29
>[10,]�  � 10�  � 20�  � 30
> > bb<-matrix(c(100,100,1),nrow=1,ncol=3); bb
>�  �  � [,1] [,2] [,3]
>[1,]�  100�  100�  �  1
> > dim(aa)
>[1] 10�  3
> > dim(bb)
>[1] 1 3
> > aa*bb
>Error in aa * bb : non-conformable arrays
>
> >
>
>
>​Assuming that this is exactly what you want to do, then�
>
>aa[,1:2]<-aa[,1:2]*100;
>
>transcript:
>
> > aa<-matrix(1:30,nrow=10,ncol=3);
> > aa
>   [,1] [,2] [,3]
>  [1,]1   11   21
>  [2,]2   12   22
>  [3,]3   13   23
>  [4,]4   14   24
>  [5,]5   15   25
>  [6,]6   16   26
>  [7,]7   17   27
>  [8,]8   18   28
>  [9,]9   19   29
>[10,]   10   20   30
> > aa[,1:2]<-aa[,1:2]*100
> > aa
>   [,1] [,2] [,3]
>  [1,]  100 1100   21
>  [2,]  200 1200   22
>  [3,]  300 1300   23
>  [4,]  400 1400   24
>  [5,]  500 1500   25
>  [6,]  600 1600   26
>  [7,]  700 1700   27
>  [8,]  800 1800   28
>  [9,]  900 1900   29
>[10,] 1000 2000   30
>
> >
>​
>�
>
>--
>​
>While a transcendent vocabulary is laudable, one 
>must be eternally careful so that the calculated 
>objective of communication does not become 
>ensconced in obscurity.�  In other words, eschew obfuscation.
>
>111,111,111 x 111,111,111 = 12,345,678,987,654,321
>
>Maranatha! <><
>John McKown

[[alternative HTML version deleted]]

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


[R] Package corpcor: Putting symmetric matrix entries in vector

2015-01-30 Thread Steven Yen

Dear
I use sm2vec from package corpcor to puts the lower triagonal entries 
of a symmetric matrix (matrix A) into a vector. However, sm2vec goes 
downward (columnwise, vector B), but I would like it to go across 
(rowwise). So I define a vector to re-map the vector (vector C). This 
works. But is there a short-cut (simpler way)? Thank you.


> A<-cor(e); A
[,1]   [,2][,3][,4]   [,5][,6]
[1,]  1.  0.5240809  0.47996616  0.11200672 -0.1751103 -0.09276455
[2,]  0.52408090  1.000  0.54135982 -0.15985028 -0.2627738 -0.14184545
[3,]  0.47996616  0.5413598  1. -0.06823105 -0.2046897 -0.23815967
[4,]  0.11200672 -0.1598503 -0.06823105  1.  0.2211311  0.08977677
[5,] -0.17511026 -0.2627738 -0.20468966  0.22113112  1.000  0.23567235
[6,] -0.09276455 -0.1418455 -0.23815967  0.08977677  0.2356724  1.
> B<-sm2vec(A); B
 [1]  0.52408090  0.47996616  0.11200672 -0.17511026 -0.09276455
 [6]  0.54135982 -0.15985028 -0.26277383 -0.14184545 -0.06823105
[11] -0.20468966 -0.23815967  0.22113112  0.08977677  0.23567235
> jj<-c(1,2,6,3,7,10,4,8,11,13,5,9,12,14,15)
> C<-B[jj]; C
 [1]  0.52408090  0.47996616  0.54135982  0.11200672 -0.15985028
 [6] -0.06823105 -0.17511026 -0.26277383 -0.20468966  0.22113112
[11] -0.09276455 -0.14184545 -0.23815967  0.08977677  0.23567235

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


Re: [R] Package corpcor: Putting symmetric matrix entries in vector

2015-01-30 Thread Steven Yen

Great! Thanks. Thanks to all who tried to help.
as.vector(r[upper.tri(r)]) does it:

> e<-as.matrix(cbind(u1,u2,u3,v1,v2,v3))
> r<-cor(e); r
[,1]   [,2][,3][,4]   [,5][,6]
[1,]  1.  0.5240809  0.47996616  0.11200672 -0.1751103 -0.09276455
[2,]  0.52408090  1.000  0.54135982 -0.15985028 -0.2627738 -0.14184545
[3,]  0.47996616  0.5413598  1. -0.06823105 -0.2046897 -0.23815967
[4,]  0.11200672 -0.1598503 -0.06823105  1.  0.2211311  0.08977677
[5,] -0.17511026 -0.2627738 -0.20468966  0.22113112  1.000  0.23567235
[6,] -0.09276455 -0.1418455 -0.23815967  0.08977677  0.2356724  1.
> as.vector(r[upper.tri(r)])
 [1]  0.52408090  0.47996616  0.54135982  0.11200672 -0.15985028 -0.06823105
 [7] -0.17511026 -0.26277383 -0.20468966  0.22113112 -0.09276455 -0.14184545
[13] -0.23815967  0.08977677  0.23567235



At 06:56 PM 1/30/2015, Peter Langfelder wrote:

If you have a symmetric matrix, you can work with the upper triangle
instead of the lower one, and you get what you want by simply using

as.vector(A[upper.tri(A)])

Example:

> a = matrix(rnorm(16), 4, 4)
> A = a + t(a)
> A
   [,1]  [,2]   [,3][,4]
[1,]  0.3341294 0.5460334 -0.4388050  1.09415343
[2,]  0.5460334 0.1595501  0.3907721  0.24021833
[3,] -0.4388050 0.3907721 -0.4024922 -1.62140865
[4,]  1.0941534 0.2402183 -1.6214086  0.03987924
> as.vector(A[upper.tri(A)])
[1]  0.5460334 -0.4388050  0.3907721  1.0941534  0.2402183 -1.6214086

No need to play with potentially error-prone index vectors; upper.tri
does that for you.

Hope this helps,

Peter

On Fri, Jan 30, 2015 at 3:03 PM, Steven Yen  wrote:
> Dear
> I use sm2vec from package corpcor to puts the lower triagonal entries of a
> symmetric matrix (matrix A) into a vector. However, sm2vec goes downward
> (columnwise, vector B), but I would like it to go across (rowwise). So I
> define a vector to re-map the vector (vector C). This works. But is there a
> short-cut (simpler way)? Thank you.
>
>> A<-cor(e); A
> [,1]   [,2][,3][,4]   [,5][,6]
> [1,]  1.  0.5240809  0.47996616  0.11200672 -0.1751103 -0.09276455
> [2,]  0.52408090  1.000  0.54135982 -0.15985028 -0.2627738 -0.14184545
> [3,]  0.47996616  0.5413598  1. -0.06823105 -0.2046897 -0.23815967
> [4,]  0.11200672 -0.1598503 -0.06823105  1.  0.2211311  0.08977677
> [5,] -0.17511026 -0.2627738 -0.20468966  0.22113112  1.000  0.23567235
> [6,] -0.09276455 -0.1418455 -0.23815967  0.08977677  0.2356724  1.
>> B<-sm2vec(A); B
>  [1]  0.52408090  0.47996616  0.11200672 -0.17511026 -0.09276455
>  [6]  0.54135982 -0.15985028 -0.26277383 -0.14184545 -0.06823105
> [11] -0.20468966 -0.23815967  0.22113112  0.08977677  0.23567235
>> jj<-c(1,2,6,3,7,10,4,8,11,13,5,9,12,14,15)
>> C<-B[jj]; C
>  [1]  0.52408090  0.47996616  0.54135982  0.11200672 -0.15985028
>  [6] -0.06823105 -0.17511026 -0.26277383 -0.20468966  0.22113112
> [11] -0.09276455 -0.14184545 -0.23815967  0.08977677  0.23567235
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

> and provide commented, minimal, self-contained, reproducible code.


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


[R] Problem with Rtools version 3.5.0.4

2018-07-31 Thread Steven Yen
I am trying to build an R package with Rtools version 3.5.0.4 along with 
R-3.5.1
using the following  sequence of commands:

File -> Open Project -> Build -> Build Binary Package

I received the following error message:

zip I/O error: No such file or directory
zip error: Temporary file failure (Y:/ziPu2G1b)
running 'zip' failed

I then removed Rtools version 3.5.0.4 and installed Rtools version 3.4. 
It worked. What am I missing? Or, shall I wait till the next version of 
Rtools?

Full log file below.

==> Rcmd.exe INSTALL --build --preclean yenlib3

* installing to library 'C:/Users/syen01/Documents/R/win-library/3.5'
* installing *source* package 'yenlib3' ...
** R
** data
*** moving datasets to lazyload DB
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
   converting help for package 'yenlib3'
     finding HTML links ... done
     aids    html
     all.variables   html
     ate.boprobit    html
(list truncated)
     ate.boprobitE0  html
     zxcombined  html
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* MD5 sums
zip I/O error: No such file or directory
zip error: Temporary file failure (Y:/ziPu2G1b)
running 'zip' failed
* DONE (yenlib3)
In R CMD INSTALL

Binary package written to Y:/
-- 

st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Polygon

2018-10-02 Thread Steven Yen
Can someone help me with polygon. The following codes are self-runnable 
and mark a shaded area under the standard normal curve in the x-range 
(-3,-1).
Is there a way to also mark the area in (1,3), at the same time.
That is, I want shaded areas in both tails. Thank you...

===
# Create data for the area to shade
cord.x <- c(-3,seq(-3,-1,0.01),-1)
cord.y <- c(0,dnorm(seq(-3,-1,0.01)),0)

# Make a curve
curve(dnorm(x,0,1), xlim=c(-3,3), main='Standard Normal')

# Add the shaded area.
polygon(cord.x,cord.y,col='skyblue')

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


Re: [R] Polygon

2018-10-02 Thread Steven Yen
Great. Thanks! It did wonders.
1. Is there a way to suppress the obvious tick stops (-3,-2,-1,0,1,2,3) 
and mark only the ticks -1.96 and 1.96.
2. Better yet, to draw vertical lines at x = -1.96 and x = 1.96.
Thanks.
Steven

On 10/3/2018 12:51 AM, Rui Barradas wrote:
> Hello,
>
> Continue with
>
>
> polygon(-rev(cord.x), rev(cord.y), col = 'skyblue')
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 17:25 de 02/10/2018, Steven Yen escreveu:
>> Can someone help me with polygon. The following codes are self-runnable
>> and mark a shaded area under the standard normal curve in the x-range
>> (-3,-1).
>> Is there a way to also mark the area in (1,3), at the same time.
>> That is, I want shaded areas in both tails. Thank you...
>>
>> ===
>> # Create data for the area to shade
>> cord.x <- c(-3,seq(-3,-1,0.01),-1)
>> cord.y <- c(0,dnorm(seq(-3,-1,0.01)),0)
>>
>> # Make a curve
>> curve(dnorm(x,0,1), xlim=c(-3,3), main='Standard Normal')
>>
>> # Add the shaded area.
>> polygon(cord.x,cord.y,col='skyblue')
>>
>

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


Re: [R] Polygon

2018-10-02 Thread Steven Yen
Thanks!!! It did wonders.
Steven

On 10/3/2018 9:39 AM, David Winsemius wrote:
>> On Oct 2, 2018, at 5:50 PM, Steven Yen  wrote:
>>
>> Great. Thanks! It did wonders.
>> 1. Is there a way to suppress the obvious tick stops (-3,-2,-1,0,1,2,3)
>> and mark only the ticks -1.96 and 1.96.
>> 2. Better yet, to draw vertical lines at x = -1.96 and x = 1.96.
>> Thanks.
> Read ?plot.default
>
> Then add xaxt="n" to the arguments to curve, ... and afterwards:
>
> axis( 1, at=c(-1.96, 1.96),lab=c(-1.96, 1.96) )
> abline( v= c(-1.96, 1.96) )
>
> --
>> Steven
>>
>> On 10/3/2018 12:51 AM, Rui Barradas wrote:
>>> Hello,
>>>
>>> Continue with
>>>
>>>
>>> polygon(-rev(cord.x), rev(cord.y), col = 'skyblue')
>>>
>>>
>>> Hope this helps,
>>>
>>> Rui Barradas
>>>
>>> Às 17:25 de 02/10/2018, Steven Yen escreveu:
>>>> Can someone help me with polygon. The following codes are self-runnable
>>>> and mark a shaded area under the standard normal curve in the x-range
>>>> (-3,-1).
>>>> Is there a way to also mark the area in (1,3), at the same time.
>>>> That is, I want shaded areas in both tails. Thank you...
>>>>
>>>> ===
>>>> # Create data for the area to shade
>>>> cord.x <- c(-3,seq(-3,-1,0.01),-1)
>>>> cord.y <- c(0,dnorm(seq(-3,-1,0.01)),0)
>>>>
>>>> # Make a curve
>>>> curve(dnorm(x,0,1), xlim=c(-3,3), main='Standard Normal')
>>>>
>>>> # Add the shaded area.
>>>> polygon(cord.x,cord.y,col='skyblue')
>>>>
>> -- 
>> st...@ntu.edu.tw (S.T. Yen)
>>
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'   
> -Gehm's Corollary to Clarke's Third Law
>
>
>
>
>
>

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Graphing output

2018-10-09 Thread Steven Yen
Is it possible to release the file destination after sending it to a pdf 
file?
Below, line 3 send the graph to a pdf file.
I like to release the devise so that I can see result produced by line 
for on the console (screen). Thanks.

x<-1:10
pdf("test1.pdf") # pdf {grDevices}
boxplot(x) # This goes to pdf file
boxplot(x) # Like this to go to console

-- 
st...@ntu.edu.tw  (S.T. Yen)


[[alternative HTML version deleted]]

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


Re: [R] Polygon

2018-10-21 Thread Steven Yen
David, Rui, and All:
Greetings.
1. I need a helping hand with the polygon statement below so that I can 
have the area under the curve highlighted, between (z1,z2).
2. Is it possible to label the X-axis with in two scale, in the current 
z-scale and another, say x = (z+5)*2?
Thank you.

z1<- -1
z2<-  2
curve(dnorm(x,0,1),xlim=c(-4,4),main="Standard 
Normal",xaxt="n",frame=F,xlab="z")
jj<-seq(z1,z2,0.01)
cord.x<-c(jj)
cord.y<-c(dnorm(jj))
#polygon(cord.x,cord.y,col="skyblue")
axis(1,at=c(-5,z1,0,z2,5),lab=c(-5,z1,0,z2,5))
abline(v=c(z1,z2))

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Using apply

2018-10-30 Thread Steven Yen
I need help with "apply". Below, I have no problem getting the column sums.
1. How do I get the sum of squares?
2. In general, where do I look up these functions?
Thanks.

x<-matrix(1:10,nrow=5); x
sum <- apply(x,2,sum); sum




[[alternative HTML version deleted]]

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


[R] Printing with cat in a procedure

2018-12-22 Thread Steven Yen
How do I print a matrix running a procedure? In the code below, I print 
with the cat command and get a vector (from A and C).

A<-matrix(rpois(16,lambda=5),nrow=4,byrow=T)
B<-diag(4)

try5<-function(A,B){
  C<-A+B
  cat("\nA =",A,"\nC = ",C)
structure(list(A=A,B=B,C=C))
}

v<-try5(A,B)
v$C

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


Re: [R] Printing with cat in a procedure

2018-12-22 Thread Steven Yen
Thank you all - print works wonders.

On 12/22/2018 10:36 PM, Eric Berger wrote:
> Hi Steven,
> Here's one way, using print
>
> try5<-function(A,B){
>   C<-A+B
>   #cat("\nA =",A,"\nC = ",C)
>   cat("\nA = ")
>   print(A)
>   cat("\nC = ")
>   print(C)
>   structure(list(A=A,B=B,C=C))
> }
>
> HTH,
> Eric
>
>
> On Sat, Dec 22, 2018 at 4:32 PM Steven Yen  <mailto:st...@ntu.edu.tw>> wrote:
>
> How do I print a matrix running a procedure? In the code below, I
> print
> with the cat command and get a vector (from A and C).
>
> A<-matrix(rpois(16,lambda=5),nrow=4,byrow=T)
> B<-diag(4)
>
> try5<-function(A,B){
>   C<-A+B
>   cat("\nA =",A,"\nC = ",C)
> structure(list(A=A,B=B,C=C))
> }
>
> v<-try5(A,B)
> v$C
>
> -- 
> st...@ntu.edu.tw <mailto:st...@ntu.edu.tw> (S.T. Yen)
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Random seed

2018-12-22 Thread Steven Yen
I have known from the old days to set a random seed of a LARGE ODD 
NUMBER. Now I read instructions of set.seed and it requires ANY INTEGER. 
Any idea? Or, does it matter. Thanks.

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Retrievable results in a procedure

2018-12-25 Thread Steven Yen
I would like to suppressed printing of retrievable results in a 
procedure and to print only when retrieved.

In line 10 below I call procedure "try" and get matrices A,B,C all 
printed upon a call to the procedure. I get around this unwanted 
printing by calling with v<-try(A,B) as in line 11.

Any way to suppress printing of the retrievable results listed in the 
structure command? Thank you, and Merry Christmas to all.


A<-matrix(rpois(16,lambda=5),nrow=4,byrow=T)
B<-diag(4)

try<-function(A,B){
  C<-A+B
  cat("\nC:\n"); print(C)
structure(list(A=A,B=B,C=C))
}

try(A,B)# line 10
v<-try(A,B) # line 11

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


Re: [R] Retrievable results in a procedure

2018-12-25 Thread Steven Yen
Thanks Sarah. Below, replacing "structure" with "invisible" does 
wonders--that serves my need. What I want is quite simple - I call a 
procedure and it does two things: (1) display results for all; (2) save 
retrievable results for use in further analysis, e.g., in knitr. 
Earlier, with "structure" (or with results<-list(...)) it spits out the 
main results, with components repeated (printed) in a painfully long 
list. Yet, as I said, calling with foo<-try(...) prints the main results 
with the list suppressed. I am just looking for option to NOT have to 
call with foo<- always. There must be more ways to do this, but I am 
happy with invisible. Thanks again.


On 12/25/2018 11:10 PM, Sarah Goslee wrote:
> I'm a bit confused about what you actually want, but I think 
> invisible() might be the answer.
>
> Note that there's already a base function try() so that's not a great 
> name for test functions.
>
> Sarah
>
> On Tue, Dec 25, 2018 at 8:47 AM Steven Yen  <mailto:st...@ntu.edu.tw>> wrote:
>
> I would like to suppressed printing of retrievable results in a
> procedure and to print only when retrieved.
>
> In line 10 below I call procedure "try" and get matrices A,B,C all
> printed upon a call to the procedure. I get around this unwanted
> printing by calling with v<-try(A,B) as in line 11.
>
> Any way to suppress printing of the retrievable results listed in the
> structure command? Thank you, and Merry Christmas to all.
>
>
> A<-matrix(rpois(16,lambda=5),nrow=4,byrow=T)
> B<-diag(4)
>
> try<-function(A,B){
>   C<-A+B
>   cat("\nC:\n"); print(C)
> structure(list(A=A,B=B,C=C))
> }
>
> try(A,B)# line 10
> v<-try(A,B) # line 11
>
> -- 
> st...@ntu.edu.tw <mailto:st...@ntu.edu.tw> (S.T. Yen)
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> -- 
> Sarah Goslee (she/her)
> http://www.sarahgoslee.com

-- 
st...@ntu.edu.tw (S.T. Yen)


[[alternative HTML version deleted]]

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


[R] Installing package into...

2019-03-12 Thread Steven Yen
I install package using either the command line or Tools -> Install 
packages... (in RStudio) and get a non-fatal message saying...
Installing package into ‘C:/Users/xuhaer/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
I know it is not a fatal message. But, is there a way to do a cleaner 
installation without getting such message? Thanks.

-- 
s...@hqu.edu.cn


[[alternative HTML version deleted]]

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


[R] Printing vectrix

2019-03-24 Thread Steven Yen
I like to print a vector, wrapped by rows of 10.
Below the first command below works for 20 numbers.

The second command is ugly. How can I print the 25 numbers into 2 rows 
of ten plus a helf row of 5? Thanks.

 > x<-1:20; matrix(x,nrow=2,byrow=T)
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    2    3    4    5    6    7    8    9    10
[2,]   11   12   13   14   15   16   17   18   19    20
 > x<-1:25; matrix(x,nrow=2,byrow=T)
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,]    1    2    3    4    5    6    7    8    9    10    11 12    13
[2,]   14   15   16   17   18   19   20   21   22    23    24 25 1
Warning message:
In matrix(x, nrow = 2, byrow = T) :
   data length [25] is not a sub-multiple or multiple of the number of 
rows [2]
 >

-- 
s...@hqu.edu.cn


[[alternative HTML version deleted]]

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


[R] Overwriting a procedure

2014-09-02 Thread Steven Yen

Is there a way to over-write a procedure (subroutine)?

I include a default procedure fixx in a list of procedures which are 
compiled into a package. By default, the procedure deliver the data matrix x.


fixx <- function(x){
result <- list(x=x)
return(result)
}

In some applications, I have transformations (such as squared terms) 
in some column(s) in x. So I include the following procedure in the 
mail (calling) program, hoping to over-write the default procedure 
under the same name in the package (which is the way other languages 
works, e.g., Gauss):


fixx <- function(x){
x[,6]<-x[,5]^2/10
result <- list(x=x)
return(result)
}

This does not seem to work. The procedure in the main (calling) 
program seems to get ignored. Any idea? Thanks.


__
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] Overwriting a procedure

2014-09-24 Thread Steven Yen

Thank you all. Various ideas led to a simple solution.
I include an argument in the calling function, i.e., v.transform, 
default being FALSE. Function fixzx is removed entirely from the 
package, which is OK by default. The function is called only when 
v.transform=TRUE:


if (v.transform){
  v<-fixzx(z1,x1); z1<-v$z; x1<-v$x
}

Then, when I do need to transform variable(s), I include function 
fixx(x) in the main program (which I had meant to do anyway as 
transformations are problem specific):


fixzx <- function(z,x){
z[,4]=z[,3]^2/10; x[,4]=z[,4];
x[,18]<-x[,17]^2/10
result <- list(z=z,x=x)
return(result)
}

This works out nicely. The fact that a function fixx is not needed 
when v.transform=FALSE is very convenient. Other programming 
languages, e.g., Gauss, do not allow the function to be missing when 
v.transform=FALSE. Thank you all.


At 04:41 PM 9/2/2014, Greg Snow wrote:

A perhaps better approach would be to have the functions that
currently call fixx accept an argument of a function to use.  It could
default to fixx, but if the caller passed in a new function it would
use that function instead.

If you really want to overwrite a function inside of a package
namespace then look at the assignInNamespace function in the utils
package (but note the warning in the description on the help page).

On Tue, Sep 2, 2014 at 12:45 PM, Steven Yen  wrote:
> Is there a way to over-write a procedure (subroutine)?
>
> I include a default procedure fixx in a list of procedures which are
> compiled into a package. By default, the procedure deliver the data matrix
> x.
>
> fixx <- function(x){
> result <- list(x=x)
> return(result)
> }
>
> In some applications, I have transformations (such as squared 
terms) in some

> column(s) in x. So I include the following procedure in the mail (calling)
> program, hoping to over-write the default procedure under the same name in
> the package (which is the way other languages works, e.g., Gauss):
>
> fixx <- function(x){
> x[,6]<-x[,5]^2/10
> result <- list(x=x)
> return(result)
> }
>
> This does not seem to work. The procedure in the main (calling) program
> seems to get ignored. Any idea? Thanks.
>
> __
> 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.



--
Gregory (Greg) L. Snow Ph.D.
538...@gmail.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] Writing .csv file

2014-09-24 Thread Steven Yen

I use the following command to write data to a .csv file:

write.csv(yxz,file="foo.csv")

And I get the following in the file, with one column appended to the file:

"","fsp","fsec","cincome",
"1",0,3,2.25,...
"2",0,1,2.75,...
"3",1,1,0.625,...

Question: is there a way to avoid the first column? Thanks.

__
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] Writing .csv file

2014-09-24 Thread Steven Yen

Wonderful. It worked like charms and I love it! Thank you Don.
Steven

At 05:06 PM 9/24/2014, Don McKenzie wrote:

I believe you need to specify row.names = FALSE

See the help for write.table()

On Sep 24, 2014, at 2:00 PM, Steven Yen  wrote:

> I use the following command to write data to a .csv file:
>
>write.csv(yxz,file="foo.csv")
>
> And I get the following in the file, with one column appended to the file:
>
> "","fsp","fsec","cincome",
> "1",0,3,2.25,...
> "2",0,1,2.75,...
> "3",1,1,0.625,...
>
> Question: is there a way to avoid the first column? Thanks.
>
> __
> 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.

Don McKenzie
Research Ecologist
Pacific Wildland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Environmental and Forest Sciences
University of Washington

d...@uw.edu


__
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] Reading text file with fortran format

2014-09-30 Thread Steven Yen
Hello

I read data with fortran format:
mydata<-read.fortran('foo.txt',
  c("4F10.4","F8.3","3F3.0","20F2.0"))
colnames(mydata)<-c("q1","q2","q3","q4","income","hhsize",
  "weekend","dietk","quart1","quart2","quart3","male","age35",
  "age50","age65","midwest","south","west","nonmetro",
  "suburb","black","asian","other","hispan","hhtype1",
  "hhtype2","hhtype3","emp_stat")
dstat(mydata,digits=6)

I produced the following sample statistics for the first 4
variables (q1,q2,q3,q4):

  Mean  Std.dev Min   Max  Obs
q1   0.000923 0.002509   0  0.035245 5649
q2   0.000698 0.001681   0  0.038330 5649
q3   0.000766 0.002138   0  0.040100 5649
q4   0.000373 0.001140   0  0.026374 5649

The correct sample statistics are:
Variable|   Mean   Std.Dev. Minimum  Maximum
+
   Q1| 9.227632 25.09311  0.0 352.4508
   Q2| 6.983078 16.80984  0.0 383.2995
   Q3| 7.657381 21.38337  0.0 400.9950
   Q4| 3.727952 11.40446  0.0 263.7398
   INCOME| 16.01603 13.70296  0.0100.0
   HHSIZE| 2.586475 1.464282  1.0 16.0

In other words, values for q1-q4 were scaled down by a factor of 10,000.
My raw data look like (with proper format)

 0.0.0.0.  48.108...
 0.0.0.0.  11.640...
35.34500.   95.76560.   4.667...
 0.0.0.0.   9.000...
84.4.80380.3.1886   2.923...
 0.0.0.1.1636  10.000...
 0.   10.7818  109.78840.  17.000...
 0.7.95280.4.7829  35.000...

True that the data here are space delimited. But I need to read data 
elsewhere where data are not space delimited.

Any idea/suggestion would be appreciated.


[[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] Reading text file with fortran format

2014-09-30 Thread Steven Yen

Thanks to all.
Steven Yen

At 06:18 PM 9/30/2014, Nordlund, Dan (DSHS/RDA) wrote:

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Steven Yen
> Sent: Tuesday, September 30, 2014 2:04 PM
> To: r-help
> Subject: [R] Reading text file with fortran format
>
> Hello
>
> I read data with fortran format:
> mydata<-read.fortran('foo.txt',
>   c("4F10.4","F8.3","3F3.0","20F2.0"))
> colnames(mydata)<-c("q1","q2","q3","q4","income","hhsize",
>   "weekend","dietk","quart1","quart2","quart3","male","age35",
>   "age50","age65","midwest","south","west","nonmetro",
>   "suburb","black","asian","other","hispan","hhtype1",
>   "hhtype2","hhtype3","emp_stat")
> dstat(mydata,digits=6)
>
> I produced the following sample statistics for the first 4
> variables (q1,q2,q3,q4):
>
>   Mean  Std.dev Min   Max  Obs
> q1   0.000923 0.002509   0  0.035245 5649
> q2   0.000698 0.001681   0  0.038330 5649
> q3   0.000766 0.002138   0  0.040100 5649
> q4   0.000373 0.001140   0  0.026374 5649
>
> The correct sample statistics are:
> Variable|   Mean   Std.Dev. Minimum  Maximum
> +
>Q1| 9.227632 25.09311  0.0 352.4508
>Q2| 6.983078 16.80984  0.0 383.2995
>Q3| 7.657381 21.38337  0.0 400.9950
>Q4| 3.727952 11.40446  0.0 263.7398
>INCOME| 16.01603 13.70296  0.0100.0
>HHSIZE| 2.586475 1.464282  1.0 16.0
>
> In other words, values for q1-q4 were scaled down by a factor of
> 10,000.
> My raw data look like (with proper format)
>
>  0.0.0.0.  48.108...
>  0.0.0.0.  11.640...
> 35.34500.   95.76560.   4.667...
>  0.0.0.0.   9.000...
> 84.4.80380.3.1886   2.923...
>  0.0.0.1.1636  10.000...
>  0.   10.7818  109.78840.  17.000...
>  0.7.95280.4.7829  35.000...
>
> True that the data here are space delimited. But I need to read data
> elsewhere where data are not space delimited.
>
> Any idea/suggestion would be appreciated.
>

The read.fortran function appears to work differently from how 
FORTRAN would read the data if there are already decimals points in 
the numbers.  If memory serves, FORTRAN ignores the decimal portion 
of the format if it finds a decimal in what it reads.  The 
read.fortran function appears to read the number 'as is' and then 
multiplies by 10^-d, where d is the number of decimal places in the 
format.  Since you have decimals specified, you should specify the 
format with 0 decimal places, i.e.


c("4F10.0","F8.0","3F3.0","20F2.0"))


hope this is helpful,

Dan


Daniel J. Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


__
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] Reading text file with fortran format

2014-10-13 Thread Steven Yen

Hello
Any idea how to read a text file with fortran format, WITH MULTIPLE 
RECORDS? My fortran format is as follows, and I do know I need to 
change F7.4 to F7.0, and 2F2.0 to 2I2, etc.
I just have no idea how to handle the "slash" (/) which dictates a 
jump to the next record in fortran. Thank you all.

---

 10   FORMAT(F8.0,4F2.0,6F7.4,F8.4,3F4.1,2F3.0,36F2.0,11F8.5
 * /2F8.5,F10.4,F2.0,F8.1,F10.4,F11.4,F6.2,F2.0,3F10.4,2F12.7,2F2.0,
 * F4.0,2F2.0,F8.5,5F2.0)

__
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] Checking if a matrix exists/is defined

2014-10-18 Thread Steven Yen
Hello
Can someone help me with the following, specifically in judging 
whether a matrix exists. I have trouble with the first line below. In 
this case, matrix obj$hessian exists and is 74 x 74. I receive the 
error message:

Warning message:
In all(w$hessian) : coercing argument of type 'double' to logical

Thank you all.

---
if (!all(obj$hessian)|OPG){
   vb<-obj$gradientObs; vb<-solve(t(vb)%*%vb)
   vb.method<-"; v(b)=inv(G'G)"
} else {
   vb<- solve(-obj$hessian)
   vb.method<-"; v(b)=inv(-H)"
} 
[[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] Checking if a matrix exists/is defined

2014-10-19 Thread Steven Yen
Thank you Rich. It works like a charm! Earlier I worked around 
by  judging its determinant:


dd<-NULL
if (invH) dd<-det(obj$hessian)
if (invH & exists("dd")){
...
}

Now I do

if (!is.null(obj$hessian) & invH){
...
}

which is more direct. Thanks again.

Steven

At 01:50 AM 10/19/2014, Richard M. Heiberger wrote:

all() takes a logical argument, not numeric.  See ?all

I think you are looking for
is.null(obj$hessian)

If this isn't what you are looking for, please send a reproducible example
to the entire list.

Rich

On Sun, Oct 19, 2014 at 12:17 AM, Steven Yen  wrote:
> Hello
> Can someone help me with the following, specifically in judging
> whether a matrix exists. I have trouble with the first line below. In
> this case, matrix obj$hessian exists and is 74 x 74. I receive the
> error message:
>
> Warning message:
> In all(w$hessian) : coercing argument of type 'double' to logical
>
> Thank you all.
>
> ---
> if (!all(obj$hessian)|OPG){
>vb<-obj$gradientObs; vb<-solve(t(vb)%*%vb)
>vb.method<-"; v(b)=inv(G'G)"
> } else {
>vb<- solve(-obj$hessian)
>vb.method<-"; v(b)=inv(-H)"
> }
> [[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] Selecting rows/columns of a matrix

2014-10-26 Thread Steven Yen

Dear

I am interested in selecting rows and columns of a matrix with a 
criterion defined by a binary indicator vector. Let  matrix a be


> a<-matrix(1:16, 4,4,byrow=T)
> a
 [,1] [,2] [,3] [,4]
[1,]1234
[2,]5678
[3,]9   10   11   12
[4,]   13   14   15   16

Elsewhere in Gauss, I select the first and third rows and columns of 
a by defining a column vector j = [1,0,1,0]. Then, select the rows of 
a using j, and then selecting the rows of the transpose of the 
resulting matrix using j again. I get the 2 x 2 matrix as desired. Is 
there a way to do this in R? below are my Gauss commands. Thank you.


---

j

1
0
1
0

a=selif(a,j); a

1  2  3  4
9 10 11 12

a=selif(a',j); a

1  9
3 11

__
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] Selecting rows/columns of a matrix

2014-10-26 Thread Steven Yen

Rui

Thanks. This works great. Below, I get the 2nd, 4th, and 6th rows/columns:

> (a<-matrix(1:36,6,6))
 [,1] [,2] [,3] [,4] [,5] [,6]
[1,]17   13   19   25   31
[2,]28   14   20   26   32
[3,]39   15   21   27   33
[4,]4   10   16   22   28   34
[5,]5   11   17   23   29   35
[6,]6   12   18   24   30   36
> (j<-matrix(c(0,1,0,1,0,1)))
 [,1]
[1,]0
[2,]1
[3,]0
[4,]1
[5,]0
[6,]1
> ((a[as.logical(j), as.logical(j)]))
 [,1] [,2] [,3]
[1,]8   20   32
[2,]   10   22   34
[3,]   12   24   36

Steven Yen

At 02:49 PM 10/26/2014, Rui Barradas wrote:

Sorry, that should be

t(a[as.logical(j), as.logical(j)])

Rui Barradas

Em 26-10-2014 18:45, Rui Barradas escreveu:

Hello,

Try the following.

a[as.logical(j), as.logical(j)]

# or
b <- a[as.logical(j), ]
t(b)[as.logical(j), ]


Hope this helps,

Rui Barradas

Em 26-10-2014 18:35, Steven Yen escreveu:

Dear

I am interested in selecting rows and columns of a matrix with a
criterion defined by a binary indicator vector. Let  matrix a be

 > a<-matrix(1:16, 4,4,byrow=T)
 > a
  [,1] [,2] [,3] [,4]
[1,]1234
[2,]5678
[3,]9   10   11   12
[4,]   13   14   15   16

Elsewhere in Gauss, I select the first and third rows and columns of a
by defining a column vector j = [1,0,1,0]. Then, select the rows of a
using j, and then selecting the rows of the transpose of the resulting
matrix using j again. I get the 2 x 2 matrix as desired. Is there a way
to do this in R? below are my Gauss commands. Thank you.

---

j

1
0
1
0

a=selif(a,j); a

1  2  3  4
9 10 11 12

a=selif(a',j); a

1  9
3 11

__
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] Injecting a column of characters to a matrix of numerics

2014-10-29 Thread Steven Yen

Hello
I am designing a regression printout, which works out nicely. Then, I 
try to inject a column of characters to indicate a discrete regressor 
with a dot (.). Then, all numbers seem to turn into characters, in 
quotations. Is there a way to do this right? Below, I show the lines 
of codes before and after. Thanks.

Steven Yen

---
out<-round(cbind(me,se,t,p),digits)
colnames(out)<-c("estimates","s.e.","|t-value|","p-value")
rownames(out)<-rownames(me)
out
estimates s.e. |t-value|  p-value
(Intercept)  0.223263 0.146167  1.527459 0.127173
sex  0.049830 0.039612  1.257973 0.208890
age -0.070423 0.029539  2.384035 0.017433
yrmarry  0.015567 0.005298  2.938126 0.003429
children 0.060525 0.044778  1.351659 0.176993
religius-0.053128 0.014413  3.686260 0.000248
educ 0.003226 0.008453  0.381636 0.702866
occu 0.003915 0.011860  0.330147 0.741404
rating  -0.077856 0.014466  5.381925 0.00

out<-round(cbind(me,se,t,p),digits); out<-cbind(out,disc)
colnames(out)<-c("estimates","s.e.","|t-value|","p-value","disc")
rownames(out)<-rownames(me)

(Intercept) "0.223263"  "0.146167" "1.527459" "0.127173" ""
sex "0.04983"   "0.039612" "1.257973" "0.20889"  "."
age "-0.070423" "0.029539" "2.384035" "0.017433" ""
yrmarry "0.015567"  "0.005298" "2.938126" "0.003429" ""
children"0.060525"  "0.044778" "1.351659" "0.176993" "."
religius"-0.053128" "0.014413" "3.68626"  "0.000248" ""
educ"0.003226"  "0.008453" "0.381636" "0.702866" ""
occu"0.003915"  "0.01186"  "0.330147" "0.741404" ""
rating  "-0.077856" "0.014466" "5.381925" "0"""

__
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] Injecting a column of characters to a matrix of numerics

2014-10-29 Thread Steven Yen

Wonderful. Works great!
Steven Yen

At 11:52 AM 10/29/2014, Kevin E. Thorpe wrote:

On 10/29/2014 11:41 AM, Steven Yen wrote:

Hello
I am designing a regression printout, which works out nicely. Then, I
try to inject a column of characters to indicate a discrete regressor
with a dot (.). Then, all numbers seem to turn into characters, in
quotations. Is there a way to do this right? Below, I show the lines of
codes before and after. Thanks.
Steven Yen

---
out<-round(cbind(me,se,t,p),digits)
colnames(out)<-c("estimates","s.e.","|t-value|","p-value")
rownames(out)<-rownames(me)
out
 estimates s.e. |t-value|  p-value
(Intercept)  0.223263 0.146167  1.527459 0.127173
sex  0.049830 0.039612  1.257973 0.208890
age -0.070423 0.029539  2.384035 0.017433
yrmarry  0.015567 0.005298  2.938126 0.003429
children 0.060525 0.044778  1.351659 0.176993
religius-0.053128 0.014413  3.686260 0.000248
educ 0.003226 0.008453  0.381636 0.702866
occu 0.003915 0.011860  0.330147 0.741404
rating  -0.077856 0.014466  5.381925 0.00

out<-round(cbind(me,se,t,p),digits); out<-cbind(out,disc)
colnames(out)<-c("estimates","s.e.","|t-value|","p-value","disc")
rownames(out)<-rownames(me)

(Intercept) "0.223263"  "0.146167" "1.527459" "0.127173" ""
sex "0.04983"   "0.039612" "1.257973" "0.20889"  "."
age "-0.070423" "0.029539" "2.384035" "0.017433" ""
yrmarry "0.015567"  "0.005298" "2.938126" "0.003429" ""
children"0.060525"  "0.044778" "1.351659" "0.176993" "."
religius"-0.053128" "0.014413" "3.68626"  "0.000248" ""
educ"0.003226"  "0.008453" "0.381636" "0.702866" ""
occu"0.003915"  "0.01186"  "0.330147" "0.741404" ""
rating  "-0.077856" "0.014466" "5.381925" "0"""


Use data frames instead.

out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,disc)
names(out)<-c("estimates","s.e.","|t-value|","p-value","disc")


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



--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016


__
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] Removing rows in a data frame containing string in rownames

2014-11-16 Thread Steven Yen
I like to remove from a data frame rows with labels containing 
certain string, e.g., "sex" and "rating". Below is a list of the data 
frame and my failed attempt to the rows. Any clues? Thanks.


> out
 est se t p disc
p.(Intercept) 26.430 13.605 1.943 0.053
p.sex  3.502  3.930 0.891 0.373 *
p.children 3.693  4.521 0.817 0.414 *
p.occu 0.740  1.116 0.663 0.508
p.rating  -7.897  1.331 5.933 0.000
c.(Intercept)  1.861  0.965 1.929 0.054
c.sex  0.221  0.249 0.889 0.374 *
c.children 0.234  0.289 0.810 0.418 *
c.occu 0.052  0.079 0.663 0.508
c.rating  -0.556  0.102 5.451 0.000
u.(Intercept)  1.943  1.017 1.910 0.057
u.sex  0.221  0.248 0.888 0.375 *
u.children 0.229  0.276 0.827 0.409 *
u.occu 0.054  0.082 0.663 0.508
u.rating  -0.581  0.109 5.331 0.000

> out<-subset(out,!(names(out) %in% c("sex","rating")))
> out
 est se t p disc
p.(Intercept) 26.430 13.605 1.943 0.053
p.sex  3.502  3.930 0.891 0.373 *
p.children 3.693  4.521 0.817 0.414 *
p.occu 0.740  1.116 0.663 0.508
p.rating  -7.897  1.331 5.933 0.000
c.(Intercept)  1.861  0.965 1.929 0.054
c.sex  0.221  0.249 0.889 0.374 *
c.children 0.234  0.289 0.810 0.418 *
c.occu 0.052  0.079 0.663 0.508
c.rating  -0.556  0.102 5.451 0.000
u.(Intercept)  1.943  1.017 1.910 0.057
u.sex  0.221  0.248 0.888 0.375 *
u.children 0.229  0.276 0.827 0.409 *
u.occu 0.054  0.082 0.663 0.508
u.rating  -0.581  0.109 5.331 0.000

__
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] Removing rows in a data frame containing string in rownames

2014-11-16 Thread Steven Yen
Thank you Bill and Dennis. grepl worked great. 
However, for reason I am not figuring out, the 
code worked as I included the procedure 
(subroutine) with a source command, viz.,

   source("z:\\R\\mylib\\me.R")

Compiling the routine into a library/package, as 
I always do, then the command got ignored. Hmm...

Steven

At 10:22 PM 11/16/2014, William Dunlap wrote:
>Try grepl() to do pattern matching in strings. � ("%in%" checks for
>equality.) � E.g., using your original 'out' do
>�  � out[ !grepl("sex|rating", rownames(out), ]
>to get all but the rows whose names contain the character sequences
>"sex" or "rating".
>
>Bill Dunlap
>TIBCO Software
>wdunlap <http://tibco.com>tibco.com
>
>On Sun, Nov 16, 2014 at 6:31 PM, Steven Yen 
><<mailto:sye...@gmail.com>sye...@gmail.com> wrote:
>I like to remove from a data frame rows with 
>labels containing certain string, e.g., "sex" 
>and "rating". Below is a list of the data frame 
>and my failed attempt to the rows. Any clues? Thanks.
>
> > out
>�  �  �  �  �  �  �  �  � est�  �  � se�  �  � t�  �  � p disc
>p.(Intercept) 26.430 13.605 1.943 0.053
>p.sex�  �  �  �  �  3.502�  3.930 0.891 0.373 *
>p.children�  �  � 3.693�  4.521 0.817 0.414 *
>p.occu�  �  �  �  � 0.740�  1.116 0.663 0.508
>p.rating�  �  �  -7.897�  1.331 5.933 0.000
>c.(Intercept)�  1.861�  0.965 1.929 0.054
>c.sex�  �  �  �  �  0.221�  0.249 0.889 0.374 *
>c.children�  �  � 0.234�  0.289 0.810 0.418 *
>c.occu�  �  �  �  � 0.052�  0.079 0.663 0.508
>c.rating�  �  �  -0.556�  0.102 5.451 0.000
>u.(Intercept)�  1.943�  1.017 1.910 0.057
>u.sex�  �  �  �  �  0.221�  0.248 0.888 0.375 *
>u.children�  �  � 0.229�  0.276 0.827 0.409 *
>u.occu�  �  �  �  � 0.054�  0.082 0.663 0.508
>u.rating�  �  �  -0.581�  0.109 5.331 0.000
>
> > out<-subset(out,!(names(out) %in% c("sex","rating")))
> > out
>�  �  �  �  �  �  �  �  � est�  �  � se�  �  � t�  �  � p disc
>p.(Intercept) 26.430 13.605 1.943 0.053
>p.sex�  �  �  �  �  3.502�  3.930 0.891 0.373 *
>p.children�  �  � 3.693�  4.521 0.817 0.414 *
>p.occu�  �  �  �  � 0.740�  1.116 0.663 0.508
>p.rating�  �  �  -7.897�  1.331 5.933 0.000
>c.(Intercept)�  1.861�  0.965 1.929 0.054
>c.sex�  �  �  �  �  0.221�  0.249 0.889 0.374 *
>c.children�  �  � 0.234�  0.289 0.810 0.418 *
>c.occu�  �  �  �  � 0.052�  0.079 0.663 0.508
>c.rating�  �  �  -0.556�  0.102 5.451 0.000
>u.(Intercept)�  1.943�  1.017 1.910 0.057
>u.sex�  �  �  �  �  0.221�  0.248 0.888 0.375 *
>u.children�  �  � 0.229�  0.276 0.827 0.409 *
>u.occu�  �  �  �  � 0.054�  0.082 0.663 0.508
>u.rating�  �  �  -0.581�  0.109 5.331 0.000
>
>__
><mailto:R-help@r-project.org>R-help@r-project.org mailing list
><https://stat.ethz.ch/mailman/listinfo/r-help>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide 
><http://www.R-project.org/posting-guide.html>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>

[[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] Multrix-vector multiplication

2015-08-22 Thread Steven Yen
I had trouble with matrix multiplication when a matrix reduces to a
vector.  In the following, lines 1 and 2 work when matrices u and a are
both of order 2.
Lines 3 and 5 do not work (message is matrix not conformable) when u is (T
x 1) and a is (1 x 2) and This causes a problem for users of other matrix
languages such as Gauss and MATLAB.
Inserting line 4 makes it work, which is annoying. But, is it proper/safe
to make it work by inserting line 4? Other approaches?
Thank you!

1 a<-solve(s22)%*%s21 # (2 x 2) <- (2 x 2) %*% (2 x 2)
2 uc<-u%*%v$a # (T x 2) <- (T x 2) %*% (2 x 2)

3 a<-solve(s22)%*%s21 # (1 x 2) <- (1 x 1) %*% (1 x 2)
4 a<-as.matrix(a) # This line makes it work. OK? Other approaches?
5 uc<-u%*%v$a # (T x 1) %*% (1 x 2)

[[alternative HTML version deleted]]

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


[R] Calling external file

2015-10-03 Thread Steven Yen
Hi
I collect a list of calls to a package in a function (routine) so that I do
not need to repeat the same sets of codes from program to program. In the
following, inserting the function into each program works. Then, I place
the function elsewhere in a PC folder, and include in with a 'source'
command. This does not work; it complains about a function (fn below) not
defined.
Compiling the function into a library file does not work either (with all
sorts of error messages saying this and that not defined).
Steven Yen

fn <- function(beta){
  f<-... (define f in this routine)
return(f)
}

max.calls<-function(method){
# ***
# Call maxLike with alternative algorithms
# ***
  many<-c("NR","BFGS","BFGSR","BHHH","SANN","CG","NM")
  if (method %in% many){
ML<-maxLik(logLik=fn,grad=NULL,hess=NULL,start,
   method,print.level,constraints=NULL, ...)}
return(ML)
}
# This works:
ML<-max.calls(method)

# Does not work:
source("z:\\R\\yenlib\\lib\\max.calls.R")
ML<-max.calls(method)

Error: object 'fn' not found

[[alternative HTML version deleted]]

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


Re: [R] Calling external file

2015-10-03 Thread Steven Yen
Thanks Michael. I am a new hand with R so this is over my head. I will
slowly explore all options suggested but for now I'd glad to get one option
to work. How do you 'declare the function into the routine I am sourcing,
i.e., max.calls? Is there something I can read?

On Sat, Oct 3, 2015 at 8:47 AM, Michael Dewey 
wrote:

> You did put the declaration of the function fn into the file you are
> sourcing, didn't you?
>
> If it were me I would
> 1 - make fn a parameter of max.calls
> 2 - use the ellipsis ... so I could pass other arguments in to MaxLike
> 3 - fix the errors I got from making it a package. It does not lie when it
> tells you things are undefined and, who knows, they may need to be defined.
>
>
> On 03/10/2015 09:47, Steven Yen wrote:
>
>> Hi
>> I collect a list of calls to a package in a function (routine) so that I
>> do
>> not need to repeat the same sets of codes from program to program. In the
>> following, inserting the function into each program works. Then, I place
>> the function elsewhere in a PC folder, and include in with a 'source'
>> command. This does not work; it complains about a function (fn below) not
>> defined.
>> Compiling the function into a library file does not work either (with all
>> sorts of error messages saying this and that not defined).
>> Steven Yen
>>
>> fn <- function(beta){
>>f<-... (define f in this routine)
>> return(f)
>> }
>>
>> max.calls<-function(method){
>> # ***
>> # Call maxLike with alternative algorithms
>> # ***
>>many<-c("NR","BFGS","BFGSR","BHHH","SANN","CG","NM")
>>if (method %in% many){
>>  ML<-maxLik(logLik=fn,grad=NULL,hess=NULL,start,
>> method,print.level,constraints=NULL, ...)}
>> return(ML)
>> }
>> # This works:
>> ML<-max.calls(method)
>>
>> # Does not work:
>> source("z:\\R\\yenlib\\lib\\max.calls.R")
>> ML<-max.calls(method)
>>
>> Error: object 'fn' not found
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>

[[alternative HTML version deleted]]

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


Re: [R] Calling external file

2015-10-03 Thread Steven Yen
Thanks Bill. Simplified content of max.calls.R (with repeated calls to
maxLik removed) are shown below in the message. No, fn does not exist in
the environment. I call a routine (say probit.R compiled into a library) to
use maxLik. Inside this routine,
1. In probit.R. likelihood function is defined yet in another nested
routine;
2. Function "max.calls" is also nested in that  probit.R;
Then, a call to max.calls works.

What I am trying to accomplish is, instead of inserting the identical
function (or set of lines) in every routine like probit.R, I like to either
compile max.calls.R or source it from inside probit.R. Thanks.


On Sat, Oct 3, 2015 at 4:47 AM, Steven Yen  wrote:

> Hi
> I collect a list of calls to a package in a function (routine) so that I
> do not need to repeat the same sets of codes from program to program. In
> the following, inserting the function into each program works. Then, I
> place the function elsewhere in a PC folder, and include in with a 'source'
> command. This does not work; it complains about a function (fn below) not
> defined.
> Compiling the function into a library file does not work either (with all
> sorts of error messages saying this and that not defined).
> Steven Yen
>
> fn <- function(beta){
>   f<-... (define f in this routine)
> return(f)
> }
>
> max.calls<-function(method){
> # ***
> # Call maxLike with alternative algorithms
> # ***
>   many<-c("NR","BFGS","BFGSR","BHHH","SANN","CG","NM")
>   if (method %in% many){
> ML<-maxLik(logLik=fn,grad=NULL,hess=NULL,start,
>method,print.level,constraints=NULL, ...)}
> return(ML)
> }
> # This works:
> ML<-max.calls(method)
>
> # Does not work:
> source("z:\\R\\yenlib\\lib\\max.calls.R")
> ML<-max.calls(method)
>
> Error: object 'fn' not found
>
>

[[alternative HTML version deleted]]

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


[R] Construct a lower-triangular matrix

2015-10-09 Thread Steven Yen
Dear
How do you construct a lower triangular matrix from a vector.

I want to make vector

a <- 1:10

into a triangular matrix

1 0 0  0
2 3 0  0
4 5 6  0
7 8 9 10

Thank you!

[[alternative HTML version deleted]]

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


[R] Constructing a symmetric matrix using library(corpcor)

2016-02-17 Thread Steven Yen
Hello

I am constructing a symmetric matrix with library "corpcor". In the
codes below, I am able to construct a symmetric matrix of order 3 and
4. However, the 5 x 5 matrix does not seem right? Help?

Thanks.


> library(corpcor)> r  <- 1:3> rr <- vec2sm(r, diag = F)> rr <- 
> rr[upper.tri(rr)]> r  <- vec2sm(rr, diag = F); diag(r) <- 1> r [,1] [,2] 
> [,3]
[1,]112
[2,]113
[3,]231> > r  <- 1:6> rr <- vec2sm(r, diag = F)> rr <-
rr[upper.tri(rr)]> r  <- vec2sm(rr, diag = F); diag(r) <- 1> r
[,1] [,2] [,3] [,4]
[1,]1124
[2,]1135
[3,]2316
[4,]4561> > r  <- 1:10> rr <- vec2sm(r, diag = F)> rr
<- rr[upper.tri(rr)]> r  <- vec2sm(rr, diag = F); diag(r) <- 1> r
[,1] [,2] [,3] [,4] [,5]
[1,]11253
[2,]11684
[3,]26179
[4,]5871   10
[5,]349   101

>

[[alternative HTML version deleted]]

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


[R] Constructing a symmetric matrix with library(corpcor)

2016-02-21 Thread Steven Yen
I like to compose a symmetric matrix in the pattern as shown below (for 3 x
3 and 4 x 4). For a symmetric matrix of order 5, the result does not seem
right. Help? It is possible to write a two-level do loop for the task, but
I suppose that is less efficient.

> library(corpcor)> r  <- 1:3; r[1] 1 2 3> rr <- vec2sm(r, diag = F); rr 
> [,1] [,2] [,3]
[1,]   NA12
[2,]1   NA3
[3,]23   NA> rr <- rr[upper.tri(rr)]; rr[1] 1 2 3> r  <-
vec2sm(rr, diag = F); diag(r) <- 1; r [,1] [,2] [,3]
[1,]112
[2,]113
[3,]231> r  <- 1:6; r[1] 1 2 3 4 5 6> rr <- vec2sm(r, diag
= F); rr [,1] [,2] [,3] [,4]
[1,]   NA123
[2,]1   NA45
[3,]24   NA6
[4,]356   NA> rr <- rr[upper.tri(rr)]; rr[1] 1 2 4 3 5 6>
r  <- vec2sm(rr, diag = F); diag(r) <- 1; r [,1] [,2] [,3] [,4]
[1,]1124
[2,]1135
[3,]2316
[4,]4561> r  <- 1:10; r [1]  1  2  3  4  5  6  7  8  9
10> rr <- vec2sm(r, diag = F); rr [,1] [,2] [,3] [,4] [,5]
[1,]   NA1234
[2,]1   NA567
[3,]25   NA89
[4,]368   NA   10
[5,]479   10   NA> rr <- rr[upper.tri(rr)]; rr [1]  1  2
5  3  6  8  4  7  9 10> r  <- vec2sm(rr, diag = F); diag(r) <- 1; r
 [,1] [,2] [,3] [,4] [,5]
[1,]11253
[2,]11684
[3,]26179
[4,]5871   10
[5,]349   101


(Doesn't seem right).
This is what I need:

 [,1] [,2] [,3] [,4] [,5]
[1,]11247
[2,]11358
[3,]23169
[4,]4561   10
[5,]789   101

>

[[alternative HTML version deleted]]

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


[R] Retrieving response variable in the probit

2016-05-02 Thread Steven Yen
Can anyone tell me how to retrieve the response (dependent) variable
from a probit regression object (as much as model.matrix(obj)
retrieves the data matrix). Below is a self-runnable set of codes.
Thank you!

library(sampleSelection)
data<-read.csv("https://dl.dropboxusercontent.com/u/220037024/Yen/data/pta.csv";)
eq1<-d~sex+age+educ
p1<-probit(eq1,data=data)
summary(p1)
attributes(p1)

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


[R] grep command

2016-05-03 Thread Steven Yen
Dear all
In the grep command below, is there a way to identify only "age" and
not "age2"? Thanks.

> x<-c("abc","def","rst","xyz","age","age2")
> x
[1] "abc"  "def"  "rst"  "xyz"  "age"  "age2"
> grep("age2",x)
[1] 6
> grep("age",x) # I need to grab "age" only, not "age2"
[1] 5 6

Also, I post message to r-help@r-project.org and that's subject to
approval by the list moderator. Am I sending it to the wrong address?

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


[R] Grep command

2016-05-03 Thread Steven Yen
Dear all
In the grep command below, is there a way to identify only "age" and
not "age2"? In other words, I like to greb "age" and "age2"
separately, one at a time. Thanks.

x<-c("abc","def","rst","xyz","age","age2")
x

[1] "abc"  "def"  "rst"  "xyz"  "age"  "age2"

grep("age2",x)

[1] 6

grep("age",x) # I need to grab "age" only, not "age2"

[1] 5 6

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


[R] Fwd: Grep command

2016-05-03 Thread Steven Yen
Hi all
Both \\b and $ do the job. Thanks.

> x<-c("abc","def","rst","xyz","age","age2")
> x
[1] "abc"  "def"  "rst"  "xyz"  "age"  "age2"
> grep("age2\\b",x)
[1] 6
> grep("age\\b",x)
[1] 5
> grep("age2$",x)
[1] 6
> grep("age$",x)
[1]


From: Jim Lemon 
Date: Wed, May 4, 2016 at 2:19 AM
Subject: Re: [R] Grep command
To: Steven Yen 


Does not:

abcplus<-c("zxzxabc","zxzxabc2rst")
grepl("abc",abcplus) & nchar(abcplus)<8

do the job?

Jim

On Wed, May 4, 2016 at 4:15 PM, Steven Yen  wrote:
> Thanks but no.
> There will be time when I have
>
> zxzxabc and zxzxabc2rst
>
> and I don't like to grep with the string "abc" and end up with both.
>
>
> On Wed, May 4, 2016 at 2:02 AM, Jim Lemon  wrote:
>> Hi Steven,
>> If this is just a one-off, you could do this:
>>
>> grepl("age",x) & nchar(x)<4
>>
>> returning a logical vector containing TRUE for "age" but not "age2"
>>
>> Jim
>>
>>
>> On Wed, May 4, 2016 at 3:45 PM, Steven Yen  wrote:
>>> Dear all
>>> In the grep command below, is there a way to identify only "age" and
>>> not "age2"? In other words, I like to greb "age" and "age2"
>>> separately, one at a time. Thanks.
>>>
>>> x<-c("abc","def","rst","xyz","age","age2")
>>> x
>>>
>>> [1] "abc"  "def"  "rst"  "xyz"  "age"  "age2"
>>>
>>> grep("age2",x)
>>>
>>> [1] 6
>>>
>>> grep("age",x) # I need to grab "age" only, not "age2"
>>>
>>> [1] 5 6
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.

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


[R] gls procedure in nlme

2017-01-04 Thread Steven Yen
I need help with gls{nlme}.
Specifically, I am estimating an equation with AR(1) using 
maximum-likelihood. I am not understanding the correlationoption below. 
Help appreciated.

===
library(nlme)
eq1<-log(chnimp)~log(chempi)+log(gas)+log(rtwex)+befile6+
  affile6+afdec6
reg1<-gls(eq1,data=mydata,correlation=corAR1(),method="ML",verbose=T)


[[alternative HTML version deleted]]

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


[R] Echos for comment line (with #)

2017-02-11 Thread Steven Yen
I need help with what may be a simple option in R (or Rstudio)--to 
receive an echo of a comment line.

Running the following two-line script in plain R,

# adding
1+2

I did get the echo:

 > # adding
 > 1+2
[1] 3
 >

However, running the same lines in RStudio, the comment line does not 
appear in output:

 > 1+2
[1] 3
 >

Please help. Thanks.



[[alternative HTML version deleted]]

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


[R] Calling a procedure

2020-09-20 Thread Steven Yen
Can someone tell me a proper call to a procedure, in this case, pnorm. 
In what follows, I had expected a = b, but they are not equal. What are 
wrong with first call and second call? Thank you!


try<-function(x,log.p=FALSE){
a<-pnorm(x,log.p)   # first call
b<-pnorm(x,log.p=log.p) # second call
list(a=a,b=b)
}

try(x=1.2,log.p=TRUE)$a
try(x=1.2,log.p=TRUE)$b

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


Re: [R] Calling a procedure

2020-09-20 Thread Steven Yen
Thanks. So, to be safe, always a good idea to give the argument, e.g., 
q=1.96, log.p=FALSE, skipping mean=0 and sd=1 if not needed. Thanks.

pnorm(q=1.96, log.p = FALSE)

On 2020/9/20 下午 06:36, Rui Barradas wrote:
> Hello,
>
> You are making a confusion between
>
> 1. the formal argument log.p
> 2. the variable log.p
>
> In the function body, log.p is a variable that exists in the 
> function's frame, not the formal argument of pnorm.
> The first and the 3rd calls that follow output the same value.
>
> try(x = 1.2, log.p = TRUE)$a
> try(x = 1.2, log.p = TRUE)$b
> try(x = 1.2, 1)$a
>
> This is because in the function
>
>   a<-pnorm(x,log.p)   # first call
>
> passes log.p as the *second* argument, not as a value for pnorm's 
> formal argument log.p. Unless when named, the arguments are passed in 
> the order they appear in the function's definition:
>
> pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
>
> and that becomes
>
>   a<-pnorm(x,TRUE)   # first call
>   a<-pnorm(x,1)  # first call, coerced to numeric.
>
>
> Let me give another example. In the function that follows the default 
> is z = FALSE.
>
> In the first call the name z is not the name of the argument, it's the 
> name of a variable that exists in the .GlobalEnv.
>
> In the second call, z = z assign the formal argument z the value of 
> the variable z.
>
>
> f <- function(x, y = 0, z = FALSE){
>   a <- x
>   b <- y
>   d <- z
>   list(a = a, b = b, d = d)
> }
> z <- 2
> f(1, z)
> f(1, z = z)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 11:11 de 20/09/20, Steven Yen escreveu:
>> Can someone tell me a proper call to a procedure, in this case, 
>> pnorm. In what follows, I had expected a = b, but they are not equal. 
>> What are wrong with first call and second call? Thank you!
>>
>> try<-function(x,log.p=FALSE){
>> a<-pnorm(x,log.p)   # first call
>> b<-pnorm(x,log.p=log.p) # second call
>> list(a=a,b=b)
>> }
>>
>> try(x=1.2,log.p=TRUE)$a
>> try(x=1.2,log.p=TRUE)$b
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


Re: [R] Calling a procedure

2020-09-20 Thread Steven Yen
Thanks to all for educating me about procedures and argument. Those were 
very helpful!!

On 2020/9/21 上午 12:26, Bert Gunter wrote:
> Argument passing is fundamental, even more so when you write your own 
> functions, which any half-serious R user will want to do. What has 
> heretofore been discussed in this thread is not the whole story (e.g. 
> there are ... arguments and functions as binary operators, among other 
> things).  See section 10 of the "Introduction to R" document that 
> ships with R or any other decent R tutorial of your choice. The R 
> language definition is the definitive reference (section 4 especially 
> for this).
>
> All imo of course.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along 
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Sep 20, 2020 at 8:57 AM Mark Leeds  <mailto:marklee...@gmail.com>> wrote:
>
> Hi Steven: Rui's detailed explanation was great.  The way I think
> of it is,
> if you don't
> want to send the  variables in with the same  order as the formal
>     arguments, then you
> better  name them as you send them in.
>
>
>
>
>
> On Sun, Sep 20, 2020 at 7:23 AM Steven Yen  <mailto:st...@ntu.edu.tw>> wrote:
>
> > Thanks. So, to be safe, always a good idea to give the argument,
> e.g.,
> > q=1.96, log.p=FALSE, skipping mean=0 and sd=1 if not needed. Thanks.
> >
> > pnorm(q=1.96, log.p = FALSE)
> >
> > On 2020/9/20 下午 06:36, Rui Barradas wrote:
> > > Hello,
> > >
> > > You are making a confusion between
> > >
> > > 1. the formal argument log.p
> > > 2. the variable log.p
> > >
> > > In the function body, log.p is a variable that exists in the
> > > function's frame, not the formal argument of pnorm.
> > > The first and the 3rd calls that follow output the same value.
> > >
> > > try(x = 1.2, log.p = TRUE)$a
> > > try(x = 1.2, log.p = TRUE)$b
> > > try(x = 1.2, 1)$a
> > >
> > > This is because in the function
> > >
> > >   a<-pnorm(x,log.p)       # first call
> > >
> > > passes log.p as the *second* argument, not as a value for pnorm's
> > > formal argument log.p. Unless when named, the arguments are
> passed in
> > > the order they appear in the function's definition:
> > >
> > > pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
> > >
> > > and that becomes
> > >
> > >   a<-pnorm(x,TRUE)       # first call
> > >   a<-pnorm(x,1)          # first call, coerced to numeric.
> > >
> > >
> > > Let me give another example. In the function that follows the
> default
> > > is z = FALSE.
> > >
> > > In the first call the name z is not the name of the argument,
>     it's the
> > > name of a variable that exists in the .GlobalEnv.
> > >
> > > In the second call, z = z assign the formal argument z the
> value of
> > > the variable z.
> > >
> > >
> > > f <- function(x, y = 0, z = FALSE){
> > >   a <- x
> > >   b <- y
> > >   d <- z
> > >   list(a = a, b = b, d = d)
> > > }
> > > z <- 2
> > > f(1, z)
> > > f(1, z = z)
> > >
> > >
> > > Hope this helps,
> > >
> > > Rui Barradas
> > >
> > > Às 11:11 de 20/09/20, Steven Yen escreveu:
> > >> Can someone tell me a proper call to a procedure, in this case,
> > >> pnorm. In what follows, I had expected a = b, but they are
> not equal.
> > >> What are wrong with first call and second call? Thank you!
> > >>
> > >> try<-function(x,log.p=FALSE){
> > >> a<-pnorm(x,log.p)       # first call
> > >> b<-pnorm(x,log.p=log.p) # second call
> > >> list(a=a,b=b)
> > >> }
> > >>
> > >> try(x=1.2,log.p=TRUE)$a
> > >> try(x=1.2,log.p=TRUE)$b
> > >>
> > >> __
> > >> R-help@r-project.org <mailto:R-he

[R] unable to access index for repository...

2020-10-05 Thread Steven Yen
I had to install/use an older version of (R-3.0.3) for a reason. While 
installing a package from CRAN (either in RStudio or R), I received the 
following warning message saying unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0. See message below. In 
this case, I tried to install "aod". The install nevertheless went 
through, as confirmed by the library statement (I did not try to use 
it). Any idea? Thank you.

=

Warning: unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0 Warning: unable to 
access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0 > 
install.packages("aod") Warning in install.packages : unable to access 
index for repository http://cran.rstudio.com/bin/windows/contrib/3.0 
Warning in install.packages : unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0 package ‘aod’ is 
available as a source package but not as a binary Warning in 
install.packages : package ‘aod’ is not available (for R version 3.0.3) 
 > library(aod)


[[alternative HTML version deleted]]

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


Re: [R] unable to access index for repository...

2020-10-05 Thread Steven Yen
Thanks for the help. I do update to the latest R-4.0.2. As I said, for 
reasons that's hard to explain, some of my tasks are better handled with 
an older version of R, in this case R-3.0.3. Please just help me install 
packages successfully with this older version of R.

I ran the following line but obviously was not getting it across.

=

> install.packages("aod",repos='https://cran-archive.r-project.org/bin/windows/contrib/3.0/')
>   Warning in install.packages : unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0 Warning in 
install.packages : unable to access index for repository 
https://cran-archive.r-project.org/bin/windows/contrib/3.0/bin/windows/contrib/3.0
 
Warning in install.packages : package ‘aod’ is not available (for R 
version 3.0.3)

On 2020/10/5 下午 04:12, Uwe Ligges wrote:
> From
>
> ../ReadMe
> in the mentioned web resource:
>
> "Packages for R >= 1.7.0 and R < 3.2.0 are available from
> https://cran-archive.r-project.org/bin/windows/contrib/";
>
> We do not hold binaries of several year old versions of R on CRAN.
>
> Note that R 3.0.0 is 7 years old. You shoudl realy consider to update 
> to 4.0.2.
>
> Best,
> Uwe Ligges
>
>
>
>
> On 05.10.2020 09:56, Steven Yen wrote:
>> I had to install/use an older version of (R-3.0.3) for a reason. While
>> installing a package from CRAN (either in RStudio or R), I received the
>> following warning message saying unable to access index for repository
>> http://cran.rstudio.com/bin/windows/contrib/3.0. See message below. In
>> this case, I tried to install "aod". The install nevertheless went
>> through, as confirmed by the library statement (I did not try to use
>> it). Any idea? Thank you.
>>
>> =
>>
>> Warning: unable to access index for repository
>> http://cran.rstudio.com/bin/windows/contrib/3.0 Warning: unable to
>> access index for repository
>> http://cran.rstudio.com/bin/windows/contrib/3.0 >
>> install.packages("aod") Warning in install.packages : unable to access
>> index for repository http://cran.rstudio.com/bin/windows/contrib/3.0
>> Warning in install.packages : unable to access index for repository
>> http://cran.rstudio.com/bin/windows/contrib/3.0 package ‘aod’ is
>> available as a source package but not as a binary Warning in
>> install.packages : package ‘aod’ is not available (for R version 3.0.3)
>>   > library(aod)
>>
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>

[[alternative HTML version deleted]]

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


Re: [R] unable to access index for repository...

2020-10-05 Thread Steven Yen
Thanks. I did as suggested but still received a warning, though the 
installation went through. Anything I could do to install without the 
warning message.


What is the contrib.url argument?

> install.packages("aod",repos='https://cran-archive.r-project.org')
Warning in install.packages :
  unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0
trying URL 
'https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip'

Content type 'application/zip' length 225712 bytes (220 Kb)
opened URL
downloaded 220 Kb

package ‘aod’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\Rtmp46p9a3\downloaded_packages
>

On 2020/10/5 下午 04:58, Uwe Ligges wrote:

Then you'd rather need

install.packages("aod",repos='https://cran-archive.r-project.org')

or use the contrib.url argument.

Best,
Uwe Ligges


On 05.10.2020 10:47, Steven Yen wrote:
Thanks for the help. I do update to the latest R-4.0.2. As I said, 
for reasons that's hard to explain, some of my tasks are better 
handled with an older version of R, in this case R-3.0.3. Please just 
help me install packages successfully with this older version of R.


I ran the following line but obviously was not getting it across.

=

install.packages("aod",repos='https://cran-archive.r-project.org/bin/windows/contrib/3.0/') 
Warning in 
install.packages : unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0 Warning in 
install.packages : unable to access index for repository 
https://cran-archive.r-project.org/bin/windows/contrib/3.0/bin/windows/contrib/3.0 
Warning in install.packages : package ‘aod’ is not available (for R 
version 3.0.3)


On 2020/10/5 下午 04:12, Uwe Ligges wrote:

From

../ReadMe
in the mentioned web resource:

"Packages for R >= 1.7.0 and R < 3.2.0 are available from
https://cran-archive.r-project.org/bin/windows/contrib/";

We do not hold binaries of several year old versions of R on CRAN.

Note that R 3.0.0 is 7 years old. You shoudl realy consider to 
update to 4.0.2.


Best,
Uwe Ligges




On 05.10.2020 09:56, Steven Yen wrote:

I had to install/use an older version of (R-3.0.3) for a reason. While
installing a package from CRAN (either in RStudio or R), I received 
the

following warning message saying unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0. See message below. In
this case, I tried to install "aod". The install nevertheless went
through, as confirmed by the library statement (I did not try to use
it). Any idea? Thank you.

=

Warning: unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0 Warning: unable to
access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0 >
install.packages("aod") Warning in install.packages : unable to access
index for repository http://cran.rstudio.com/bin/windows/contrib/3.0
Warning in install.packages : unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0 package ‘aod’ is
available as a source package but not as a binary Warning in
install.packages : package ‘aod’ is not available (for R version 
3.0.3)

  > library(aod)


[[alternative HTML version deleted]]

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

and provide commented, minimal, self-contained, reproducible code.



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


Re: [R] unable to access index for repository...

2020-10-08 Thread Steven Yen
Thanks. You gentlemen please tell me what this means. In R (outside of 
RStudio) I ran:

install.packages("aod")

Received a warning (and installation did not seem to go through).

Then I tried

install.packages("aod",repos='https://cran-archive.r-project.org')

Received a warning but it went on to try

https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip

and it worked. See log below.

I expect to continue to use R-3.0.3 for a while and I very much like 
this to become a routine. Thank you all.

Steven Yen

 > install.packages("aod")
Warning in install.packages :
   unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0
Warning in install.packages :
   unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0

    package ‘aod’ is available as a source package but not as a binary

Warning in install.packages :
   package ‘aod’ is not available (for R version 3.0.3)
 > install.packages("aod",repos='https://cran-archive.r-project.org')
Warning in install.packages :
   unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0
trying URL 
'https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip'
Content type 'application/zip' length 225712 bytes (220 Kb)
opened URL
downloaded 220 Kb

package ‘aod’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\RtmpY7t6Ll\downloaded_packages

On 2020/10/8 下午 10:52, Duncan Murdoch wrote:
> Just remembered:  RStudio runs its own wrapper around 
> install.packages().  Steven, you should try doing the install from 
> outside of RStudio, and see if it makes a difference.
>
> Duncan Murdoch
>
> On 08/10/2020 9:59 a.m., Duncan Murdoch wrote:
>> He didn't specify the RStudio repos, though it's probably implicitly
>> specified in getOption("repos").  I wonder why install.packages() is
>> looking there, when repos is given explicitly?
>>
>> On 08/10/2020 8:54 a.m., Uwe Ligges wrote:
>>> Drop the RStudio repos.
>>>
>>> Best,
>>> Uwe Ligges
>>>
>>> On 05.10.2020 11:10, Steven Yen wrote:
>>>> Thanks. I did as suggested but still received a warning, though the
>>>> installation went through. Anything I could do to install without the
>>>> warning message.
>>>>
>>>> What is the contrib.url argument?
>>>>
>>>>    > 
>>>> install.packages("aod",repos='https://cran-archive.r-project.org')
>>>> Warning in install.packages :
>>>>      unable to access index for repository
>>>> http://cran.rstudio.com/bin/windows/contrib/3.0
>>>> trying URL
>>>> 'https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip' 
>>>>
>>>> Content type 'application/zip' length 225712 bytes (220 Kb)
>>>> opened URL
>>>> downloaded 220 Kb
>>>>
>>>> package ‘aod’ successfully unpacked and MD5 sums checked
>>>>
>>>> The downloaded binary packages are in
>>>> C:\Users\USER\AppData\Local\Temp\Rtmp46p9a3\downloaded_packages
>>>>    >
>>>>
>>>> On 2020/10/5 下午 04:58, Uwe Ligges wrote:
>>>>> Then you'd rather need
>>>>>
>>>>> install.packages("aod",repos='https://cran-archive.r-project.org')
>>>>>
>>>>> or use the contrib.url argument.
>>>>>
>>>>> Best,
>>>>> Uwe Ligges
>>>>>
>>>>>
>>>>> On 05.10.2020 10:47, Steven Yen wrote:
>>>>>> Thanks for the help. I do update to the latest R-4.0.2. As I said,
>>>>>> for reasons that's hard to explain, some of my tasks are better
>>>>>> handled with an older version of R, in this case R-3.0.3. Please 
>>>>>> just
>>>>>> help me install packages successfully with this older version of R.
>>>>>>
>>>>>> I ran the following line but obviously was not getting it across.
>>>>>>
>>>>>> =
>>>>>>
>>>>>>> install.packages("aod",repos='https://cran-archive.r-project.org/bin/windows/contrib/3.0/')
>>>>>>>  
>>>>>>>
>>>>>>> Warning in
>>>>>> install.packages : unable to access index for repository
>>>>>> http://cran.rstudio.com/bin/windows/contri

Re: [R] unable to access index for repository...

2020-10-08 Thread Steven Yen
Sorry Gentlemen and all. Now this is becoming a joke (to me). I repeated 
what I did earlier, with and without the option to set repos suggested 
by Duncan. Now it does not work. I wonder whether it is dependent on the 
mirror I chose, but I do not remember the one I chose earlier when it work.


I need your help, gentlemen, as I need to use R-3.0.3 for my task.

> options(repos="https://cran-archive.r-project.org";)
> chooseCRANmirror()
> install.packages("aod")
Warning: unable to access index for repository 
https://cran-archive.r-project.org/bin/windows/contrib/3.0
Warning: unable to access index for repository 
http://lib.stat.cmu.edu/R/CRAN/bin/windows/contrib/3.0


   package ‘aod’ is available as a source package but not as a binary

Warning message:
package ‘aod’ is not available (for R version 3.0.3)
> install.packages("aod",repos='https://cran-archive.r-project.org')
Warning: unable to access index for repository 
https://cran-archive.r-project.org/bin/windows/contrib/3.0

Warning message:
package ‘aod’ is not available (for R version 3.0.3)

On 2020/10/9 上午 12:02, Duncan Murdoch wrote:

Okay, so it's not an RStudio issue.  However, I'd guess setting

  options(repos = "https://cran-archive.r-project.org";)

at the start of your session could make everything work.  (I'm 
guessing you currently have it set to "http://cran.rstudio.com";, which 
is the source of the last warning below, probably due to an R bug.  
But since you're using an obsolete version of R, it shouldn't surprise 
you that it has bugs that nobody else is seeing.)


Duncan Murdoch

On 08/10/2020 11:54 a.m., Steven Yen wrote:
Thanks. You gentlemen please tell me what this means. In R (outside 
of RStudio) I ran:


install.packages("aod")

Received a warning (and installation did not seem to go through).

Then I tried

install.packages("aod",repos='https://cran-archive.r-project.org')

Received a warning but it went on to try

https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip

and it worked. See log below.

I expect to continue to use R-3.0.3 for a while and I very much like 
this to become a routine. Thank you all.


Steven Yen

 > install.packages("aod")
Warning in install.packages :
   unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0

Warning in install.packages :
   unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0


    package ‘aod’ is available as a source package but not as a binary

Warning in install.packages :
   package ‘aod’ is not available (for R version 3.0.3)
 > install.packages("aod",repos='https://cran-archive.r-project.org')
Warning in install.packages :
   unable to access index for repository 
http://cran.rstudio.com/bin/windows/contrib/3.0
trying URL 
'https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip'

Content type 'application/zip' length 225712 bytes (220 Kb)
opened URL
downloaded 220 Kb

package ‘aod’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\RtmpY7t6Ll\downloaded_packages

On 2020/10/8 下午 10:52, Duncan Murdoch wrote:
Just remembered:  RStudio runs its own wrapper around 
install.packages().  Steven, you should try doing the install from 
outside of RStudio, and see if it makes a difference.


Duncan Murdoch

On 08/10/2020 9:59 a.m., Duncan Murdoch wrote:

He didn't specify the RStudio repos, though it's probably implicitly
specified in getOption("repos").  I wonder why install.packages() is
looking there, when repos is given explicitly?

On 08/10/2020 8:54 a.m., Uwe Ligges wrote:

Drop the RStudio repos.

Best,
Uwe Ligges

On 05.10.2020 11:10, Steven Yen wrote:

Thanks. I did as suggested but still received a warning, though the
installation went through. Anything I could do to install without 
the

warning message.

What is the contrib.url argument?

   > 
install.packages("aod",repos='https://cran-archive.r-project.org')

Warning in install.packages :
     unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0
trying URL
'https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip' 


Content type 'application/zip' length 225712 bytes (220 Kb)
opened URL
downloaded 220 Kb

package ‘aod’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\Rtmp46p9a3\downloaded_packages
   >

On 2020/10/5 下午 04:58, Uwe Ligges wrote:

Then you'd rather need

install.packages("aod",repos='https://cran-archive.r-project.org')

or use the contrib.url argument.

Best,
Uwe Ligges


On 05.10.2020 10:47, Steven Yen wrote:

Thanks for the help. I do update to the lates

Re: [R] unable to access index for repository...

2020-10-08 Thread Steven Yen
Thanks for the help. I have a reason to continue with R-3.0.3. I used 
maxLik to estimate econometric models and some of them are better 
handled with R-3.0.3 (but not later)a sad reality I do not like.


Here is what I did. I downloaded

https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip

and installed the zip file, which worked in both RStudio and R (without 
RStudio).


In RStudio, I go Tools -> Install packages -> Install from -> (Choose 
zip) -> (Browse to the zip file)


IN R, I go Packages -> Install packages from local file(s) -> (Browse to 
the zip file)...


Below is the command line generated and the prompt.

> install.packages("C:/Users/USER/Downloads/aod_1.3.zip", repos = NULL, 
type = "win.binary")

package ‘aod’ successfully unpacked and MD5 sums checked

I will always be able to download the proper .zip file from CRAC 
Archive, right. So, this will always work for me? Thank you all !! If 
there are more direct options that work, I would still be interested to 
know.


Steven Yen

On 2020/10/9 上午 12:49, Duncan Murdoch wrote:

Don't choose a mirror.  That will override the repos choice.

Do update R to a current version if you aren't able to debug this 
yourself.


Duncan Murdoch

On 08/10/2020 12:38 p.m., Steven Yen wrote:

Sorry Gentlemen and all. Now this is becoming a joke (to me). I repeated
what I did earlier, with and without the option to set repos suggested
by Duncan. Now it does not work. I wonder whether it is dependent on the
mirror I chose, but I do not remember the one I chose earlier when it 
work.


I need your help, gentlemen, as I need to use R-3.0.3 for my task.

  > options(repos="https://cran-archive.r-project.org";)
  > chooseCRANmirror()
  > install.packages("aod")
Warning: unable to access index for repository
https://cran-archive.r-project.org/bin/windows/contrib/3.0
Warning: unable to access index for repository
http://lib.stat.cmu.edu/R/CRAN/bin/windows/contrib/3.0

     package ‘aod’ is available as a source package but not as a binary

Warning message:
package ‘aod’ is not available (for R version 3.0.3)
  > install.packages("aod",repos='https://cran-archive.r-project.org')
Warning: unable to access index for repository
https://cran-archive.r-project.org/bin/windows/contrib/3.0
Warning message:
package ‘aod’ is not available (for R version 3.0.3)

On 2020/10/9 上午 12:02, Duncan Murdoch wrote:

Okay, so it's not an RStudio issue. However, I'd guess setting

   options(repos = "https://cran-archive.r-project.org";)

at the start of your session could make everything work.  (I'm
guessing you currently have it set to "http://cran.rstudio.com";, which
is the source of the last warning below, probably due to an R bug.
But since you're using an obsolete version of R, it shouldn't surprise
you that it has bugs that nobody else is seeing.)

Duncan Murdoch

On 08/10/2020 11:54 a.m., Steven Yen wrote:

Thanks. You gentlemen please tell me what this means. In R (outside
of RStudio) I ran:

install.packages("aod")

Received a warning (and installation did not seem to go through).

Then I tried

install.packages("aod",repos='https://cran-archive.r-project.org')

Received a warning but it went on to try

https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip

and it worked. See log below.

I expect to continue to use R-3.0.3 for a while and I very much like
this to become a routine. Thank you all.

Steven Yen

  > install.packages("aod")
Warning in install.packages :
    unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0
Warning in install.packages :
    unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0

 package ‘aod’ is available as a source package but not as a 
binary


Warning in install.packages :
    package ‘aod’ is not available (for R version 3.0.3)
  > install.packages("aod",repos='https://cran-archive.r-project.org')
Warning in install.packages :
    unable to access index for repository
http://cran.rstudio.com/bin/windows/contrib/3.0
trying URL
'https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip' 


Content type 'application/zip' length 225712 bytes (220 Kb)
opened URL
downloaded 220 Kb

package ‘aod’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\RtmpY7t6Ll\downloaded_packages

On 2020/10/8 下午 10:52, Duncan Murdoch wrote:

Just remembered:  RStudio runs its own wrapper around
install.packages().  Steven, you should try doing the install from
outside of RStudio, and see if it makes a difference.

Duncan Murdoch

On 08/10/2020 9:59 a.m., Duncan Murdoch wrote:

He didn't specify the RStudio repos, though it's probably implicit

Re: [R] [External] Re: unable to access index for repository...

2020-10-08 Thread Steven Yen
Hmm. You raised an interesting point. Actually I am not having problems with 
aod per se—-it is just a supporting package I need while using old R. The 
essential package I need, maxLik, simply works better under R-3.0.3, for reason 
I do not understand—specifically the numerical gradients of the likelihood 
function are not evaluated as accurately in newer versions of R in my 
experience, which is why I continue to use R-3.0.3. Because I use this older 
version of R, naturally I need to install other supporting packages such as aod 
and AER. 
Certainly, I will install the zip file of the older version of maxLik to the 
latest R and see what happens. Thank you.

I will install the new maxLik in old R, and old maxLik in new R, and see what 
happens.

Sent from my iPhone
Beware: My autocorrect is crazy

> On Oct 9, 2020, at 2:17 AM, Richard M. Heiberger  wrote:
> 
> I wonder if you are perhaps trying to solve the wrong problem.
> 
> If you like what the older version of the aod package does, but not
> the current version,
> then I think the solution is to propose an option to the aod
> maintainer that would restore your
> preferred algorithm into the current version, and then use the current R.
> 
> A less good, but possibly workable, option is to compile the old
> version of aod into the current R.
> 
>> On Thu, Oct 8, 2020 at 1:45 PM Jeff Newmiller  
>> wrote:
>> 
>> All support on this list is voluntary, and support for old versions of R is 
>> not even necessarily on-topic here which is why you keep getting nudged to 
>> upgrade. Your "need" for support for an old version is definitely not "our" 
>> problem, so I suggest you start looking for a consultant if this issue is 
>> that important to you. Such is the nature of volunteer-developed open source 
>> software... so support your local experts.
>> 
>>> On October 8, 2020 10:22:54 AM PDT, Steven Yen  wrote:
>>> Thanks for the help. I have a reason to continue with R-3.0.3. I used
>>> maxLik to estimate econometric models and some of them are better
>>> handled with R-3.0.3 (but not later)a sad reality I do not like.
>>> 
>>> Here is what I did. I downloaded
>>> 
>>> https://cran-archive.r-project.org/bin/windows/contrib/3.0/aod_1.3.zip
>>> 
>>> and installed the zip file, which worked in both RStudio and R (without
>>> 
>>> RStudio).
>>> 
>>> In RStudio, I go Tools -> Install packages -> Install from -> (Choose
>>> zip) -> (Browse to the zip file)
>>> 
>>> IN R, I go Packages -> Install packages from local file(s) -> (Browse
>>> to
>>> the zip file)...

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


Re: [R] [External] Re: unable to access index for repository...

2020-10-08 Thread Steven Yen
Oh Hi Arne,
You may recall we visited with this before. I do not believe the problem is 
algorithm specific. The algorithms I use the most often are BFGS and BHHH (or 
maxBFGS and maxBHHH). For simple econometric models such as probit, Tobit, and 
evening sample selection models, old and new versions of R work equally well (I 
write my own programs  and do not use ones from AER or sampleSekection). For 
more complicated models the newer R would converge with not-so-nice gradients 
while R-3.0.3 would still do nicely (good gradient). I use numerical graduent 
of course. I wonder whether numerical gradient routine were revised at the time 
of transition from R-3.0.3 to newer. Not knowing how different your versions of 
maxLik are between, I will try as I said I would, that is, use new version of 
maxLik from old R and vice versa, and see what happens.

Sent from my iPhone
Beware: My autocorrect is crazy

> On Oct 9, 2020, at 4:28 AM, Arne Henningsen  wrote:
> 
> Hi Steven
> 
> Which optimisation algorithms in maxLik work better under R-3.0.3 than
> under the current version of R?
> 
> /Arne
> 
>> On Thu, 8 Oct 2020 at 21:05, Steven Yen  wrote:
>> 
>> Hmm. You raised an interesting point. Actually I am not having problems with 
>> aod per se—-it is just a supporting package I need while using old R. The 
>> essential package I need, maxLik, simply works better under R-3.0.3, for 
>> reason I do not understand—specifically the numerical gradients of the 
>> likelihood function are not evaluated as accurately in newer versions of R 
>> in my experience, which is why I continue to use R-3.0.3. Because I use this 
>> older version of R, naturally I need to install other supporting packages 
>> such as aod and AER.
>> Certainly, I will install the zip file of the older version of maxLik to the 
>> latest R and see what happens. Thank you.
>> 
>> I will install the new maxLik in old R, and old maxLik in new R, and see 
>> what happens.
>> 
>> Sent from my iPhone
>> Beware: My autocorrect is crazy
>> 
>>>> On Oct 9, 2020, at 2:17 AM, Richard M. Heiberger  wrote:
>>> 
>>> I wonder if you are perhaps trying to solve the wrong problem.
>>> 
>>> If you like what the older version of the aod package does, but not
>>> the current version,
>>> then I think the solution is to propose an option to the aod
>>> maintainer that would restore your
>>> preferred algorithm into the current version, and then use the current R.
>>> 
>>> A less good, but possibly workable, option is to compile the old
>>> version of aod into the current R.

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


[R] Language environment

2020-11-17 Thread Steven Yen
In R, I was able to set the language environment by fixing the line

in file "C:\Program Files\R\R-4.0.3\etc\Rconsole", line 70 below, set 
language to EN:

language = EN

In RStudio, I am not able to do that, except to include the line

Sys.setenv(LANG="en");

in every one of my program file. That's too much work. Any idea? Thank you!




[[alternative HTML version deleted]]

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


Re: [R] Language environment

2020-11-17 Thread Steven Yen

Thanks. YES, include the line

Sys.setenv(LANG="en");

in my Rprofile file and it worked.

On 2020/11/18 上午 12:43, Jeff Newmiller wrote:

put it in your .Rprofile file. Read the R Installation and Administration 
Manusl for more info.

On November 17, 2020 5:00:06 AM PST, Steven Yen  wrote:

In R, I was able to set the language environment by fixing the line

in file "C:\Program Files\R\R-4.0.3\etc\Rconsole", line 70 below, set
language to EN:

language = EN

In RStudio, I am not able to do that, except to include the line

Sys.setenv(LANG="en");

in every one of my program file. That's too much work. Any idea? Thank
you!




[[alternative HTML version deleted]]

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


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


[R] Printing upon calling a function

2020-11-30 Thread Steven Yen
I hope I can get away without presenting a replicable set of codes 
because doing so would impose burdens.


I call a function which return a data frame, with the final line

return(out)

In one case the data frame gets printed (similar to a regression 
printout), with simply a call


me.probit(obj)

In another case with a similar function, I could not get the results 
printed and the only way to print is to do the following:


v<-me.oprobit(obj); v

This is a puzzle, and I hope to find some clues. Thanks to all.

My function looks like the following:

me.oprobit0 <- function(obj,mean=FALSE,vb.method,jindex=NA,
resampling=FALSE,ndraws=100,mc.method=1,times100=TRUE,
    Stata.mu=FALSE,testing=FALSE,digits=3){
...
return(out) # out is a data frame
}

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


Re: [R] Printing upon calling a function

2020-11-30 Thread Steven Yen
Thanks. I know, my point was on why I get something printed by simply 
doing line 1 below and at other occasions had to do line 2.


me.probit(obj)

v<-me.probit(obj); v

On 2020/11/30 下午 05:33, Jim Lemon wrote:

Hi Steven,
You seem to be assigning the result of me.oprobit(obj) to v instead of
printing it. By appending ";v" tp that command line, you implicitly
call "print".

Jim

On Mon, Nov 30, 2020 at 7:15 PM Steven Yen  wrote:

I hope I can get away without presenting a replicable set of codes
because doing so would impose burdens.

I call a function which return a data frame, with the final line

return(out)

In one case the data frame gets printed (similar to a regression
printout), with simply a call

me.probit(obj)

In another case with a similar function, I could not get the results
printed and the only way to print is to do the following:

v<-me.oprobit(obj); v

This is a puzzle, and I hope to find some clues. Thanks to all.

My function looks like the following:

me.oprobit0 <- function(obj,mean=FALSE,vb.method,jindex=NA,
resampling=FALSE,ndraws=100,mc.method=1,times100=TRUE,
  Stata.mu=FALSE,testing=FALSE,digits=3){
...
return(out) # out is a data frame
}

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


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


Re: [R] Printing upon calling a function

2020-11-30 Thread Steven Yen
No. I wrote the function so I am sure no "invisible" command was used. 
Strangely enough, compiling the function isto part of a package, results 
were NOT printed. Yes if I call the function during run, by preceding 
the call with a line that attach the source code:


source("A:/.../R/oprobit.R")

it did print. I do not understand.

On 2020/11/30 下午 06:41, Stefan Evert wrote:

On 30 Nov 2020, at 10:41, Steven Yen  wrote:

Thanks. I know, my point was on why I get something printed by simply doing 
line 1 below and at other occasions had to do line 2.

me.probit(obj)

That means the return value of me.probit() has been marked as invisible, so it 
won't auto-print.  You have to use an explicit print

print(me.probit(obj))

or use your work-around to convince R that you actually meant to print the 
output.

If you dig through the full code of me.probit(), you'll probably find the 
function invisible() called somewhere.

Best,
Stefan


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


Re: [R] Printing upon calling a function

2020-11-30 Thread Steven Yen
No, sorry. Line 1 below did not print for me and I had to go around and 
do line 2 to print:


me.probit(obj)

v<-me.probit(obj); v

A puzzle.


On 2020/11/30 下午 07:00, Duncan Murdoch wrote:

On 30/11/2020 5:41 a.m., Stefan Evert wrote:



On 30 Nov 2020, at 10:41, Steven Yen  wrote:

Thanks. I know, my point was on why I get something printed by 
simply doing line 1 below and at other occasions had to do line 2.


me.probit(obj)


That means the return value of me.probit() has been marked as 
invisible, so it won't auto-print.  You have to use an explicit print


print(me.probit(obj))

or use your work-around to convince R that you actually meant to 
print the output.


If you dig through the full code of me.probit(), you'll probably find 
the function invisible() called somewhere.




I think you misread his post.  "me.probit(obj)" on its own *did* 
print.  It was when he assigned it to a variable using "v <- 
me.probit(obj)" that it didn't.  Assignments are almost always 
invisible in R.


The other thing that people sometimes find confusing is that 
evaluating expressions that are visible are the top level doesn't make 
them print when they are nested in a block of code.  Usually this 
happens in a function, e.g. typing a number normally makes it visible, 
but


f <- function() {
  1
  2
}
f()

doesn't print 1, it only prints 2, and that happens because 2 is the 
return value of the function.


Duncan Murdoch


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


Re: [R] Printing upon calling a function

2020-11-30 Thread Steven Yen
Thanks to all. Presenting a large-scale, replicable example can be a 
burden to the READERs which was why I was reluctant.


I am embarrassed to report that after having to restart Windows after 
the system hang on something unrelated, the issue was resolved and 
printing was normal. I bet it had nothing to do with the R function. 
Problem caused by my Windows system memory or something. This sometimes 
yes, sometimes no situation makes i thard to pinpoint the problem and 
present a replicable example. I am OK now. Thanks to all.


On 2020/11/30 下午 07:21, Duncan Murdoch wrote:


By not posting a reproducible example, you're wasting everyone's time.

Duncan Murdoch

On 30/11/2020 6:06 a.m., Steven Yen wrote:

No, sorry. Line 1 below did not print for me and I had to go around and
do line 2 to print:

me.probit(obj)

v<-me.probit(obj); v

A puzzle.


On 2020/11/30 下午 07:00, Duncan Murdoch wrote:

On 30/11/2020 5:41 a.m., Stefan Evert wrote:



On 30 Nov 2020, at 10:41, Steven Yen  wrote:

Thanks. I know, my point was on why I get something printed by
simply doing line 1 below and at other occasions had to do line 2.

me.probit(obj)


That means the return value of me.probit() has been marked as
invisible, so it won't auto-print.  You have to use an explicit print

 print(me.probit(obj))

or use your work-around to convince R that you actually meant to
print the output.

If you dig through the full code of me.probit(), you'll probably find
the function invisible() called somewhere.



I think you misread his post.  "me.probit(obj)" on its own *did*
print.  It was when he assigned it to a variable using "v <-
me.probit(obj)" that it didn't.  Assignments are almost always
invisible in R.

The other thing that people sometimes find confusing is that
evaluating expressions that are visible are the top level doesn't make
them print when they are nested in a block of code.  Usually this
happens in a function, e.g. typing a number normally makes it visible,
but

f <- function() {
   1
   2
}
f()

doesn't print 1, it only prints 2, and that happens because 2 is the
return value of the function.

Duncan Murdoch




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


[R] Defining partial list of variables

2021-01-04 Thread Steven Yen
I constantly define variable lists from a data frame (e.g., to define a 
regression equation). Line 3 below does just that. Placing each variable 
name in quotation marks is too much work especially for a long list so I 
do that with line 4. Is there an easier way to accomplish thisto 
define a list of variable names containing "a","c","e"? Thank you!


> data<-as.data.frame(matrix(1:30,nrow=6))
> colnames(data)<-c("a","b","c","d","e"); data

  a  b  c  d  e
1 1  7 13 19 25
2 2  8 14 20 26
3 3  9 15 21 27
4 4 10 16 22 28
5 5 11 17 23 29
6 6 12 18 24 30
> x1<-c("a","c","e"); x1 # line 3
[1] "a" "c" "e"
> x2<-colnames(subset(data,select=c(a,c,e))); x2 # line 4

[1] "a" "c" "e"

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


  1   2   >