[R] knitr and tinytex

2023-04-26 Thread Steven T. Yen

Dear tinytex users

I install knitr and tinytex with the following line commands in RStudio 
and it seems to work:


install.packages("knitr")
install.packages('tinytex')

In the long past I was told to also run the following lines but now they 
do not seem to be needed.

#update.packages(ask = FALSE, checkBuilt = TRUE)
#tinytex::tlmgr_update()
#tinytex::reinstall_tinytex()

Would running the first two lines above be adequate? Is it also OK run 
run in RStudio by Tool -> Install.packages? Thanks you!


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


Re: [R] R does not run under latest RStudio

2023-04-06 Thread Steven T. Yen
p.s. But now I click some (but not all)  .R file and cannot see the 
source code.


On 4/6/2023 5:28 PM, Steven T. Yen wrote:

I updated to latest RStudio (RStudio-2023.03.0-386.exe) but
R would not run. Error message:

Error Starting R
The R session failed to start.

RSTUDIO VERSION
RStudio 2023.03.0+386 "Cherry Blossom " (3c53477a, 2023-03-09) for 
Windows

[No error available]

I also tried RStudio 2022.12.0+353 --- same problem.

I then tried another older version of RStudio (not sure version
as I changed file name by accident) and R ran.

Any clues? Please help. 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.


[R] R does not run under latest RStudio

2023-04-06 Thread Steven T. Yen

I updated to latest RStudio (RStudio-2023.03.0-386.exe) but
R would not run. Error message:

Error Starting R
The R session failed to start.

RSTUDIO VERSION
RStudio 2023.03.0+386 "Cherry Blossom " (3c53477a, 2023-03-09) for Windows
[No error available]

I also tried RStudio 2022.12.0+353 --- same problem.

I then tried another older version of RStudio (not sure version
as I changed file name by accident) and R ran.

Any clues? Please help. 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] Removing variables from data frame with a wile card

2023-02-12 Thread Steven T. Yen
Thanks Jeff and Andrew. My initial file, mydata, is a data frame with 92 
columns (variables). After the operation (trimming), it remains a data 
frame with 72 variables. So yes indeed, I do not need the drop=FALSE.

> is.data.frame(mydata) [1] TRUE > ncol(mydata) [1] 92 > 
mydata<-mydata[,!grepl("^yr",colnames(mydata)),drop=FALSE] > 
is.data.frame(mydata) [1] TRUE > ncol(mydata) [1] 72

On 2/13/2023 6:57 AM, Jeff Newmiller wrote:
> x["V2"]
>
> is more efficient than using drop=FALSE, and perfectly normal syntax (data 
> frames are lists of columns).  I would ignore the naysayers, or put a comment 
> in if you want to accelerate their uptake.
>
> As I understand it, one of the main reasons tibbles exist is because of 
> drop=TRUE. List-slice (single-dimension) indexing works equally well with 
> both standard and tibble types of data frames.
>
> On February 12, 2023 2:30:15 PM PST, Andrew Simmons  
> wrote:
>> drop = FALSE means that should the indexing select exactly one column, then
>> return a data frame with one column, instead of the object in the column.
>> It's usually not necessary, but I've messed up some data before by assuming
>> the indexing always returns a data frame when it doesn't, so drop = FALSE
>> let's me that I will always get a data frame.
>>
>> ```
>> x <- data.frame(V1 = 1:5, V2 = letters[1:5])
>> x[, "V2"]
>> x[, "V2", drop = FALSE]
>> ```
>>
>> You'll notice that the first returns a character vector, a through e, where
>> the second returns a data frame with one column where the object in the
>> column is the same character vector.
>>
>> You could alternatively use
>>
>> x["V2"]
>>
>> which should be identical to x[, "V2", drop = FALSE], but some people don't
>> like that because it doesn't look like matrix indexing anymore.
>>
>>
>> On Sun, Feb 12, 2023, 17:18 Steven T. Yen  wrote:
>>
>>> In the line suggested by Andrew Simmons,
>>>
>>> mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE]
>>>
>>> what does drop=FALSE do? Thanks.
>>>
>>> On 1/14/2023 8:48 PM, Steven Yen wrote:
>>>
>>> Thanks to all. Very helpful.
>>>
>>> Steven from iPhone
>>>
>>> On Jan 14, 2023, at 3:08 PM, Andrew Simmons
>>>   wrote:
>>>
>>> You'll want to use grep() or grepl(). By default, grep() uses extended
>>> regular expressions to find matches, but you can also use perl regular
>>> expressions and globbing (after converting to a regular expression).
>>> For example:
>>>
>>> grepl("^yr", colnames(mydata))
>>>
>>> will tell you which 'colnames' start with "yr". If you'd rather you
>>> use globbing:
>>>
>>> grepl(glob2rx("yr*"), colnames(mydata))
>>>
>>> Then you might write something like this to remove the columns starting
>>> with yr:
>>>
>>> mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE]
>>>
>>> On Sat, Jan 14, 2023 at 1:56 AM Steven T. Yen
>>>   wrote:
>>>
>>>
>>> I have a data frame containing variables "yr3",...,"yr28".
>>>
>>>
>>> How do I remove them with a wild cardsomething similar to "del yr*"
>>>
>>> in Windows/doc? Thank you.
>>>
>>>
>>> colnames(mydata)
>>>
>>>[1] "year"   "weight" "confeduc"   "confothr" "college"
>>>
>>>[6] ...
>>>
>>>   [41] "yr3""yr4""yr5""yr6" "yr7"
>>>
>>>   [46] "yr8""yr9""yr10"   "yr11" "yr12"
>>>
>>>   [51] "yr13"   "yr14"   "yr15"   "yr16" "yr17"
>>>
>>>   [56] "yr18"   "yr19"   "yr20"   "yr21" "yr22"
>>>
>>>   [61] "yr23"   "yr24"   "yr25"   "yr26" "yr27"
>>>
>>>   [66] "yr28"...
>>>
>>>
>>> __
>>>
>>> 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 guidehttp://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] Removing variables from data frame with a wile card

2023-02-12 Thread Steven T. Yen
In the line suggested by Andrew Simmons,

mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE]

what does drop=FALSE do? Thanks.

On 1/14/2023 8:48 PM, Steven Yen wrote:
> Thanks to all. Very helpful.
>
> Steven from iPhone
>
>> On Jan 14, 2023, at 3:08 PM, Andrew Simmons  wrote:
>>
>> You'll want to use grep() or grepl(). By default, grep() uses extended
>> regular expressions to find matches, but you can also use perl regular
>> expressions and globbing (after converting to a regular expression).
>> For example:
>>
>> grepl("^yr", colnames(mydata))
>>
>> will tell you which 'colnames' start with "yr". If you'd rather you
>> use globbing:
>>
>> grepl(glob2rx("yr*"), colnames(mydata))
>>
>> Then you might write something like this to remove the columns 
>> starting with yr:
>>
>> mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE]
>>
>> On Sat, Jan 14, 2023 at 1:56 AM Steven T. Yen  wrote:
>>>
>>> I have a data frame containing variables "yr3",...,"yr28".
>>>
>>> How do I remove them with a wild cardsomething similar to "del yr*"
>>> in Windows/doc? Thank you.
>>>
>>>> colnames(mydata)
>>>   [1] "year"   "weight" "confeduc"   "confothr" "college"
>>>   [6] ...
>>>  [41] "yr3"    "yr4"    "yr5"    "yr6" "yr7"
>>>  [46] "yr8"    "yr9"    "yr10"   "yr11" "yr12"
>>>  [51] "yr13"   "yr14"   "yr15"   "yr16" "yr17"
>>>  [56] "yr18"   "yr19"   "yr20"   "yr21" "yr22"
>>>  [61] "yr23"   "yr24"   "yr25"   "yr26" "yr27"
>>>  [66] "yr28"...
>>>
>>> __
>>> 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.


[R] Removing variables from data frame with a wile card

2023-01-13 Thread Steven T. Yen

I have a data frame containing variables "yr3",...,"yr28".

How do I remove them with a wild cardsomething similar to "del yr*" 
in Windows/doc? Thank you.


> colnames(mydata)
  [1] "year"   "weight" "confeduc"   "confothr" "college"
  [6] ...
 [41] "yr3"    "yr4"    "yr5"    "yr6" "yr7"
 [46] "yr8"    "yr9"    "yr10"   "yr11" "yr12"
 [51] "yr13"   "yr14"   "yr15"   "yr16" "yr17"
 [56] "yr18"   "yr19"   "yr20"   "yr21" "yr22"
 [61] "yr23"   "yr24"   "yr25"   "yr26" "yr27"
 [66] "yr28"...

__
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] Background for word

2023-01-11 Thread Steven T. Yen

Dear,

I am having a lucky day. I am programming in RStudio and when I type 
"black" (quotation signs included, the word turn into a word with black 
ground. Couldn't get rid of the backgroundcopying to Word, Excel, 
text editor and paste back to Rstudio, the word is still in black 
background? Help!


    dv.group<-c("black","othrrace"); cat.ref<-"white"

__
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] Format printing with R

2022-11-22 Thread Steven T. Yen

Thanks to all. And yes, Ivan, round() did it:

> dput(head(Mean))
c(afactfem = 0.310796641158209, afactblk = 0.188030178893171,
age = 45.3185794338312, nodiscfem = 0.506637018185968, discfem = 
0.493362981814032,

notradgrol = 0.702915000493879)
> dput(head(Std.dev))
c(afactfem = 0.462819715443265, afactblk = 0.390736267472797,
age = 16.3136348021933, nodiscfem = 0.499955948049025, discfem = 
0.499955948049025,

notradgrol = 0.456974290933931)
> round(cbind(Mean,Std.dev),2)[1:10,]
    Mean Std.dev
afactfem    0.31    0.46
afactblk    0.19    0.39
age    45.32   16.31
nodiscfem   0.51    0.50
discfem 0.49    0.50
notradgrol  0.70    0.46
tradgrol    0.30    0.46
nofemnopol  0.80    0.40
femnopol    0.20    0.40
nopreshurt  0.66    0.47

On 11/22/2022 3:08 PM, Ivan Krylov wrote:

On Tue, 22 Nov 2022 08:15:57 +0800
"Steven T. Yen"  wrote:


Thanks to all, but no, signif() did not work:

It worked, just didn't do what you wanted it to do. I think you want
round(), not signif(). Some of your numbers (45.3185794) will be rounded
to 4 significant digits and others (0.096) will be rounded to 1
significant digit, but the number of decimal places will be 2.



__
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] Format printing with R

2022-11-21 Thread Steven T. Yen

Thanks to all, but no, signif() did not work:

> print(signif(cbind(Mean,Std.dev),digits=2))
    Mean Std.dev
 [1,]  0.310    0.46
 [2,]  0.190    0.39
 [3,] 45.000   16.00
 [4,]  0.510    0.50
 [5,]  0.490    0.50
 [6,]  0.700    0.46

On 11/22/2022 5:41 AM, Andrew Simmons wrote:

For print(), digits is the minimal number of significant digits. In
your case, rounding the first column to the 3rd decimal place gives at
least 2 sigfigs and rounding the second column to the 2nd decimal
place.

If you want to print all numbers to two significant digits, regardless
of what other numbers are in the column, use signif() before print():

Mean <- c(0.3107966, 0.1880302, 45.3185794, 0.506637, 0.493363,
 0.702915, 0.297085, 0.7967066, 0.2032934, 0.6582301, 0.3417699,
 0.7262913, 0.2737087, 0.6415484, 0.3584516, 0.9110264, 0.0889736,
 0.5211453, 0.4788547, 0.5481055, 0.4518945, 0.913509, 0.086491,
 0.8727269, 0.1272731, 0.1015717, 0.6043692, 0.2940592, 0.2735274,
 0.3777426, 0.34873, 0.1603127, 0.1723783, 0.1230961, 0.1779381,
 0.0964334, 0.1584698, 0.1113717, 0.3349813, 0.4081109, 0.2569078,
 0.1034356, 0.6741233, 0.1254412, 0.096, 0.0587457, 0.4401115,
 0.4689114, 0.0322313, 0.5907618, 0.1591195, 0.1132923, 0.1124207,
 0.0244058, 0.7058787, 0.2941213, 0.0746892, 0.474911, 0.3471837,
 0.0435036, 0.0597126, 0.0478775, 0.1152615, 0.2074968, 0.2440626,
 0.1605995, 0.0804598, 0.1442422, 0.3443231, 0.428056, 0.0528221,
 0.0805222, 0.0457169, 0.0485596, 0.1333443, 0.0932917, 0.0653987,
 0.0573934, 0.1399086, 0.0887337, 0.0984479, 0.0914421, 0.1155505,
 0.1363764, 0.113457, 1.2985286)
Std.dev <- c(0.46282, 0.390736, 16.313635, 0.499956, 0.499956,
 0.456974, 0.456974, 0.402449, 0.402449, 0.474303, 0.474303, 0.445861,
 0.445861, 0.479546, 0.479546, 0.284706, 0.284706, 0.499553, 0.499553,
 0.49768, 0.49768, 0.281088, 0.281088, 0.333279, 0.333279, 0.302084,
 0.488986, 0.455619, 0.445769, 0.484823, 0.476568, 0.366896, 0.377709,
 0.328547, 0.382461, 0.295185, 0.365181, 0.314592, 0.471984, 0.491484,
 0.436928, 0.304527, 0.468701, 0.331218, 0.295958, 0.235148, 0.4964,
 0.499033, 0.176614, 0.491693, 0.365787, 0.31695, 0.315883, 0.154305,
 0.455647, 0.455647, 0.262889, 0.49937, 0.476075, 0.203988, 0.236954,
 0.213507, 0.319337, 0.405514, 0.42953, 0.367161, 0.272004, 0.351335,
 0.475147, 0.494797, 0.223678, 0.2721, 0.20887, 0.214945, 0.339946,
 0.290841, 0.247228, 0.232593, 0.346892, 0.284359, 0.297919, 0.288237,
 0.319685, 0.343188, 0.317151, 0.739096)
print(signif(cbind(Mean, Std.dev), 2))

which looks like:


print(signif(cbind(Mean, Std.dev), 2))

 Mean Std.dev
  [1,]  0.3100.46
  [2,]  0.1900.39
  [3,] 45.000   16.00
  [4,]  0.5100.50
  [5,]  0.4900.50
  [6,]  0.7000.46
  [7,]  0.3000.46
  [8,]  0.8000.40
  [9,]  0.2000.40
[10,]  0.6600.47
[11,]  0.3400.47
[12,]  0.7300.45
[13,]  0.2700.45
[14,]  0.6400.48
[15,]  0.3600.48
[16,]  0.9100.28
[17,]  0.0890.28
[18,]  0.5200.50
[19,]  0.4800.50
[20,]  0.5500.50
[21,]  0.4500.50
[22,]  0.9100.28
[23,]  0.0860.28
[24,]  0.8700.33
[25,]  0.1300.33
[26,]  0.1000.30
[27,]  0.6000.49
[28,]  0.2900.46
[29,]  0.2700.45
[30,]  0.3800.48
[31,]  0.3500.48
[32,]  0.1600.37
[33,]  0.1700.38
[34,]  0.1200.33
[35,]  0.1800.38
[36,]  0.0960.30
[37,]  0.1600.37
[38,]  0.1100.31
[39,]  0.3300.47
[40,]  0.4100.49
[41,]  0.2600.44
[42,]  0.1000.30
[43,]  0.6700.47
[44,]  0.1300.33
[45,]  0.0970.30
[46,]  0.0590.24
[47,]  0.4400.50
[48,]  0.4700.50
[49,]  0.0320.18
[50,]  0.5900.49
[51,]  0.1600.37
[52,]  0.1100.32
[53,]  0.1100.32
[54,]  0.0240.15
[55,]  0.7100.46
[56,]  0.2900.46
[57,]  0.0750.26
[58,]  0.4700.50
[59,]  0.3500.48
[60,]  0.0440.20
[61,]  0.0600.24
[62,]  0.0480.21
[63,]  0.1200.32
[64,]  0.2100.41
[65,]  0.2400.43
[66,]  0.1600.37
[67,]  0.0800.27
[68,]  0.1400.35
[69,]  0.3400.48
[70,]  0.4300.49
[71,]  0.0530.22
[72,]  0.0810.27
[73,]  0.0460.21
[74,]  0.0490.21
[75,]  0.1300.34
[76,]  0.0930.29
[77,]  0.0650.25
[78,]  0.0570.23
[79,]  0.1400.35
[80,]  0.0890.28
[81,]  0.0980.30
[82,]  0.0910.29
[83,]  0.1200.32
[84,]  0.1400.34
[85,]  0.1100.32
[86,]  1.3000.74
R will still print 3 decimal places for the third column since it
wants them to be of the same format, but each number is 2 sigfigs.

On Mon, Nov 21, 2022 at 3:41 PM Steven T. Yen via R-help
 wrote:

Hi, I have two variables with 86 observations each. Below I print with
the print command with digit=2. But, I am getting three decimal places
for my first variable and two for the second. Please help. Thanks.

  > cbind(Mean,Std.dev)
  Mean   S

[R] Format printing with R

2022-11-21 Thread Steven T. Yen via R-help
Hi, I have two variables with 86 observations each. Below I print with 
the print command with digit=2. But, I am getting three decimal places 
for my first variable and two for the second. Please help. Thanks.


> cbind(Mean,Std.dev)
    Mean   Std.dev
 [1,]  0.3107966  0.462820
 [2,]  0.1880302  0.390736
 [3,] 45.3185794 16.313635
 [4,]  0.5066370  0.499956
 [5,]  0.4933630  0.499956
 [6,]  0.7029150  0.456974
 [7,]  0.2970850  0.456974
 [8,]  0.7967066  0.402449
 [9,]  0.2032934  0.402449
[10,]  0.6582301  0.474303
[11,]  0.3417699  0.474303
[12,]  0.7262913  0.445861
[13,]  0.2737087  0.445861
[14,]  0.6415484  0.479546
[15,]  0.3584516  0.479546
[16,]  0.9110264  0.284706
[17,]  0.0889736  0.284706
[18,]  0.5211453  0.499553
[19,]  0.4788547  0.499553
[20,]  0.5481055  0.497680
[21,]  0.4518945  0.497680
[22,]  0.9135090  0.281088
[23,]  0.0864910  0.281088
[24,]  0.8727269  0.333279
[25,]  0.1272731  0.333279
[26,]  0.1015717  0.302084
[27,]  0.6043692  0.488986
[28,]  0.2940592  0.455619
[29,]  0.2735274  0.445769
[30,]  0.3777426  0.484823
[31,]  0.3487300  0.476568
[32,]  0.1603127  0.366896
[33,]  0.1723783  0.377709
[34,]  0.1230961  0.328547
[35,]  0.1779381  0.382461
[36,]  0.0964334  0.295185
[37,]  0.1584698  0.365181
[38,]  0.1113717  0.314592
[39,]  0.3349813  0.471984
[40,]  0.4081109  0.491484
[41,]  0.2569078  0.436928
[42,]  0.1034356  0.304527
[43,]  0.6741233  0.468701
[44,]  0.1254412  0.331218
[45,]  0.096  0.295958
[46,]  0.0587457  0.235148
[47,]  0.4401115  0.496400
[48,]  0.4689114  0.499033
[49,]  0.0322313  0.176614
[50,]  0.5907618  0.491693
[51,]  0.1591195  0.365787
[52,]  0.1132923  0.316950
[53,]  0.1124207  0.315883
[54,]  0.0244058  0.154305
[55,]  0.7058787  0.455647
[56,]  0.2941213  0.455647
[57,]  0.0746892  0.262889
[58,]  0.4749110  0.499370
[59,]  0.3471837  0.476075
[60,]  0.0435036  0.203988
[61,]  0.0597126  0.236954
[62,]  0.0478775  0.213507
[63,]  0.1152615  0.319337
[64,]  0.2074968  0.405514
[65,]  0.2440626  0.429530
[66,]  0.1605995  0.367161
[67,]  0.0804598  0.272004
[68,]  0.1442422  0.351335
[69,]  0.3443231  0.475147
[70,]  0.4280560  0.494797
[71,]  0.0528221  0.223678
[72,]  0.0805222  0.272100
[73,]  0.0457169  0.208870
[74,]  0.0485596  0.214945
[75,]  0.1333443  0.339946
[76,]  0.0932917  0.290841
[77,]  0.0653987  0.247228
[78,]  0.0573934  0.232593
[79,]  0.1399086  0.346892
[80,]  0.0887337  0.284359
[81,]  0.0984479  0.297919
[82,]  0.0914421  0.288237
[83,]  0.1155505  0.319685
[84,]  0.1363764  0.343188
[85,]  0.1134570  0.317151
[86,]  1.2985286  0.739096
> print(cbind(Mean,Std.dev),digits=2)
    Mean Std.dev
 [1,]  0.311    0.46
 [2,]  0.188    0.39
 [3,] 45.319   16.31
 [4,]  0.507    0.50
 [5,]  0.493    0.50
 [6,]  0.703    0.46
 [7,]  0.297    0.46
 [8,]  0.797    0.40
 [9,]  0.203    0.40
[10,]  0.658    0.47
[11,]  0.342    0.47
[12,]  0.726    0.45
[13,]  0.274    0.45
[14,]  0.642    0.48
[15,]  0.358    0.48
[16,]  0.911    0.28
[17,]  0.089    0.28
[18,]  0.521    0.50
[19,]  0.479    0.50
[20,]  0.548    0.50
[21,]  0.452    0.50
[22,]  0.914    0.28
[23,]  0.086    0.28
[24,]  0.873    0.33
[25,]  0.127    0.33
[26,]  0.102    0.30
[27,]  0.604    0.49
[28,]  0.294    0.46
[29,]  0.274    0.45
[30,]  0.378    0.48
[31,]  0.349    0.48
[32,]  0.160    0.37
[33,]  0.172    0.38
[34,]  0.123    0.33
[35,]  0.178    0.38
[36,]  0.096    0.30
[37,]  0.158    0.37
[38,]  0.111    0.31
[39,]  0.335    0.47
[40,]  0.408    0.49
[41,]  0.257    0.44
[42,]  0.103    0.30
[43,]  0.674    0.47
[44,]  0.125    0.33
[45,]  0.097    0.30
[46,]  0.059    0.24
[47,]  0.440    0.50
[48,]  0.469    0.50
[49,]  0.032    0.18
[50,]  0.591    0.49
[51,]  0.159    0.37
[52,]  0.113    0.32
[53,]  0.112    0.32
[54,]  0.024    0.15
[55,]  0.706    0.46
[56,]  0.294    0.46
[57,]  0.075    0.26
[58,]  0.475    0.50
[59,]  0.347    0.48
[60,]  0.044    0.20
[61,]  0.060    0.24
[62,]  0.048    0.21
[63,]  0.115    0.32
[64,]  0.207    0.41
[65,]  0.244    0.43
[66,]  0.161    0.37
[67,]  0.080    0.27
[68,]  0.144    0.35
[69,]  0.344    0.48
[70,]  0.428    0.49
[71,]  0.053    0.22
[72,]  0.081    0.27
[73,]  0.046    0.21
[74,]  0.049    0.21
[75,]  0.133    0.34
[76,]  0.093    0.29
[77,]  0.065    0.25
[78,]  0.057    0.23
[79,]  0.140    0.35
[80,]  0.089    0.28
[81,]  0.098    0.30
[82,]  0.091    0.29
[83,]  0.116    0.32
[84,]  0.136    0.34
[85,]  0.113    0.32
[86,]  1.299    0.74
>

__
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] cannot print a list with cat

2022-10-24 Thread Steven T. Yen

Thanks to all, who have helped greatly. I essentially followed Rui to do:

  fmt_string<-paste0("\ntol = %.1e","\nreltol  = %.1e","\nsteptol = 
%.1e","\ngradtol = %.1e")
#msg<-sprintf(fmt_string,mycontrol$tol,mycontrol$reltol,mycontrol$steptol,mycontrol$gradtol) 
#works

msg<-with(mycontrol,sprintf(fmt_string,tol,reltol,steptol,gradtol))
  cat(msg)

tol = 0.0e+00
reltol  = 0.0e+00
steptol = 1.0e-08
gradtol = 1.0e-10

Thids has worked great! Thanks again to all.

Steven Yen

On 10/25/2022 3:23 AM, Rui Barradas wrote:

Às 16:21 de 24/10/2022, Steven T. Yen escreveu:
Thanks to everyone. I read ? sprint and the following is best I came 
up with. If there are ways to collapse the lines I'd be glad to know. 
Otherwise, I will live with this. Thanks again.


cat(sprintf("\ntol = %e",mycontrol$tol),
 sprintf("\nreltol  = %e",mycontrol$reltol),
 sprintf("\nsteptol = %e",mycontrol$steptol),
 sprintf("\ngradtol = %e",mycontrol$gradtol))

tol = 0.00e+00
reltol  = 0.00e+00
steptol = 1.00e-08
gradtol = 1.00e-10

On 10/24/2022 10:02 PM, Rui Barradas wrote:

Hello,

There's also ?message.


msg <- sprintf("(tol,reltol,steptol,gradtol): %E %E %E %E",

mycontrol$tol,mycontrol$reltol,mycontrol$steptol,mycontrol$gradtol)
message(msg)


Hope this helps,

Rui Barradas

Às 14:25 de 24/10/2022, Steven T. Yen escreveu:

Thank, Boris and Ivan.

The simple command suggested by Ivan ( print(t(mycontrol)) ) 
worked. I went along with Boris' suggestion and do/get the following:


cat(sprintf("(tol,reltol,steptol,gradtol): %E %E %E %E",mycontrol$tol,
mycontrol$reltol,mycontrol$steptol,mycontrol$gradtol))

(tol,reltol,steptol,gradtol): 0.00E+00 0.00E+00 
1.00E-08 1.00E-12


This works great. Thanks.

Steven

On 10/24/2022 9:05 PM, Boris Steipe wrote:

???  t() is the transpose function. It just happens to return your 
list unchanged. The return value is then printed to console if it 
is not assigned, or returned invisibly. Transposing your list is 
probably not what you wanted to do.


Returned values do not get printed from within a loop or from a 
source()'d script. That's why it "works" interactively, but not 
from a script file.


If you want to print the contents of your list, just use:
   print(mycontrol)

Or use some incantation with sprintf() if you want more control 
about the format of what gets printed. Eg:


  cat(sprintf("Tolerance: %f (%f %%)", mycontrol$tol, 
mycontrol$reltol))


etc.


B.




On 2022-10-24, at 08:47, Ivan Krylov  wrote:

В Mon, 24 Oct 2022 20:39:33 +0800
"Steven T. Yen"  пишет:


Printing this in a main program causes no problem (as shown above).
But, using the command t(mycontrol) the line gets ignored.
t() doesn't print, it returns a value. In R, there's 
auto-printing in
the toplevel context (see ?withAutoprint), but not when you move 
away
from the interactive prompt. I think that it should be possible 
to use

an explicit print(t(mycontrol)) to get the behaviour you desire.

--
Best regards,
Ivan

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


Hello,

Here is a way. I leave it in may code lines to make it more 
understandale, I hope.



# From Spencer's post
(mycontrol <- list(tol=0, reltol=0, steptol=1e-8, gradtol=1e-12))
#> $tol
#> [1] 0
#>
#> $reltol
#> [1] 0
#>
#> $steptol
#> [1] 1e-08
#>
#> $gradtol
#> [1] 1e-12

fmt_string <- paste0(
  "\ntol = %e",
  "\nreltol  = %e",
  "\nsteptol = %e",
  "\ngradtol = %e"
)

msg <- sprintf(fmt_string, mycontrol$tol, mycontrol$reltol, 
mycontrol$steptol, mycontrol$gradtol)


msg
#> [1] "\ntol = 0.00e+00\nreltol  = 0.00e+00\nsteptol = 
1.00e-08\ngradtol = 1.00e-12"


cat(msg)
#>
#> tol = 0.00e+00
#> reltol  = 0.00e+00
#> steptol = 1.00e-08
#> gradtol = 1.00e-12

message(msg)
#>
#> tol = 0.00e+00
#> reltol  = 0.00e+00
#> steptol = 1.00e-08
#> gradtol = 1.00e-12


You also can write the format string all in a row.


msg2 <- with(mycontrol, sprintf("\ntol = %e\nreltol  = %e\nsteptol 
= %e\ngradtol = %e", tol, reltol, steptol, gradtol))

cat(msg2)
#>
#> tol = 0.00e+00
#> reltol  = 0.0

Re: [R] cannot print a list with cat

2022-10-24 Thread Steven T. Yen
Thanks to everyone. I read ? sprint and the following is best I came up 
with. If there are ways to collapse the lines I'd be glad to know. 
Otherwise, I will live with this. Thanks again.


cat(sprintf("\ntol = %e",mycontrol$tol),
    sprintf("\nreltol  = %e",mycontrol$reltol),
    sprintf("\nsteptol = %e",mycontrol$steptol),
    sprintf("\ngradtol = %e",mycontrol$gradtol))

tol = 0.00e+00
reltol  = 0.00e+00
steptol = 1.00e-08
gradtol = 1.00e-10

On 10/24/2022 10:02 PM, Rui Barradas wrote:

Hello,

There's also ?message.


msg <- sprintf("(tol,reltol,steptol,gradtol): %E %E %E %E",

mycontrol$tol,mycontrol$reltol,mycontrol$steptol,mycontrol$gradtol)
message(msg)


Hope this helps,

Rui Barradas

Às 14:25 de 24/10/2022, Steven T. Yen escreveu:

Thank, Boris and Ivan.

The simple command suggested by Ivan ( print(t(mycontrol)) ) worked. 
I went along with Boris' suggestion and do/get the following:


cat(sprintf("(tol,reltol,steptol,gradtol): %E %E %E %E",mycontrol$tol,
mycontrol$reltol,mycontrol$steptol,mycontrol$gradtol))

(tol,reltol,steptol,gradtol): 0.00E+00 0.00E+00 1.00E-08 
1.00E-12


This works great. Thanks.

Steven

On 10/24/2022 9:05 PM, Boris Steipe wrote:

???  t() is the transpose function. It just happens to return your 
list unchanged. The return value is then printed to console if it is 
not assigned, or returned invisibly. Transposing your list is 
probably not what you wanted to do.


Returned values do not get printed from within a loop or from a 
source()'d script. That's why it "works" interactively, but not from 
a script file.


If you want to print the contents of your list, just use:
   print(mycontrol)

Or use some incantation with sprintf() if you want more control 
about the format of what gets printed. Eg:


  cat(sprintf("Tolerance: %f (%f %%)", mycontrol$tol, 
mycontrol$reltol))


etc.


B.




On 2022-10-24, at 08:47, Ivan Krylov  wrote:

В Mon, 24 Oct 2022 20:39:33 +0800
"Steven T. Yen"  пишет:


Printing this in a main program causes no problem (as shown above).
But, using the command t(mycontrol) the line gets ignored.

t() doesn't print, it returns a value. In R, there's auto-printing in
the toplevel context (see ?withAutoprint), but not when you move away
from the interactive prompt. I think that it should be possible to use
an explicit print(t(mycontrol)) to get the behaviour you desire.

--
Best regards,
Ivan

__
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-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] cannot print a list with cat

2022-10-24 Thread Steven T. Yen

Thank, Boris and Ivan.

The simple command suggested by Ivan ( print(t(mycontrol)) ) worked. I 
went along with Boris' suggestion and do/get the following:


cat(sprintf("(tol,reltol,steptol,gradtol): %E %E %E %E",mycontrol$tol,
mycontrol$reltol,mycontrol$steptol,mycontrol$gradtol))

(tol,reltol,steptol,gradtol): 0.00E+00 0.00E+00 1.00E-08 
1.00E-12


This works great. Thanks.

Steven

On 10/24/2022 9:05 PM, Boris Steipe wrote:


???  t() is the transpose function. It just happens to return your list 
unchanged. The return value is then printed to console if it is not assigned, 
or returned invisibly. Transposing your list is probably not what you wanted to 
do.

Returned values do not get printed from within a loop or from a source()'d script. That's 
why it "works" interactively, but not from a script file.

If you want to print the contents of your list, just use:
   print(mycontrol)

Or use some incantation with sprintf() if you want more control about the 
format of what gets printed. Eg:

  cat(sprintf("Tolerance: %f (%f %%)", mycontrol$tol, mycontrol$reltol))

etc.


B.




On 2022-10-24, at 08:47, Ivan Krylov  wrote:

В Mon, 24 Oct 2022 20:39:33 +0800
"Steven T. Yen"  пишет:


Printing this in a main program causes no problem (as shown above).
But, using the command t(mycontrol) the line gets ignored.

t() doesn't print, it returns a value. In R, there's auto-printing in
the toplevel context (see ?withAutoprint), but not when you move away
from the interactive prompt. I think that it should be possible to use
an explicit print(t(mycontrol)) to get the behaviour you desire.

--
Best regards,
Ivan

__
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] cannot print a list with cat

2022-10-24 Thread Steven T. Yen

I have a "list" containing four elements, as shown below:

> t(mycontrol)

 tol reltol steptol gradtol
[1,] 0   0  1e-08   1e-12

Printing this in a main program causes no problem (as shown above).
But, using the command t(mycontrol) the line gets ignored. Any idea? Thanks.
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.


Re: [R] cat in a subroutine

2022-10-13 Thread Steven T. Yen
Hello, Oh Lord, yes, I had a function called "cat", with argument "j". 
That was very dumb.

Renaming function cat resolved the problem. I had lived with this 
problem too long---avoiding printing with cat altogether in this 
program. Thanks to all-Bill, Iva, Jim, Erin, Andrew for help!

On 10/13/2022 10:30 PM, Bill Dunlap wrote:
> Do you have another function called "cat" in scope? (with an argument 
> called "j")?  Before calling cat("...") call print(cat) and 
> print(find("cat")).
>
> -Bill
>
>
> On Thu, Oct 13, 2022 at 12:35 AM Steven T. Yen  wrote:
>
> I have had an issue with printing (with cat) in a subroutine for
> which I
> do not have a applicable example, but I am still hoping to get some
> help. In the following, the first block of code works fine.
>
> ...
>
> t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
> sig<-my.sig.levels(p)
> out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
> rownames(out)<-names(me)
> colnames(out)<-c("est","se","t","p","sig")
> j<-grep(".one\\b",rownames(out))
> out<-out[-j,]
> return(out)
> }
>
> But as soon as I insert lines to print (cat) soething simple, it
> spits
> out message that appears to be nonsence (unrelated). Any idea. Please
> help. Thanks.
>
> t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
> sig<-my.sig.levels(p)
> out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
> rownames(out)<-names(me)
> colnames(out)<-c("est","se","t","p","sig")
> cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit
> Probabilities",
>  "\n\nlogistic =",logistic)
> j<-grep(".one\\b",rownames(out))
> out<-out[-j,]
> return(out)
> }
>
> In this particular case, the error message was as follows:
>
> Error in cat("\nMarginal and Discrete Effects of Gen Ordered Logit /
> Probit Probabilities",  :
>    unused argument (logistic)
>
> I have printed this way in numerous routines without problem and
> do not
> see why this is happending.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
[[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] cat in a subroutine

2022-10-13 Thread Steven T. Yen

Not really.

fortytwo<-42
cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit 
Probabilities",

    "logisitic =",fortytwo,"\n")

> goprobit1.r.me.kr<-me.gologit.r(goprobit1,embellished=TRUE,
+ resampling=TRUE,ndraws=5); 
goprobit1.r.me.kr
Error in cat("\nMarginal and Discrete Effects of Gen Ordered Logit / 
Probit Probabilities",  :

  unused arguments (fortytwo, "\n")

On 10/13/2022 4:46 PM, Jim Lemon wrote:

Hi Steven & Erin,
This works:

fortytwo<-42
cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit
Probabilities","logisitic =",fortytwo,"\n")
j<-grep(".one\\b",c(".one\\a",".one\\b"))

Marginal and Discrete Effects of Gen Ordered Logit / Probit
Probabilities logisitic = 42

If I don't define fortytwo before calling cat, it doesn't.
So we know what the answer is.

Jim

On Thu, Oct 13, 2022 at 7:36 PM Steven Yen  wrote:

t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
sig<-my.sig.levels(p)
out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
rownames(out)<-names(me)
colnames(out)<-c("est","se","t","p","sig")
cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit
Probabilities",
  "\n\nlogistic =",logistic)
j<-grep(".one\\b",rownames(out))
out<-out[-j,]
return(out)
}

Steven from iPhone


On Oct 13, 2022, at 3:37 PM, Erin Hodgess  wrote:

t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
sig<-my.sig.levels(p)
out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
rownames(out)<-names(me)
colnames(out)<-c("est","se","t","p","sig")
cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit
Probabilities",
  "\n\nlogistic =",logistic)
j<-grep(".one\\b",rownames(out))
out<-out[-j,]
return(out)
}

 [[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] cat in a subroutine

2022-10-13 Thread Steven T. Yen
Thanks Erin.

No. Removing the second line (so that cat simply prints something else),

cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit 
Probabilities")
#    "\n\nlogistic =",logistic)

I get yet another nonsense:

Error in cat("\nMarginal and Discrete Effects of Gen Ordered Logit / 
Probit Probabilities") :
   argument "j" is missing, with no default
 >

On 10/13/2022 3:37 PM, Erin Hodgess wrote:
> Hi Steven:
>
> Do you have a variable called logistic, please?  I think that might be 
> the culprit.
>
> Thanks,
> Erin
>
> On Thu, Oct 13, 2022 at 1:35 AM Steven T. Yen  wrote:
>
> I have had an issue with printing (with cat) in a subroutine for
> which I
> do not have a applicable example, but I am still hoping to get some
> help. In the following, the first block of code works fine.
>
> ...
>
> t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
> sig<-my.sig.levels(p)
> out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
> rownames(out)<-names(me)
> colnames(out)<-c("est","se","t","p","sig")
> j<-grep(".one\\b",rownames(out))
> out<-out[-j,]
> return(out)
> }
>
> But as soon as I insert lines to print (cat) soething simple, it
> spits
> out message that appears to be nonsence (unrelated). Any idea. Please
> help. Thanks.
>
> t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
> sig<-my.sig.levels(p)
> out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
> rownames(out)<-names(me)
> colnames(out)<-c("est","se","t","p","sig")
> cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit
> Probabilities",
>  "\n\nlogistic =",logistic)
> j<-grep(".one\\b",rownames(out))
> out<-out[-j,]
> return(out)
> }
>
> In this particular case, the error message was as follows:
>
> Error in cat("\nMarginal and Discrete Effects of Gen Ordered Logit /
> Probit Probabilities",  :
>    unused argument (logistic)
>
> I have printed this way in numerous routines without problem and
> do not
> see why this is happending.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
> -- 
> Erin Hodgess, PhD
> mailto: erinm.hodg...@gmail.com
[[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] cat in a subroutine

2022-10-13 Thread Steven T. Yen
I have had an issue with printing (with cat) in a subroutine for which I 
do not have a applicable example, but I am still hoping to get some 
help. In the following, the first block of code works fine.


...

t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
sig<-my.sig.levels(p)
out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
rownames(out)<-names(me)
colnames(out)<-c("est","se","t","p","sig")
j<-grep(".one\\b",rownames(out))
out<-out[-j,]
return(out)
}

But as soon as I insert lines to print (cat) soething simple, it spits 
out message that appears to be nonsence (unrelated). Any idea. Please 
help. Thanks.


t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
sig<-my.sig.levels(p)
out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
rownames(out)<-names(me)
colnames(out)<-c("est","se","t","p","sig")
cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit 
Probabilities",

    "\n\nlogistic =",logistic)
j<-grep(".one\\b",rownames(out))
out<-out[-j,]
return(out)
}

In this particular case, the error message was as follows:

Error in cat("\nMarginal and Discrete Effects of Gen Ordered Logit / 
Probit Probabilities",  :

  unused argument (logistic)

I have printed this way in numerous routines without problem and do not 
see why this is happending.


__
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] Help with a simple subroutine

2022-09-09 Thread Steven T. Yen
Thanks to all. It was just programming error. The following now works. 
Essentially, to impose non-negative restrictions I estimated the natural 
logs of two parameters and then do exponential transformation to uncover 
the parameters, with mathematical transformation (delta method) for 
their standard errors.


I believe deltaMethod {car} does that sort of things. I have yet to look 
up if it does that for nonlinear regression object. But since the 
exponential transformation is a simple transformation (with a derivative 
equal to itself), I tried to program my own. Thanks to all.


> obj<-cbp11.pooled
> j<-grep("gamma",names(obj$est),value=TRUE); j
[1] "log.gamma1" "log.gamma2"
> obj$estimate[j]
log.gamma1 log.gamma2
  -1.82378   -1.11313
> obj$stat$vb[j,j]
   log.gamma1 log.gamma2
log.gamma1  0.0842252  0.0138778
log.gamma2  0.0138778  0.0793592
> mydelta <- function(obj,j){
+ # ***
+ # Delta method for exponential transformation
+ # ***
+   b<-obj$estimate[j]
+   v<-obj$stat$vb[j,j]; v
+   gamma<-exp(b)
+   db<-gamma
+   vgamma<-db^2*v
+   sgamma<-sqrt(diag(vgamma))
+   t<-gamma/sgamma
+   df<-n<-obj$stat$n
+   p<-2*(1-pt(abs(t),df))
+   list(gamma=gamma,sgamma=sgamma,b=b,t=t,p=p)
+ }
> v<-mydelta(obj,j)
> v$b
log.gamma1 log.gamma2
  -1.82378   -1.11313
> v$gamma
log.gamma1 log.gamma2
  0.161414   0.328529
> v$sgamma
log.gamma1 log.gamma2
 0.0468449  0.0925490
> v$t
log.gamma1 log.gamma2
   3.44571    3.54978
> v$p
 log.gamma1  log.gamma2
0.000574108 0.000388996
>

On 9/9/2022 8:39 PM, Ebert,Timothy Aaron wrote:


If t = 1/sqrt(v[2,2]) and there is no code to change the value of v[2,2] and no 
code to change to a different cell why would you get two different values?

One approach to debugging is to make a small example and see if the code output 
matches (line-by-line) the output you get from doing a manual calculation. If 
they do not match you at least know where to start looking for a problem. Hand 
calculation can use pencil and paper or Excel or other tools. It is a tedious 
task but very effective.

Tim

-----Original Message-
From: R-help  On Behalf Of Ivan Krylov
Sent: Friday, September 9, 2022 5:03 AM
To: Steven T. Yen 
Cc: R-help Mailing List 
Subject: Re: [R] Help with a simple subroutine

[External Email]

В Fri, 9 Sep 2022 16:46:00 +0800
"Steven T. Yen"  пишет:


I am expecting the line  t<-gamma/sgamma to produce two different
values. But I confirm that it is doing tt<-gamma[1]/sgamma[1]

No, it just happens that gamma[1]/sgamma[1] is the same as gamma[2]/sgamma[2], 
subject to rounding errors:


+   gamma<-exp(b)
+   vgamma<-gamma^2*v[2,2]
+   sgamma<-sqrt(vgamma)
+   t<-gamma/sgamma

t = gamma / sgamma = gamma / sqrt(gamma^2 * v[2,2]) =
   = gamma / (abs(gamma) * sqrt(v[2,2])) = (given gamma = exp(b) > 0)
   = 1 / sqrt(v[2,2]).

--
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7C96597c0724d947d3c1ea08da9242e073%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637983113179778561%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=EnaoCEmoUJNXsukvk8jqZVZ1tIveOeUCIX%2Bic5tMRLM%3Dreserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%7C96597c0724d947d3c1ea08da9242e073%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637983113179778561%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=18MG1xlJnQE%2Bqo54jNxYAIAGqSQC%2FFQOgTOkl7Ysvc8%3Dreserved=0
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] Rtools required

2020-04-28 Thread Steven T. Yen
Dear All

I updated to R-4.0.0. and also installed the latest Rtools 4.0 (to now 
the new default folder c:\rtools40). While compiling a package (binary) 
I received the follow marning message saying Rtools is required. Any 
clues? Thanks.

Steven Yen

WARNING: Rtools is required to build R packages but is not currently 
installed. Please download and install the appropriate version of Rtools 
before proceeding: https://cran.rstudio.com/bin/windows/Rtools/


[[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] hist{graphics}

2019-07-13 Thread Steven T. Yen

# Can someone help with this simple frequency histogram problem (n = 15)?
# I use four class limits: [90,95], [95,100], [100,105], [105,110].
# These coincide with the limits obtain by pretty {base}.
# Proper frequencies would be: (1,5,6,3).
# But hist{graphics} gives me a histogram showing frequencies (1,8,3,3),
# with or without argument break = ...
# Replicable codes below. Thanks.

set.seed(123)
x<-rnorm(15,mean=100,sd=5); x<-as.integer(x)
x<-sort(x)
x
breaks<-seq(90,110,by=5); breaks
pretty(x,n=5) # pretty {base}
x.cut<-cut(x,breaks,right=F) ; x.cut
freq<-table(x.cut); cbind(freq)
hist(x,breaks=breaks) # hist {graphics}
hist(x)

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