Re: [R] interactive Map: Popups

2015-07-23 Thread daniel
Marie-Louise,

As long sa I know you have to gie googleVis the ISO code for provinces.

GR <- data.frame( ISO = c("DE-BW",
"DE-BY",
"DE-BE",
"DE-BB",
"DE-HB",
"DE-HH",
"DE-HE",
"DE-MV",
"DE-NI",
"DE-NW",
"DE-RP",
"DE-SL",
"DE-SN",
"DE-ST",
"DE-SH",
"DE-TH"),
name = c("Baden-Württemberg",
"Bayern",
"Berlin",
"Brandenburg",
"Bremen",
"Hamburg",
"Hessen",
"Mecklenburg-Vorpommern",
"Niedersachsen",
"Nordrhein-Westfalen",
"Rheinland-Pfalz",
"Saarland",
"Sachsen",
"Sachsen-Anhalt",
"Schleswig-Holstein",
"Thüringen"), value = 1:16)

G3 <- gvisGeoMap(GR, locationvar='ISO',
numvar='value', options=list(region="DE",
displayMode="regions", resolution="provinces,"))
plot(G3)

Daniel Merino


2015-07-23 17:00 GMT-03:00 Erich Neuwirth :

> Some shapefiles for Germany can be found here
>
> http://www.statsilk.com/maps/download-free-shapefile-maps <
> http://www.statsilk.com/maps/download-free-shapefile-maps>
>
> > On Jul 23, 2015, at 21:36, Erin Hodgess  wrote:
> >
> > Hello Erich:
> >
> > I just looked at your leaflet package and its examples.  It is awesome!
> >
> > Thanks,
> > Erin
> >
> >
> > On Thu, Jul 23, 2015 at 6:28 AM, Erich Neuwirth <
> erich.neuwi...@univie.ac.at <mailto:erich.neuwi...@univie.ac.at>> wrote:
> > I am quite happy with that package leaflet which is not yet on CRAN
> > but available on Githib.
> >
> > https://github.com/rstudio/leaflet <https://github.com/rstudio/leaflet>
> <https://github.com/rstudio/leaflet <https://github.com/rstudio/leaflet>>
> >
> >
> > __
> > 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 <
> 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
> > Associate Professor
> > Department of Mathematical and Statistics
> > University of Houston - Downtown
> > mailto: erinm.hodg...@gmail.com <mailto:erinm.hodg...@gmail.com>
>
> __
> 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.
>



-- 
Daniel

[[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] Time outside limits

2014-10-16 Thread daniel
Bart,

Check if the following could help you.

library(xts)
y <- c(rnorm(10,25), rnorm(10,32),rnorm(10,25), rnorm(10,20),
rnorm(10,25)); x <- seq(c(ISOdate(2000,3,20)), by = "hour", length.out =
length(y))
z <- xts( y, order.by=as.POSIXct(x))
limit <- ifelse( lag(z) < 22 | z > 27, 1, 0)


Daniel Merino

2014-10-16 15:12 GMT-03:00 Bart Joosen :

> Hi,
> I'm currently facing the problem that I need to write a function where I
> get a dataframe back which contains the time (in hours) outside the limits
> of a temperature sensor, each month, and for how long exactly.
> I wrote a for loop which check:- if a datapoint is outside the limit- if
> the previous datapoint is outside the limt, then count + 1- if the next
> datapoint isn't outside: write in dataframe.
> I guess this could be with some vectorisation function, I tried with
> seq_along, and match, but couldn't figure it out.
> Here some sample data:
> y <- c(rnorm(10,25), rnorm(10,32),rnorm(10,25), rnorm(10,20),
> rnorm(10,25))x <- seq(c(ISOdate(2000,3,20)), by = "hour", length.out =
> length(y))
> limits of y: c(22,27)
> Thanks
> Bart
> [[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.
>



-- 
Daniel

[[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] converting individual data series to natural log (continuously compounded return)

2014-10-31 Thread daniel
Upananda,

I don't know your fut data, next time would help a simple dput(fut). Taking
into account the error message check the following:

library(PerformanceAnalytics)
df <- data.frame( sample(10)/100+100, seq(as.Date("2014-10-22"),
as.Date("2014-10-31"), by="day"))
str(df)
Return.calculate(df, "log")
#Error en checkData(prices, method = "xts") :
#  The data cannot be converted into a time series.  If you are trying to
pass in names from a data object with one column, you should use the form
'data[rows, columns, drop = FALSE]'.  Rownames should have standard date
formats, such as '1985-03-15'.
df <- data.frame( sample(10)/100+100, row.names=seq(as.Date("2014-10-22"),
as.Date("2014-10-31"), by="day"))
str(df)
Return.calculate(df, "log")
df <- xts( sample(10)/100+100, order.by=seq(as.Date("2014-10-22"),
as.Date("2014-10-31"), by="day"))
str(df)
Return.calculate(df, "log")

If you are going to use the PerformanceAnalytics package I highly recommend
you to checkl the xts package.

Daniel Merino



2014-10-31 15:24 GMT-03:00 Upananda Pani :

> Hi All,
>
> I want to convert my price data into  natural log (continuously compounded
> return)  by using Performance Analytics Package, I am getting the following
> error.
>
>  rfut = Return.calculate(fut)
> Error in checkData(prices, method = "xts") :
>
>
> Please help me.
>
> With sincere regards,
> Upananda
>
> --
>
>
> You may delay, but time will not.
>
>
> Research Scholar
> alternative mail id: up...@iitkgp.ac.in
> Department of HSS, IIT KGP
> KGP
>
> ______
> 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.
>
>


-- 
Daniel

[[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] Function that create day of the year column.

2014-11-04 Thread daniel
Frederic,

Check the lubridate library.

install.packages("lubridate")
library(lubridate)
yday(Sys.Date())
d <- 4
m <- 11
y <- 2014
yday(as.Date(paste(y,m,d,sep="-")))

Daniel Merino

2014-11-04 7:01 GMT-03:00 Frederic Ntirenganya :

> Dear All,
>
> I would like to make a function that create Day of the year column in a
> dataset.
> State of the problem: write a function that create a day column either from
> a single date column (string/or factors) or from date in 3 columns (year,
> month, day).
>
> I made the following function for a single date. I would like to add a
> condition for date in 3 columns (year, month, day). My data is daily
> climate data.
> #write a function that create a day column either from a single date column
> (string/or factors)
> #or from date in 3 columns (year, month, day).
>
> DOY=function(data){
>
> #=
> #This function create day of teh year from a single date
> column(ex:2009-08-02) or/and
> #from the date in 3 columns (Year, month, Day).
> #
>   data$Rain=as.numeric(as.character(data$Rain))
>   dt=yday(data$Date) # single date of the data
>   datelp= dt>59 & !leap_year(data$Date)# tell us that the date occurs
> during a leap year
>   dt[datelp]=dt[datelp]+1 # add one for non leap_year
>   cbind(data, dt) # combining columns of data
>   conames(data)="DOY" # name of new column. ??I have a problem on how I can
> precise the column in gerenal.
> }
>
> ex: year  month day   Date Rain Tmin Tmax
>   1971   1 11971-01-01   0 8.2  15
>1971  1 21971-01-02   0 4.2  11
> ..  .   .   .  .  .
> ..  .   .   .  .  .
> ..  .   .   .  .  .
>
> Any ideal on how I can make this function is welcome. thanks!
> Frederic Ntirenganya
> Maseno University,
> African Maths Initiative,
> Kenya.
> Mobile:(+254)718492836
> Email: fr...@aims.ac.za
> https://sites.google.com/a/aims.ac.za/fredo/
>
> [[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.
>



-- 
Daniel

[[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] Function that create day of the year column.

2014-11-04 Thread daniel
Maybe, you can add a parameter with a list of the column names and inside
the function an if statement, if the list lenght is 1 use the function with
1 column else the 3 columns.  I am sure you can find better solutions.

Daniel Merino

2014-11-04 9:30 GMT-03:00 Frederic Ntirenganya :

> Hi Daniel,
>
> How can I add an if conditiopn or for loop to implement this in my
> function?
>
> ex: option1 : single date
>  option2: date in 3 columns (year,moth,day)
>
> yday(Sys.Date())
> yday(as.Date(paste(y,m,d,sep="-")))
>
> Regards,
> Frederic.
>
>
> Frederic Ntirenganya
> Maseno University,
> African Maths Initiative,
> Kenya.
> Mobile:(+254)718492836
> Email: fr...@aims.ac.za
> https://sites.google.com/a/aims.ac.za/fredo/
>
> On Tue, Nov 4, 2014 at 3:20 PM, daniel  wrote:
>
>> Frederic,
>>
>> Check the lubridate library.
>>
>> install.packages("lubridate")
>> library(lubridate)
>> yday(Sys.Date())
>> d <- 4
>> m <- 11
>> y <- 2014
>> yday(as.Date(paste(y,m,d,sep="-")))
>>
>> Daniel Merino
>>
>> 2014-11-04 7:01 GMT-03:00 Frederic Ntirenganya :
>>
>>> Dear All,
>>>
>>> I would like to make a function that create Day of the year column in a
>>> dataset.
>>> State of the problem: write a function that create a day column either
>>> from
>>> a single date column (string/or factors) or from date in 3 columns (year,
>>> month, day).
>>>
>>> I made the following function for a single date. I would like to add a
>>> condition for date in 3 columns (year, month, day). My data is daily
>>> climate data.
>>> #write a function that create a day column either from a single date
>>> column
>>> (string/or factors)
>>> #or from date in 3 columns (year, month, day).
>>>
>>> DOY=function(data){
>>>
>>> #=
>>> #This function create day of teh year from a single date
>>> column(ex:2009-08-02) or/and
>>> #from the date in 3 columns (Year, month, Day).
>>> #
>>>   data$Rain=as.numeric(as.character(data$Rain))
>>>   dt=yday(data$Date) # single date of the data
>>>   datelp= dt>59 & !leap_year(data$Date)# tell us that the date occurs
>>> during a leap year
>>>   dt[datelp]=dt[datelp]+1 # add one for non leap_year
>>>   cbind(data, dt) # combining columns of data
>>>   conames(data)="DOY" # name of new column. ??I have a problem on how I
>>> can
>>> precise the column in gerenal.
>>> }
>>>
>>> ex: year  month day   Date Rain Tmin Tmax
>>>   1971   1 11971-01-01   0 8.2  15
>>>1971  1 21971-01-02   0 4.2  11
>>> ..  .   .   .  .  .
>>> ..  .   .   .  .  .
>>> ..  .   .   .  .  .
>>>
>>> Any ideal on how I can make this function is welcome. thanks!
>>> Frederic Ntirenganya
>>> Maseno University,
>>> African Maths Initiative,
>>> Kenya.
>>> Mobile:(+254)718492836
>>> Email: fr...@aims.ac.za
>>> https://sites.google.com/a/aims.ac.za/fredo/
>>>
>>> [[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.
>>>
>>
>>
>>
>> --
>> Daniel
>>
>
>


-- 
Daniel

[[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] ggplot2, qplot, problems

2016-12-05 Thread Daniel
Dear the R Community,

I just encountered an error while using ggplot2 and the qplot function
(please see below for the warnings and error), and i have no idea about how
to make changes so that it will work.
Could anyone kindly advise me a bit and help me out here?

--
> library(ggplot2)
Warning message:
package ‘ggplot2’ was built under R version 3.2.5

> library(ggplot2)
> dodge <- position_dodge(width = .9)
> plot <- qplot(happening, target.looking_M, data=d.c2.subjects,
stat="identity",
+ geom="bar", position=dodge,
+ ylab="Proportion of looks", xlab="happening",
+ fill=happening, colour=happening,
+ main="Proportion target looking by condition and testing phase for each
single subject")

Warning messages:
1: `stat` is deprecated
2: `position` is deprecated

> plot <- plot + facet_grid(type ~ subjectname)
> plot

Error: stat_count() must not be used with a y aesthetic.
-------

thank you very much.

Cheers,
Daniel

[[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] Print table in lme

2010-02-19 Thread Daniel
Hello, I'm trying to add lme results in a table with lm coef results, but as
I know, estout or xtabel cannot  support lme objects.
I'm a new in R and I'll appreciate some helpful comments.

-- 
Daniel Marcelino
Phone: (647) 8910939

[[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] ODBC with Filemaker

2010-02-26 Thread Daniel
Hi all,
anybody get connection with Filemarker 10 for mac?
How do that?
I suppose did right, but it is not working.


-- 
Daniel Marcelino
Phone: (647) 8910939

[[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] updating cells

2010-06-17 Thread Daniel
Hello all,I have a table with about 18000 rows, I need to UPDATE the strings
in the "name.x" column in each row by the strings from "name.y" given if
"name.x" is NA or " ". How can I do it?
Also I want to update values in other columns, but I think that will be the
same job.
Daniel
-- 
Daniel Marcelino
http://bit.ly/pol4vc

[[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 for loop

2010-12-17 Thread Daniel
Hello all,
Is there any way to get each file from a website list and aggregate in a
data frame?
Otherwise I have to type 23 thousand web address into a long script like it:

base1 <- read.table("site 1", sep=";", header=T,
fileEncoding="windows-1252")
base2 <- read.table("site 2", sep=";", header=T,
fileEncoding="windows-1252")

I need to download each .CSV file from each address in the list vector and
 row bind all them into a big data frame.
Also I need to decode each object to UTF-8. Of course, many of web sites
from the list maybe be empty, so, my loop needs to jump for the next
address.

My first shot look looks like working, but, after one night and half a dia,
it didn't finish. That I mean, much time for the task. Can somebody help
me?

Example, few address:

mysites <-c("
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=4000613&sgUe=AM&cpfCnpjDoador=";,
"
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=4000620&sgUe=AM&cpfCnpjDoador=";,
"
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=4000259&sgUe=AM&cpfCnpjDoador=";,
"
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=25002241&sgUe=SP&cpfCnpjDoador=";,
"
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=25002438&sgUe=SP&cpfCnpjDoador=
", "
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=4000257&sgUe=AM&cpfCnpjDoador=
","
http://spce2010.tse.gov.br/spceweb.consulta.receitasdespesas2010/exportaReceitaCsvCandidato.action?sqCandidato=12000162&sgUe=MS&cpfCnpjDoador=";
)

big.data <- NULL
base <-NULL
  for (i in mysites) {
  try(base <- read.table(i, sep=";", header=T, as.is=T,
fileEncoding="windows-1252"), TRUE)
  if(!is.null(base)) big.data <- rbind(big.data, base)
  }

-- 
Daniel Marcelino
Skype: dmsilv
http://marcelino.pbworks.com/

[[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] Help needed with aggregate or other solution

2017-10-26 Thread Daniel Nordlund
uot;, "2012-04-20 00:00:00", "2012-04-20 06:00:00",
"2012-04-20 12:00:00", "2012-04-20 18:00:00", "2012-04-21 00:00:00",
"2012-04-21 06:00:00", "2012-04-21 12:00:00", "2012-04-21 18:00:00",
"2012-04-22 00:00:00", "2012-04-22 06:00:00", "2012-04-22 12:00:00",
"2012-04-22 18:00:00", "2012-04-23 00:00:00", "2012-04-23 06:00:00",
"2012-04-23 12:00:00", "2012-04-23 18:00:00", "2012-04-24 00:00:00",
"2012-04-24 06:00:00", "2012-04-24 12:00:00", "2012-04-24 18:00:00",
"2012-04-25 00:00:00", "2012-04-25 06:00:00", "2012-04-25 12:00:00",
"2012-04-25 18:00:00", "2012-04-26 00:00:00", "2012-04-26 06:00:00",
"2012-04-26 12:00:00", "2012-04-26 18:00:00", "2012-04-27 00:00:00",
"2012-04-27 06:00:00

Re: [R] Count non-zero values in excluding NA Values

2017-10-29 Thread Daniel Nordlund

On 10/29/2017 3:25 AM, Engin YILMAZ wrote:

Dear R Staff

You can see my data.csv file in the annex.

I try to count non-zero values in dataset but I need to exclude NA in this
calculation

My code is very long (following),
How can I write this code more efficiently and shortly?

## [NA_Count] - Find NA values

data.na =sapply(data[,3:ncol(data)], function(c) sum(length(which(is.na
(c)


## [Zero] - Find zero values

data.z=apply(data[,3:ncol(data)], 2, function(c) sum(c==0))


## [Non-Zero] - Find non-zero values

data.nz=nrow(data[,3:ncol(data)])- (data.na+data.z)


Sincerely
Engin YILMAZ

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
__
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.



this looks like a good place for apply()

   apply(data,2,function(x) sum(x != 0, na.rm=TRUE))


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Missing information in source()

2017-11-07 Thread Daniel Nordlund

On 11/7/2017 12:01 PM, Tom Backer Johnsen wrote:

Dear R-help,

I am running a Mac under Sierra, with R version 3.4.2 and RStudio 1.1.383.  When 
running head () or tail () on an object in a script using source (

[R] IBM Power vs Markdown

2018-01-19 Thread Daniel King

Hi, folks.

I was wondering if any of you could point me in the right direction.

Using R 3.3.3 (and later), on an IBM Power LPAR, Red Hat 7 PPC64le, markdown 
build fails as below.

> install.packages("markdown")
trying URL 'https://cloud.r-project.org/src/contrib/markdown_0.8.tar.gz'
Content type 'unknown' length 80583 bytes (78 KB) 
==
downloaded 78 KB

installing source package 'markdown' ...
** package 'markdown' successfully unpacked and MD5 sums checked
** libs
/opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -I/usr/local/lib64/R/include -DNDEBUG 
-I/usr/local/include -qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c Rbase64.c -o 
Rbase64.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -I/usr/local/lib64/R/include 
-DNDEBUG -I/usr/local/include -qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c 
Rinit.c -o Rinit.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 
-I/usr/local/lib64/R/include -DNDEBUG -I/usr/local/include -qpic -g -O2 
-qstrict -qfloat=nomaf:fenv -c Rmarkdown.c -o Rmarkdown.o 
/opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -I/usr/local/lib64/R/include -DNDEBUG 
-I/usr/local/include -qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c autolink.c -o 
autolink.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -I/usr/local/lib64/R/include 
-DNDEBUG -I/usr/local/include -qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c 
buffer.c -o buffer.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 
-I/usr/local/lib64/R/include -DNDEBUG -I/usr/local/include -qpic -g -O2 
-qstrict -qfloat=nomaf:fenv -c houdini_href_e.c -o houdini_href_e.o 
/opt/ibm/xlC/13.1.
 6/bin/xlc_r -q64 -I/usr/local/lib64/R/include -DNDEBUG -I/usr/local/include 
-qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c houdini_html_e.c -o 
houdini_html_e.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 
-I/usr/local/lib64/R/include -DNDEBUG -I/usr/local/include -qpic -g -O2 
-qstrict -qfloat=nomaf:fenv -c html.c -o html.o /opt/ibm/xlC/13.1.6/bin/xlc_r 
-q64 -I/usr/local/lib64/R/include -DNDEBUG -I/usr/local/include -qpic -g -O2 
-qstrict -qfloat=nomaf:fenv -c html_smartypants.c -o html_smartypants.o 
/opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -I/usr/local/lib64/R/include -DNDEBUG 
-I/usr/local/include -qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c markdown.c -o 
markdown.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -I/usr/local/lib64/R/include 
-DNDEBUG -I/usr/local/include -qpic -g -O2 -qstrict -qfloat=nomaf:fenv -c 
stack.c -o stack.o /opt/ibm/xlC/13.1.6/bin/xlc_r -q64 -qmkshrobj -shared 
-L/usr/local/lib64/R/lib -L/usr/local/lib64 -o markdown.so Rbase64.o Rinit.o 
Rmarkdown.o autolink.o buffer.o houdini_href_e.o houdin
 i_html_e.o html.o html_smartypants.o markdown.o stack.o 
-L/usr/local/lib64/R/lib -lR
markdown.o: In function find_block_tag': 
/tmp/RtmpqYsbzz/R.INSTALL1cb764af1cf/markdown/src/./html_blocks.h:206: 
undefined reference tofind_block_tag$AF85_1'
/usr/bin/ld: markdown.so: internal symbol `find_block_tag$AF85_1' isn't defined
/usr/bin/ld: final link failed: Bad value
make: *** [markdown.so] Error 1
ERROR: compilation failed for package 'markdown'
removing '/usr/local/lib64/R/library/markdown'
The downloaded source packages are in
'/tmp/Rtmpl7vFYx/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("markdown") :
installation of package 'markdown' had non-zero exit status

...

It looks like the issue can be traced down to, "!gperf_case_strncmp (str, s, 
len)" ... is there a way to trace this down further?

# tail markdown/src/html_blocks.h
  if (key <= MAX_HASH_VALUE && key >= 0)
{
  register const char *s = wordlist[key];

  if unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && 
!gperf_case_strncmp (str, s, len) && s[len] == '\0')
return s;
}
}
  return 0;
}

Any assistance is appreciated.

A. Daniel King
Haverty Furniture Companies, Inc.

__
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] Simulation based on runif to get mean

2018-01-30 Thread Daniel Nordlund

On 1/29/2018 9:03 PM, smart hendsome via R-help wrote:

Hello everyone,
I have a question regarding simulating based on runif.  Let say I have 
generated matrix A and B based on runif. Then I find mean for each matrix A and 
matrix B.  I want this process to be done let say 10 times. Anyone can help me. 
 Actually I want make the function that I can play around with the number of 
simulation process that I want. Thanks.
Eg:
a <- matrix(runif(5,1, 10))

b <- matrix(runif(5,10, 20))

c <- cbind(a,b); c

mn <- apply(c,2,mean); mn

Regards,
Zuhri

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



Here is a straight forward implementation of your code in a function 
with a parameter for the number simulations you want to run.


sim <- function(n){
  mn <- matrix(0,n, 2)
  for(i in 1:n) {
a <- runif(5,1, 10)
b <- runif(5,10, 20)
c <- cbind(a,b)
mn[i,] <- apply(c, 2, mean)
}
  return(mn)
  }
# run 10 iterations
sim(10)

In your case, there doesn't seem to be a need to create a and b as 
matrices; vectors work just as well.  Also, several of the statements 
could be combined into one.  Whether this meets your needs depends on 
what your real world task actually is.



Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] command line fails

2018-02-02 Thread Daniel Nordlund

On 2/2/2018 4:52 AM, Michael Ashton wrote:

Hi - Think this is quick help. Not sure how to trap what is causing my simple 
script to run fine in R, but fail immediately when called from rscript. I can 
put all sorts of traps in the script itself, but when called from the command 
line the r window simply flashes and closes.

There's probably a way to find out why rscript is failing, but I don't know it and can't 
seem to find it online. To be clear, I'm not really trying to save the OUTPUT of the 
file...it never even executes as far as I can tell. I'm calling it with C:\Program 
Files\R\R-3.4.3\bin\Rscript.exe "P:\Investments\Trading Tools\RV 
Tools\myfile.r" And again, it executes perfectly if I open the GUI first and then 
run it within R.

Thanks for the help!

Mike

Michael Ashton, CFA
Managing Principal

Enduring Investments LLC
W: 973.457.4602
C: 551.655.8006



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



Mike,

on Windows, anytime you send a path that contains a space to the command 
line it needs to be enclosed in double quotes.  Try a call like


"C:/Program Files/R/R-3.4.3/bin/Rscript.exe" "P:/Investments/Trading 
Tools/RV Tools/myfile.r"


I don't know how rscript handles the '\' character (i.e. as an escape or 
not) so I changed the '\' to '/' just to be safe.  And note, the program 
pathname and the file being passed need to be quoted separately.



Hope this helps,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] How to turn off warnings about class name conflicts

2018-02-14 Thread Daniel Nordlund

On 2/13/2018 11:47 PM, Ayhan yuksel wrote:

Hi,

I am using two packages (quantmod and FRAPO)

Quantmod and FRAPO both have a class names "zoo"

R is displaying the following warning when I manipulate an object of class
zoo:

Found more than one class "zoo" in cache; using the first, from namespace
'quantmod'
Also defined by ‘FRAPO’

The warning is displayed every time I manipulate a zoo object and becomes
pretty annoying.

I searched for a solution but couldn't found.

A related but unanswered question is here:
http://r.789695.n4.nabble.com/setOldClass-quot-xts-quot-td4714332.html

How can I turn off the warning?

Reproducible example:

library(quantmod)
library(FRAPO)
z<-zoo(runif(100),1:100)


Session Info (I am using Microsoft R):

R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

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

other attached packages:
  [1] FRAPO_0.4-1   timeSeries_3022.101.2 timeDate_3012.100
  Rglpk_0.6-2
  [5] slam_0.1-40   cccp_0.2-4quantmod_0.4-12
  TTR_0.23-2
  [9] xts_0.10-1zoo_1.8-0 RevoUtils_10.0.7
RevoUtilsMath_10.0.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.10 lattice_0.20-35  codetools_0.2-15 grid_3.4.3
  curl_3.1
[6] tools_3.4.3  compiler_3.4.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.



I tried your example (in a clean session) under R-3.4.3 from CRAN and 
Microsoft R Open 3.4.3.0 and did not get the message you are getting.  I 
suspect you have something in your workspace that is causing the problem.


Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Empirical density estimation

2018-03-11 Thread Daniel Nordlund

On 3/11/2018 3:35 PM, Christofer Bogaso wrote:

But for my reporting purpose, I need to generate a bell curve like
plot based on empirical PDF, that also contains original points.

Any idea would be helpful. Thanks,




Christofer,

something like the following may get you what you want:

## get the kernel density estimate
dens <- density(Dat)

## estimate the density at your original points
dnew <- approx(dens$x,dens$y,xout=Dat)

## plot kernel density estimate
plot(dx)

## add your original values with the estimated density
points(dnew, pch=1, cex=0.5, col="red")


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA


On Mon, Mar 12, 2018 at 3:49 AM, Bert Gunter  wrote:

You need to re-read ?density and perhaps think again -- or do some study --
about how a (kernel) density estimate works. The points at which the
estimate is calculated are *not* the values given, nor should they be!

Cheers,
Bert



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, Mar 11, 2018 at 11:45 AM, Christofer Bogaso
 wrote:


Hi,

Let say I have below vector of data-points :

Dat = c(-0.444, -0.25, -0.237449799196787, -0.227467046669042,

-0.227454464682363, -0.22, -0.214876033057851, -0.211781206171108,

-0.199891067538126, -0.192920353982301, -0.192307692307692,
-0.186046511627907,

-0.184418145956608, -0.181818181818182, -0.181818181818182,
-0.181266261925412,

-0.181003118503119, -0.179064587973274, -0.178217821782178,
-0.17809021675454,

-0.177685950413223, -0.177570093457944, -0.176470588235294,
-0.176470588235294,

-0.174825741611282, -0.168021680216802, -0.167,
-0.167,

-0.166380789022298, -0.164209115281501, -0.164011246485473,
-0.162689804772234,

-0.162361623616236, -0.160161507402423, -0.16, -0.155038759689922,

-0.154172560113154, -0.15311004784689, -0.151515151515152,
-0.151462994836489,

-0.151098901098901, -0.150537634408602, -0.150442477876106,
-0.150406504065041,

-0.149904214559387, -0.149882903981265, -0.149797570850202,
-0.148496240601504,

-0.148325358851675, -0.147540983606557, -0.147239263803681,
-0.146989966555184,

-0.14622641509434, -0.146095717884131, -0.145994832041344,
-0.14572864321608,

-0.145161290322581, -0.144292237442922, -0.144144144144144,
-0.144021739130435,

-0.14375, -0.142212189616253, -0.141122913505311, -0.140324963072378,

-0.139344262295082, -0.13884007029877, -0.138356164383562,
-0.137626262626263,

-0.137142857142857, -0.136690647482014, -0.136577708006279,
-0.136363636363636,

-0.136094674556213, -0.135879774577332, -0.135586319218241,
-0.135135135135135,

-0.132780082987552, -0.132209405501331, -0.132023755139333,
-0.131233595800525,

-0.130434782608696, -0.130434782608696, -0.130268199233717,
-0.128813559322034,

-0.1284046692607, -0.128205128205128, -0.128182616330114,
-0.127937336814621,

-0.126283367556468, -0.125853658536585, -0.125448028673835,
-0.125425564840607,

-0.125311203319502, -0.125, -0.124401913875598, -0.124248496993988,

-0.124031007751938, -0.123572170301142, -0.123188405797102,
-0.122905027932961,

-0.1216667, -0.121573685907772, -0.120658135283364,
-0.120540019286403,

-0.119858156028369, -0.11965811965812, -0.11965811965812,
-0.119565217391304,

-0.118942731277533, -0.117820324005891, -0.116257947320618,
-0.115789473684211,

-0.115683584819387, -0.115384615384615, -0.115281501340483,
-0.114492753623188,

-0.114357262103506, -0.114285714285714, -0.114035087719298,
-0.113181972212809,

-0.112790697674419, -0.112781954887218, -0.112195121951219,
-0.112191473448018,

-0.111, -0.111, -0.110813226094727,
-0.110384300899428,

-0.110147441457069, -0.110137672090113, -0.109913793103448,
-0.109792284866469,

-0.109375, -0.10919540229885, -0.109112709832134, -0.10844250363901,

-0.107776617954071, -0.10752688172043, -0.107317073170732,
-0.106674272675414,

-0.106382978723404, -0.106100795755968, -0.106060606060606,
-0.10595160235448,

-0.105742474070326, -0.105263157894737, -0.104454685099846,
-0.104283054003724,

-0.103916449086162, -0.103723404255319, -0.103448275862069,
-0.102737680438029,

-0.10267471958585, -0.101696871753434, -0.100893997445721,
-0.10041265474553,

-0.100042983021706, -0.1, -0.0995111731843576, -0.099502487562189,

-0.0994117647058824, -0.0991561181434598, -0.0989492119089317,

-0.0988372093023255, -0.0983908045977012, -0.0983050847457627,

-0.0977198697068404, -0.0974702380952382, -0.0973819695475956,

-0.097345132743363, -0.0971472629144179, -0.0971438645980254,

-0.0961538461538461, -0.096062667491239, -0.0957347238935687,

-0.0956521739130435, -0.0954773869346733, -0.0954115076474873,

-0.0952380952380952, -0.0951115834218915, -0.0950642007303569,

-0.0949423247559894, -0.0947368421052631, -0.0946291560102303,

-0.0945220193340494, -0.0944309927360775, -0.0943016759776536,

-0.0

Re: [R] Average of results coming from B=100 repetitions (looping)

2018-05-08 Thread Daniel Nordlund

On 5/8/2018 12:26 PM, varin sacha via R-help wrote:


  Dear R-experts,

Here below the reproducible example. I am trying to get the average of the 100 results 
coming from the "lst" function. I have tried lst$mean and mean(lst). It does 
not work.
Any help would be highly appreciated >


  ## R script for getting MedAe and MedAeSQ from HBR model on Testing data
install.packages("robustbase")
install.packages( "MASS" )
install.packages( "quantreg" )
install.packages( "RobPer")
install.packages("devtools")
library("devtools")
install_github("kloke/hbrfit")
install.packages('http://www.stat.wmich.edu/mckean/Stat666/Pkgs/npsmReg2_0.1.1.tar.gz')
library(robustbase)
library(MASS)
library(quantreg)
library(RobPer)
library(hbrfit)

# numeric variables
A=c(2,3,4,3,2,6,5,6,4,3,5,55,6,5,4,5,6,6,7,52)
B=c(45,43,23,47,65,21,12,7,18,29,56,45,34,23,12,65,4,34,54,23)
D=c(21,54,34,12,4,56,74,3,12,71,14,15,63,34,35,23,24,21,69,32)

# Create a dataframe
BIO<-data.frame(A,B,D)

# Create a list to store the results
lst<-list()


<<>>

You need to spend some time with the Introduction to R that came with 
your R installation.  First, lst in your example is not a function, it 
is a list. And as you found, the mean() function does not work on a 
list. Second, your "minimal reproducible" example could have been 
something like this


lst <- list()
for (i in 1:10) lst[i] <- i
mean(lst)  # does not work

The documentation for mean, ?mean, says that it is looking for a numeric 
or logical vector.  To convert your list to a numeric vector you could 
unlist() it.


mean(unlist(lst))


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Bootstrap and average median squared error

2018-05-22 Thread Daniel Nordlund

On 5/22/2018 2:32 AM, Rui Barradas wrote:

bootMedianSE <- function(data, indices){
  d <- data[indices, ]
  fit <- rq(crp ~ bmi + glucose, tau = 0.5, data = d)
  ypred <- predict(fit)
  y <- d$crp
  median(y - ypred)^2
}


since the OP is looking for the "median squared error", shouldn't the 
final line of the function be


median((y - ypred)^2)


Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Using tryCatch in a for loop

2018-05-22 Thread Daniel Nordlund
e summary(seg.reg) object (RSyear is NULL).
2.  the coefficients[] matrix in the summary(seg.reg) object does not 
have 3 rows, so you get an error and SlopeDiff is not created.


You need to correct these problems, and any others, so that your code 
runs correctly when there are no data problems.  Then you can worry 
about trapping errors in the case where there are data problems.


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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 Load A Package

2018-06-02 Thread Daniel Nordlund

On 6/1/2018 4:17 PM, Duncan Murdoch wrote:

On 01/06/2018 5:24 PM, Shivi Bhatia wrote:

Hi All,

I am trying to download semnet package but getting the error:
package not available for R version 3.4.4.


As far as I can see, there is no semnet package on CRAN, and never has 
been (or if there was, it was there by mistake).


Packages whose names start with "sem" are:

sem    Structural Equation Models
semantic.dashboard    Dashboard with Semantic UI Support for 'shiny'
Semblance    Pair-Wise Semblance Using a Rank-Based Kernel
semdiag    Structural equation modeling diagnostics
semds    Structural Equation Multidimensional Scaling
semGOF    Goodness-of-fit indexes for structural equation models
semiArtificial    Generator of Semi-Artificial Data
SemiCompRisks    Hierarchical Models for Parametric and Semi-Parametric 
Analyses of Semi-Competing Risks Data

SEMID    Identifiability of Linear Structural Equation Models
SemiMarkov    Multi-States Semi-Markov Models
seminr    Domain-Specific Language for Building PLS Structural Equation 
Models

SemiPar    Semiparametic Regression
SemiParSampleSel    Semi-Parametric Sample Selection Modelling with 
Continuous or Discrete Response

SemiSupervised    Safe Semi-Supervised Learning Tools
semisupKernelPCA    Kernel PCA projection, and semi-supervised variant
SEMModComp    Model Comparisons for SEM
SemNetCleaner    An Automated Cleaning Tool for Semantic and Linguistic 
Data
semPlot    Path Diagrams and Visual Analysis of Various SEM Packages' 
Output

semPLS    Structural Equation Modeling Using Partial Least Squares
semPower    Power Analyses for SEM
semsfa    Semiparametric Estimation of Stochastic Frontier Models
semTools    Useful Tools for Structural Equation Modeling
semtree    Recursive Partitioning for Structural Equation Models
semver    'Semantic Versioning V2.0.0' Parser

Perhaps you really want one of those.

Duncan Murdoch



I tried downloading it from
install.packages('semnet',repos='http://cran.us.r-project.org')
and 
install.packages('semnet',repos='http://cran.revolutionanalytics.com/')

and even the https://cran.r-project.org/src/contrib/semnet.tar.gz but
doesnt seem to get success.

Please suggest some alternate.

Regards, Shivi

[[alternative HTML version deleted]]



Maybe this is what the OP is looking for

library(devtools)
install_github("kasperwelbers/semnet")


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

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

2018-06-23 Thread Daniel Nordlund

On 6/22/2018 4:43 AM, Bill Poling wrote:

Good morning.


I have data in the form:

head(Edit041IA, n=25)
ClaimServiceID  ClaimID DiagnosisCode
1   183056004 78044473  C562
2   183056004 78044473  C778
3   183056004 78044473  C784
4   183056004 78044473  C786
5   183056004 78044473 C7961
6   183056004 78044473 C7982
7   183056004 78044473 C7989
8   183056008 78044473  C562
9   183056008 78044473  C778
10  183056008 78044473  C784
11  183056008 78044473  C786
12  183056008 78044473 C7961
13  183056008 78044473 C7982
14  183056008 78044473 C7989
15  183139945 78078925M79606
16  183139945 78078925 M7989
17  183139945 78078925  R600
18  183236728 78119632H02831
19  183236728 78119632H02832
20  183236728 78119632H02834
21  183236728 78119632H02835
22  183236728 78119632H04123
23  183236728 78119632  Z411
24  183236728 78119632 H2513
25  183236728 78119632H43813

And wish to transpose to single record for single claimServiceID, ClaimID, and 
Dx1,Dx2,Dx3, etc:

There can be multiple claimServiceIDs for a ClaimID so I want the unique 
ClaimServiceID as the identifier when I join this data back into a longer 
single record length file by that column.

 claimServiceID ClaimID  Dx1   Dx2Dx3  ...etc
1 18305600478044473 C562 C778 C784 C786 C7961 ...etc
2 18305600878044473 C562 C778 C784 C786 C7961 ...etc


(If you would prefer the complete  dput of the 1272 records I will gladly provide .Names 
= c("ClaimServiceID",

"ClaimID", "DiagnosisCode"), class = "data.frame", row.names = c(NA,

-1272L))



At the moment the classes are:

classes <- as.character(sapply(Edit041IA, class))

classes

# [1] "integer"   "integer"   "character" <---but do not have to be if that 
helps its just that's how the csv load pulled them in

The max number of columns based on this transpose of the DiagnosisCode column 
(in this dataset) is 12 if that is important to know.

I have looked at a variety of webpages and cannot get this right,

dta2 <- melt(dta1, id=c("ClaimServiceID","ClaimID"))
View(dta2)
  # https://www.r-bloggers.com/pivot-tables-in-r/

# 
https://stackoverflow.com/questions/18449938/pivot-on-data-table-similar-to-rehape-melt-function


dta3 <- cast(Edit041IA, ClaimServiceID ~ DiagnosisCode, ClaimID)
View(dta3)
dta3 <- cast(Edit041IA, DiagnosisCode ~ ClaimServiceID, ClaimID)
View(dta3)

dta3 <- melt(Edit041IA, id=c("ClaimServiceID"))
View(dta3)

dta3 <- aggregate(Edit041IA, by=list(ClaimServiceID, ClaimID, DiagnosisCode))
View(dta3)


dta3 <- aggregate(Edit041IA, by=list(ClaimServiceID))
View(dta3)
  # https://www.r-statistics.com/tag/transpose/

  dta3 <- aggregate(Edit041IA, by=list(DiagnosisCode, ClaimServiceID, ClaimID))
View(dta3)


I am sure it's a basic,  simple procedure, but I am pressed for time on this 
one, any support will be greatly appreciated, thank you.

WHP





Confidentiality Notice This message is sent from Zelis. ...{{dropped:15}}

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



Bill,

you have received some good suggestions and since you are pressed for 
time this may be too late.  However, here is a solution using ave() 
function and  cast() from the reshape package.


# create diagnosis variable names
dxnames <- paste('Dx',ave(rep(1, nrow(have)), have[,1:2], FUN = 
seq_along), sep='')

# cast the data into wide format
cast(cbind(have,dxnames), ClaimServiceID + ClaimID ~ dxnames, 
value='DiagnosisCode')



Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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 function stopped working

2017-04-04 Thread DANIEL PRECIADO
The following function is supposed to search the workspace and save
plots  (i.e. listing all objects in the workspace named "Figs", which
are all ggplot2 plots, and saving them as png files)

SaveFigs <- function()
{
for (i in ls(pattern="_Figs_"))
{
filename = paste(Plots_Path, i, ".png", sep="")
png(filename)
print(eval(as.name(i)))
dev.off()
}
}


It was working perfectly until some days ago, but now nothing happens
when the function is called. No error, no output, no result, no files,
nothing at all. Completely useless.

If I run the for loop inside alone, without the function, it works
perfectly and produces the expected result (png files in the defined
folder). But running it as a function doesn't do anything at all.

Can anyone explain why did this function simply and suddenly stopped
working?

(using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
__
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 function stopped working

2017-04-04 Thread DANIEL PRECIADO
Thanks, but printing doesn't work within the function either. (i.e, no
result or output, or error). Also, like I said, the loop is working
fine on its own (so the path, name, filename, and all other variables
called from the function exist, are available and are recognized just
fine). It just doesn't do anything (anymore) if the loop is inside a
function.


On Tue, 2017-04-04 at 11:21 +0200, peter dalgaard wrote:
> How about inserting print() statements on the output of "ls()" and
> the value of "filename". In particular, is the value of Plots_path
> the same as last week?
> 
> -pd
> 
> 
> > On 4 Apr 2017, at 10:50 , DANIEL PRECIADO 
> > wrote:
> > 
> > The following function is supposed to search the workspace and save
> > plots  (i.e. listing all objects in the workspace named "Figs",
> > which
> > are all ggplot2 plots, and saving them as png files)
> > 
> > SaveFigs <- function()
> > {
> > for (i in ls(pattern="_Figs_"))
> > {
> > filename = paste(Plots_Path, i, ".png", sep="")
> > png(filename)
> > print(eval(as.name(i)))
> > dev.off()
> > }
> > }
> > 
> > 
> > It was working perfectly until some days ago, but now nothing
> > happens
> > when the function is called. No error, no output, no result, no
> > files,
> > nothing at all. Completely useless.
> > 
> > If I run the for loop inside alone, without the function, it works
> > perfectly and produces the expected result (png files in the
> > defined
> > folder). But running it as a function doesn't do anything at all.
> > 
> > Can anyone explain why did this function simply and suddenly
> > stopped
> > working?
> > 
> > (using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
> > __
> > 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-g
> > uide.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] R function stopped working

2017-04-04 Thread DANIEL PRECIADO
To your first comment: Yes, the function used to work, and the loop inside it 
still does (as indicated in my first email). I wouldn't bother asking otherwise.
To your second, no, specifying the environment in the ls() call doesn't help, 
the problem persist.


On Tue, 2017-04-04 at 15:26 +0200, peter dalgaard wrote:

Given the following little experiment



foobar <- 1
f <- function() ls()
f()


character(0)


f <- function(x) ls()
f(2)


[1] "x"






... I am pretty sure that your code _never_ actually worked.

It probably helps if you tell ls() which environment to list, as in:



f <- function() ls(.GlobalEnv)
f()


[1] "f"      "foobar"




On 4 Apr 2017, at 12:27 , DANIEL PRECIADO 
mailto:danp...@hotmail.com>> wrote:

Thanks, but printing doesn't work within the function either. (i.e, no
result or output, or error). Also, like I said, the loop is working
fine on its own (so the path, name, filename, and all other variables
called from the function exist, are available and are recognized just
fine). It just doesn't do anything (anymore) if the loop is inside a
function.


On Tue, 2017-04-04 at 11:21 +0200, peter dalgaard wrote:


How about inserting print() statements on the output of "ls()" and
the value of "filename". In particular, is the value of Plots_path
the same as last week?

-pd




On 4 Apr 2017, at 10:50 , DANIEL PRECIADO 
mailto:danp...@hotmail.com>>
wrote:

The following function is supposed to search the workspace and save
plots  (i.e. listing all objects in the workspace named "Figs",
which
are all ggplot2 plots, and saving them as png files)

SaveFigs <- function()
{
for (i in ls(pattern="_Figs_"))
{
filename = paste(Plots_Path, i, ".png", sep="")
png(filename)
print(eval(as.name(i)))
dev.off()
}
}


It was working perfectly until some days ago, but now nothing
happens
when the function is called. No error, no output, no result, no
files,
nothing at all. Completely useless.

If I run the for loop inside alone, without the function, it works
perfectly and produces the expected result (png files in the
defined
folder). But running it as a function doesn't do anything at all.

Can anyone explain why did this function simply and suddenly
stopped
working?

(using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
__
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-g
uide.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] R function stopped working

2017-04-04 Thread DANIEL PRECIADO
Thanks! I was not aware of the browser() function, seems pretty useful for 
debugging.
However, for this particular case, adding it to the mentioned function doesn't 
do much: Again I get no errors, no output in the terminal and no files are 
created.

If I include browser() within the for-loop (not defining it as a function, but 
running it directly), I do get to examine every step of the way, and it runs 
fine (as expected). But if the exact same for-loop is sitting inside a 
function, it doesn't do anything at all, with or without browser().

D.

On Tue, 2017-04-04 at 10:19 -0400, Boris Steipe wrote:

I discourage the use of print() for debugging.
Put a browser() statement into your loop and when execution takes you to the 
debugger interface, examine your variables and expressions one by one.


B.






On Apr 4, 2017, at 10:09 AM, DANIEL PRECIADO 
mailto:danp...@hotmail.com>> wrote:

To your first comment: Yes, the function used to work, and the loop inside it 
still does (as indicated in my first email). I wouldn't bother asking otherwise.
To your second, no, specifying the environment in the ls() call doesn't help, 
the problem persist.


On Tue, 2017-04-04 at 15:26 +0200, peter dalgaard wrote:

Given the following little experiment



foobar <- 1
f <- function() ls()
f()


character(0)


f <- function(x) ls()
f(2)


[1] "x"






... I am pretty sure that your code _never_ actually worked.

It probably helps if you tell ls() which environment to list, as in:



f <- function() ls(.GlobalEnv)
f()


[1] "f"  "foobar"




On 4 Apr 2017, at 12:27 , DANIEL PRECIADO 
mailto:danp...@hotmail.com><mailto:danp...@hotmail.com>> 
wrote:

Thanks, but printing doesn't work within the function either. (i.e, no
result or output, or error). Also, like I said, the loop is working
fine on its own (so the path, name, filename, and all other variables
called from the function exist, are available and are recognized just
fine). It just doesn't do anything (anymore) if the loop is inside a
function.


On Tue, 2017-04-04 at 11:21 +0200, peter dalgaard wrote:


How about inserting print() statements on the output of "ls()" and
the value of "filename". In particular, is the value of Plots_path
the same as last week?

-pd




On 4 Apr 2017, at 10:50 , DANIEL PRECIADO 
mailto:danp...@hotmail.com><mailto:danp...@hotmail.com>>
wrote:

The following function is supposed to search the workspace and save
plots  (i.e. listing all objects in the workspace named "Figs",
which
are all ggplot2 plots, and saving them as png files)

SaveFigs <- function()
{
   for (i in ls(pattern="_Figs_"))
   {
   filename = paste(Plots_Path, i, ".png", sep="")
   png(filename)
   print(eval(as.name(i)))
   dev.off()
   }
}


It was working perfectly until some days ago, but now nothing
happens
when the function is called. No error, no output, no result, no
files,
nothing at all. Completely useless.

If I run the for loop inside alone, without the function, it works
perfectly and produces the expected result (png files in the
defined
folder). But running it as a function doesn't do anything at all.

Can anyone explain why did this function simply and suddenly
stopped
working?

(using R version 3.3.3 on an ubuntu 16.10, if that is of any help)
__
R-help@r-project.org<mailto: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-g
uide.html
and provide commented, minimal, self-contained, reproducible code.











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


[R] Question on accessing foreign files

2017-04-18 Thread Daniel Molinari
Hi all,

I have several data files provided in mtw format (Minitab) and sdd format
(S-Plus) and I need to read them in R.

I do not have access either to Minitab or to S-Plus.

How can I accomplish this task ?

Thank you,
Daniel

[[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] Unusual behavior in e1071?

2017-05-01 Thread Daniel Jeske
Hello -

I have noticed that when I run svm() the order of my data matters.  If the
first case in the data frame has y=+1 I get the expected decision rule that
says to classify as +1 if f(x)>0.  However, if the first case in the data
frame has y=-1 then apparently the decision rule being used says to
classify as +1 if f(x)<0, and in this case all the coefficients are
negative of their values compared to the first case.  So the two
classification rules are equivalent, but is a user really supposed to know
the difference?  It is likely they would assume the decision rule is always
to classify as +1 if f(x)>0.  Does anyone think the behavior I have noticed
is as intended, or is otherwise benign?

Thank you,
Daniel Jeske
Professor
Department of Statistics
University of California - Riverside

[[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] display double dot over character in plotmath?

2017-05-12 Thread Daniel Nordlund

On 5/12/17 4:55 PM, Ranjan Maitra wrote:

Hi,

Is it possible to display double dot (umlaut) over a character such as would be 
possible using \ddot x in LaTeX? I can do this using tikzDevice but I wanted 
something simpler to point to.

Here is an example of what I would like to do, but it is not quite there:

require(ggplot2)
data<-as.data.frame(c("a","b","c","a","b","c"))
colnames(data)<-"Y"
data$X<-c(1:6)
data$Z<-c(1,2,3,1,2,3)

ggplot(data, aes(x=X)) + geom_line(aes(y = Z), size=0.43) + 
xlab(expression(atop(top,bold(Age~"à"

I would like to put in a double dot over the "a" in the x-axis instead of "`".

Many thanks for any suggestions and best wishes,
Ranjan



You haven't told what OS you are using, but with Windows OS, you can get 
the 'ä' by making sure the NUMLOCK key is on, hold down the alt key and 
press 0228 on the numeric keypad.



Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] S-mode PCAs

2017-06-13 Thread Daniel Vecellio
Hi all,

I have a file of average SWE observations for 40 years at over 4,000 points
and am attempting to do a spatiotemporal analysis of the data using PCA,
much like this paper did using snow depth:
http://journals.ametsoc.org/doi/pdf/10.1175/1520-0442%281998%29011%3C0856%3ATCIRWS%3E2.0.CO%3B2

I have followed the code in the link below by my loadings are far too small
(For example, the paper listed above had loading above 0.5 and below -0.5
while my loadings for PC1 go between 0.02 and -0.03).

https://stackoverflow.com/questions/41022927/principal-component-analysis-pca-of-time-series-data-spatial-and-temporal-pat

I have standardized the data in the prcomp function so that a correlation
matrix is used in my study, just like the paper above. Does anyone have any
idea why my loadings might be so off and any suggestions regarding the PCA
functions in R to help solve this problem?

Thanks in advance,
Dan

-- 

*Daniel J. Vecellio*

*Ph.D. Student - Climate Science Lab, **Department of Geography, **Texas
A&M University*

[[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] dplyr's arrange function

2016-06-15 Thread Daniel Nordlund

On 6/15/2016 2:08 PM, Muhuri, Pradip (AHRQ/CFACT) wrote:

Hello,

I am using the dplyr's arrange() function to sort  one of the  many data frames  on a 
character variable (named "prevalence").

Issue: I am not getting the desired output  (line 7 is the problem, which 
should be the very last line in the sorted data frame) because the sorted field 
is character, not numeric.

The reproducible example and the output are appended below.

Is there any work-around  to convert/treat  this character variable (named 
"prevalence" in the data frame below)  as numeric before using the arrange() 
function within the dplyr package?

Any hints will be appreciated.

Thanks,

Pradip Muhuri

# Reproducible Example

library("readr")
testdata <- read_csv(
"indicator,  prevalence
1. Health check-up, 77.2 (1.19)
2. Blood cholesterol checked,  84.5 (1.14)
3. Recieved flu vaccine, 50.0 (1.33)
4. Blood pressure checked, 88.7 (0.88)
5. Aspirin use-problems, 11.7 (1.02)
6.Colonoscopy, 60.2 (1.41)
7. Sigmoidoscopy,  6.1 (0.61)
8. Blood stool test, 14.6 (1.00)
9.Mammogram,  72.6 (1.82)
10. Pap Smear test, 73.3 (2.37)")

# Sort on the character variable in descending order
arrange(testdata, desc(prevalence))

# Results from Console

  indicator  prevalence
  (chr)   (chr)
1 4. Blood pressure checked 88.7 (0.88)
2  2. Blood cholesterol checked 84.5 (1.14)
31. Health check-up 77.2 (1.19)
410. Pap Smear test 73.3 (2.37)
5   9.Mammogram 72.6 (1.82)
6 6.Colonoscopy 60.2 (1.41)
7  7. Sigmoidoscopy  6.1 (0.61)
8   3. Recieved flu vaccine 50.0 (1.33)
9   8. Blood stool test 14.6 (1.00)
10  5. Aspirin use-problems 11.7 (1.02)


Pradip K. Muhuri,  AHRQ/CFACT
 5600 Fishers Lane # 7N142A, Rockville, MD 20857
Tel: 301-427-1564





The problem is that you are sorting a character variable.


testdata$prevalence

 [1] "77.2 (1.19)" "84.5 (1.14)" "50.0 (1.33)" "88.7 (0.88)" "11.7 (1.02)"
 [6] "60.2 (1.41)" "6.1 (0.61)"  "14.6 (1.00)" "72.6 (1.82)" "73.3 (2.37)"




Notice that the 7th element is "6.1 (0.61)".  The first CHARACTER is a 
"6", so it is going to sort BEFORE the "50.0 (1.33)" (in descending 
order).  If you want the character value of line 7 to sort last, it 
would need to be "06.1 (0.61)" or " 6.1 (0.61)" (notice the leading space).


Hope this is helpful,

Dan

Daniel Nordlund
Port Townsend, WA USA

__
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] better loop for simulation

2016-06-18 Thread Dalthorp, Daniel
try:

n.questions <- 10  # or however many you want
mult.choice <- 2
scores <- rbinom(1000, size = n.questions, prob = 1/mult.choice)


On Sat, Jun 18, 2016 at 3:12 PM, Naresh Gurbuxani <
naresh_gurbux...@hotmail.com> wrote:

> I want to calculate a function many times over.  My solution below works,
> but does not seem very elegant.
>
> # my function to run many times over
> stud.score <- function(n.questions, mult.choice = 2) {
> prob.success <- 1 / mult.choice
> answers <- (runif(n.questions) < prob.success)
> return(sum(answers))
> }
>
> # my method to run above function 1000 times and store results
> count.df <- data.frame(n.count = rep(10, 1000))
> scores.df <- apply(count.df, 1, function(x) return(stud.score(x)))
>
> Creating a data frame just to repeat the the count seems wasteful.  How
> can I generate scores.df without count.df?
>
> Thanks,
> Naresh
> __
> 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.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] tclArray() --- "active"?!

2016-07-06 Thread Dalthorp, Daniel
Sometimes when working with tclArray's, an empty element called "active" is
appended to the array. Does anyone know when (and why) this happens? And
how to prevent it (or at least predict it so that it can be removed by
hand)?

E.g.,
library(tcltk); library(tcltk2)
tt<-tktoplevel()
dat<-tclArray()
tab<-tk2table(tt, variable = dat)
tkgrid(tab)
dat[[0,0]]<-5
dat[[1,0]]<-4
dat[[2,0]]<-56
tkdelete(tab,"rows",2, 8)
names(dat)

Any help would be greatly appreciated!

-Dan

-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] tclArray() --- "active"?!

2016-07-06 Thread Dalthorp, Daniel
Thanks, Peter.

When it comes time to read the array back to R, I can explicitly delete the
"active" cell first...

On Wed, Jul 6, 2016 at 8:35 AM, peter dalgaard  wrote:

> I am not up to speed on Tcl/Tk these days, but I would suspect that the
> issue lies in tkTable and not in tclArray. The table widget has the notion
> of an active cell, which can be used in indexing operations. According to
> the widget documentation
>
> --
> Command-Line Name:-variable
> Database Name: variable
> Database Class: Variable
>
> Global Tcl array variable to attach to the table's C array. It will be
> created if it doesn't already exist or is a simple variable. Keys used by
> the table in the array are of the form row,col for cells and the special
> key active which contains the value of the active cell buffer. [...]
> --
>
> I think this suggests that you just need to assume that the "active"
> element might be there when you deal with the tclArray and work around it
> if it gets in the way.
>
> (A conjecture as to why it appears in your example could be that you
> deleted the row with the active cell, and that the widget needs to record
> the fact that there is now no active cell.)
>
> -pd
>
>
> > On 06 Jul 2016, at 16:18 , Dalthorp, Daniel  wrote:
> >
> > Sometimes when working with tclArray's, an empty element called "active"
> is
> > appended to the array. Does anyone know when (and why) this happens? And
> > how to prevent it (or at least predict it so that it can be removed by
> > hand)?
> >
> > E.g.,
> > library(tcltk); library(tcltk2)
> > tt<-tktoplevel()
> > dat<-tclArray()
> > tab<-tk2table(tt, variable = dat)
> > tkgrid(tab)
> > dat[[0,0]]<-5
> > dat[[1,0]]<-4
> > dat[[2,0]]<-56
> > tkdelete(tab,"rows",2, 8)
> > names(dat)
> >
> > Any help would be greatly appreciated!
> >
> > -Dan
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
> >   [[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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] Sampe numbers

2016-07-19 Thread Daniel Nordlund

Frederic,

you need to be more clear about what you want to do.  If you are 
sampling 100 numbers from 1:100 with replacement, the sum will always be 
greater than 50 (as has already been pointed out).


In addition, you mention trying to eliminate zeros.  If you are sampling 
from 1:100 there will be no zeros.  So what are you really trying to do?



Dan

Dan Nordlund
Port Townsend, WA  USA


On 7/19/2016 11:54 AM, Frederic Ntirenganya wrote:

The problem is that there
are some zeros  while the numbers should range from 1 to  100

As the replace= TRUE if the smallest candidate is 1 may be replaced
because if I can have 1, fifty times this is equal to 50.
Remember that it is a sampling with a replacement

I am still wondering how I can remove the zero value.


Frederic Ntirenganya
Maseno University,
African Maths Initiative,
Kenya.
Mobile:(+254)718492836
Email: fr...@aims.ac.za
https://sites.google.com/a/aims.ac.za/fredo/

On Tue, Jul 19, 2016 at 9:11 PM,  wrote:


N <- 100
C <- 50
x <- numeric(N)
for (i in 1:N){
  x[i] <- sample(C-sum(x),1)
}
x
sum(x)




*Frederic Ntirenganya >*
Sent by: "R-help" 

07/19/2016 01:41 PM
To
"r-help@r-project.org" ,

cc
Subject
[R] Sampe numbers




Hi Guys,
I am trying to sample 100 numbers from 1:100
i did it  like this:

sample(1:100,100, replace= TRUE)
but i want again include a constraint that their sum must be equal to 50

How could I do it?

Cheers

Frederic Ntirenganya
Maseno University,
African Maths Initiative,
Kenya.
Mobile:(+254)718492836
Email: fr...@aims.ac.za
https://sites.google.com/a/aims.ac.za/fredo/


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




--
Daniel Noredlund
Bothell, WA USA

__
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] how to expand the dataframe

2016-07-21 Thread Daniel Nordlund

On 7/20/2016 8:26 PM, lily li wrote:

Yes, I tried to create a dataframe and merge it with the shortened
dataframe. The resulting dataframe goes with the short one and truncates
the complete date column, so it does not work.

On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius 
wrote:




On Jul 20, 2016, at 1:31 PM, lily li  wrote:

Hi R users,

I have a dataframe, where there is a column 'time' represents time series
but is not complete. How to expand the dataframe so this column will

become

complete, where other columns with the newly added rows have NA values?
Thanks.

df
A B C time
105 3.3 1990-01-01
115  4 1990-02-07
124 3  1990-02-14
...


Make a dataframe with a 'time' column using seq.Date and merge that
dataframe with your df dataframe.



  [[alternative HTML version deleted]]


Really  isn't it time you learned how to send plain text. You've
posted many questions on Rhelp.  It's really not that difficult on gmail. I
also have a gmail account and have had no difficulty finding instructions
on how to do it.



__
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






Don't just say you tried to do the merge and it doesn't work.  At a 
minimum show us the ACTUAL code you used and give us any error messages 
you got or show us a portion of the results and explain why it is not 
what you expected.  If possible, give us a small amount of data using 
dput() so that we can "play along at home" (i.e. give us a reproducible 
example).


Dan

Daniel Nordlund
Port Townsend, WA



--
Daniel Noredlund
Bothell, WA USA

__
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] font size in graphs...can R read Windows settings?

2016-07-27 Thread Dalthorp, Daniel
Hi All,
I am putting together a package that (among other things) draws some nice
graphs for users. I place some explanatory text on figs using "text" and
"mtext". But the size of the text depends on the Windows display settings:
Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
panel | Appearance and personalization | Display | Make text and other
items smaller or larger). If I create figs that look good with one setting,
the text is too big (or too small) if another setting is used in Windows.
If I know the Windows setting, I can use cex in R to make the right sized
labels, but if I don't know a user's Windows display size setting...is
there a way for R to read the setting? Or is there another way to control
label size so that text labels on graphs look good regardless of WIndows
display size setting?

Many thanks for Ideas,

-Dan
-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] font size in graphs...can R read Windows settings?

2016-07-28 Thread Dalthorp, Daniel
Thanks, Duncan. This is close to what I was looking for. But I'm not using
lattice. And the fontsize$text and fontsize$points are independent of
display settings in Windows (screen resolution and 'size of objects').

I need to make my graphs [esp. placement and size of text(), mtext()] look
good regardless of display settings.

Here's what I'm working with at the moment...

When package is loaded, I store the default graph size ('din') which is
correlated with OS display parameters. Then, I simply multiple my current
'cex' values by the stored 'din' divided by 7 (which is the 'din'
associated with the display parameters that I created the figs in
initially). It seems to work just fine for my text() and mtext() text
sizes.

But some of my algorithms for placing text and subfigs in margins still
need fixing...combinations of 'plt' and 'usr' seem to be working, but it's
tedious.

-Dan

On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay  wrote:

> Hi  Dan
>
> For devices png, pdf, postscript and ? others the pointsize argument
> controls the font size which is modified by cex
>
> For lattice there are the settings in trellis.par.get()
>
> trellis.par.get()$fontsize
> $text
> [1] 12
>
> $points
> [1] 8
>
> which you can set and there is no real need to change font size except if
> you need to change main.
> trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
> text
>
> these could be set globally by trellis.par.set() or individually with
> argument par.settings eg
> xyplot(y ~ x, data = datm,
>  par.settings = list(strip.background = list(col =
> "transparent"),
>  fontsize = list(text = 16,
>
> points = 12),  # large size;  need to refine
> superpose.polygon= list(col
> = c("red","blue"),
>
> border = c("red","blue"))),
> type = "b")
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
> Daniel
> Sent: Thursday, 28 July 2016 07:02
> To: r-help@R-project.org (r-help@r-project.org)
> Subject: [R] font size in graphs...can R read Windows settings?
>
> Hi All,
> I am putting together a package that (among other things) draws some nice
> graphs for users. I place some explanatory text on figs using "text" and
> "mtext". But the size of the text depends on the Windows display settings:
> Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
> panel | Appearance and personalization | Display | Make text and other
> items smaller or larger). If I create figs that look good with one setting,
> the text is too big (or too small) if another setting is used in Windows.
> If I know the Windows setting, I can use cex in R to make the right sized
> labels, but if I don't know a user's Windows display size setting...is
> there a way for R to read the setting? Or is there another way to control
> label size so that text labels on graphs look good regardless of WIndows
> display size setting?
>
> Many thanks for Ideas,
>
> -Dan
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
>
> [[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.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] font size in graphs...can R read Windows settings?

2016-07-28 Thread Dalthorp, Daniel
The trouble is getting the figs to look right for different users who
happen to have different display settings. Nearly all my users will be on
MS Windows, and, for the parameter set you gave, the figs will look
different, depending on which "display size" parameter value is active and
the screen resolution (for Windows 7 --- Control Panel | Appearance and
Personalization | Display | Make text and other items larger or smaller).

For example, the following gives different look (for text(), mtext(), axis
labels, etc.) "smaller" than for "larger" or for fine resolution vs. coarse
resolution. Getting it wrong makes the figs look sloppy and hard to read.
If I knew users' display parameters ahead of time, I could adjust the
drawing algorithms using par parameters, but I don't know the display
parameters. 'din' values at time of package attachment (and after closing
of open devices) gives a reasonable proxy in a lot of cases but not always.

par(mfrow = c(1,1),
 las = 1,
 mai = c(0.85, 0.85, 0.32, 0.12),
 font.main = 1,
 cex.main = 1.0,
 cex.lab  = 1.0,
 cex.axis = 0.9)
plot(0,0)
plot(0,0, type='n')
text(0,0, 'junk')
mtext(side = 3, line = .5, "more junk")


On Thu, Jul 28, 2016 at 6:15 PM, Duncan Mackay  wrote:

> Hi Dan
>
>
>
> This is one of  the features/problems of proportional graphing – getting
> it exactly right.
>
>
>
> Anyway good graphs usually take time
>
>
>
> I wonder if aspect in both base and lattice may be of use.
>
> Also I have a default par settings for base graphics where I sometimes
> change the mai command for multiple graphs and rarely the font size.
>
>
>
> par(mfrow = c(1,1),
>
> las = 1,
>
> mai = c(0.85, 0.85, 0.32, 0.12),
>
> font.main = 1,
>
> cex.main = 1.0,
>
> cex.lab  = 1.0,
>
> cex.axis = 0.9)
>
>
>
> Duncan
>
>
>
> *From:* Dalthorp, Daniel [mailto:ddalth...@usgs.gov]
> *Sent:* Friday, 29 July 2016 09:22
> *To:* Duncan Mackay
> *Cc:* R
> *Subject:* Re: [R] font size in graphs...can R read Windows settings?
>
>
>
> Thanks, Duncan. This is close to what I was looking for. But I'm not using
> lattice. And the fontsize$text and fontsize$points are independent of
> display settings in Windows (screen resolution and 'size of objects').
>
>
>
> I need to make my graphs [esp. placement and size of text(), mtext()] look
> good regardless of display settings.
>
>
>
> Here's what I'm working with at the moment...
>
>
>
> When package is loaded, I store the default graph size ('din') which is
> correlated with OS display parameters. Then, I simply multiple my current
> 'cex' values by the stored 'din' divided by 7 (which is the 'din'
> associated with the display parameters that I created the figs in
> initially). It seems to work just fine for my text() and mtext() text
> sizes.
>
>
>
> But some of my algorithms for placing text and subfigs in margins still
> need fixing...combinations of 'plt' and 'usr' seem to be working, but it's
> tedious.
>
>
>
> -Dan
>
>
>
> On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay 
> wrote:
>
> Hi  Dan
>
> For devices png, pdf, postscript and ? others the pointsize argument
> controls the font size which is modified by cex
>
> For lattice there are the settings in trellis.par.get()
>
> trellis.par.get()$fontsize
> $text
> [1] 12
>
> $points
> [1] 8
>
> which you can set and there is no real need to change font size except if
> you need to change main.
> trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
> text
>
> these could be set globally by trellis.par.set() or individually with
> argument par.settings eg
> xyplot(y ~ x, data = datm,
>  par.settings = list(strip.background = list(col =
> "transparent"),
>  fontsize = list(text = 16,
>
> points = 12),  # large size;  need to refine
> superpose.polygon= list(col
> = c("red","blue"),
>
> border = c("red","blue"))),
> type = "b")
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
> Daniel
> Sent: Thursday, 28 July 2016 07:02
> To: r-help@R-project.org (r-help@r-project.org)
&

Re: [R] I'm getting confused with notation and terminology in output from weibull parametric survival model from survreg()

2016-07-29 Thread Dalthorp, Daniel
The parameterization for Weibull in the 'survival' package corresponds to
base R's dweibull, etc. suite as 1/scale --> shape and exp(coef[1]) -->
scale

On Fri, Jul 29, 2016 at 1:07 PM, Christopher W. Ryan 
wrote:

> I'm trying to run a Weibull parametric survival model for recurrent event
> data, with subject-specific frailties, using survreg() in the survival
> package, and I'm having trouble understanding the output and its notation,
> and how that translates to some of the books I am using as references (DF
> Moore, Applied Survival Analysis Using R; and Kleinbaum and Klein, Survival
> Analysis A Self-Learning Text). I understand there are different notations
> for different ways of parameterizing a Weibull or a gamma distribution, and
> perhaps that's where I am getting hung up. I also may be confusing "scale"
> for the Weibull distribution of the survial times with "scale" for the
> gamma distribution of the frailties.
>
> My ultimate goal is to display example survival curves: say, one for
> "typically frail" subjects, one for "extra-frail" subjects, and one for
> "not-so-frail" subjects. I'd like to get estimated "frailty" for each of my
> subjects; or at least the distribution of those frailties. Do I need the
> parameters of the gamma distribution to do that? If so, how do I extract
> them? Or are they readily available in the survreg object?
>
> Here is what I have tried so far:
>
> ## create some data similar to my real data, in which
> ## vast majority of subjects had no event
> id <- c(1:600, rep(601:630, each=1), rep(631:650, each=2), rep(651:656,
> each=3), rep(677:679, each=4), rep(680, 5))
> time <- c(rpois(lambda=800, 600), rpois(lambda=600, length(601:630)),
> rpois(lambda=600, length(631:650)*2), rpois(lambda=600, length(651:656)*3),
> rpois(lambda=600, length(677:679)*4), rpois(lambda=600, 5))
> event <- c(rep(0, 600), rep(1, (length(id) - 600)))
> dd <- data.frame(id=id, time=time, event=event)
> dd.2 <- dd[order(id, time), ]
> str(dd.2)
> table(table(dd.2$id))
> # time until censoring, for those without events
> summary(subset(dd.2, event==0, select=time))
>
> library(survival)
> Surv.1 <- Surv(time, event)
>
> # model without frailties
> model.1 <- survreg(Surv.1 ~ 1, data=dd.2, dist="weibull")
>
> # add frailty term
> model.2 <- survreg(Surv.1 ~ 1 + frailty(id), data=dd.2, dist="weibull")
>
> # should be same as above line
> model.2.b <- survreg(Surv.1 ~ 1 + frailty(id, distribution="gamma"),
> data=dd.2, dist="weibull")
>
> # I don't know if this is the right way to go about it
> a.scale <- model.2$scale
> var.X <- model.2$history$frailty$theta
> s.shape <- sqrt(var.X/a.scale)
>
> gamma.frail.x <- function(a,s,q){ 1/((s^a) * gamma(a)) * (q^(a-1) *
> exp(-(q/s))) }
> q <- seq(0.1, 10, by=0.2)
>
> maybe.my.frailties <- gamma.frail.x(a.scale, s.shape, q)))
> plot(density(maybe.my.frailties))
>
> ## end code
>
>
> Or, would I be better off changing tactics and using frailtypack?
>
> Thanks for any help.  Session info is below, in case it is relevant.
>
> --Chris Ryan
>
>
>
> > sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] survival_2.39-5
>
> loaded via a namespace (and not attached):
> [1] compiler_3.3.1  Matrix_1.2-6tools_3.3.1 splines_3.3.1
> [5] grid_3.3.1  lattice_0.20-33
>
> __
> 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.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] SAS file

2016-08-07 Thread Daniel Nordlund

On 8/7/2016 7:49 AM, John Kane wrote:

As Jim says the file did not arrive. R-help is very fussy about what kind of 
files it accepts. If you are still having a problem it would be a good idea to 
upload it to file-sharing place such as Dropbox or Mediafire and just post the 
link here.

John Kane
Kingston ON Canada



-Original Message-
From: r-help@r-project.org
Sent: Fri, 5 Aug 2016 10:10:13 + (UTC)
To: r-help@r-project.org
Subject: [R] SAS file

Hello,I have a SAS formatted file as attached, when I use lookup.xport i
got error below> lookup.xport("patient.ssd01")Error in
lookup.xport.inner(file) :   unable to open file: 'No such file or
directory'

can anyone please help me to figure it out?
thanksc
__
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.



Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.

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



The file extension, '.ssd01' is typically used for a standard Unix SAS 
dataset.  the R function, lookup.xport(), is for examining SAS XPORT 
files.  So, you are using the wrong approach to read the file.


You will need to get an XPORT format file, or have SAS available, or get 
some 3rd party software that will read SAS datasets.



Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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 bug when started in Windows 10

2016-08-14 Thread Daniel Nordlund

On 8/14/2016 12:57 PM, Itamar José G. Nunes wrote:

Greetings, CRAN supporter. I am Itamar José, a Brazilian programmer and
biotechnology student.
I'm using R from some time ago, most of the time working with it in Windows
7, but since I changed to Windows 10, I'm having some bugs when R platform
particularly in this new operational system. If there's not problem, I
would like some help from you for what I can do about this issue.
I have asked about this problem in StarkOverflow, but no resolution was
suggested until now. As I said there, I'm working with a software project
that requires the portable version of R platform and my intention is to use
R in any version of Windows and in any compatible computer. I'm copying
here my answer, as shown below:



*From
[http://stackoverflow.com/questions/37173431/r-platform-failed-to-start-in-windows-10-when-inside-directory-containing-white
<http://stackoverflow.com/questions/37173431/r-platform-failed-to-start-in-windows-10-when-inside-directory-containing-white>]Problem:*
In Windows 7, R works fine without any worries, even in portable version.
However, in Windows 10 (and probably also in Windows 8), R does not start
when put the entire folder inside a directory containing whitespaces (ex.:
"C:/Users/Main/Documents/My Folder/RVersion").

In Windows 10, with the absence of spaces, R runs fine. In the presence of
spaces, all executable (Rscript.exe, R.exe, etc) except Rgui.exe just open
a console and closes instantly. The problem is: I really need that R works
in any folder (this is a important part of the project).

*Additional information:*

   -

   I found that R does not work well in directories without the 8dot3
   format - and it think that Windows 10 lost this property, which was present
   in Windows 7. Also, the problem is clear when I run Rgui.exe in a
   whitespace-containing directory and try to run system("R.exe", intern=TRUE)
   function: It throws an error indicating that only the part before the first
   space in directory name was taken into account. Here is the message:

   > system("R.exe", intern=TRUE)

   [1] "'C:\\Users\\Main\\DOCUME~1\\My' nÆo ‚ reconhecido como um comando
   interno" [2] "ou externo, um programa oper vel ou um arquivo em lotes."
   attr(,"status") [1] 1 Warning message: running command 'R.exe' had status 1

*Translation of messages [1] and [2]: "'C:\...\My'" not recognized as a
internal or external command, nor a program operation or dataset*

   -

   The same occurs with non-portable version of R, as I already tested.
   -

   When I run with a .bat file with the corrected (quoted) directory as
   input, R.exe runs, but in a disfunctional form and looking like cmd.exe (no
   R command worked).
   -

   I have no ideia how to change variables such as R_HOME to a readable
   version before R prompt starts.

*System/Resources:*

   - Windows 10 Home 64-bit with the last update.
   - Dell Notebook with Intel i7-5500U 2.40 GHz (not so relevant, I think)
   - R and R portable 3.3 (last version until this post), downloaded here: [
   https://sourceforge.net/projects/rportable/]
   <https://sourceforge.net/projects/rportable/%5D>


I believe that, with the popularity of Windows 10, many other users could
face this problem (specially those who depend of R portability). Because no
answers were made, and since it remains as a little known issue, I think
the CRAN support is the only one that knows, most than everyone, how to
reach the resolution.

Thanks in advance!



For this problem, you need to give the EXACT commands you use to start R 
and run your scripts.  In other words, give us a reproducible example, 
so that if we run your example we will see the same failure that you see.


Now in the absence of the reproducible exampole, I did notice one 
problem in the example you did give of a directory with spaces.  It 
looks like you were using single quotes (') around the path/filename. 
Windows requires that there be double quotes (") around any 
path/filename that contains spaces.


If you provide a reproducible example, then you may get more detailed help.


Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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 concernig Survsplit, package survival

2016-08-22 Thread Wollschlaeger, Daniel
Thanks for bringing this issue in the book's description of survSplit() to my 
attention. It seems the change to the behavior of survSplit() was introduced in 
survival version 2.39-2. Up to (including) version 2.38-3, no formula was 
required if arguments 'end' and 'event' were specified.

A corrected pdf of the chapter is available at 
http://dwoll.de/r/gddmr/09_survival.pdf

Daniel Wollschlaeger

On August 19, 2016 4:21:31 AM PDT, "Vinzenz Völkel via R-help"  wrote:
>Dear R-help-community,
>
> 
>
>I hope, that?s the appropiate channel to post a quastion?
>
> 
>
>For some days I have been struggling with a problem concerning the
>?survSplit?-function of the package ?survival?. Searching the internet
>I
>have found a pretty good -German- description of Daniel Wollschläger
>describing how to use survSplit:
>
> 
>
>(https://books.google.de/books?id=9G4oBgAAQBAJ
><https://books.google.de/books?id=9G4oBgAAQBAJ&pg=PA345&lpg=PA345&dq=daniel+
>wollschl%C3%A4ger+survsplit&source=bl&ots=ajPgInB83d&sig=noQIAXMWe6oQJ-LwsTC
>kroWdwHQ&hl=de&sa=X&ved=0ahUKEwiqwoX8q83OAhVlM5oKHSMGDrEQ6AEIHjAA#v=onepage&
>q=daniel%20wollschl%C3%A4ger%20survsplit&f=false>
>&pg=PA345&lpg=PA345&dq=daniel+wollschl%C3%A4ger+survsplit&source=bl&ots=ajPg
>InB83d&sig=noQIAXMWe6oQJ-LwsTCkroWdwHQ&hl=de&sa=X&ved=0ahUKEwiqwoX8q83OAhVlM
>5oKHSMGDrEQ6AEIHjAA#v=onepage&q=daniel%20wollschl%C3%A4ger%20survsplit&f=fal
>se
>
> 
>
>Mr. Wollschl?ger also provides the dataset, all of the code he used and
>an
>excerpt of his output:
>
> 
>
> 
>
>> library(survival) # f?r survSplit()
>
>> dfSurvCP <- survSplit(dfSurv, cut=seq(30, 90, by=30), end="obsT",
>
>+ event="status", start="start", id="ID", zero=0)
>
># sortiere nach Beobachtungsobjekt und linken Intervallgrenzen
>
>> idxOrd <- order(dfSurvCP$ID, dfSurvCP$start)
>
>> head(dfSurvCP[idxOrd, ], n=7)
>
>obsTstatus sex  X IVstart ID
>
>1  300  f   -1.3130607 A 0
>1
>
>181  600  f   -1.3130607 A 30
>1
>
>361  631  f   -1.3130607 A 60
>1
>
>10111  f   -1.2282824 A 0
>10
>
>100  271  m -0.1018403 B 0
>100
>
>101  300  m -0.4079027 B 0
>101
>
>281  421  m -0.4079027 B 30
>101
>
> 
>
> 
>
>Unfortunaltely when I tried to copy Mr. Wollschl?gers operations using
>his
>very dataset, RStudio just returned the following error-message:
>
> 
>
>> dfSurvCP2 <-
>survSplit(dfSurv,cut=seq(30,90,by=30),end="obsT",event="status",start="start
>",id="ID",zero=0)
>
>Error in formula.default(eval(parse(text = x, keep.source =
>FALSE)[[1L]])) :
>
>
>  invalid formula
>
> 
>
>I tried to figure out what?s wrong, but so far didn?t find any
>solutions? I
>would be very glad if anyone could help me out here.
>
> 
>
>vhfv
>
> 
>
>
>   [[alternative HTML version deleted]]
>
>
>
>
>
>__
>R-help at 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] Rotating points, preferably in grid

2016-08-24 Thread Dalthorp, Daniel
Silly? Not really.

It's simple. It works.

You could jump into unicode for your text and make it look nicer, e.g.,
using '\u2191' or some other shape in place of 'T'

http://unicode.org/charts/
http://unicode.org/charts/PDF/U2190.pdf

-Dan

On Wed, Aug 24, 2016 at 7:16 PM, Thomas Levine <_...@thomaslevine.com> wrote:

> I want to make a plot in polar coordinates. I want to use pch with
> shapes that do not have radial symmetry, so I want to rotate them such
> that they face inwards. I am using grid for my plotting, but I provide
> motivating examples in graphics.
>
> The following plot almost gets me what I want.
>
>   theta <- 2*pi*seq(0,7/8,1/8)
>   plot(cos(theta), sin(theta), pch=2, axes=F, asp=1)
>
> But I want the points to face inwards. I can do something like this with
> text, but I can set only a constant rotation
>
>   plot.new()
>   plot.window(c(-1,1),c(-1,1), asp=1)
>   text(cos(theta), sin(theta), 'Tom', srt
>  =runif(1,0,360))
>
> To rotate all of the points, I can do something like this.
>
>   plot.new()
>   plot.window(c(-1,1),c(-1,1), asp=1)
>   for (the.theta in theta)
> text(cos(the.theta), sin(the.theta), 'Tom',
>  srt=(360/(2*pi))*(the.theta-(1/4)*2*pi))
>
> So perhaps I could use a "T" instead of a numeric pch and consequently
> do something like this.
>
>   plot.new()
>   plot.window(c(-1,1),c(-1,1), asp=1)
>   for (the.theta in theta)
> text(cos(the.theta), sin(the.theta), 'T',
>  srt=(360/(2*pi))*(the.theta+(1/4)*2*pi))
>
> But that seems a bit silly.
>
> Is there a more declarative way of doing this, preferably in grid?
>
> 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.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] Help with strftime error "character string is not in a standard unambiguous format"

2016-09-12 Thread Daniel Nordlund

On 9/11/2016 10:57 PM, Chris Evans wrote:

I am trying to read activity data created by Garmin. It outputs dates like this:

"Thu, 25 Aug 2016 6:34 PM"

The problem that has stumped me is this:


strftime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")

Error in as.POSIXlt.character(x, tz = tz) :
  character string is not in a standard unambiguous format

I _thought_ I had this running OK but that error is catching me now.  I think 
I've read ?strftime and written that format string correctly to match the input 
but I'm stumped now.

Can someone advise me?  Many thanks in advance,

Chris



sessionInfo()

R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 10586)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

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

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




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



I have always used strptime() for this task, and

> strptime("Thu, 25 Aug 2016 6:34 PM",format="%a, %d %b %Y %I:%M %p")
[1] "2016-08-25 18:34:00 PDT"

works for me.


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Writing data onto xlsx file without cell formatting

2016-09-26 Thread Daniel Nordlund

On 9/26/2016 2:56 PM, Christofer Bogaso wrote:

Hi again,

I have been following above suggestion to export data from R to xlsx
file using XLconnect. However recently I am facing Java memory
allocation problem with large dataset (looks like a known issue with
this package) and therefore decided to move to using "xlsx" package.

Now I started facing that same problem of losing my existing formating
when I use xlsx package for data export. Can someone help me with some
pointer on how can I preserve the cell formating after exporting
data.frame to some existing xlsx file using "xlsx" package.

Thanks for your time.

On Mon, Jul 11, 2016 at 10:43 AM, Ismail SEZEN  wrote:

I think, this is what you are looking for:

http://stackoverflow.com/questions/11228942/write-from-r-into-template-in-excel-while-preserving-formatting

On 11 Jul 2016, at 03:43, Christofer Bogaso 
wrote:

Hi again,

I am trying to write a data frame to an existing Excel file (xlsx)
from row 5 and column 6 of the 1st Sheet. I was going through a
previous instruction which is available here :

http://stackoverflow.com/questions/32632137/using-write-xlsx-in-r-how-to-write-in-a-specific-row-or-column-in-excel-file

However trouble is that it is modifying/removing formatting of all the
affected cells. I have predefined formatting of those cells where data
to be pasted, and I dont want to modify or remove that formatting.

Any idea if I need to pass some additional argument.

Appreciate your valuable feedback.

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



It would help the list to help you if you gave a reproducible example. 
In the absence of that, at least show the actual code you are using to 
write to the Excel (.xlsx) sheet.


But maybe reading about the "create" argument on page 13 of this linked 
document will help:


https://cran.r-project.org/web/packages/xlsx/xlsx.pdf


Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Bootstrapping in R

2016-10-01 Thread Daniel Nordlund

On 9/30/2016 6:44 PM, Bryan Mac wrote:

Hi,

I have read the help page and it was helpful but, I am having concerns because 
each time I run this code I get the same value.
I expected that each time I run the code, I will get different values due to 
random sampling.

How do I get this randomization? The values shouldn’t be the same each time the 
code is run, correct?


result <- boot(n_data, statistic = DataSummary, R = 100).


Best,

Bryan Mac
bryanmac...@gmail.com




On Sep 29, 2016, at 12:16 PM, ruipbarra...@sapo.pt wrote:

Hello,

Read the help page ?boot::boot.
For instance, try the following.


library(boot)

x <- rnorm(100)
stat <- function(x, f) mean(x[f])
boot(x, stat, R = 100)

Hope this helps,

Rui Barradas



Citando bryan.mac24 :


Hi all,
I am wondering how to conduct bootstrapping in R. I need bootstrap 100 times. 
The trick I need to figure out is how to do get a random sample of 100 out of 
the total number of case.
Best,
BM
[[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.



Bryan,

You haven't told us anything about the structure of your data, or the 
definition of the DataSummary function.  We are left to guess what you 
are doing.  The posting guide calls for a reproducible example.  At a 
minimum give us some sample data (myabe use dput()), the definition of 
DataSummary, the code you use to set up and call the boot() funtion, and 
examples of your output that shows you "getting the same answer."


Someone may then be able to do more than guess at what the problem is.

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] dotplot

2015-05-16 Thread Daniel Nordlund

On 5/16/2015 12:32 PM, li li wrote:

Hi all,
   I wrote the following code and have two questions:
   (1) As you can see, I would like different colors for different
types. It does not come out that way in the graph from this code.
Anyone know how to fix this?
(2) How do I made the lots number on x axis eligible to read?
(3) How do I remove the verticle line in the graph.
 Thanks for your help.
   Hanna


lot <- as.character(c("D130" ,"D135" ,"D1300010", "D1300015",
"D1300020",
  "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
  "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
  "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
  "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
  "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045"))

val <- rnorm(30)
type <- rep(1:3,each=10)
tmp <- as.data.frame(cbind(val, type, lot))
tmp$sybm <- rep(c(1, 12, 16), each=10)
tmp$color <- rep(c("blue", "red", "green"), each=10)
tmp$val <- as.numeric(tmp$val)
dotplot(val ~ lot, tmp,
 ylab = "values", xlab="lot", aspect=1,
 pch=tmp$sybm, color=tmp$color)



Li Li,

1. if the dotplot function you are referring to is from the lattice 
package, then the correct name for the "color" parameter is col.  You 
could just use col=type to get different colors but you won't have 
control over the colors chosen.  I created a vector, color, specifying 
the colors and the order they will be applied.


2.  the scales parameter is what you are looking for.  The parameter is 
looking for a list which consists of name=value pairs. You can rotate 
the labels by a specified number of degrees.  In my example, I chose 30 
degrees, rot=30.


3. I don't know how to eliminate the vertical lines, but if you read the 
lattice documentation, you will find it (if it is possible).


color=c("blue", "red", "green")
dotplot(val ~ lot, tmp,
ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
pch=tmp$sybm, col=color)


Hope this is helpful,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] dotplot

2015-05-16 Thread Daniel Nordlund

On 5/16/2015 1:19 PM, Daniel Nordlund wrote:

On 5/16/2015 12:32 PM, li li wrote:

Hi all,
   I wrote the following code and have two questions:
   (1) As you can see, I would like different colors for different
types. It does not come out that way in the graph from this code.
Anyone know how to fix this?
(2) How do I made the lots number on x axis eligible to read?
(3) How do I remove the verticle line in the graph.
 Thanks for your help.
   Hanna


lot <- as.character(c("D130" ,"D135" ,"D1300010", "D1300015",
"D1300020",
  "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
  "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
  "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
  "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
  "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045"))

val <- rnorm(30)
type <- rep(1:3,each=10)
tmp <- as.data.frame(cbind(val, type, lot))
tmp$sybm <- rep(c(1, 12, 16), each=10)
tmp$color <- rep(c("blue", "red", "green"), each=10)
tmp$val <- as.numeric(tmp$val)
dotplot(val ~ lot, tmp,
 ylab = "values", xlab="lot", aspect=1,
 pch=tmp$sybm, color=tmp$color)



Li Li,

1. if the dotplot function you are referring to is from the lattice
package, then the correct name for the "color" parameter is col.  You
could just use col=type to get different colors but you won't have
control over the colors chosen.  I created a vector, color, specifying
the colors and the order they will be applied.

2.  the scales parameter is what you are looking for.  The parameter is
looking for a list which consists of name=value pairs. You can rotate
the labels by a specified number of degrees.  In my example, I chose 30
degrees, rot=30.

3. I don't know how to eliminate the vertical lines, but if you read the
lattice documentation, you will find it (if it is possible).

color=c("blue", "red", "green")
dotplot(val ~ lot, tmp,
 ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
 pch=tmp$sybm, col=color)


Hope this is helpful,

Dan



I apologize; my use of the color vector was incorrect.  You could just 
use the tmp$color values with the correct color parameter name.  Like


dotplot(val ~ lot, tmp,
ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
pch=tmp$sybm, col=tmp$color)


Dan



--
Daniel Nordlund
Bothell, WA USA

__
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] Vincentizing Reaction Time data in R

2015-05-20 Thread Daniel Nordlund

On 5/20/2015 6:22 PM, John Kane wrote:




-Original Message-
From: gabriel.wein...@gmail.com
Sent: Wed, 20 May 2015 22:31:48 +0200
To: jrkrid...@inbox.com, john.archie.mck...@gmail.com
Subject: Re: [R] Vincentizing Reaction Time data in R

John Kane : I already read the paper and wrote an e-mail to the author,
he used matlab and suggested me to ask this same question on this forum.
But thank you for your answer.


The paper said that they had used R !  They must have forgotten to add what may 
have been a minor bit of use of mintabl

I had a look at the equation in the Wiki article and I have long ago forgotten 
how to read such a thing but I wonder how complicated it is as an algorithm?  R 
is very flexible and it might be fairly easy to just write a function to do it.

Actually I just had a very quick look at the Ratcliff paper in Psychological 
Bulletin 1979, Vol. 86, No. 3, 446-461 
(http://star.psy.ohio-state.edu/coglab/People/roger/pdf/Papers/psychbull79.pdf)

I am tired and it is not my area of expertise but it does not look too 
difficult to write a function in R to do this. But I have been wrong before. :)



John McKown : thanks a lot, this could be a great help to me but I have
to take a closer look.

Again thank you for your replies.

Regards,

--
Gabriel Weindel
Master student in Neuropsychology - Aix-Marseille University (France)



Le 20/05/2015 18:41, John Kane a écrit :

John Kane
Kingston ON Canada


-Original Message-
From: john.archie.mck...@gmail.com
Sent: Wed, 20 May 2015 09:38:47 -0500
To: gabriel.wein...@gmail.com
Subject: Re: [R] Vincentizing Reaction Time data in R

On Wed, May 20, 2015 at 5:13 AM, Gabriel WEINDEL

wrote:


Dear all,

For my master thesis, I'm currently working in cognitive neuroscience
on
executive control through measurement of reaction time and I need to
get
my
data 'vincentized' with an exclusive use of R set by my statistic
teacher
for a test purpose, for this reason I can't use the python code the
lab
team usually uses.
Despite a dozen hours of research I couldn't find any package or
R-code
which would allow the use of vincentization, that's why I'm querying
help
on the R forum.

So has anyone ever used vincentization in R ?



I haven't. And I failed statistics in school. But a Google search got
me
to
this page, which I hope might be of some help to you. If not, my
apologies.

https://stat.ethz.ch/pipermail/r-help/2003-May/034272.html
[https://stat.ethz.ch/pipermail/r-help/2003-May/034272.html]

I never heard of it either and I passed a couple out of some number > 2
but we always thought the perception and cognition people strange.
I think this paper may be a lead. An email to the authors might help
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4017132/
[http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4017132/]





Gabriel Weindel
Master student in Neuropsychology - Aix-Marseille University (France)





A (very) brief search regarding 'vincentizing' reaction time (RT) 
suggests that it just involves binning the RTs and computing the means 
within bins (typically deciles), then analyzing how the distribution of 
means differs across experimental conditions.  This may help you get 
started.


# create some data
rt <- rnorm(100,200,50)
# create deciles for binning
decile <- as.numeric(cut(rt, quantile(rt,0:10)/10),include.lowest=TRUE))
# collect into a dataframe (not really necessary)
df <- data.frame(rt=rt, decile=decile)
#compute the bin means
aggregate(rt,list(decile),mean,data=df)


This should give you a start,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] Getting a cdf equal to 1 from a variable kernel density estimation

2015-05-27 Thread Daniel Nordlund

On 5/27/2015 2:43 AM, Lionel Delmas wrote:

When I integrate the variable kernel density estimation of a sample from
-inf to inf, I should get 1. But it is not what I get with my code below. I
find a value higher than 2. How can I fix this?

n<-1000
df <- data.frame(x=unlist(lapply(1, function(i) rnorm(n, 0,sd=1
df<-as.data.frame(df[order(df$x),])
names(df)[1]<-"x"

library(functional)

gaussianKernel <- function(u, h) exp(-sum(u^2)/(2*h^2))

densityFunction <- function(x, df, ker, h){
 difference = t(t(df) - x)
 W = sum(apply(difference, 1, ker, h=h))
 W/(nrow(df)*(h^(length(df}

myDensityFunction <- Curry(densityFunction, df=df, ker=gaussianKernel , h=2)

vect<-vector()for (i in 1:length(df$x)){
f<-myDensityFunction(df$x[i])
vect<-c(vect,f)}

plot(df$x,vect,ylim=c(0,1),xlim=c(-5,5),type="l")

f <- approxfun(df$x, vect, yleft = 0, yright = 0)
integrate(f, -Inf, Inf)

Thanks




I ran your code.  Looking at the plot output, it is obvious that there 
is something wrong with you density estimates.  Since you are estimating 
density for standard normal random variates, the density for values near 
0 should be approximately 0.4, and for values in the tails the density 
should be "close" to 0.


You mention "variable kernel density estimation", but I don't see where 
you are varying your smoothing parameter, h, or any distance measure.  R 
provides a density function that could be used here, unless you are just 
wanting an excerise in how density estimation works (or this is a 
homework problem).


This is not my area of expertise, but the main problem(s) appears to be 
how gaussianKernel() and densityFunction() are written.  I think you 
want something like the following:


gaussianKernel <- function(u) exp(-u^2/2)/(2*pi)^.5

densityFunction <- function(x, df, ker, h){
difference = t(t(df) - x)/h
W = sum(apply(difference, 1, ker)) / (nrow(df)*h)
}


If you are wanting to do density estimation for real world work, I would 
get help from someone in your local area.



Hope this is helpful,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] Combining multiple probability weights for the sample() function.

2015-06-03 Thread Daniel Nordlund

On 6/3/2015 11:26 AM, Boris Steipe wrote:

If letters 1 and 2 must be equal with p=0.5, and 1 and 3 must be equal with 
p=0.5, then letter 1 must be the same as either 2 or 3. Therefore:

Choose a letter.
Make a pair of (letter, (not letter)).
Reverse the pair with p = 0.5
Concatenate your letter and the pair.


Is that what you need?


B.



On Jun 2, 2015, at 8:26 AM, Benjamin Ward (ENV)  wrote:


Dear R-List,

I have a set of possibilities I want to sample from:

bases <- list(c('A', 'C'), c('A', 'G'), c('C', 'T'))
possibilities <- as.matrix(expand.grid(bases))


possibilities

Var1 Var2 Var3
[1,] "A"  "A"  "C"
[2,] "C"  "A"  "C"
[3,] "A"  "G"  "C"
[4,] "C"  "G"  "C"
[5,] "A"  "A"  "T"
[6,] "C"  "A"  "T"
[7,] "A"  "G"  "T"
[8,] "C"  "G"  "T"

If I want to randomly sample one of these rows. If I do this, I find that it is 25% likely that my choice will have an identical first and 
last letter (e.g. [1,] "A"  "A"  "C"). It is also 25% likely that my choice will have an identical first and 
third letter (e.g. [4,] "C"  "G"  "C"). It is not likely at all that the second and third letter of my choice 
could be identical.

What I would like to do, is sample one of the rows, but given the constraint 
that the probability of drawing identical letters 1 and 2 should be 50% or 0.5, 
and at the same time the probability of drawing identical letters 1 and 3 
should be 50%. I am unsure on how to do this, but I know it involves coming up 
with a modified set of weights for the sample() function. My progress is below, 
any advice is much appreciated.

Best Wishes,

Ben Ward, UEA.


So I have used the following code to come up with a matrix, which contains 
weighting according to each criteria:

possibilities <- as.matrix(expand.grid(bases))
  identities <- apply(possibilities, 1, function(x) c(x[1] == x[2], x[1] == 
x[3], x[2] == x[3]))
  prob <- matrix(rep(0, length(identities)), ncol = ncol(identities))
  consProb <- apply(identities, 1, function(x){0.5 / length(which(x))})
  polProb <- apply(identities, 1, function(x){0.5 / length(which(!x))})
  for(i in 1:nrow(identities)){
prob[i, which(identities[i,])] <- consProb[i]
prob[i, which(!identities[i,])] <- polProb[i]
  }
  rownames(prob) <- c("1==2", "1==3", "2==3")
  colnames(prob) <- apply(possibilities, 1, function(x)paste(x, collapse = ", 
"))

This code gives the following matrix:

A, A, CC, A, C  A, G, CC, G, C   A, A, 
T C, A, T   A, G, T   C, G, T
1==2 0.2500 0.0833 0.0833 0.0833 0.2500 0.0833 
0.0833 0.0833
1==3 0.0833 0.2500 0.0833 0.2500 0.0833 0.0833 
0.0833 0.0833
2==3 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 
0.0625 0.0625

Each column is one of the choices from 'possibilities', and each row gives a 
series of weights based on three different criteria:

Row 1, that if it possible from the choices for letter 1 == letter 2, that 
combined chance be 50%.
Row 2, that if it possible from the choices for letter 1 == letter 3, that 
combined chance be 50%.
Row 3, that if it possible from the choices for letter 2 == letter 3, that 
combined chance be 50%.

So:

If I used sample(x = 1:now(possibilities), size = 1, prob = prob[1,]) 
repeatedly, I expect about half the choices to contain identical letters 1 and 
2.

If I used sample(x = 1:now(possibilities), size = 1, prob = prob[2,]) 
repeatedly, I expect about half the choices to contain identical letters 1 and 
3.

If I used sample(x = 1:now(possibilities), size = 1, prob = prob[3,]) 
repeatedly, I expect about half the choices to contain identical letters 2 and 
3. Except that in this case, since it is not possible.

Note each row sums to 1.

What I would like to do - if it is possible - is combine these three sets of 
weights into one set, that when used with
sample(x = 1:nrow(possibilities, size = 1, prob = MAGICPROB) will give me a 
list of choices, where ~50% of them contain identical letters 1 and 2, AND ~50% 
of them contain identical letters 1 and 3, AND ~50% again contain identical 
letters 2 and 3 (except in this example as it is not possible from the choices).

Can multiple probability weightings be combined in such a manner?




Ben,

If I correctly understand your requirements, you can't do what you are 
asking.  If you only have the eight possibilities that you list, then to 
get letters 1 and two to match 50% of the time you must select row 1 
with probability=.25 and row 5 with probability=.25. 

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread Daniel Nordlund

On 6/22/2015 9:42 AM, C W wrote:

Hello R list,

I am have question about sampling unique coordinate values.

Here's how my data looks like


dat <- cbind(x1 = rep(1:5, 3), x2 = rep(c(3.7, 2.9, 5.2), each=5))
dat

   x1  x2
  [1,]  1 3.7
  [2,]  2 3.7
  [3,]  3 3.7
  [4,]  4 3.7
  [5,]  5 3.7
  [6,]  1 2.9
  [7,]  2 2.9
  [8,]  3 2.9
  [9,]  4 2.9
[10,]  5 2.9
[11,]  1 5.2
[12,]  2 5.2
[13,]  3 5.2
[14,]  4 5.2
[15,]  5 5.2


If I sampled (1, 3.7), then, I don't want (1, 2.9) or (2, 3.7).

I want to avoid either the first or second coordinate repeated.  It leads
to undefined matrix inversion.

I thought of using sampling(), but not sure about applying it to a data
frame.

Thanks in advance,

Mike



I am not sure you gave us enough information to solve your real world 
problem.  But I have a few comments and a potential solution.


1. In your example the unique values in in x1 are completely crossed 
with the unique values in x2.
2. since you don't want duplicates of either number, then the maximum 
number of samples that you can take is the minimum number of unique 
values in either vector, x1 or x2 (in this case x2 with 3 unique values).

3. Sample without replace from the smallest set of unique values first.
4. Sample without replacement from the larger set second.

> x <- 1:5
> xx <- c(3.7, 2.9, 5.2)
> s2 <- sample(xx,2, replace=FALSE)
> s1 <- sample(x,2, replace=FALSE)
> samp <- cbind(s1,s2)
>
> samp
 s1  s2
[1,]  5 3.7
[2,]  1 5.2
>

Your actual data is probably larger, and the unique values in each 
vector may not be completely crossed, in which case the task is a little 
harder.  In that case, you could remove values from your data as you 
sample.  This may not be efficient, but it will work.


smpl <- function(dat, size){
  mysamp <- numeric(0)
  for(i in 1:size) {
s <- dat[sample(nrow(dat),1),]
mysamp <- rbind(mysamp,s, deparse.level=0)
dat <- dat[!(dat[,1]==s[1] | dat[,2]==s[2]),]
}
  mysamp
}


This is just an example of how you might approach your real world 
problem.  There is no error checking, and for large samples it may not 
scale well.



Hope this is helpful,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] Function returning multiple objects but printing only one

2015-07-13 Thread Daniel Caro
Hello,

Sorry if this has already been addressed before but I could not find any
helpful references.

I would like to create a function that outputs a single element of a list
but stores all elements, similar to  'lm' and many other functions. There
are several answers on how to return multiple objects with lists, for
example:

http://r.789695.n4.nabble.com/How-to-return-multiple-values-in-a-function-td858528.html

http://stackoverflow.com/questions/8936099/returning-multiple-objects-in-an-r-function

But the examples show how to print multiple outputs, such as

functionReturningTwoValues <- function() {return(list(first=1, second=2))}
functionReturningTwoValues()

And I only want the function to print a single element from the list but
still store the other elements such that they can be retrieved with
functionReturningTwoValues$first, for example. My function produces
bootstrap coefficients so clearly I don't want to print the bootstrap
output but I do want users to be able to access it.

Many thanks,
Daniel

[[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] remove 0 and NA values

2015-07-13 Thread Daniel Nordlund

On 7/13/2015 6:02 PM, Lida Zeighami wrote:

Hi Dan,

Thanks for reply,
Sorry the format of matrix is ruiend!
Yes, this matrix is 6×6 but my orginal matrix is so biger than this!!

No, I don't think so your code do that for me!
I want to remove the columns which the sum of their values are equal to
zero!

On Jul 13, 2015 5:31 PM, "Daniel Nordlund" mailto:djnordl...@frontier.com>> wrote:

On 7/13/2015 3:01 PM, Lida Zeighami wrote:

Hi there,

I have a matrix which its elements are 0, 1,2,NA
I want to remove the columns which the colsums are equal to 0 or
NA and
drop these columns from the original matrix and create the new
matrix for
the nonzero and NA value?
   (I think I have consider na.rm=True and remove the colums
with colsum=0,
   because if I consider na.rm=False all the values of my
colsums get NA)

this is my matrix format:

mat[1:5,1:5]

 1:1105901701:110888172 1:110906406
  1:110993854
   1:110996710   1:44756
A05363   00 0
  0 NA 0
A05370   00 0
  0 0 NA
A05380   1
   NA   2  0
   NA 0
A05397   00
0  1 0
  2
A05400   20 0
0 00
A05426   0
0 NA   0
00



summat <-  colSums(mat,na.rm = TRUE)

head(summat)

  [,1]
1:110590170 3
1:110888172 0
1:110906406  2
1:110993854 1
1:110996710 0
1:44756 2

   The 2nd and 5th columns have colsum=0 so I Ishould remove
them from the
met and keep the rest of columns in  another matrix.

my out put should be like below:

metnonzero

 1:110590170 1:110906406  1:110993854
1:44756
A05363   0  0
0   0
A05370   0  0
0  NA
A05380   1  2
0   0
A05397   0
0  1   2
A05400   2  0
0   0
A05426   0  NA
0   0

would you please let me know how can I do that?

Many thanks,
Lid


First, you matrix appears to be 6x6.  That being said, does this get
you what you want?

mat[, -which(summat[,1] ]


    Dan

--
Daniel Nordlund
Bothell, WA USA



Lida,

I seem to have cut-and-pasted something very badly, and for that I 
apologize.  Here is a revised version:


mat <- structure(c(0L, 0L, 1L, 0L, 2L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L,
0L, 2L, 0L, 0L, NA, 0L, 0L, 0L, 1L, 0L, 0L, NA, 0L, NA, 0L, 0L,
0L, 0L, NA, 0L, 2L, 0L, 0L), .Dim = c(6L, 6L), .Dimnames = list(
c("A05363", "A05370", "A05380", "A05397", "A05400", "A05426"), 
c("X1.110590170", "X1.110888172", "X1.110906406", "X1.110993854", 
"X1.110996710", "X1.44756")))

summat <- colSums(mat,na.rm = TRUE)
mat[,-which(summat==0)]
   X1.110590170 X1.110906406 X1.110993854 X1.44756
A053630000
A05370000   NA
A053801200
A053970012
A05400    2000
A054260   NA00
>

Hope this is more helpful,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] How to simulate informative censoring in a Cox PH model?

2015-07-22 Thread Daniel Meddings
I wish to simulate event times where the censoring is informative, and to
compare parameter estimator quality from a Cox PH model with estimates
obtained from event times generated with non-informative censoring. However
I am struggling to do this, and I conclude rather than a technical flaw in
my code I instead do not understand what is meant by informative and
un-informative censoring.

My approach is to simulate an event time T dependent on a vector of
covariates x having hazard function h(t|x)=lambda*exp(beta'*x)v*t^{v-1}.
This corresponds to T~ Weibull(lambda(x),v), where the scale parameter
lambda(x)=lambda*exp(beta'*x) depends on x and the shape parameter v is
fixed. I have N subjects where T_{i}~ Weibull(lambda(x_{i}),v_{T}),
lambda(x_{i})=lambda_{T}*exp(beta_{T}'*x_{i}), for i=1,...,N. Here I assume
the regression coefficients are p-dimensional.

I generate informative censoring times C_i~ Weibull(lambda(x_i),v_C),
lambda(x_i)=lambda_C*exp(beta_C'*x_i) and compute Y_inf_i=min(T_i,C_i) and
a censored flag delta_inf_i=1 if Y_inf_i <= C_i (an observed event), and
delta_inf_i=0 if Y_inf_i > C_i (informatively censored: event not
observed). I am convinced this is informative censoring because as long as
beta_T~=0 and beta_C~=0 then for each subject the data generating process
for T and C both depend on x.

In contrast I generate non-informative censoring times
D_i~Weibull(lambda_D*exp(beta_D),v_D), and compute Y_ninf_i=min(T_i,D_i)
and a censored flag delta_ninf_i=1 if Y_ninf_i <= D_i (an observed event),
and delta_ninf_i=0 if Y_ninf_i > D_i (non-informatively censored: event not
observed). Here beta_D is a scalar. I "scale" the simulation by choosing
the lambda_T, lambda_C and lambda_D parameters such that on average T_ihttps://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] How to simulate informative censoring in a Cox PH model?

2015-07-24 Thread Daniel Meddings
Hi Greg

Many thanks for taking the time to respond to my query. You are right about
pointing out the distinction between what variables are and are not
included in the event times process and in the censoring process. I clearly
forgot this important aspect. I amended my code to do as you advise and now
I am indeed getting biased estimates when using the informatively censored
responses. The problem is now that the estimates from the independently
censored responses are the same - i.e. they are just as biased. Thus the
bias seems to be due entirely to model mis-specification and not the
informative censoring.


To give a concrete example I simulate event times T_i and censoring times
C_i from the following models;


T_i~ Weibull(lambda_t(x),v_t),lambda_t(x)=lambda_t*exp( beta_t_0 +
(beta_t_1*Treat_i) + (beta_t_2*Z_i) + (beta_t_3*Treat_i*Z_i)  )

C_i~ Weibull(lambda_c(x),v_c),lambda_c(x)=lambda_c*exp( beta_c_0 +
(beta_c_1*Treat_i) + (beta_c_2*Z_i) + (beta_c_3*Treat_i*Z_i)  )

D_i~Weibull(lambda_d(x),v_D), lambda_d(x)=lamda_d*exp( beta_d_0)

where ;

beta_t_0 = 1,  beta_t_1 = -1,   beta_t_2 = 1,  beta_t_3 = -2,   lambda_t=0.5

beta_c_0 = 0.2,  beta_c_1 = -2,   beta_c_2 = 2,  beta_c_3 = -2,
lambda_c=0.5

beta_d_0 = -0.7,  lambda_d=0.1

When I fit the cox model to both the informatively censored responses and
the independent censored responses I include only the Treatment covariate
in the model.

I simulate Treatment from a Bernoulli distribution with p=0.5 and Z_i from
a beta distribution so that Z ranges from 0 to 1 (I like to think of Z as a
"poor" prognosis probability where Z_i=1 means a subject is 100% certain to
have a poor prognosis and Z_i=0 means zero chance). These parameter choices
give approximately 27% and 25% censoring for the informatively censored
responses (using C_i) and the independent censored responses (using D_i)
respectively. I use N=2000 subjects and 2000 simulation replications.

The above simulation I get estimates of beta_t_2 of -1.526 and -1.537 for
the informatively censored responses and the independent censored responses
respectively.

Furthermore when I fit a cox model to the full responses (no censoring at
all) I get an estimate of beta_t_2 of -1.542. This represents the best that
can possibly be done given that Z and Treat*Z are not in the model. Clearly
censoring is not making much of a difference here - model mis-specification
dominates.

I still must be doing something wrong but I cannot figure this one out.

Thanks

Dan



On Thu, Jul 23, 2015 at 12:33 AM, Greg Snow <538...@gmail.com> wrote:

> I think that the Cox model still works well when the only information
> in the censoring is conditional on variables in the model.  What you
> describe could be called non-informative conditional on x.
>
> To really see the difference you need informative censoring that
> depends on something not included in the model.  One option would be
> to use copulas to generate dependent data and then transform the
> values using your Weibul.  Or you could generate your event times and
> censoring times based on x1 and x2, but then only include x1 in the
> model.
>
> On Wed, Jul 22, 2015 at 2:20 AM, Daniel Meddings 
> wrote:
> > I wish to simulate event times where the censoring is informative, and to
> > compare parameter estimator quality from a Cox PH model with estimates
> > obtained from event times generated with non-informative censoring.
> However
> > I am struggling to do this, and I conclude rather than a technical flaw
> in
> > my code I instead do not understand what is meant by informative and
> > un-informative censoring.
> >
> > My approach is to simulate an event time T dependent on a vector of
> > covariates x having hazard function h(t|x)=lambda*exp(beta'*x)v*t^{v-1}.
> > This corresponds to T~ Weibull(lambda(x),v), where the scale parameter
> > lambda(x)=lambda*exp(beta'*x) depends on x and the shape parameter v is
> > fixed. I have N subjects where T_{i}~ Weibull(lambda(x_{i}),v_{T}),
> > lambda(x_{i})=lambda_{T}*exp(beta_{T}'*x_{i}), for i=1,...,N. Here I
> assume
> > the regression coefficients are p-dimensional.
> >
> > I generate informative censoring times C_i~ Weibull(lambda(x_i),v_C),
> > lambda(x_i)=lambda_C*exp(beta_C'*x_i) and compute Y_inf_i=min(T_i,C_i)
> and
> > a censored flag delta_inf_i=1 if Y_inf_i <= C_i (an observed event), and
> > delta_inf_i=0 if Y_inf_i > C_i (informatively censored: event not
> > observed). I am convinced this is informative censoring because as long
> as
> > beta_T~=0 and beta_C~=0 then for each subject the data generating process
> > for T and C both depend on x.
> >
> > In contrast I generate non-informative censoring times
> > D_i~Weibull(lambda_D*exp(beta_D),v_D), and 

Re: [R] How to simulate informative censoring in a Cox PH model?

2015-07-30 Thread Daniel Meddings
tes would be different compared to those obtained when
modelling only non-censored times?



On Wed, Jul 29, 2015 at 5:37 PM, Greg Snow <538...@gmail.com> wrote:

> As models become more complex it becomes harder to distinguish
> different parts and their effects.  Even for a straight forward linear
> regression model if X1 and X2 are correlated with each other then it
> becomes difficult to distinguish between the effects of X1^2, X2^2,
> and X1*X2.  In your case the informative censoring and model
> misspecification are becoming hard to distinguish (and it could be
> argued that having informative censoring is really just a form of
> model misspecification).  So I don't think so much that you are doing
> things wrong, just that you are learning that the models are complex.
>
> Another approach to simulation that you could try is to simulate the
> event time and censoring time using copulas (and therefore they can be
> correlated to give informative censoring, but without relying on a
> term that you could have included in the model) then consider the
> event censored if the censoring time is shorter.
>
> On Fri, Jul 24, 2015 at 10:14 AM, Daniel Meddings 
> wrote:
> > Hi Greg
> >
> > Many thanks for taking the time to respond to my query. You are right
> about
> > pointing out the distinction between what variables are and are not
> included
> > in the event times process and in the censoring process. I clearly forgot
> > this important aspect. I amended my code to do as you advise and now I am
> > indeed getting biased estimates when using the informatively censored
> > responses. The problem is now that the estimates from the independently
> > censored responses are the same - i.e. they are just as biased. Thus the
> > bias seems to be due entirely to model mis-specification and not the
> > informative censoring.
> >
> >
> > To give a concrete example I simulate event times T_i and censoring times
> > C_i from the following models;
> >
> >
> > T_i~ Weibull(lambda_t(x),v_t),lambda_t(x)=lambda_t*exp( beta_t_0 +
> > (beta_t_1*Treat_i) + (beta_t_2*Z_i) + (beta_t_3*Treat_i*Z_i)  )
> >
> > C_i~ Weibull(lambda_c(x),v_c),lambda_c(x)=lambda_c*exp( beta_c_0 +
> > (beta_c_1*Treat_i) + (beta_c_2*Z_i) + (beta_c_3*Treat_i*Z_i)  )
> >
> > D_i~Weibull(lambda_d(x),v_D), lambda_d(x)=lamda_d*exp( beta_d_0)
> >
> > where ;
> >
> > beta_t_0 = 1,  beta_t_1 = -1,   beta_t_2 = 1,  beta_t_3 = -2,
>  lambda_t=0.5
> >
> > beta_c_0 = 0.2,  beta_c_1 = -2,   beta_c_2 = 2,  beta_c_3 = -2,
> > lambda_c=0.5
> >
> > beta_d_0 = -0.7,  lambda_d=0.1
> >
> > When I fit the cox model to both the informatively censored responses and
> > the independent censored responses I include only the Treatment
> covariate in
> > the model.
> >
> > I simulate Treatment from a Bernoulli distribution with p=0.5 and Z_i
> from a
> > beta distribution so that Z ranges from 0 to 1 (I like to think of Z as a
> > "poor" prognosis probability where Z_i=1 means a subject is 100% certain
> to
> > have a poor prognosis and Z_i=0 means zero chance). These parameter
> choices
> > give approximately 27% and 25% censoring for the informatively censored
> > responses (using C_i) and the independent censored responses (using D_i)
> > respectively. I use N=2000 subjects and 2000 simulation replications.
> >
> > The above simulation I get estimates of beta_t_2 of -1.526 and -1.537 for
> > the informatively censored responses and the independent censored
> responses
> > respectively.
> >
> > Furthermore when I fit a cox model to the full responses (no censoring at
> > all) I get an estimate of beta_t_2 of -1.542. This represents the best
> that
> > can possibly be done given that Z and Treat*Z are not in the model.
> Clearly
> > censoring is not making much of a difference here - model
> mis-specification
> > dominates.
> >
> > I still must be doing something wrong but I cannot figure this one out.
> >
> > Thanks
> >
> > Dan
> >
> >
> >
> > On Thu, Jul 23, 2015 at 12:33 AM, Greg Snow <538...@gmail.com> wrote:
> >>
> >> I think that the Cox model still works well when the only information
> >> in the censoring is conditional on variables in the model.  What you
> >> describe could be called non-informative conditional on x.
> >>
> >> To really see the difference you need informative censoring that
> >> depends on something not included in the model.  One option would be
> >> to use copulas to generate depe

Re: [R] How to simulate informative censoring in a Cox PH model?

2015-08-03 Thread Daniel Meddings
Hi Greg

The copulas concept seems a nicely simple way of simulating event times
that are subject to informative censoring (in contrast to the double cox
model approach I use). The correlation between the marginal uniform random
variables you speak of reminded me that my approach should also induce this
correlation, just in a different way. Similarly I should also observe zero
correlation between my event times from my outcome model and the censoring
times. Unfortunately this was not the case - to cut a long story short I
was inadvertently generating my independent censoring times from a model
that depended on covariates in the outcome model. This now explains the
mixed results I rather laboriously attempted to describe previously.

Re-running some scenarios with my new error-free code I can now clearly
observe the points you have been making, that is informative censoring only
leads to bias if the covariates in the censoring model are not in the
outcome model. Indeed I can choose the common (to both models) treatment
effect to be vastly different (with all other effects the same) and have no
bias, yet small differences in the censoring Z effect (not in the outcome
model) effect lead to moderate biases.

I am still somewhat confused at the other approach to this problem where I
have seen in various journal articles authors assuming an outcome model for
the censored subjects - i.e. an outcome model for the unobserved event
times. Using this approach the definition of informative censoring appears
to be where the observed and un-observed outcome models are different. This
approach also makes sense to me - censoring merely loses precision of the
parameter estimators due to reduced events, but does not lead to bias.
However the concept of correlated event and censoring times does not even
present itself here?

Thanks

Dan



On Fri, Jul 31, 2015 at 5:06 PM, Greg Snow <538...@gmail.com> wrote:

> Daniel,
>
> Basically just responding to your last paragraph (the others are
> interesting, but I think that you are learning as much as anyone and I
> don't currently have any other suggestions).
>
> I am not an expert on copulas, so this is a basic understanding, you
> should learn more about them if you choose to use them.  The main idea
> of a copula is that it is a bivariate or multivariate distribution
> where all the variables have uniform marginal distributions but the
> variables are not independent from each other.  How I would suggest
> using them is to choose a copula and generate random points from a
> bivariate copula, then put those (uniform) values into the inverse pdf
> function for the Weibull (or other distribution), one of which is the
> event time, the other the censoring time.  This will give you times
> that (marginally) come from the distributions of interest, but are not
> independent (so would be considered informative censoring).  Repeat
> this with different levels of relationship in the copula to see how
> much difference it makes in your simulations.
>
> On Thu, Jul 30, 2015 at 2:02 PM, Daniel Meddings 
> wrote:
> > Thanks Greg once more for taking the time to reply. I certainly agree
> that
> > this is not a simple set-up, although it is realistic I think. In short
> you
> > are correct about model mis-specification being the key to producing more
> > biased estimates under informative than under non-informative censoring.
> > After looking again at my code and trying various things I realize that
> the
> > key factor that leads to the informative and non-informative censoring
> data
> > giving rise to the same biased estimates is how I generate my Z_i
> variable,
> > and also the magnitude of the Z_i coefficient in both of the event and
> > informative censoring models.
> >
> > In the example I gave I generated Z_i (I think of this as a "poor
> prognosis"
> > variable) from a beta distribution so that it ranged from 0-1. The biased
> > estimates for "beta_t_1" (I think of this as the effect of a treatment on
> > survival) were approximately 1.56 when the true value was -1. What I
> forgot
> > to mention was that estimating a cox model with 1,000,000 subjects to the
> > full data (i.e. no censoring at all) arguably gives the best treatment
> > effect estimate possible given that the effects of Z_i and Z_i*Treat_i
> are
> > not in the model. This "best possible" estimate turns out to be 1.55 -
> i.e.
> > the example I gave just so happens to be such that even with 25-27%
> > censoring, the estimates obtained are almost the best that can be
> attained.
> >
> > My guess is that the informative censoring does not bias the estimate
> more
> > than non-informative censoring because the only variable not accounted
> f

[R] Chaining multiple replacement functions in R

2014-12-30 Thread Daniel Gabrieli
I cross posted this on Stack Overflow:
http://stackoverflow.com/questions/27694466/chaining-multiple-replacement-functions-in-r


I am using R to work with a large JS object (using the library rjsonio). As
such, I have a lot of nested lists, which are getting somewhat cumbersome
to work with. I have a simplified example below. I am trying to work with
this object by creating some form of ‘getter’ and ‘setter’ functions. After
looking around, I have found a pretty nice ‘getter’ function that recurses
through the object and returns the value for the first matching label. This
is especially great because it lends itself to chaining functions together.
However, I can not figure out a way to get the same effect for a ‘setter’
function. Any thoughts on how to create a ‘setter’ function that can be
chained together in a similar fashion?

#example, simplified, object
app = list(
  1,
  2,
  d=list(a=123,
 b=456,
 list(
   FirstKey=list(attr1='good stuff', attr2=12345),
   SecondKey=list(attr1='also good stuff', attr2=4321)
   )
 )
  )


#Return a function that returns the value
#associated with first label that matches 'name'
getByName <- function(name){
  rmatch <- function(x) {
pos <- match(name, names(x))
if (!is.na(pos))
  return(x[[pos]])
for (el in x) {
  if (class(el) == "list") {
out <- Recall(el)
if (!is.null(out)) return(out)
  }
}
  }
  rmatch
}

getFirstKey <- getByName("FirstKey")
getAttr1 <- getByName("attr1")
getAttr2 <- getByName("attr2")

#I like that I can chain these functions together
getAttr1(getFirstKey(app))
getAttr2(getFirstKey(app))

# I would like to be able to do something like this
# But this won't work
###getAttr1(getFirstKey(app)) <- 9876

# This does work,,, but I loose the ability to chain functions together
# Closure around a replacement function
setterKeyAttr <- function(keyName, attr){
  function(x, value){
x$d[[3]][[keyName]][[attr]] <- value
x
  }
}

`setFirstKeyAttr2<-` <- setterKeyAttr("FirstKey", "attr2")
setFirstKeyAttr2(app) <- 2
#check the answer is correct
getAttr2(getFirstKey(app))



references:

http://stackoverflow.com/questions/23124096/r-decorator-to-change-both-input-and-output

http://r.789695.n4.nabble.com/How-to-get-a-specific-named-element-in-a-nested-list-td3037430.html

http://adv-r.had.co.nz/Functions.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] Chaining multiple replacement functions in R

2014-12-30 Thread Daniel Gabrieli
That is really helpful.  I am trying to get the rmatch function to return
the position of the 'name' instead of the value.  So rmatch(app, "FirsKey")
would return c(3,3,1).  Then app[[c(3,3,1)]] <- 'new value' would be
perfect.



On Tue, Dec 30, 2014 at 6:43 AM, Duncan Murdoch 
wrote:

> On 29/12/2014 4:41 PM, Daniel Gabrieli wrote:
> > I cross posted this on Stack Overflow:
> >
> http://stackoverflow.com/questions/27694466/chaining-multiple-replacement-functions-in-r
> >
> >
> > I am using R to work with a large JS object (using the library rjsonio).
> As
> > such, I have a lot of nested lists, which are getting somewhat cumbersome
> > to work with. I have a simplified example below. I am trying to work with
> > this object by creating some form of ‘getter’ and ‘setter’ functions.
> After
> > looking around, I have found a pretty nice ‘getter’ function that
> recurses
> > through the object and returns the value for the first matching label.
> This
> > is especially great because it lends itself to chaining functions
> together.
> > However, I can not figure out a way to get the same effect for a ‘setter’
> > function. Any thoughts on how to create a ‘setter’ function that can be
> > chained together in a similar fashion?
>
> I haven't worked through the details here so this might not work, but
> the assignment function could add extra information saying which part of
> the object was modified.  In the example below, "Firstkey" is
> app[[c(3,3,1)]], so a function that modified it could attach c(3,3,1) as
> an attribute, and later functions that wanted to do more things to it
> could start looking there.
>
> I guess the tricky part would be getting rid of that attribute if you
> didn't want to pass it along the chain, e.g. the final call shouldn't
> return it.
>
> Duncan Murdoch
>
> >
> > #example, simplified, object
> > app = list(
> >   1,
> >   2,
> >   d=list(a=123,
> >  b=456,
> >  list(
> >FirstKey=list(attr1='good stuff', attr2=12345),
> >SecondKey=list(attr1='also good stuff', attr2=4321)
> >)
> >  )
> >   )
> >
> >
> > #Return a function that returns the value
> > #associated with first label that matches 'name'
> > getByName <- function(name){
> >   rmatch <- function(x) {
> > pos <- match(name, names(x))
> > if (!is.na(pos))
> >   return(x[[pos]])
> > for (el in x) {
> >   if (class(el) == "list") {
> > out <- Recall(el)
> > if (!is.null(out)) return(out)
> >   }
> > }
> >   }
> >   rmatch
> > }
> >
> > getFirstKey <- getByName("FirstKey")
> > getAttr1 <- getByName("attr1")
> > getAttr2 <- getByName("attr2")
> >
> > #I like that I can chain these functions together
> > getAttr1(getFirstKey(app))
> > getAttr2(getFirstKey(app))
> >
> > # I would like to be able to do something like this
> > # But this won't work
> > ###getAttr1(getFirstKey(app)) <- 9876
> >
> > # This does work,,, but I loose the ability to chain functions together
> > # Closure around a replacement function
> > setterKeyAttr <- function(keyName, attr){
> >   function(x, value){
> > x$d[[3]][[keyName]][[attr]] <- value
> > x
> >   }
> > }
> >
> > `setFirstKeyAttr2<-` <- setterKeyAttr("FirstKey", "attr2")
> > setFirstKeyAttr2(app) <- 2
> > #check the answer is correct
> > getAttr2(getFirstKey(app))
> >
> >
> >
> > references:
> >
> >
> http://stackoverflow.com/questions/23124096/r-decorator-to-change-both-input-and-output
> >
> >
> http://r.789695.n4.nabble.com/How-to-get-a-specific-named-element-in-a-nested-list-td3037430.html
> >
> > http://adv-r.had.co.nz/Functions.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.
> >
>
>

[[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] Chaining multiple replacement functions in R

2014-12-30 Thread Daniel Gabrieli
This is what I came up with (to make the recursive function return the
position of the 'name' and still be able to chain the calls together).  I
am not sure if this is a great way to do it... but it seems to be
working...

rmatch.pos <- function(object, name, seq=NA, level=NULL){
  ##return the vector of integers corresponding to the first match
  ##of 'name' to a label in object or NULL if no match is found
###object: a list, likely deeply nested
##name: the name of the label to look for
##seq: starting point to search for 'name' in 'object' i.e. c(2,3,3)
##level: don't touch this; it keeps track of how deep the recursive
execution is
  ##can be chained together to reduce ambiguity or result:
##obj <- list(a=1, b=list(c=2, d=list(e=1, attr1="really?",
f=list(attr1 = "found me!"
##obj[[rmatch.pos(obj, "attr1", rmatch.pos(obj, "f"))]]

  if(is.null(seq)){
#short circuit if NULL gets passed
#when chaining, this forces the whole 'chain'
#to NULL when any 'link' is NULL
return(NULL)
  }
  if(is.null(level)){
level <- length(na.omit(seq))
  }
  if(any(is.na(seq))){
temp <- object
  }else{
temp <- object[[seq]]
  }
  level <- level + 1
  pos <- match(name, names(temp))
  if(!is.na(pos)){
seq[level] <- pos
return(seq)
  }
  for(el in seq_along(temp)){
if(class(temp[[el]]) == "list"){
  seq[level] <- el
  out <- Recall(object, name, seq, level)
  if(!is.null(out)){
return(out)
  }
}
  }
}


rmatch.pos(app, "ThirdKey")
rmatch.pos(app, "attr2")
#chaining example
rmatch.pos(app, "attr2", rmatch.pos(app, "FirstKey"))
rmatch.pos(app, "attr2", rmatch.pos(app, "SecondKey"))
rmatch.pos(app, "attr1", rmatch.pos(app, "ERROR"))
rmatch.pos(app, "ERROR", rmatch.pos(app, "attr1"))




On Tue, Dec 30, 2014 at 1:08 PM, Daniel Gabrieli 
wrote:

> That is really helpful.  I am trying to get the rmatch function to return
> the position of the 'name' instead of the value.  So rmatch(app, "FirsKey")
> would return c(3,3,1).  Then app[[c(3,3,1)]] <- 'new value' would be
> perfect.
>
>
>
> On Tue, Dec 30, 2014 at 6:43 AM, Duncan Murdoch 
> wrote:
>
>> On 29/12/2014 4:41 PM, Daniel Gabrieli wrote:
>> > I cross posted this on Stack Overflow:
>> >
>> http://stackoverflow.com/questions/27694466/chaining-multiple-replacement-functions-in-r
>> >
>> >
>> > I am using R to work with a large JS object (using the library
>> rjsonio). As
>> > such, I have a lot of nested lists, which are getting somewhat
>> cumbersome
>> > to work with. I have a simplified example below. I am trying to work
>> with
>> > this object by creating some form of ‘getter’ and ‘setter’ functions.
>> After
>> > looking around, I have found a pretty nice ‘getter’ function that
>> recurses
>> > through the object and returns the value for the first matching label.
>> This
>> > is especially great because it lends itself to chaining functions
>> together.
>> > However, I can not figure out a way to get the same effect for a
>> ‘setter’
>> > function. Any thoughts on how to create a ‘setter’ function that can be
>> > chained together in a similar fashion?
>>
>> I haven't worked through the details here so this might not work, but
>> the assignment function could add extra information saying which part of
>> the object was modified.  In the example below, "Firstkey" is
>> app[[c(3,3,1)]], so a function that modified it could attach c(3,3,1) as
>> an attribute, and later functions that wanted to do more things to it
>> could start looking there.
>>
>> I guess the tricky part would be getting rid of that attribute if you
>> didn't want to pass it along the chain, e.g. the final call shouldn't
>> return it.
>>
>> Duncan Murdoch
>>
>> >
>> > #example, simplified, object
>> > app = list(
>> >   1,
>> >   2,
>> >   d=list(a=123,
>> >  b=456,
>> >  list(
>> >FirstKey=list(attr1='good stuff', attr2=12345),
>> >SecondKey=list(attr1='also good stuff', attr2=4321)
>> >)
>> >  )
>> >   )
>> >
>> >
>> > #Return a function that returns the value
>> > #associated with first label that matches 'name'
>> > getByName <- function(name){
>> >   rmatch

[R] Creating two autocorrelated and correlated time series

2015-02-05 Thread Daniel Marmander
I can create both correlated series and autocorrelated time series with
well defined correlation factors. I am however having trouble creating two
series given fixed autocorrelation for some number of lags in the series
(autocorrelation might differ between the two as well), that also has a
specific correlation between the series.

I have found some help here:
http://stats.stackexchange.com/questions/71211/how-to-generate-normal-random-variable-vector-which-is-spatially-auto-correlated
but I have a hard time implementing it in R, being a R-novice.


Thanks,
Daniel

[[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] SAS equivalent for R's signif function?

2015-02-09 Thread Daniel Nordlund

On 2/9/2015 7:02 PM, Allen Bingham wrote:

Probably posting this to the wrong list ... but I'm in the process of
learning R, after many years of using SAS --- so I thought I'd ask this
question here:

  Is there with a function (or macro) in SAS that performs the same
action as R's "signif" function, if so please provide?

Tried to find via a Google search to no success. Doesn't seem to be in the
"R for SAS and SPSS Users" by Robert A. Munchen (first edition is what I
have), or in SAS and R by Ken Kleinman and Nicholas J. Horton (2nd edition)
[although in the latter they do list the R "signif" function on page 61 ...
but don't list a SAS equivalent.

If you have a suggestion for a different list that I might ask this question
(assuming I don't get the answer here), provide that as well.

Thanks-Allen

__
Allen Bingham
Bingham Statistical Consulting
aebingh...@gmail.com
LinkedIn Profile: www.linkedin.com/pub/allen-bingham/3b/556/325

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



Yes, this is the wrong list.  Your question is about SAS (that is what 
SAS-L or SAScommunity is about) and this list is about R, and you 
already know what function to use in R.  That said, I searched for "SAS 
round to fixed number of significant digits" and found this link


http://support.sas.com/kb/24/728.html

You could turn this into a function style macro (but it will be ugly). 
If you have a recent enough version of SAS you could use PROC FCMP to 
turn this into a function.


If you are interested contact me offline and I will send you a PROC FCMP 
implementation.



Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] generating phi using function()

2015-03-29 Thread Daniel Nordlund


The argument 'K' is missing since you are only passing four arguments to 
the phi() function, but you defined it with five formal parameters. It 
looks like the argument 'j' is not necessary in the function.  It is an 
unnecessary carry-over from the summation notation and it is never used 
in the function.


Dan


On 3/29/2015 4:08 PM, Jim Lemon wrote:

Hi T.,
Your translation of the formula looks okay, and the error message is about
a missing argument. Perhaps you have not included the necessary arguments
to "phi" in the call to "mls".

Jim


On Sun, Mar 29, 2015 at 11:59 PM, T.Riedle  wrote:


Hi everybody,
I am trying to generate the formula shown in the attachment. My formula so
far looks as follows:

phi <- function(w1, w2, j, k, K){
zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
return( zaehler/nenner )
}

Unfortunately something must be wrong here as I get the following message
when running a midas regression

m22.phi<- midas_r(rv~mls(rvh,1:max.lag+h1,1,phi), start = list(rvh=c(1,1)))
Error in phi(c(1, 1), 44L, 1) : argument "K" is missing, with no default
Called from: .rs.breakOnError(TRUE)
Browse[1]> K<-125
Browse[1]> 125

Could anybody look into my phi formula and tell me what is wrong with it?

Thanks in advance.


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




--
Daniel Nordlund
Bothell, WA USA

__
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] Sampling

2015-03-29 Thread Daniel Nordlund

On 3/29/2015 11:10 PM, Partha Sinha wrote:

I have 1000 data points.  i want to take 30 samples and find mean. I
also want to repeat this process 100 times. How to go about it?
Regards
Parth

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



see ?replicate and ?sample.  Simple example where yourdata is a simple 
vector of values, and assuming you want to sample without replacement. 
Generalizing it to other data structures is left as an exercise for the 
reader.


replicate(100,mean(sample(yourdata,30, replace=FALSE)))

hope this is helpful,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] generating phi using function()

2015-03-30 Thread Daniel Nordlund

On 3/30/2015 12:30 PM, T.Riedle wrote:

Hi,
I am struggling with following function

phi <- function(w1, w2, j, k, K){

+   zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
+   nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
+   return( zaehler/nenner )
+ }

phi(c(1, 1), 44L, 1)

Error in phi(c(1, 1), 44L, 1) : argument "k" is missing, with no default


Hence, I have changed the function to

phi <- function(w, k, K){
+ w1 <- w[1]
+ w2 <- w[2]
+ zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
+ nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
+ return( zaehler/nenner )
+ }

  Unfortunately, when running the midas regression I get the following error 
message

  m22.phi<- midas_r(rv~mls(rvh,1:max.lag+h1,1,phi), start = list(rvh=c(1,1)))

Error in X[, inds] %*% fun(st) : non-conformable arguments

I guess the problem is w but I do not find a solution how to produce the 
formula shown in the attached file where the exponents are w1 and w2, 
respectively.

Thanks for your help


From: jlu...@ria.buffalo.edu [mailto:jlu...@ria.buffalo.edu]
Sent: 30 March 2015 16:01
To: T.Riedle
Cc: r-help@r-project.org; R-help
Subject: Re: [R] generating phi using function()

Your function phi has 5 arguments with no defaults.  Your call only has 3 
arguments.  Hence the error message.

phi <- function(w1, w2, j, k, K){

+   zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
+   nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
+   return( zaehler/nenner )
+ }

phi(c(1, 1), 44L, 1)

Error in phi(c(1, 1), 44L, 1) : argument "k" is missing, with no default











"T.Riedle" mailto:tr...@kent.ac.uk>>
Sent by: "R-help" 
mailto:r-help-boun...@r-project.org>>

03/29/2015 08:59 AM

To

"r-help@r-project.org<mailto:r-help@r-project.org>" 
mailto:r-help@r-project.org>>,

cc

Subject

[R] generating phi using function()







Hi everybody,
I am trying to generate the formula shown in the attachment. My formula so far 
looks as follows:

phi <- function(w1, w2, j, k, K){
zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
return( zaehler/nenner )
}

Unfortunately something must be wrong here as I get the following message when 
running a midas regression

m22.phi<- midas_r(rv~mls(rvh,1:max.lag+h1,1,phi), start = list(rvh=c(1,1)))
Error in phi(c(1, 1), 44L, 1) : argument "K" is missing, with no default
Called from: .rs.breakOnError(TRUE)
Browse[1]> K<-125
Browse[1]> 125

Could anybody look into my phi formula and tell me what is wrong with it?

Thanks in advance.

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



You haven't provided a reproducible example, so it is difficult to 
trouble shoot errors.  However, it is not obvious to me that the error 
message has anything to do with parameter, w, in the phi function.  In 
reading the documentation for midas_r(), the help says of the formula 
argument


formula 

formula for restricted MIDAS regression or midas_r object. Formula must 
include fmls function


your formula does not include the fmls() function, it uses mls().  So I 
think your problem may have to do with how you are calling the midas_r 
function, and how the parameters are created and passed to phi().



Unfortunately, I can't be of much more help,

Dan

--
Daniel Nordlund
Bothell, WA USA

__
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 build system adds line break in DESCRIPTION URL

2015-04-03 Thread Daniel Lewandowski
Has anybody noticed that if field URL in DESCRIPTION contains a uri with 
66 or more characters, then file DESCRIPTION in the resulting package 
includes a line break at the beginning?


So this (source DESCRIPTION):

URL: 
http://ecdc.europa.eu/en/data-tools/seroincidence-calculator-tool/Pages/default.aspx


becomes (again file DESCRIPTION, but inside the package)

URL:
http://ecdc.europa.eu/en/data-tools/seroincidence-calculator-tool/Pages/default.aspx

This has been tested with R on Windows 8.1 (devel 01/04/2015 and 3.1.3) 
and Linux Mint (3.1.3). It has many sad implications including not 
acceptance of such packages to CRAN.


__
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] BIG difficulties in Using boot.ci (bot package)

2015-04-13 Thread Daniel Nordlund

On 4/13/2015 9:06 AM, varin sacha wrote:

Hi Michael,

Thanks for your response. About the data frame not necessary. I correct the 
code according to your comments. I still get the following warnings :
[1] "All values of t are equal to  5.75620151906917 \n Cannot calculate confidence 
intervals"
NULL

I have found this on the Net :
"Note that boot.ci just gives a warning and returns NA values, if all values 
are equal. There is no error and if you can work with NAs, there is no need for the 
if condition.
The boot package assumes that the bootstrap
statistic has all ways the same dimension.
Whenever you have a statistic with less dimensions you get an NA
or 0 or whatever you want".

The reproducible code :

GDP.LOG <-c(14,12,13,15.5,16,17,16.5,13.5,12.5,12)
Quality.score <-c(12,11,13,14,15,16,12,10,9,9)
Competitivness.score=c(8,6,7,5,6.5,7,8,4.5,6,7)
fit <- lm(formula = GDP.LOG ~ Quality.score + Competitivness.score)
install.packages("boot")
library(boot)
bs=function(formula,data,indices){
d=data[indices,]
fit=lm(formula,data=d)
(coef(fit))
}
results=boot(data=Dataset,statistic=bs, R=2000,formula= GDP.LOG ~ Quality.score 
+ Competitivness.score)
boot.ci(results,type="bca",index=1)
boot.ci(results,type="bca",index=2)
boot.ci(results,type="bca",index=3)

How is it possible to avoid that warning ?

Best,
S





The first problem is that this is not reproducible code.  This is what I 
get when I run your code on my computer:



GDP.LOG <-c(14,12,13,15.5,16,17,16.5,13.5,12.5,12)
Quality.score <-c(12,11,13,14,15,16,12,10,9,9)
Competitivness.score=c(8,6,7,5,6.5,7,8,4.5,6,7)
fit <- lm(formula = GDP.LOG ~ Quality.score + Competitivness.score)
#install.packages("boot")
library(boot)
bs=function(formula,data,indices){

+ d=data[indices,]
+ fit=lm(formula,data=d)
+ (coef(fit))
+ }

results=boot(data=Dataset,statistic=bs, R=2000,formula= GDP.LOG ~ Quality.score 
+ Competitivness.score)

Error in NROW(data) : object 'Dataset' not found

boot.ci(results,type="bca",index=1)

Error in boot.ci(results, type = "bca", index = 1) :
  object 'results' not found

boot.ci(results,type="bca",index=2)

Error in boot.ci(results, type = "bca", index = 2) :
  object 'results' not found

boot.ci(results,type="bca",index=3)

Error in boot.ci(results, type = "bca", index = 3) :
  object 'results' not found





A reproducible example means that when I run your code on my machine, I 
get the same results / warnings / errors that you get.  I got something 
different.



Dan

--
Daniel Nordlund
Bothell, WA USA

__
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] Rendo and dataMultilevelIV

2018-08-02 Thread Daniel Nordlund

On 8/2/2018 7:11 PM, cjg15 wrote:

Hi - Does anyone know what the variables CID and SID are in the
dataMultilevelIV dataset?

The example from page 18-19 of
https://cran.r-project.org/web/packages/REndo/REndo.pdf has

formula1 <- y ~ X11 + X12 + X13 + X14 + X15 + X21 + X22 + X23 + X24 + X31 +
X32 + X33 + (1 + X11 | CID) + (1|SID)

what exactly are the (1 + X11|CID) and (1|SID) terms?

does (1|SID) mean random intercepts for SID, and SID is student ID?

Thanks in advance, Chris

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



Did you read pages 9-10 of the document you provided a link to above 
(which describes the dataMultilevelIV dataset)?



Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Converting chr to num

2018-08-19 Thread Daniel Nordlund

See comment inline below:

On 8/18/2018 10:06 PM, Rui Barradas wrote:

Hello,

It also works with class "factor":

df <- data.frame(variable = c("12.6%", "30.9%", "61.4%"))
class(df$variable)
#[1] "factor"

as.numeric(gsub(pattern = "%", "", df$variable))
#[1] 12.6 30.9 61.4


This is because sub() and gsub() return a character vector and the 
instruction becomes an equivalent of what the help page ?factor 
documents in section Warning:


To transform a factor f to approximately its original numeric values, 
as.numeric(levels(f))[f] is recommended and slightly more efficient than 
as.numeric(as.character(f)).



Also, I would still prefer

as.numeric(sub(pattern = "%$","",df$variable))
#[1] 12.6 30.9 61.4

The pattern is more strict and there is no need to search&replace 
multiple occurrences of '%'.


The pattern is more strict, and that could cause the conversion to fail 
if the process that created the strings resulted in trailing spaces. 
Without the '$' the conversion succeeds.


df <- data.frame(variable = c("12.6% ", "30.9%", "61.4%"))
as.numeric(sub('%$', '', df$variable))
[1]   NA 30.9 61.4
Warning message:
NAs introduced by coercion


<<>>


Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] seq() problem with chron

2018-09-06 Thread Daniel Nordlund

On 9/5/2018 10:00 PM, Waichler, Scott R wrote:

Hi,

I encountered the problem below where the last value in the chron vector created with 
seq() should have a time of 15:30, but instead has 15:15.  What causes this and how can I 
make sure that the last value in the chron vector is the same as the "to" value 
in seq()?

library(chron)
dt1 <- chron("02/20/13", "00:00:00")
dt2 <- chron("07/03/18", "15:30:00")
dt <- seq(from=dt1, to=dt2, by=1/(24*4))
dt[length(dt)]
#[1] (07/03/18 15:15:00)

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnnl.gov

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



This is not a chron problem, it is a floating-point arithmetic problem 
(basically, FAQ 7.31).  You are adding incrementing by 1/96, which can't 
be represent exactly in binary representation.  So, when you expected 
that you should get a time of 15:30, it is slightly larger and the 
sequence is stopped at 15:15.


You could change dt2 to be chron("07/03/18", "15:31:00").  Or or you 
could use POSIX datetimes with something like the following, where the 
increment 900 is the number of seconds in 15 minutes.


dt1 <- strptime("02/20/13 00:00:00", "%m/%d/%y %H:%M:%S")
dt2 <- strptime("07/03/18 15:30:00", "%m/%d/%y %H:%M:%S")
dt <- seq(from=dt1, to=dt2, by=900)
dt[length(dt)]

There might also be some useful functions in the lubridate package.


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Newton-RaphsonMethod

2019-02-24 Thread Daniel Nordlund

On 2/24/2019 5:25 AM, malika yassa via R-help wrote:

HELLOplease I want to approximate the solution of the equation 
f(x)=x*(x-2)+log(x)=0
for that i did this program

f <- function(x){x*(x-2)+log(x)}
x <- c(1 : 2)
f(x)
h <- 1e-7
df.dx <- function(x){(f(x + h) - f(x)) / h}
df.dx(3/2);df.dx(2)
  newton <- function(f, tol = 1e-7, x0 = 3/2, N = 100){
  h = 1e-7
  i = 1; x1 = x0
  p = numeric(N)
  while (i <= N) {
  df.dx = (f(x + h) - f(x)) / h
  x1 = (x0 - (f(x0) / df.dx))
  p[1] = x1
  i = i + 1
  if (abs(x1 - x0) < tol) break
  x0 = x1
  }
  return(p[1 : (i-1)])
  }
  app <- newton(f, x0 = 3/2)

but i cann't find this approximation
please can you help me?






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


As Bert pointed out there is a no homework policy on this list. But I 
will point out that when I ran your presented code, I got a lot of 
warnings.  They were not immediately informative (at least to me) 
because of a subtle programming error in your code.  Your main problem 
(but not your only one) is in the calculation of the derivative of the 
function inside the while loop. The following line is the problem:


df.dx = (f(x + h) - f(x)) / h

I will leave the solution of the problem to you.

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Rank ANCOVA

2019-03-13 Thread Jackson, Daniel
Hi Frank and Dennis

I am in a similar situation but I would prefer to use a proportional odds 
model. 2 questions.


  1.  Has rank ancova been implemented in R now, despite its short comings?
  2.  Where has it been shown to yield unreliable analyses? I would like this 
evidence (which I believe but I would like to convince others!).

Thanks, Dan


AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:16}}

__
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] Rank ANCOVA

2019-03-14 Thread Jackson, Daniel
Thanks I am now in personal communication with Frank anyway!

Dan

-Original Message-
From: peter dalgaard 
Sent: 14 March 2019 10:37
To: Jackson, Daniel 
Cc: r-help@r-project.org
Subject: Re: [R] Rank ANCOVA

1. This is the R-help mailing list, not "Frank and Dennis"
2. You seem to be referring to two posts from July 2010 by Frank Harrell and 
Dennis Fisher.

-pd

> On 13 Mar 2019, at 12:06 , Jackson, Daniel  
> wrote:
>
> Hi Frank and Dennis
>
> I am in a similar situation but I would prefer to use a proportional odds 
> model. 2 questions.
>
>
>  1.  Has rank ancova been implemented in R now, despite its short comings?
>  2.  Where has it been shown to yield unreliable analyses? I would like this 
> evidence (which I believe but I would like to convince others!).
>
> Thanks, Dan
> 
>
> AstraZeneca UK Limited is a company incorporated in
> Engl...{{dropped:16}}
>
> __
> 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.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 
Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com












AstraZeneca UK Limited is a company incorporated in England and Wales with 
registered number:03674842 and its registered office at 1 Francis Crick Avenue, 
Cambridge Biomedical Campus, Cambridge, CB2 0AA.

This e-mail and its attachments are intended for the above named recipient only 
and may contain confidential and privileged information. If they have come to 
you in error, you must not copy or show them to anyone; instead, please reply 
to this e-mail, highlighting the error to the sender and then immediately 
delete the message. For information about how AstraZeneca UK Limited and its 
affiliates may process information, personal data and monitor communications, 
please see our privacy notice at 
www.astrazeneca.com<https://www.astrazeneca.com>

__
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] Downloading R Data

2019-04-14 Thread Daniel Nordlund

On 4/14/2019 3:36 PM, Spencer Brackett wrote:

   I am also looking to be able to read this file on an appropriate
application. As of now, it’s too large to view directly in GoogleDrive or
word, and I can only get a mistranslated version of the script included as
a .txt file.



[image: File]
GBM_Data.RData
<https://drive.google.com/a/saintjosephhs.com/file/d/1vZup-A4ai2D2Ir_DxFlQb87kiYboW9AC/view?usp=drivesdk>

Best,

Spencer

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


Spencer,

this looks like an saved R workspace.  I went to provided link using 
Firefox and clicked on the icon to download a file.  Once the file was 
downloaded, I started the RGui and entered the following command


load(file.choose())

This opened a window in which I could browse to the file and load it 
into R.  Also, I could double click on the file and Rstudio would load 
the file into the workspace.


If you wish to do something else, you will need to be more specific 
about what you want.



Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

__
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] Linear relative rate / excess relative risk models

2014-07-29 Thread Wollschlaeger, Daniel
A while ago, I inquired about fitting excess relative risk models in R. This is 
a follow-up about what I ended up doing in case the question pops up again.

While I was not successful in using standard tools, switching to Bayesian 
modeling using rstan (mc-stan.org/rstan.html) worked better. The results 
closely match those from Epicure.

Using the data here: http://dwoll.de/err/dat.txt
The stan model fit below replicates the results from Epicure here: 
http://dwoll.de/err/epicure.log

Of course I am still interested in learning about other options or approaches.

Daniel

##---
## rstan code for fitting an excess relative risk model with linear 
dose-response
## events = personYears * exp(beta0 + beta1*age + beta2*sex) * (1 +beta3*dose)

dat_code <- '
data {
int N;
vector[N] pyears;
vector[N] age;
vector[N] sex;
vector[N] dose;
int event[N];
}
transformed data {
vector[N] log_pyears;
log_pyears <- log(pyears);
}
parameters {
vector[2] beta;
real beta0;  # baseline intercept param
real betaD; # dose param -> non-negative
}
model {
# beta0 unspecified -> uniform prior (improper)
beta  ~ normal(0, 100);  # flat normal prior for params
betaD ~ cauchy(0, 2.5);  # ok even if not truncated, cf. stan reference
event ~ poisson_log(log_pyears + beta0 + beta[1]*age + beta[2]*sex +
log(1 + betaD*dose));
}
'

library(rstan)
stan_dat <- with(dat,
 list(pyears=pyears,
  age=age,
  sex=sex,
  N=length(pyears),
  event=event,
  dose=dose))

stanFit <- stan(model_code=dat_code, data=stan_dat,
thin=5, iter=1, chains=2)

traceplot(stanFit)
stanFit

-Original Message-
From: Wollschlaeger, Daniel 
Sent: Thursday, January 9, 2014 10:44 AM
To: David Winsemius
Cc: r-help@r-project.org
Subject: RE: AW: [R] Linear relative rate / excess relative risk models

Thanks for your suggestions! Here are links to simulated data and the Epicure 
syntax + reference fit:
http://dwoll.de/err/dat.txt
http://dwoll.de/err/epicure.log

The model tested in Epicure is

lambda = exp(alpha0 + alpha1*agePyr)*(1 + beta0*dosePyr*exp(beta1*agePyr))

with counts in variable event and offset pyears.

Many thanks, D

> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net]
> Sent: Thursday, January 09, 2014 4:33 AM
> To: Wollschlaeger, Daniel
> Cc: r-help@r-project.org
> Subject: Re: AW: [R] Linear relative rate / excess relative risk models
> 
> 
> On Jan 8, 2014, at 3:22 PM, Wollschlaeger, Daniel wrote:
> 
> > If I understand you correctly, that is exactly the approach taken by
> > Atkinson & Therneau: They get the baseline rates from published rate
> > tables from the general population, multiply them by the appropriate
> > person-time from their data to get expected counts, and use this as
> > offset.
> >
> > Unfortunately, I won't have comparable baseline rate tables. And
> > while I could fit a separate model only to the unexposed group for
> > expected counts, I'd prefer to fit both factors (lambda0 and 1+ERR)
> > simultaneously - as it is typically done in the existing literature.
> 
> If you would describe your data situation more completely (ideally
> with a reproducible example) you might get a better answer. It's also
> considered polite on this mailing list to include the email chain, so
> appending original question:
> 
> --
> David
> 
> >
> > Best, Daniel
> >
> > 
> > Von: David Winsemius [dwinsem...@comcast.net]
> > Gesendet: Mittwoch, 8. Januar 2014 19:06
> > An: Wollschlaeger, Daniel
> > Cc: r-help@r-project.org
> > Betreff: Re: [R] Linear relative rate / excess relative risk models
> >
> > I would fit a Poisson model to the dose-response data with offsets
> > for the baseline expecteds.
> 
> David Winsemius, MD
> Alameda, CA, USA
> 
> 
> My question is how I can fit linear relative rate models (= excess
> relative risk models, ERR) using R. In radiation epidemiology, ERR
> models are used to analyze dose-response relationships for event rate
> data and have the following form [1]:
> 
> lambda = lambda0(z, alpha) * (1 + ERR(x, beta))
> 
> * lambda is the event rate
> * lambda0 is the baseline rate function for non-exposed persons and
> depends on covariates z with parameters alpha
> * ERR is the excess relative risk function for exposed persons and
> depends on covariates x (among them dose) with parameters beta
> * lambda/lambda0 = 1 + ERR is the relative rate function
> 
> Often, the covariates z are a subset 

[R] lm weights argument within function

2014-08-01 Thread Daniel Caro
Hi all,

I need to loop over "lm" within a function using "weights". For example:

mydata = data.frame(y=rnorm(100, 500, 100), x= rnorm(100),
group=rep(c(0,1), 50), myweight=1/runif(100))

reg.by.wt <- function(formula, wt, by, data) {
  if(missing(by)) {
summary(lm(formula=formula, data=data, weights=data[[wt]]))
  } else {
lapply(split(data, data[by]), function(i)
summary(lm(formula=formula, data=i, weights=data[[wt]])))
  }
}

reg.by.wt(formula = y ~ x, by="group", data=mydata, wt="myweight")

Error in summary(lm(formula = formula, data = i, weights = data[[wt]])) :
  error in evaluating the argument 'object' in selecting a method for
function 'summary': Error in eval(expr, envir, enclos) : object 'wt'
not found

The functions works if I change "weights=data[[wt]]" for
"weights=myweight", but I need wt to be an argument in quotes, not an
object. It seems the issue is related to ?lm = "All of weights, subset
and offset are evaluated in the same way as variables in formula, that
is first in data and then in the environment of formula., but I can't
figure it out. Can you please provide any advice? Thank you.

Daniel

__
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] "no visible binding for global variable" and with() vs. within()

2014-08-17 Thread Daniel Braithwaite
R CMD check does not object to this code when checking a package:

foo1 <- function (bar) {
with(bar, {
x })
}

but produces a warning:

foo2: no visible binding for global variable 'x'

in response to this:

foo2 <- function (bar) {
within(bar, {
x })
}

Is this an R bug, or at least, an inadvertent inconsistency?  Here is
sessionInfo() from my machine, right after starting an interactive session:

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

[[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] Problem when estimating through "dlm" package

2014-09-16 Thread Daniel Miquelluti
I'm trying to set up an AR(2) model in the dlm context. I've generated a time 
series utilizing the code: 

am = 800; #sample size 
des = 200; #initial values to be discarded 
V = 0.5 
v = rnorm((am+des+1),0,sqrt(V)) 
W = 0.9 
w = rnorm((am+des+1),0,sqrt(W)) 
U = 0.9 
u = rnorm((am+des+1),0,sqrt(U)) 
phi1 = 0.6; 
phi2 = -0.4; 
mu=matrix(0,nrow=(am+des+1)) 
mu[2,1] = 10; 
x=matrix(0,nrow=(am+des+1)) 
x[1,1] = 0; 
x[2,1] = 0; 
#-- 
   yg=NULL 
   for (i in 3:(am+des+1)) { 
   mu[i] = mu[i-1] + w[i] 
   x[i] = phi1*x[i-1] + phi2*x[i-2] + u[i] 
   yg[i] = mu[i] + x[i] + v[i] 
  } 

 y=NULL 
 for (i in 1:(am + 1)) { 
 y[i] = yg[(i+des)] 
 } 
And obtained the estimates through: 

 buildfun = function(theta) { 
 
dlm(FF=t(c(1,1,0)),GG=matrix(c(1,0,0,0,theta[1],theta[2],0,1,0),nrow=3,byrow=T),
 
 V=exp(theta[3]),W=diag(c(exp(theta[4]),exp(theta[5]),0)), 
 m0=c(0,0,0),C0=diag(c(0.3,0.8,0.7))) 
 } 

 estMLE = dlmMLE (y, parm = c(0,0,0,0,0), build=buildfun) 
 phis=estMLE$par[1:2] 
 variances=exp(estMLE$par[3:5]) 
 c(phis,variances) 

The estimates are not very close to the values defined in the series generated. 
I think there is some sort of problem in the model specified in "buildfun", 
however, I cannot identify it. Any help is 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.


[R] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Howdy,

I have searched the lists and can not seem to find a solution to my
problem. I need to be able to dynamically modify a string inside a
function to build a new function. "sub" replaces with a quoted
string... and "parse" of "sub" returns expression... How can I get an
unquoted string from a regex to stick into a "body" of a function?

Thanks for your help!
dan

# Original Function
fsong=function(x){
 song=paste("my name is fuka,",x)
 return(song)
}
fsong("I live on the second floor")
#
# Copy and modify using "sub" returns quoted string with escaped quotes
#   internally... as expected.. which can not be evaluated.
nsong=fsong
body(nsong)[[grep("fuka",body(nsong))]]=
   sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))

nsong("I live on the second floor") # broken

#
# Copy and modify with "parse" of  "sub",  returns expression.. but
without quotes,
# o getting closer.
#
nsong=fsong
body(nsong)[[grep("fuka",body(nsong))]]=
   parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))

__
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] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Howdy Duncan,

Thanks for the quick reply!  I must be missing something
simple/obvious. I need to have the "sub()" not return quoted and
escaped characters to "just edit the language expression". In my
problem, there is a function that is supported from a different
package. So I always want to use the supported function as my base...
but a url in the supported function needs to be changed dynamically
for my application, which is easiest using "sub()".

I am trying to do what you correctly indicate I would need to do:
"just edit the language expression that body(fsong) gives you, and
assign it back"
BUT, using sub, I get back a quoted string in my example if I just use sed:

> fsong
function(x){
 song=paste("my name is fuka,",x)
 return(song)
}
# Using "sub()" becomes:
> nsong
function (x)
{
"song = paste(\"my name is muka,\", x)"
return(song)
}

Thanks again for the quick reply and help you are giving me!
dan

On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
 wrote:
> On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>>
>> Howdy,
>>
>> I have searched the lists and can not seem to find a solution to my
>> problem. I need to be able to dynamically modify a string inside a
>> function to build a new function. "sub" replaces with a quoted
>> string... and "parse" of "sub" returns expression... How can I get an
>> unquoted string from a regex to stick into a "body" of a function?
>
>
> It's possible to do what you want, though you don't want to be using
> parse(), you can just edit the language expression that body(fsong) gives
> you, and assign it back.  But that's a messy way to solve your problem.
>
> Why not create a new function containing the new string?  e.g.
>
> makefsong <- function(name = "fuka") {
>   line1 <- paste("my name is", name)
>   function(x) {
> song <- paste(line1, x)
> return(song)
>   }
> }
>
> f1 <- makefsong()
> f1("I live on the second floor")
> f2 <- makefsong("muka")
> f2("I live on the second floor")
>
> Duncan Murdoch
>
>>
>> Thanks for your help!
>> dan
>>
>> # Original Function
>> fsong=function(x){
>>   song=paste("my name is fuka,",x)
>>   return(song)
>> }
>> fsong("I live on the second floor")
>> #
>> # Copy and modify using "sub" returns quoted string with escaped quotes
>> #   internally... as expected.. which can not be evaluated.
>> nsong=fsong
>> body(nsong)[[grep("fuka",body(nsong))]]=
>> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>>
>> nsong("I live on the second floor") # broken
>>
>> #
>> # Copy and modify with "parse" of  "sub",  returns expression.. but
>> without quotes,
>> # o getting closer.
>> #
>> nsong=fsong
>> body(nsong)[[grep("fuka",body(nsong))]]=
>>
>> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>

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


Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Unfortunately in this specific case the owner/maintainer is a complete
idiot and a major jerk... he is.. well.. me in this case. But, this is
something I have also been wanting to figure out for some time as it
is often the case when a quick and simple regex based "patch" to a
function can be useful. I do not see why even when I "noquote()" the
assignment into a line of a "body()" it keeps adding the quotes and
associated escapes.



On Mon, Sep 22, 2014 at 12:01 PM, William Dunlap  wrote:
> If you really want to continue to use the function in the supported
> package, then you could try asking the maintainer of the package to
> make the problematic URL an argument to the function.  I thnk that
> changing the function on the fly, no matter how you do it, is likely
> to cause problems when the maintainer changes the function in a future
> release of the package.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Mon, Sep 22, 2014 at 8:34 AM, Daniel Fuka  wrote:
>> Howdy Duncan,
>>
>> Thanks for the quick reply!  I must be missing something
>> simple/obvious. I need to have the "sub()" not return quoted and
>> escaped characters to "just edit the language expression". In my
>> problem, there is a function that is supported from a different
>> package. So I always want to use the supported function as my base...
>> but a url in the supported function needs to be changed dynamically
>> for my application, which is easiest using "sub()".
>>
>> I am trying to do what you correctly indicate I would need to do:
>> "just edit the language expression that body(fsong) gives you, and
>> assign it back"
>> BUT, using sub, I get back a quoted string in my example if I just use sed:
>>
>>> fsong
>> function(x){
>>  song=paste("my name is fuka,",x)
>>  return(song)
>> }
>> # Using "sub()" becomes:
>>> nsong
>> function (x)
>> {
>> "song = paste(\"my name is muka,\", x)"
>> return(song)
>> }
>>
>> Thanks again for the quick reply and help you are giving me!
>> dan
>>
>> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>>  wrote:
>>> On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>>>>
>>>> Howdy,
>>>>
>>>> I have searched the lists and can not seem to find a solution to my
>>>> problem. I need to be able to dynamically modify a string inside a
>>>> function to build a new function. "sub" replaces with a quoted
>>>> string... and "parse" of "sub" returns expression... How can I get an
>>>> unquoted string from a regex to stick into a "body" of a function?
>>>
>>>
>>> It's possible to do what you want, though you don't want to be using
>>> parse(), you can just edit the language expression that body(fsong) gives
>>> you, and assign it back.  But that's a messy way to solve your problem.
>>>
>>> Why not create a new function containing the new string?  e.g.
>>>
>>> makefsong <- function(name = "fuka") {
>>>   line1 <- paste("my name is", name)
>>>   function(x) {
>>> song <- paste(line1, x)
>>> return(song)
>>>   }
>>> }
>>>
>>> f1 <- makefsong()
>>> f1("I live on the second floor")
>>> f2 <- makefsong("muka")
>>> f2("I live on the second floor")
>>>
>>> Duncan Murdoch
>>>
>>>>
>>>> Thanks for your help!
>>>> dan
>>>>
>>>> # Original Function
>>>> fsong=function(x){
>>>>   song=paste("my name is fuka,",x)
>>>>   return(song)
>>>> }
>>>> fsong("I live on the second floor")
>>>> #
>>>> # Copy and modify using "sub" returns quoted string with escaped quotes
>>>> #   internally... as expected.. which can not be evaluated.
>>>> nsong=fsong
>>>> body(nsong)[[grep("fuka",body(nsong))]]=
>>>> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>>>>
>>>> nsong("I live on the second floor") # broken
>>>>
>>>> #
>>>> # Copy and modify with "parse" of  "sub",  returns expression.. but
>>>> without quotes,
>>>> # o getting closer.
>>>> #
>>>> nsong=fsong
>>>> body(nsong)[[grep("fuka",body(nsong))]]=
>>>>
>>>> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>>>>
>>>> __
>>>> R-help@r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread Daniel Fuka
Thanks everyone for the help. I need to step back and refresh my
memory on expressions as I am still unclear as to why I can not
directly edit:
body(nsong)[[2]]
# Which can be located from a grep:
body(nsong)[[grep("fuka",body(nsong))]]
# though I believe
class(body(nsong)[[2]])
[1] "="
# is trying to give me a pretty blatant hint... {: -)

On Mon, Sep 22, 2014 at 1:24 PM, Duncan Murdoch
 wrote:
> On 22/09/2014 11:34 AM, Daniel Fuka wrote:
>>
>> Howdy Duncan,
>>
>> Thanks for the quick reply!  I must be missing something
>> simple/obvious. I need to have the "sub()" not return quoted and
>> escaped characters to "just edit the language expression". In my
>> problem, there is a function that is supported from a different
>> package. So I always want to use the supported function as my base...
>> but a url in the supported function needs to be changed dynamically
>> for my application, which is easiest using "sub()".
>>
>> I am trying to do what you correctly indicate I would need to do:
>> "just edit the language expression that body(fsong) gives you, and
>> assign it back"
>> BUT, using sub, I get back a quoted string in my example if I just use
>> sed:
>>
>> > fsong
>> function(x){
>>   song=paste("my name is fuka,",x)
>>   return(song)
>> }
>> # Using "sub()" becomes:
>> > nsong
>> function (x)
>> {
>>  "song = paste(\"my name is muka,\", x)"
>>  return(song)
>> }
>
>
> You didn't do it right :-).   With fsong as above, the string to edit is
> body(fsong)[[c(2,3,2)]].  (Why c(2,3,2)?  Because that's where the string is
> in the parse tree.  Try looking at variations on body(fsong)[[c(2,3,2)]] to
> figure it out, e.g.
> body(fsong)[[c(2,3)]], or body(fsong)[[c(2,3,3)]], etc.)
>
> So this code would work:
>
> orig <- body(fsong)[[c(2,3,2)]]
> new <- sub("fuka", "muka", orig)
>
> # Now put it back in nsong:
> nsong <- fsong
> body(nsong)[[c(2,3,2)]] <- new
>
> But as Bill said, this is a really bad idea.  If you just *think* about
> changing that fsong function, it will break.
>
> Duncan Murdoch
>
>>
>> Thanks again for the quick reply and help you are giving me!
>> dan
>>
>> On Mon, Sep 22, 2014 at 10:37 AM, Duncan Murdoch
>>  wrote:
>> > On 22/09/2014 9:16 AM, Daniel Fuka wrote:
>> >>
>> >> Howdy,
>> >>
>> >> I have searched the lists and can not seem to find a solution to my
>> >> problem. I need to be able to dynamically modify a string inside a
>> >> function to build a new function. "sub" replaces with a quoted
>> >> string... and "parse" of "sub" returns expression... How can I get an
>> >> unquoted string from a regex to stick into a "body" of a function?
>> >
>> >
>> > It's possible to do what you want, though you don't want to be using
>> > parse(), you can just edit the language expression that body(fsong)
>> > gives
>> > you, and assign it back.  But that's a messy way to solve your problem.
>> >
>> > Why not create a new function containing the new string?  e.g.
>> >
>> > makefsong <- function(name = "fuka") {
>> >   line1 <- paste("my name is", name)
>> >   function(x) {
>> > song <- paste(line1, x)
>> > return(song)
>> >   }
>> > }
>> >
>> > f1 <- makefsong()
>> > f1("I live on the second floor")
>> > f2 <- makefsong("muka")
>> > f2("I live on the second floor")
>> >
>> > Duncan Murdoch
>> >
>> >>
>> >> Thanks for your help!
>> >> dan
>> >>
>> >> # Original Function
>> >> fsong=function(x){
>> >>   song=paste("my name is fuka,",x)
>> >>   return(song)
>> >> }
>> >> fsong("I live on the second floor")
>> >> #
>> >> # Copy and modify using "sub" returns quoted string with escaped quotes
>> >> #   internally... as expected.. which can not be evaluated.
>> >> nsong=fsong
>> >> body(nsong)[[grep("fuka",body(nsong))]]=
>> >> sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))
>> >>
>> >> nsong("I live on the second floor") # broken
>> >>
>> >> #
>> >> # Copy and modify with "parse" of  "sub",  returns expression.. but
>> >> without quotes,
>> >> # o getting closer.
>> >> #
>> >> nsong=fsong
>> >> body(nsong)[[grep("fuka",body(nsong))]]=
>> >>
>> >>
>> >> parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])))
>> >>
>> >> __
>> >> 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] quantreg crq function-incomplete taus fitted

2014-10-07 Thread daniel castro
Hello ,

I'm trying to fit a quantile regression model for rigth censoring data
and I think I'm misunderstanding the behaviour of the function crq

I've tried

qreg1<-crq(Surv(TIME,EVENT,type="right")~VAR1+VAR2,
   data=DATA_TRAIN,method = "Portnoy",tau=-1)

qreg1<-crq(Surv(TIME,EVENT,type="right")~VAR1+VAR2,
   data=DATA_TRAIN,method = "Portnoy",tau=0.1)

this two first attemps give me 78 set of values for every tau in
$fitted.values or in $sol starting in 0 and ending in 0.348 (values of
tau) but then where are the rest un itl 1?

qreg1<-crq(Surv(TIME,EVENT,type="right")~VAR1+VAR2,
   data=DATA_TRAIN,method = "Portnoy",grid=seq(0.1,1,by=0.1))

gives only one value for tau=0.0

I want to control the parameters tau or grid to get the results for
the quantiles I want, but it seems that I went wrong somewhere..but
where?

Thank you in advance,

Daniel Castro

__
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] errors in initial values in R2winBUGS

2014-10-11 Thread Daniel Miquelluti
You are separating the objects using commas, the correct should be semicolons.

Example:
xi1=matrix(data=rep(0.0,600),ncol=3);xi2=matrix(data=rep(0.0,600),ncol=3))


Best regards,
Daniel Miquelluti



Em S�bado, 11 de Outubro de 2014 18:06, Uwe Ligges 
 escreveu:
 




On 11.10.2014 06:09, thanoon younis wrote:
> Dear all R users
> I am trying to find the bayesian analysis using R2winBUGS but i have errors
> in initial values with two groups.
> the R-code
> #Initial values for the MCMC in WinBUGS
>
> init1<-list(uby1=rep(0.0,10),lam1=c(0.0,0.0,0.0,0.0,0.0,0.0),
> gam1=c(1.0,1.0,1.0,1.0,1.0,1.0),psd1=1.0,phi1=matrix(data=c(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),ncol=3,byrow=TRUE),uby2=rep(0.0,10),lam2=c(0.0,0.0,0.0,0.0,0.0,0.0),
> gam2=c(1.0,1.0,1.0,1.0,1.0,1.0),psd2=1.0,phi2=matrix(data=c(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),ncol=3,byrow=TRUE),
> xi1=matrix(data=rep(0.0,600),ncol=3),xi2=matrix(data=rep(0.0,600),ncol=3)),


The comma at the very end is too much 

Best,
Uwe Ligges


> init2<-list(uby1=rep(0.5,10),lam1=c(0.5,0.5,0.5,0.5,0.5,0.5),
> gam1=c(0.0,0.0,0.0,0.0,0.0,0.0),psd1=0.6,phi1=matrix(data=c(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),ncol=3,byrow=TRUE),uby2=rep(0.5,10),lam2=c(0.5,0.5,0.5,0.5,0.5,0.5),
> gam2=c(0.0,0.0,0.0,0.0,0.0,0.0),psd2=0.6,phi2=matrix(data=c(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),ncol=3,byrow=TRUE),
> xi1=matrix(data=rep(0.0,600),ncol=3),xi2=matrix(data=rep(0.0,600),ncol=3)),
>
>
> and the errors are
>
> Error: unexpected ',' in:
> "3,byrow=TRUE),uby2=rep(0.0,10),lam2=c(0.0,0.0,0.0,0.0,0.0,0.0),
> gam2=c(1.0,1.0,1.0,1.0,1.0,1.0),psd2=1.0,phi2=matrix(data=c(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),ncol=3,byrow=TRUE),
> xi1=matrix(data=rep(0.0,600),ncol=3),xi2=matrix(data=rep(0.0,600),ncol=3)),"
>
> and
>
> Error: unexpected ',' in:
> "3,byrow=TRUE),uby2=rep(0.5,10),lam2=c(0.5,0.5,0.5,0.5,0.5,0.5),
> gam2=c(0.0,0.0,0.0,0.0,0.0,0.0),psd2=0.6,phi2=matrix(data=c(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),ncol=3,byrow=TRUE),
> xi1=matrix(data=rep(0.0,600),ncol=3),xi2=matrix(data=rep(0.0,600),ncol=3)),"
>
>
>
> any help would be greatly appreciated
>
>

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

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


Re: [R] loops in R

2014-11-05 Thread Daniel Nordlund

On 11/5/2014 5:41 AM, Noha Osman wrote:

Hi Folks

Iam  a new user of R and I have a question . Hopefully anyone help me in that 
issue


I have that dataset as following

  Sample  Population  Species  Tissue R GB
1 Bari1_062-1  Bari1 ret   seed  94.52303  80.70346 67.91760
2 Bari1_062-2  Bari1 ret   seed  98.27683  82.68690 68.55485
3 Bari1_062-3  Bari1 ret   seed 100.53170  86.56411 73.27528
4 Bari1_062-4  Bari1 ret   seed  96.65940  84.09197 72.05974
5 Bari1_062-5  Bari1 ret   seed 117.62474  98.49354 84.65656
6 Bari1_063-1  Bari1 ret   seed 144.39547 113.76170 99.95633

and I have 20 populations as following

[1] Bari1  Bari2  Bari3  Besev  Cermik Cudi   Derici
 Destek Egil
[10] GunasanKalkan Karabace   Kayatepe   Kesentas   OrtancaOyali
  Cultivated Sarikaya
[19] Savur  Sirnak

I need to calculate mean and variance of each population using column [R] using 
 for-loop


Thanks



You don't want to use loops here, but rather some vectorized function. 
One possibility is some thing like the following:


with(your_data_frame,aggregate(R,list(Population), mean))
with(your_data_frame,aggregate(R,list(Population), var))

hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA  USA

__
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] Lme4 Package Help!

2014-11-06 Thread Daniel Mello
Hello, all! 

So, as stated in the title, the Lme4 package used to output p-values for the
fixed effects. What happened?!

Literally 2 weeks ago, I ran code, got output with no errors, and had
p-values listed for my fixed effects.

Now, running THE SAME CODE with THE SAME DATASET (nothing at all has
changed, not the data, not my computer, not R, nothing), I do not get
p-values.

I've tried other computers, I've tried resetting R.

Any ideas? I'd really need to get some p-values.

Thank you!

D

__
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] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)

2014-11-09 Thread Daniel Nordlund

On 11/8/2014 8:40 PM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

Hello,



The example data frame in the reproducible code below has 5 columns (1 column 
for id and 4 columns for dates), and there are 7 observations.  I would like to 
insert the most recent date from those 4 date columns into a new column 
(oiddate) using the mutate() function in the dplyr package.   I am getting 
correct results (NA in the new column) if a given row has all NA's in the four 
columns.  However, the issue is that the date value inserted into the new 
column (oidflag) is incorrect for 5 of the remaining 6 rows (with a non-NA 
value in at least 1 of the four columns).



I would appreciate receiving your help toward resolving the issue.  Please see 
the R console and the R script (reproducible example)below.



Thanks in advance.



Pradip





##  from the console 

print (data2)

   idmrjdatecocdateinhdatehaldateoidflag

1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2011-11-04

2  2   

3  3 2009-10-242011-10-132011-11-04

4  4 2007-10-10  2011-11-04

5  5 2006-09-01 2005-08-10   2011-11-04

6  6 2007-09-04 2011-10-05   2011-11-04

7  7 2005-10-25   2011-11-04 2011-11-04





##  Reproducible code and data 
#



library(dplyr)

library(lubridate)

library(zoo)

# data object - description of the



temp <- "id  mrjdate cocdate inhdate haldate

1 2004-11-04 2008-07-18 2005-07-07 2007-11-07

2 NA NA NA NA

3 2009-10-24 NA 2011-10-13 NA

4 2007-10-10 NA NA NA

5 2006-09-01 2005-08-10 NA NA

6 2007-09-04 2011-10-05 NA NA

7 2005-10-25 NA NA 2011-11-04"



# read the data object



data1 <- read.table(textConnection(temp),

 colClasses=c("character", "Date", "Date", "Date", "Date"),

 header=TRUE, as.is=TRUE

 )

# create a new column



data2 <- mutate(data1,

 oidflag= ifelse(is.na(mrjdate) & is.na(cocdate) & is.na(inhdate)  
& is.na(haldate), NA,

   max(mrjdate, cocdate, inhdate, 
haldate,na.rm=TRUE )

 )

 )



# convert to date

data2$oidflag = as.Date(data2$oidflag, origin="1970-01-01")



# print records



print (data2)





Pradip K. Muhuri, PhD

SAMHSA/CBHSQ

1 Choke Cherry Road, Room 2-1071

Rockville, MD 20857

Tel: 240-276-1070

Fax: 240-276-1260





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



I am not familiar with the mutate() function from dplyr, but you can get 
your wanted results as follows:


data2 <- within(data1, oidflag <- apply(data1[,-1], 1, max, na.rm=TRUE))


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

__
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] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)

2014-11-09 Thread Daniel Nordlund

On 11/9/2014 3:05 AM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

Hi Dan,

Thank you so much for sending me your code that provides me desired results. 
But, I don't understand  why I am getting the follow warning message, In 
FUN(newX[, i], ...) : no non-missing arguments, returning NA. Any thoughts?

Regards,

Pradip



data2x <- within(data1, oidflag <- apply(data1[,-1], 1, max, na.rm=TRUE))

Warning message:
In FUN(newX[, i], ...) : no non-missing arguments, returning NA

data2x

   idmrjdatecocdateinhdatehaldateoidflag
1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2008-07-18
2  2   
3  3 2009-10-242011-10-132011-10-13
4  4 2007-10-10  2007-10-10
5  5 2006-09-01 2005-08-10   2006-09-01
6  6 2007-09-04 2011-10-05   2011-10-05
7  7 2005-10-25   2011-11-04 2011-11-04


Pradip K. Muhuri, PhD
SAMHSA/CBHSQ
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857
Tel: 240-276-1070
Fax: 240-276-1260

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Daniel Nordlund
Sent: Sunday, November 09, 2014 5:33 AM
To: r-help@r-project.org
Subject: Re: [R] Getting the most recent dates in a new column from dates in 
four columns using the dplyr package (mutate verb)

On 11/8/2014 8:40 PM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

Hello,



The example data frame in the reproducible code below has 5 columns (1 column 
for id and 4 columns for dates), and there are 7 observations.  I would like to 
insert the most recent date from those 4 date columns into a new column 
(oiddate) using the mutate() function in the dplyr package.   I am getting 
correct results (NA in the new column) if a given row has all NA's in the four 
columns.  However, the issue is that the date value inserted into the new 
column (oidflag) is incorrect for 5 of the remaining 6 rows (with a non-NA 
value in at least 1 of the four columns).



I would appreciate receiving your help toward resolving the issue.  Please see 
the R console and the R script (reproducible example)below.



Thanks in advance.



Pradip





##  from the console 

print (data2)

idmrjdatecocdateinhdatehaldateoidflag

1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2011-11-04

2  2   

3  3 2009-10-242011-10-132011-11-04

4  4 2007-10-10  2011-11-04

5  5 2006-09-01 2005-08-10   2011-11-04

6  6 2007-09-04 2011-10-05   2011-11-04

7  7 2005-10-25   2011-11-04 2011-11-04





##  Reproducible code and data
#



library(dplyr)

library(lubridate)

library(zoo)

# data object - description of the



temp <- "id  mrjdate cocdate inhdate haldate

1 2004-11-04 2008-07-18 2005-07-07 2007-11-07

2 NA NA NA NA

3 2009-10-24 NA 2011-10-13 NA

4 2007-10-10 NA NA NA

5 2006-09-01 2005-08-10 NA NA

6 2007-09-04 2011-10-05 NA NA

7 2005-10-25 NA NA 2011-11-04"



# read the data object



data1 <- read.table(textConnection(temp),

  colClasses=c("character", "Date", "Date", "Date",
"Date"),

  header=TRUE, as.is=TRUE

  )

# create a new column



data2 <- mutate(data1,

  oidflag= ifelse(is.na(mrjdate) & is.na(cocdate) &
is.na(inhdate)  & is.na(haldate), NA,

max(mrjdate, cocdate, inhdate,
haldate,na.rm=TRUE )

  )

  )



# convert to date

data2$oidflag = as.Date(data2$oidflag, origin="1970-01-01")



# print records



print (data2)





Pradip K. Muhuri, PhD

SAMHSA/CBHSQ

1 Choke Cherry Road, Room 2-1071

Rockville, MD 20857

Tel: 240-276-1070

Fax: 240-276-1260





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



I am not familiar with the mutate() function from dplyr, but you can get your 
wanted results as follows:

data2 <- within(data1, oidflag <- apply(data1[,-1], 1, max, na.rm=TRUE))


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

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



It means what it says

[R] HELP ON NON-LINEAR MIXED MODEL

2014-11-13 Thread Popoola Daniel
Good Morning Sir/Ma,
I am POPOOLA DANIEL a Forest Biometrician in making from the University of 
Ibadan, Ibadan Nigeria. Please Sir/Ma I am having issues on performing 
Non-linear mixed model on R (using maximum likelihood approach). I am trying to 
input four different measured variables which are basal area, diameter at 
breast height, Dominant height,quadratic mean diameter as a function for height 
prediction on equation. But I have not been able to get through with the model.

Please I need your  candid options on how to go about this. Other useful tips 
on Codes entering for data analysis in R environment will also be appreciated . 

Thanks in anticipation to your reply.

__
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] Fwd: PLEASE HELP ON R-LANGUAGE

2014-12-01 Thread Daniel James
Subject: PLEASE HELP ON R-LANGUAGE


I am writing my project on "The effect of Bootstrapping on Time Series
Data". My problem is how I will write r programme to run a non stationary
time series data. I am familia to r language already.
Please help me.

[[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] Estimating group modes using GLMs for skewed distributions

2015-08-25 Thread Daniel Meddings
I am wondering why for generalized linear models with Gamma, Poisson and
Negative Binomial distributions that there appears to be no discussion
about estimating the medians or the modes of the distributions. For example
in clinical trials for count data where a log link is used it is the
quantity

E[Y|T] / E[Y|C] =   exp( beta_T + beta^{-}x^{*} )  / exp(beta_C +
beta^{-}x^{*})
   =   exp( beta_T  )  / exp(beta_C )

that seems to be of interest, where beta_T, and beta_C are the effects of
treatment and control respectively, x^{*} is the chosen covariate point to
estimate the ratio at (doesn't matter what this is here since they cancel),
and beta^{-} is the model parameters excluding the treatment and control
effects.

Whilst I have no objection to this ratio, in addition I would also wish to
know what the mode or the median of the treated and control group is (and
the difference in these quantities), given that these distributions are
skewed (i.e. the mean is not too relevant).

For example for a skewed continuous variable modeled with the gamma
distribution if $alpha$ is the shape parameter then the mode for treated
subjects at x^{*} is given as follows

mode(Y|T) = ((alpha-1)(alpha))* exp(beta_T+beta^{-}x^{*})

as long as alpha >= 1. However I see no mention of this kind of summary
being estimated in these GLMs and I am wondering why. Is it perhaps that
the ratio of means is more difficult to affect by small treatment effects
than is a difference in modes or medians - i.e. analogous to risk ratios
generally being preferred to risk differences when comparing disease
incidence rates?

The reason I am interested in estimating modes or medians is that I wish to
compare how well a linear mixed model performs (which assumes normally
distributed responses) at estimating the mode or median by using the
standard mixed model estimates of the group means when the distribution of
Y is skewed. However perhaps I should be looking at how well the mixed
model estimates the ratio of means?

For comparison I have implemented the above estimation of the treatment and
control group modes using GLMs with random effects (the formula is similar
to the above but with simple functions of the random effects covariance
parameters multiplying the expression). As expected estimates of the group
means from the mixed model agree well with the estimates of the modes from
the GLM for reasonably symmetrical distributions, but the mixed model's
mean estimates start to increase beyond the modes as the distribution
becomes skewed.

I can do inference on the difference in the modes using a parametric
bootstrap, so as far as I am concerned I cannot see any problems with this
approach. However if there are some I would welcome somebody pointing these
out.

Many thanks

Dan

[[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] Connecting R to SAS SPDS through ODBC - no results.

2015-09-18 Thread Daniel Nordlund

On 9/18/2015 12:00 PM, Charles Burchill wrote:

We have recently setup our SAS SPDS data server for use with ODBC connections.

Unfortunately when sending a query to the data server I am getting no data 
returned.  It is not clear if this is an issue with SPDS or RODBC and I am 
hoping someone has explored this already.



I know the connection works since I can query data through MS Access/Excel, or 
STATA and have data returned.



odbcConnect(ch)  - works fine.

odbcGetInfo(ch) - returns the server information



sqlTables()  returns no table information

sqlQuery()  returns the file structure but no records.

sqlFetch()  doesn't find the table (although an sqlQuery obviously does since 
it returns structure information)



I am hoping that someone can send me an example of accessing SPDS through ODBC 
using R.



Thanks!





--
Charles Burchill, Associate Director Data Access and Use,
Manitoba Centre for Health Policy
College of Medicine, Faculty of Health Sciences
408-727 McDermot Ave, winnipeg, Manitoba, R3E 3P5
Tel: 204 789 3429  Fax: 204 789 3910
charles.burch...@umanitoba.ca<mailto:charles.burch...@med.umanitoba.ca>

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

I haven't worked with SPDS data sources, but I found that when 
connecting to "regular" SAS datasets I had to set believeNRows and 
colQuote to get the connection to work properly. For example I set up a 
tmp DSN and connected like this


ch <- odbcConnect('tmp', believeNRows=FALSE, colQuote=NULL)


Hope this is helpful,

Dan

--
Daniel Nordlund
Bothell, WA  USA

__
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] retaining characters in a csv file

2015-09-23 Thread Daniel Nordlund

On 9/23/2015 5:57 AM, Therneau, Terry M., Ph.D. wrote:

Thanks for all for the comments, I hadn't intended to start a war.

My summary:
  1. Most important: I wasn't missing something obvious.  This is 
always my first suspicion when I submit something to R-help, and it's 
true more often than not.


  2. Obviously (at least it is now), the CSV standard does not specify 
that quotes should force a character result.  R is not "wrong".  Wrt 
to using what Excel does as litmus test, I consider that to be totally 
uninformative about standards: neither pro (like Duncan) or anti (like 
Rolf), but simply irrelevant.  (Like many MS choices.)


  3. I'll have to code in my own solution, either pre-scan the first 
few lines to create a colClasses, or use read_csv from the readr 
library (if there are leading zeros it keeps the string as character, 
which may suffice for my needs), or something else.


  4. The source of the data is a "text/csv" field coming from an http 
POST request.  This is an internal service on an internal Mayo server 
and coded by our own IT department; this will not be the first case 
where I have found that their definition of "csv" is not quite standard.


Terry T.




On 23/09/15 10:00, Therneau, Terry M., Ph.D. wrote:

I have a csv file from an automatic process (so this will happen
thousands of times), for which the first row is a vector of variable
names and the second row often starts something like this:

5724550,"000202075214",2005.02.17,2005.02.17,"F", .

Notice the second variable which is
   a character string (note the quotation marks)
   a sequence of numeric digits
   leading zeros are significant

The read.csv function insists on turning this into a numeric. Is there
any simple set of options that
will turn this behavior off?  I'm looking for a way to tell it to "obey
the bloody quotes" -- I still want the first, third, etc columns to
become numeric.  There can be more than one variable like this, and not
always in the second position.

This happens deep inside the httr library; there is an easy way for me
to add more options to the read.csv call but it is not so easy to
replace it with something else.


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



A fairly simple workaround is to add two lines of code to the process, 
and then add the colClasses parameter as you suggested in item 2 above.


want <- read.csv('yourfile', quote='', stringsAsFactors= FALSE, nrows=1)
classes <- sapply(want, class)
want <- read.csv('yourfile', stringsAsFactors= FALSE, colClasses=classes)

I don't know if you want your final file to convert strings to factors, 
so you can modify as needed.  In addition, if your files aren't as 
regular as I inferred, you can increase the number of rows to read in 
the first line to ensure getting the classes right.



Hope this is helpful,

Dan

--
Daniel Nordlund
Bothell, WA  USA

__
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] how to work with time of day (independent of date)

2015-10-30 Thread Daniel Nordlund
I have a data frame with date/times represented as charaacter strings 
and and a value at that date/time.  I want to get the mean value for 
each time of day, across days, and then plot time of day on the x-axis 
and means on the y-axis.  R doesn't appear to have a built-in time of 
day time type (independent of a date), unless I have missed something. 
What is the best way to create a time variable so that I can aggregate 
and plot by time of day, with time labelled in HH:MM format.  My current 
approach is to convert all date/times to the same date.  I can then 
manage the rest of what I want with ggplot2.  But I am  wondering if 
there is an easier/better way to do deal with time of day.


Here is a sample data frame.

df <- structure(list(date = structure(1:8, .Label = c("2015-10-29 
00:50:00",

"2015-10-29 09:30:00", "2015-10-29 21:10:00", "2015-10-30 00:50:00",
"2015-10-30 09:30:00", "2015-10-30 21:10:00", "2015-10-31 00:50:00",
"2015-10-31 10:30:00"), class = "factor"), value = c(88L, 17L,
80L, 28L, 23L, 39L, 82L, 79L)), .Names = c("date", "value"), row.names = 
c(NA,

-8L), class = "data.frame")


Any suggestions appreciated.

Dan

--
Daniel Nordlund
Bothell, WA  USA

__
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] how to work with time of day (independent of date)

2015-10-30 Thread Daniel Nordlund

On 10/30/2015 11:17 AM, Mark Leeds wrote:

Daniel: Just to complete my solution, here's the code for doing the
mean. Didn't expect this to take 3 emails !!! Have a good weekend.

temp <- tapply(f$value, f$justtimes, mean)
finalDF <- data.frame(chrontimes = times(rownames(temp)), values = temp)
plot(values ~ chrontimes, data = finalDF)





On Fri, Oct 30, 2015 at 2:09 PM, Mark Leeds mailto:marklee...@gmail.com>> wrote:

Hi Daniel: I forgot that you wanted the mean so my code doesn't do
exactly what you asked for but you can use jim's code for that part.
His substring approach is also good but maybe
the chron approach is more general ? Sorry for confusion.




On Fri, Oct 30, 2015 at 2:07 PM, Mark Leeds mailto:marklee...@gmail.com>> wrote:

Hi Daniel:  Assuming that you don't have to deal with time
zones, then you can use a chron object which has a seperate
field for the time.  See below for how to convert to just times.
I sent privately in order to not keep others from sending since
there may  be other ways. But, if you're okay with just this,
then you can just send to list to close out thread. No credit
needed. All the best.


library(chron)

f <- structure(list(date = structure(1:8, .Label = c("2015-10-29
00:50:00",
"2015-10-29 09:30:00", "2015-10-29 21:10:00", "2015-10-30 00:50:00",
"2015-10-30 09:30:00", "2015-10-30 21:10:00", "2015-10-31 00:50:00",
"2015-10-31 10:30:00"), class = "factor"), value = c(88L, 17L,
80L, 28L, 23L, 39L, 82L, 79L)), .Names = c("date", "value"),
row.names = c(NA,
-8L), class = "data.frame")

print(f)

f$dateandtimes <-
as.chron(as.POSIXct(as.character(f$date),format = "%Y-%m-%d
%H:%M:%S"))
print(f)

f$justtimes <- times(as.numeric(f$dateandtimes) %% 1)
print(f)

plot(value ~ justtimes, data = f)

On Fri, Oct 30, 2015 at 1:35 PM, Daniel Nordlund
mailto:djnordl...@frontier.com>> wrote:

I have a data frame with date/times represented as
charaacter strings and and a value at that date/time.  I
want to get the mean value for each time of day, across
days, and then plot time of day on the x-axis and means on
the y-axis.  R doesn't appear to have a built-in time of day
time type (independent of a date), unless I have missed
something. What is the best way to create a time variable so
that I can aggregate and plot by time of day, with time
labelled in HH:MM format.  My current approach is to convert
all date/times to the same date.  I can then manage the rest
of what I want with ggplot2.  But I am  wondering if there
is an easier/better way to do deal with time of day.

Here is a sample data frame.

df <- structure(list(date = structure(1:8, .Label =
c("2015-10-29 00:50:00",
"2015-10-29 09:30:00", "2015-10-29 21:10:00", "2015-10-30
00:50:00",
"2015-10-30 09:30:00", "2015-10-30 21:10:00", "2015-10-31
00:50:00",
"2015-10-31 10:30:00"), class = "factor"), value = c(88L, 17L,
80L, 28L, 23L, 39L, 82L, 79L)), .Names = c("date", "value"),
row.names = c(NA,
-8L), class = "data.frame")


Any suggestions appreciated.

Dan

--
Daniel Nordlund
Bothell, WA  USA

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






Thanks to all who responded (both on and off list).  Several useful 
suggestions were presented.  It looks like using the chron package may 
get me what I want, but I will play with all the solutions to see what 
works best for me.



Dan

--
Daniel Nordlund
Bothell, WA  USA

__
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] Nested ANOVA yields surprising results

2015-10-30 Thread Daniel Wagenaar

Dear R users:

All textbook references that I consult say that in a nested ANOVA (e.g., 
A/B), the F statistic for factor A should be calculated as


F_A = MS_A / MS_(B within A).

But when I run this simple example:

set.seed(1)
A <- factor(rep(1:3, each=4))
B <- factor(rep(1:2, 3, each=2))
Y <- rnorm(12)
anova(lm(Y ~ A/B))

I get this result:

  Analysis of Variance Table

  Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
  A  2 0.4735 0.23675  0.2845 0.7620
  A:B3 1.7635 0.58783  0.7064 0.5823
  Residuals  6 4.9931 0.83218

Evidently, R calculates the F value for A as MS_A / MS_Residuals.

While it is straightforward enough to calculate what I think is the 
correct result from the table, I am surprised that R doesn't give me 
that answer directly. Does anybody know if R's behavior is intentional, 
and if so, why? Equally importantly, is there a straightforward way to 
make R give the answer I expect, that is:


 Df Sum Sq Mean Sq F value Pr(>F)
  A   2 0.4735 0.23675  0.4028 0.6999

The students in my statistics class would be much happier if they didn't 
have to type things like


  a <- anova(...)
  F <- a$`Sum Sq`[1] / a$`Sum Sq`[2]
  P <- 1 - pf(F, a$Df[1], a$Df[2])

(They are not R programmers (yet).) And to be honest, I would find it 
easier to read those results directly from the table as well.


Thanks,

Daniel Wagenaar

--
Daniel A. Wagenaar, PhD
Assistant Professor
Department of Biological Sciences
McMicken College of Arts and Sciences
University of Cincinnati
Cincinnati, OH 45221
Phone: +1 (513) 556-9757
Email: daniel.wagen...@uc.edu
Web: http://www.danielwagenaar.net

__
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] (no subject)

2015-11-01 Thread Daniel Wagenaar
Thank you all for your helpful responses. I apologize for the lack of 
subject line. That is certainly not my habit. It happened because my 
first email was refused because it was sent using an incorrect "From:" 
line (an aliases email address, daniel.wagen...@uc.edu) instead of the 
address I subscribed to the list with. When I resent it, I failed to 
copy the subject line. My apologies.


- Daniel

On 10/30/2015 03:12 PM, Kevin Wright wrote:

Maybe you want

summary(aov(Y ~ A + Error(A:B)))

Kevin


On Fri, Oct 30, 2015 at 9:32 AM, Wagenaar, Daniel (wagenadl)
mailto:wagen...@ucmail.uc.edu>> wrote:

Dear R users:

All textbook references that I consult say that in a nested ANOVA
(e.g., A/B), the F statistic for factor A should be calculated as
F_A = MS_A / MS_(B within A). But when I run this simple example:

set.seed(1)
A = factor(rep(1:3, each=4))
B = factor(rep(1:2, 3, each=2))
Y = rnorm(12)
anova(lm(Y ~ A/B))

I get this result:

Analysis of Variance Table

Response: Y
   Df Sum Sq Mean Sq F value Pr(>F)
A  2 0.4735 0.23675  0.2845 0.7620
A:B3 1.7635 0.58783  0.7064 0.5823
Residuals  6 4.9931 0.83218

Evidently, R calculates the F value for A as MS_A / MS_Residuals.
While it is straightforward enough to calculate what I think is the
correct result from the table, I am surprised that R doesn't give me
that answer directly. Does anybody know if R's behavior is
intentional, and if so, why? And, perhaps most importantly, how to
get the "textbook" result in the most straightforward way? (I'd like
to be able to give me students a simple procedure...)

    Thanks,

Daniel Wagenaar

--
Daniel A. Wagenaar, PhD
Assistant Professor
Department of Biological Sciences
McMicken College of Arts and Sciences
University of Cincinnati
Cincinnati, OH 45221
Phone: +1 (513) 556-9757
Email: daniel.wagen...@uc.edu <mailto:daniel.wagen...@uc.edu>
Web: http://www.danielwagenaar.net
__
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.




--
Kevin Wright


__
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   3   4   5   6   7   8   9   10   >