Re: [R] Estimating parameters of 3 parameters lognormal distribution

2014-01-18 Thread Frede Aakmann Tøgersen
It has to do with setting a to large upper bound for the gamma parameter. 
However, we are estimating the value of gamma because we do not know it so how 
can we set an upper bound for gamma??

Perhaps other optimization algorithms in optim() can be used (Nelder-Mead works 
for this x at least).

Here is my findings:

 N - 100
 mu -  1
 sigma - 2 
 gamma - 3
 
 set.seed(42)
 x - rlnorm(N, mu, sigma) + gamma
 
 min(x)
[1] 3.006832
 
 foo - function(x, mu, sigma, gamma)
+ {dlnorm(x - gamma, mu, sigma)}
 
 ## min(x) is not the right upper bound to use for gamma
 fit  - fitdistr(x, densfun = foo,
+ start = list(mu = 0.9, sigma = 1.9, gamma = 2.9),
+ lower = c(-Inf, 0, -Inf),
+ upper=c(Inf, Inf, min(x)))
Error in stats::optim(x = c(45.178764955739, 3.87862565957867, 
8.61957940802123,  : 
  L-BFGS-B needs finite values of 'fn'
 
 ## now upper bound for gamma is not to large
 fit  - fitdistr(x, densfun = foo,
+ start = list(mu = 0.9, sigma = 1.9, gamma = 2.9),
+ lower = c(-Inf, 0, -Inf),
+ upper=c(Inf, Inf, 3))
 fit
   mu sigmagamma   
  1.08694600   2.02546254   2.99393215 
 (0.20902998) (0.17736860) (0.01663611)
 
 ## now upper bound for gamma is not to large
 ## still able to find correct estimates for parameters for other start values
 fit  - fitdistr(x, densfun = foo,
+ start = list(mu = 0, sigma = 1, gamma = 0),
+ lower = c(-Inf, 0.0001, -Inf),
+ upper=c(Inf, Inf, 3))
 fit
   mu sigmagamma   
  1.08671881   2.02579806   2.99394094 
 (0.20907178) (0.17745706) (0.01663591)
 
 ## Nelder-Mead method seems to do the job
 fit  - fitdistr(x, densfun = foo, method = Nelder-Mead,
start = list(mu = 0, sigma = 1, gamma = 0))
 fit
   mu sigmagamma   
  1.08678997   2.02571374   2.99393924 
 (0.20906041) (0.17743258) (0.01663503)
 
 ## these two functions are defined and used in the code for fitdistr
 ## myfn is the objective function to be optimized in optim()
 dens - function(parm, ...) foo(x, parm, ...)
 myfn - function(parm, ...) -sum(log(dens(parm, ...)))
 
 ## for gamma  3. Here min(x) = 3.006832
 ## have at least one illegal value of log-normal
 table(dens(1, 2, min(x))  0)

FALSE  TRUE 
199 
  
 ## resulting in
 myfn(0.9, 1.9, min(x))
[1] Inf
 ## but for gamma = 3 we get finite likelihood
 myfn(0.9, 1.9, 3.00)
[1] 322.4375
 ## also finite likelihood
 myfn(0.9, 1.9, -3.00)
[1] 456.7857


Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance  Modeling

Technology  Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


 -Original Message-
 From: Rolf Turner [mailto:r.tur...@auckland.ac.nz]
 Sent: 17. januar 2014 22:47
 To: Vito Ricci
 Cc: Frede Aakmann Tøgersen; Göran Broström; r-h...@stat.math.ethz.ch
 Subject: Re: [R] Estimating parameters of 3 parameters lognormal
 distribution
 
 
 Can you please tell us (me!) how you chose starting values?
 
 Out of curiosity I tried the following:
 
 set.seed(42)
 x - rlnorm(100,1,2) + 3
 require(MASS)
 strt - list(mu=1,sigma=2,gamma=3)
 fit  - fitdistr(x,densfun=function(x,mu,sigma,gamma)
{dlnorm(x-gamma,mu,sigma)
},
 start=strt,lower=c(0,0,-Inf),
 upper=c(Inf,Inf,min(x)))
 
 and it ran just fine and gave sensible answers.  But when I took:
 
 strt - list(mu=0.9,sigma=1.9,gamma=2.9)
 
 (not very different from the previous starting values)
 
 I got an error:
 
  Error in stats::optim(x = c(45.178764955739, 3.87862565957867,
 8.61957940802123,  :
L-BFGS-B needs finite values of 'fn'
 
 
 On 18/01/14 01:00, Vito Ricci wrote:
  OK. It runs fine! Many thanks Frede.
  Regards.
  Vito
 
 
 
  Se non ora, quando?
  Se non qui, dove?
  Se non tu, chi?
 
 
 
  Il Venerdì 17 Gennaio 2014 12:38, Frede Aakmann Tøgersen
 fr...@vestas.com ha scritto:
 
 
  In package MASS there is the fitdistr function using maximum likelihood
 estimation to infer on the parameters of distributions based on observed
 data.
 
 
  One of the arguments of fitdistr () allows you to specify the probability
 density function.
 
 
  You only know how the parametrization of your three parameters
 lognormal distribution is defined since you really haven't told us much.
 
 
  Please have a look at fitdistr() and tell us if fit your needs.

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

Re: [R] Estimating parameters of 3 parameters lognormal distribution

2014-01-18 Thread Prof Brian Ripley

On 18/01/2014 09:06, Frede Aakmann Tøgersen wrote:

It has to do with setting a to large upper bound for the gamma
parameter. However, we are estimating the value of gamma because we
do not know it so how can we set an upper bound for gamma??


You have starting values, so have some idea of the MLE 


Perhaps other optimization algorithms in optim() can be used
(Nelder-Mead works for this x at least).


The parameters could be transformed here, and probably should.  But most 
optimization methods are going to cope with such simple constraints 
provided foo() returns NA outside the feasible region.



Here is my findings:


N - 100
mu -  1
sigma - 2
gamma - 3

set.seed(42)
x - rlnorm(N, mu, sigma) + gamma

min(x)

[1] 3.006832


foo - function(x, mu, sigma, gamma)

+ {dlnorm(x - gamma, mu, sigma)}


## min(x) is not the right upper bound to use for gamma
fit  - fitdistr(x, densfun = foo,

+ start = list(mu = 0.9, sigma = 1.9, gamma = 2.9),
+ lower = c(-Inf, 0, -Inf),
+ upper=c(Inf, Inf, min(x)))
Error in stats::optim(x = c(45.178764955739, 3.87862565957867, 
8.61957940802123,  :
   L-BFGS-B needs finite values of 'fn'


## now upper bound for gamma is not to large
fit  - fitdistr(x, densfun = foo,

+ start = list(mu = 0.9, sigma = 1.9, gamma = 2.9),
+ lower = c(-Inf, 0, -Inf),
+ upper=c(Inf, Inf, 3))

fit

mu sigmagamma
   1.08694600   2.02546254   2.99393215
  (0.20902998) (0.17736860) (0.01663611)


## now upper bound for gamma is not to large
## still able to find correct estimates for parameters for other start values
fit  - fitdistr(x, densfun = foo,

+ start = list(mu = 0, sigma = 1, gamma = 0),
+ lower = c(-Inf, 0.0001, -Inf),
+ upper=c(Inf, Inf, 3))

fit

mu sigmagamma
   1.08671881   2.02579806   2.99394094
  (0.20907178) (0.17745706) (0.01663591)


## Nelder-Mead method seems to do the job
fit  - fitdistr(x, densfun = foo, method = Nelder-Mead,
start = list(mu = 0, sigma = 1, gamma = 0))
fit

mu sigmagamma
   1.08678997   2.02571374   2.99393924
  (0.20906041) (0.17743258) (0.01663503)


## these two functions are defined and used in the code for fitdistr
## myfn is the objective function to be optimized in optim()
dens - function(parm, ...) foo(x, parm, ...)
myfn - function(parm, ...) -sum(log(dens(parm, ...)))

## for gamma  3. Here min(x) = 3.006832
## have at least one illegal value of log-normal
table(dens(1, 2, min(x))  0)


FALSE  TRUE
 199


## resulting in
myfn(0.9, 1.9, min(x))

[1] Inf

## but for gamma = 3 we get finite likelihood
myfn(0.9, 1.9, 3.00)

[1] 322.4375

## also finite likelihood
myfn(0.9, 1.9, -3.00)

[1] 456.7857




Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance  Modeling

Technology  Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.



-Original Message-
From: Rolf Turner [mailto:r.tur...@auckland.ac.nz]
Sent: 17. januar 2014 22:47
To: Vito Ricci
Cc: Frede Aakmann Tøgersen; Göran Broström; r-h...@stat.math.ethz.ch
Subject: Re: [R] Estimating parameters of 3 parameters lognormal
distribution


Can you please tell us (me!) how you chose starting values?

Out of curiosity I tried the following:

set.seed(42)
x - rlnorm(100,1,2) + 3
require(MASS)
strt - list(mu=1,sigma=2,gamma=3)
fit  - fitdistr(x,densfun=function(x,mu,sigma,gamma)
{dlnorm(x-gamma,mu,sigma)
},
 start=strt,lower=c(0,0,-Inf),
 upper=c(Inf,Inf,min(x)))

and it ran just fine and gave sensible answers.  But when I took:

strt - list(mu=0.9,sigma=1.9,gamma=2.9)

(not very different from the previous starting values)

I got an error:


Error in stats::optim(x = c(45.178764955739, 3.87862565957867,

8.61957940802123,  :

   L-BFGS-B needs finite values of 'fn'



On 18/01/14 01:00, Vito Ricci wrote:

OK. It runs fine! Many thanks Frede.
Regards.
Vito



Se non ora, quando?
Se non qui, dove?
Se non tu, chi?



Il Venerdì 17 Gennaio 2014 12:38, Frede Aakmann Tøgersen

fr...@vestas.com ha scritto:




In package MASS there is the fitdistr function using maximum likelihood

estimation to infer on the parameters of distributions based on observed
data.



One of the arguments of fitdistr () allows you to specify the probability

density function.



You only know how the parametrization of your three parameters

lognormal distribution is defined since you really haven't told us much.



Please have a look at fitdistr() and tell us if fit your 

Re: [R] *** caught segfault *** :: a common problem in 3.0.2

2014-01-18 Thread Frede Aakmann Tøgersen
I think you are trying to access memory that you are not allowed to.

Or did you specify the type of all of your data to be of the right ones?

The segfault message at least say so.

  *** caught segfault ***
 address 0x2464943a08, cause 'memory not mapped'
 
 Traceback:
  1: .Call(gyroscope, ncol(Y), nrow(Y), t(Y), as.integer(as.numeric(l) - 
 1),
 as.character(lnames), as.integer(perms), as.numeric(coloring),
 as.integer(useDensity), as.integer(showProfile), as.integer(showPatch))
  2: gyro2(data)
 
Why don't you have as.integer for ncol(Y), nrow(Y)??

So are you having ncol(Y), nrow(Y) in the right order when you use t(Y)??

Why don't you have as.double for t(Y)??

Is this correct: as.integer(as.numeric(l) - 1)??

Should as.numeric be as.double?

Have you checked that all indexes for your arrays in the C/C++ code are defined 
correctly with the arguments of your  .Call()??


Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance  Modeling

Technology  Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Christopher T Gregg
 Sent: 17. januar 2014 19:48
 To: r-help@R-project.org
 Subject: [R] *** caught segfault *** :: a common problem in 3.0.2
 
 Hi,
 
 I have struggled recently with R crashing with the following error in various
 contexts.  It has occurred when running the R package RCytoscape, a package
 we generated internally and when running the base system.  I have seen
 that this is an issue with the Mavericks OS (http://citizen-
 statistician.org/2013/10/27/warning-mac-os-10-9-mavericks-and-r-dont-play-
 nicely/), but I don't run Mavericks.  I have tried reinstalling the latest R
 version without any improvements and I am seeking a solution for this
 frustating problem.  The error and sessionInfo() are below.
 
 Thank you very much for any suggestions to overcome this problem.
 
 best wishes,
 Chris
 
 Here is the error:
 
  *** caught segfault ***
 address 0x2464943a08, cause 'memory not mapped'
 
 Traceback:
  1: .Call(gyroscope, ncol(Y), nrow(Y), t(Y), as.integer(as.numeric(l) - 
 1),
 as.character(lnames), as.integer(perms), as.numeric(coloring),
 as.integer(useDensity), as.integer(showProfile), as.integer(showPatch))
  2: gyro2(data)
 
 Possible actions:
 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace
 
  sessionInfo()
 R version 3.0.2 (2013-09-25)
 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
 
 other attached packages:
 [1] gyroscope_0.9
 
 
 Christopher Gregg, PhD.
 New York Stem Cell Foundation-Robertson Investigator
 Assistant Professor, Neurobiology and Anatomy
 Adjunct Assistant Professor, Human Genetics
 323 Wintrobe Bldg 530
 University of Utah, School of Medicine
 20 North 1900 East
 Salt Lake City, Utah 84132-3401
 
 phone: (801) 581-8212
 fax: (801) 585-9736
 
 Gregg Lab Website:
 www.neuro.utah.edu/labs/gregg/index.htmlhttp://www.neuro.utah.edu/l
 abs/gregg/index.html
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] For loop on column names

2014-01-18 Thread Frede Aakmann Tøgersen
Hi

Try

for (cname in colnames(mydf))
 print((percent(length(is.null(mydf [, cname]) / lines))

Br. Frede


 Oprindelig meddelelse 
Fra: Jeff Johnson
Dato:18/01/2014 02.10 (GMT+01:00)
Til: R help
Emne: [R] For loop on column names

I'm trying to find a more efficient to calculate the percent a field is
populated and repeat it for each field (column).

First, I'm counting the number of lines:
lines - as.integer(countLines(extract) - 1)
dput(lines)
10L

extract - 'C:/Users/jeffjohn/Desktop/batchextract_100k_sample.csv'
mydf - read.csv(file = extract, header = TRUE)

Here's the list of columns in my file:
 dput(colnames(mydf))
c(PERSONPROFILE_POS, PARTY_ID, PERSON_FIRST_NAME, PERSON_LAST_NAME,
PERSON_MIDDLE_NAME, PARTY_NUMBER, ACCOUNT_NUMBER, ABILITEC_LINK,
ADDRESS1, ADDRESS2, ADDRESS3, ADDRESS4, CITY, COUNTY,
STATE, PROVINCE, POSTAL_CODE, COUNTRY, PRIMARY_PER_TYPE,
SELLTOADDR_LOS, LOCATION_ID, SELLTOADDR_SOS, PARTY_SITE_ID,
PRIMARYPHONE_CPOS, CONTACT_POINT_ID_PCP, CONTACT_POINT_PURPOSE_PCP,
PHONE_LINE_TYPE, PRIMARY_FLAG_PCP, PHONE_COUNTRY_CODE,
PHONE_AREA_CODE, PHONE_NUMBER, EMAIL_CPOS, CONTACT_POINT_ID_ECP,
CONTACT_POINT_PURPOSE_ECP, PRIMARY_FLAG_ECP, EMAIL_ADDRESS,
BB_PARTY_ID)

I want to count the percentage populated for each field. Rather than do:
percent(length(is.null(mydf$PERSONPROFILE_POS)) / lines)
percent(length(is.null(mydf$PARTY_ID)) / lines)
etc.
and repeat for each field manually, I want to use a for loop.

I am trying the following:
a - length(colnames(mydf)) # this is to get the total number of columns

for (i in 1:a)
 print((percent(length(is.null(a)) / lines))

which isn't correct. I'm new to programming, so I don't quite know how to
deal with this. Any suggestions? Thanks much.
--
Jeff

[[alternative HTML version deleted]]

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

[[alternative HTML version deleted]]

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


Re: [R] eliminating white space in lattice plot

2014-01-18 Thread Duncan Mackay
I forgot to mention for multiple plots

? print.trellis

Duncan

-Original Message-
From: Gerrit Draisma [mailto:gdrai...@xs4all.nl] 
Sent: Saturday, 18 January 2014 21:49
To: arun; Duncan Mackay
Subject: Re: [R] eliminating white space in lattice plot

Ha Arun and Duncan,
Thanks for your answers.
They helped to solve my problem.
I found that the width and height parameters can be specified directly in
the pdf() command, and more useful for me in the R-code chunk in a Sweave
source file, as =
pdf(wideplot.pdf,width=10,height=3)
xyplot(y~x,data=X,type=l,aspect=0.25)
dev.off()
=
or
=
fig=TRUE,echo=FALSE,height=10,width=7=
xyplot(y~x,data=X,type=l,aspect=0.25)
@
=
Have a good day. Mine is already.
Gerrit.


op 1/17/2014 5:37 PM arun schreef:
  Hi,
  May be this helps:
x11(width=10,height=3)
xyplot(y~x,data=X,type=l,aspect=0.25)
dev.copy2pdf(file=wideplot.pdf)
  dev.off()
  A.K.
 
 
 
 
  On Friday, January 17, 2014 11:26 AM, Gerrit Draisma gdrai...@xs4all.nl
wrote:
  Dear R-users,
  How do I get rid of the white space above and under   a plot made with
lattice xyplot?
 
  I searched the documentation but could not find how to   do it.
 
  Standard lattice plots are square,
  but sometimes I want a wide but low graph   and use aspect parameter
to obtain such a graph.
  But then the plot has a lot of white space above and below   the
graph.
  That makes it more difficult to include in a LaTeX document.
 
  Thanks,
  Gerrit Draisma
 
  =
  library(lattice)
  X-data.frame(x=1:100,y=runif(100))
  # pdf(wideplot.pdf)
  xyplot(y~x,data=X,type=l,aspect=0.25)
  # dev.off()
 
  __
  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] MULTINOMIAL LOGIT WITH ENDOGENEITY

2014-01-18 Thread Erasmo Papagni

My aim is to estimate a multinomial model with some endogenous variables.

I tried the control function approach but the results are rather bad.

I am thinking to ML estimation. Is there a package I can use to estimate 
this  model?


Thanks a lot

Erasmo Papagni

Department of economics
University of Naples II

__
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] Generate Variable Length Strings from Various Sources

2014-01-18 Thread Burhan ul haq
Hi Rainer,

Thanks for the tip.

Your suggestion works perfectly, however as per the R Mantra of avoiding
for loops,  I propose the following this alternate:

# number of strings to be created
n - 50

# random length of each string
v.length = sample( c( 2:4), n, rep = TRUE )

# letter sources
src.1 = LETTERS[ 1:10 ]
src.2 = LETTERS[ 11:20 ]
src.3 = z
src.4 = c( 1, 2 )

# turn into a list
src - list( src.1, src.2, src.3, src.4 )

my.g = function(len,src)
{
  my.s = src[[ sample( 1:4, 1 ) ]]
  tmp = sample(my.s,len,rep=TRUE)
  n1 = paste(tmp,collapse=)
  n1
} # end

sapply(v.length,my.g,src)


// Cheers.

[[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] For loop on column names

2014-01-18 Thread Bert Gunter
I doubt it.

1. The OP failed to specify how populatedness is defined. Is it
NULL, NA, ,  ,...?

2. What is percent() ? Is this the OP's function or one from a package
or pseudocode or ... ?

3.  lapply(df,function)
is generally preferable in R to:
for(name in colnames(df)) function(df[ ,name])

The former packages everything neatly in a list, while with the latter
you are stuck mucking about with canonical naming schemes and/or
assignments that may clutter up your workspace. The plyR package may
also be helpful her, especially for a novice.

Given the OP's admitted ignorance to both programming and R, it seems
to me that the obvious advice is to stop knocking around in the dark
this way and spend time with some R tutorials. A good R book, perhaps
tuned to his/her discipline, would probably also be a worthwhile
purchase.

Cheers,

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Sat, Jan 18, 2014 at 2:40 AM, Frede Aakmann Tøgersen
fr...@vestas.com wrote:
 Hi

 Try

 for (cname in colnames(mydf))
  print((percent(length(is.null(mydf [, cname]) / lines))

 Br. Frede


  Oprindelig meddelelse 
 Fra: Jeff Johnson
 Dato:18/01/2014 02.10 (GMT+01:00)
 Til: R help
 Emne: [R] For loop on column names

 I'm trying to find a more efficient to calculate the percent a field is
 populated and repeat it for each field (column).

 First, I'm counting the number of lines:
 lines - as.integer(countLines(extract) - 1)
 dput(lines)
 10L

 extract - 'C:/Users/jeffjohn/Desktop/batchextract_100k_sample.csv'
 mydf - read.csv(file = extract, header = TRUE)

 Here's the list of columns in my file:
 dput(colnames(mydf))
 c(PERSONPROFILE_POS, PARTY_ID, PERSON_FIRST_NAME, PERSON_LAST_NAME,
 PERSON_MIDDLE_NAME, PARTY_NUMBER, ACCOUNT_NUMBER, ABILITEC_LINK,
 ADDRESS1, ADDRESS2, ADDRESS3, ADDRESS4, CITY, COUNTY,
 STATE, PROVINCE, POSTAL_CODE, COUNTRY, PRIMARY_PER_TYPE,
 SELLTOADDR_LOS, LOCATION_ID, SELLTOADDR_SOS, PARTY_SITE_ID,
 PRIMARYPHONE_CPOS, CONTACT_POINT_ID_PCP, CONTACT_POINT_PURPOSE_PCP,
 PHONE_LINE_TYPE, PRIMARY_FLAG_PCP, PHONE_COUNTRY_CODE,
 PHONE_AREA_CODE, PHONE_NUMBER, EMAIL_CPOS, CONTACT_POINT_ID_ECP,
 CONTACT_POINT_PURPOSE_ECP, PRIMARY_FLAG_ECP, EMAIL_ADDRESS,
 BB_PARTY_ID)

 I want to count the percentage populated for each field. Rather than do:
 percent(length(is.null(mydf$PERSONPROFILE_POS)) / lines)
 percent(length(is.null(mydf$PARTY_ID)) / lines)
 etc.
 and repeat for each field manually, I want to use a for loop.

 I am trying the following:
 a - length(colnames(mydf)) # this is to get the total number of columns

 for (i in 1:a)
  print((percent(length(is.null(a)) / lines))

 which isn't correct. I'm new to programming, so I don't quite know how to
 deal with this. Any suggestions? Thanks much.
 --
 Jeff

 [[alternative HTML version deleted]]

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

 [[alternative HTML version deleted]]

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

__
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] Estimating parameters of 3 parameters lognormal distribution

2014-01-18 Thread Vito Ricci
Hi Rolf,

I fit 3 parameters lognormal in this way

myf-function(x,m,s,t)(1/((x-t)*s*(2*pi)^0.5))*exp(((-(log(x-t)-m)^2)/(2*s^2)))

then fitdistr(y, myf, list(m=1,s=1, t=2))

I choose initial parameters value seeing data, I noted that a goog estimate of 
t would be 2...Me too I've some errors, having NA in log function.

Best regards.
Vito


 
Se non ora, quando?
Se non qui, dove?
Se non tu, chi?



Il Venerdì 17 Gennaio 2014 22:46, Rolf Turner r.tur...@auckland.ac.nz ha 
scritto:
 

Can you please tell us (me!) how you chose starting values?

Out of curiosity I tried the following:

set.seed(42)
x - rlnorm(100,1,2) + 3
require(MASS)
strt - list(mu=1,sigma=2,gamma=3)
fit  - fitdistr(x,densfun=function(x,mu,sigma,gamma)
                                   {dlnorm(x-gamma,mu,sigma)
                           },
                start=strt,lower=c(0,0,-Inf),
                upper=c(Inf,Inf,min(x)))

and it ran just fine and gave sensible answers.  But when I took:

strt - list(mu=0.9,sigma=1.9,gamma=2.9)

(not very different from the previous starting values)

I got an error:

 Error in stats::optim(x = c(45.178764955739, 3.87862565957867, 
 8.61957940802123,  :
   L-BFGS-B needs finite values of 'fn'



On 18/01/14 01:00, Vito Ricci wrote:
 OK. It runs fine! Many thanks Frede.
 Regards.
 Vito



 Se non ora, quando?
 Se non qui, dove?
 Se non tu, chi?



 Il Venerdì 17 Gennaio 2014 12:38, Frede Aakmann Tøgersen fr...@vestas.com 
 ha scritto:


 In package MASS there is the fitdistr function using maximum likelihood 
 estimation to infer on the parameters of distributions based on observed 
 data.


 One of the arguments of fitdistr () allows you to specify the probability 
 density function.


 You only know how the parametrization of your three parameters lognormal 
 distribution is defined since you really haven't told us much.


 Please have a look at fitdistr() and tell us if fit your needs.




[[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] xts error: number of items to replace is not a multiple of replacement length

2014-01-18 Thread Joshua Ulrich
This is particularly complicated and a bit of an edge case, so I
wouldn't try too hard to understand what's going on, but I'll try to
explain anyway.

Your code creates two calls to the subset-replacement function
(xts:::`[-.xts`).  The first call replaces the value of Close in a
temporary copy of the first row of the object on the left-hand-side of
the assignment.  This works fine.  The second call tries to replace
the first *element* of the object on the left-hand-side of the
assignment with the modified temporary copy of the first row.  This is
the problem.

This throws a warning because x[1] - 1:4 is different from x[1,] -
1:4.  The former replaces the first element, the latter replaces the
first row.  If you want your original command to work, you need to use
the comma in your first subset call on the left-hand-side.

sample.xts[2007-01-02::2007-01-04,]$Close -
sample.xts[2007-01-02::2007-01-04]$Close+1

That said, I wouldn't encourage you to do this, because the code isn't
clear and it's likely you'll forget the comma and re-confuse yourself
at a later date.  Simply remember to subset by column first, then row,
if you insist on making two calls to the subset-replacement function.

I would encourage you to use Arun's solution.  It's cleaner and faster
because it's only one function call and it avoids the $ function
(which is marginally slower on xts objects).

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com


On Thu, Jan 16, 2014 at 7:53 PM, ce zadi...@excite.com wrote:
 Indeed it  works ! Thanks a lot. But why?


 -Original Message-
 From: arun [smartpink...@yahoo.com]
 Date: 01/16/2014 08:44 PM
 To: r-help@r-project.org r-help@r-project.org
 Subject: Re: [R] xts error: number of items to replace is not a multiple of   
   replacement length

 Hi,
 Try:
 sample.xts[2007-01-02::2007-01-04,Close] 
 -sample.xts[2007-01-02::2007-01-04,Close] +1


 sample.xts[2007-01-02::2007-01-04]
 #   Open High  LowClose
 #2007-01-02 50.03978 50.11778 49.95041 52.11778
 #2007-01-03 50.23050 50.42188 50.23050 52.39767
 #2007-01-04 50.42096 50.42096 50.26414 52.33236
 A.K.


 On Thursday, January 16, 2014 8:34 PM, ce zadi...@excite.com wrote:

 Dear all ,

 I am getting this error while trying to change columns of an xts object with 
 a date range as index.

 library(xts)
 Loading required package: zoo

 Attaching package: ‘zoo’

 The following object is masked from ‘package:base’:

 as.Date, as.Date.numeric

  data(sample_matrix)
  sample.xts - as.xts(sample_matrix, descr='my new xts object')
 head(sample.xts)
Open High  LowClose
 2007-01-02 50.03978 50.11778 49.95041 50.11778
 2007-01-03 50.23050 50.42188 50.23050 50.39767
 2007-01-04 50.42096 50.42096 50.26414 50.33236
 2007-01-05 50.37347 50.37347 50.22103 50.33459
 2007-01-06 50.24433 50.24433 50.11121 50.18112
 2007-01-07 50.13211 50.21561 49.99185 49.99185

 sample.xts$Close - sample.xts$Close+1

 head(sample.xts)
Open High  LowClose
 2007-01-02 50.03978 50.11778 49.95041 51.11778
 2007-01-03 50.23050 50.42188 50.23050 51.39767
 2007-01-04 50.42096 50.42096 50.26414 51.33236
 2007-01-05 50.37347 50.37347 50.22103 51.33459
 2007-01-06 50.24433 50.24433 50.11121 51.18112
 2007-01-07 50.13211 50.21561 49.99185 50.99185

 sample.xts[2007-01-02::2007-01-04]
Open High  LowClose
 2007-01-02 50.03978 50.11778 49.95041 51.11778
 2007-01-03 50.23050 50.42188 50.23050 51.39767
 2007-01-04 50.42096 50.42096 50.26414 51.33236

 sample.xts[2007-01-02::2007-01-04]$Close - 
 sample.xts[2007-01-02::2007-01-04]$Close+1
 Warning message:
 In NextMethod(.Generic) :
   number of items to replace is not a multiple of replacement length

 __
 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] shading and estimating area abetween two cdf curves

2014-01-18 Thread William Dunlap
 These examples do not apply to the objects generated by the ecdf function.

Look at the objects generated by the ecdf function and you will see
that they are functions, not vectors of numbers (the 'f' in ecdf stands
for 'function').  You need to apply the functions to vectors of numbers
to get what you want.

plot(ecdf(x)) works because there is a special plotting method for the
function objects made by ecdf() which essentially does plot(x, ecdf(x)(x)).
To go beyond that you have to evaluate the function yourself, as in
the second part of this example:
 
  data0 - log2(1:16)
  data1 - 10 / (1 + sqrt(1:15))
  ecdf0 - ecdf(data0)
  ecdf1 - ecdf(data1)
  plot(ecdf0, xlim=range(data0,data1), col=blue)
  plot(ecdf1, add=TRUE, col=orange)

  tmpx - seq(min(data0,data1), max(data0,data1), len=2001)
  p0 - ecdf0(tmpx)
  p1 - ecdf1(tmpx)
  segments(x0=tmpx, y0=p0, y1=p1, col=adjustcolor(ifelse(p0p1, red, 
black), alpha.f=0.1))

(There are better ways to fill the area between two lines, but using segments 
to make
lots of vertical lines makes for a simple example.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Peter Maclean
 Sent: Friday, January 17, 2014 11:37 PM
 To: r-help@r-project.org
 Subject: [R] shading and estimating area abetween two cdf curves
 
 I would like to shade the area between two curves generated by the ecdf 
 function.
 There are examples such as those explained here
 http://www.alisonsinclair.ca/2011/03/shading-between-curves-in-r/
 These examples do not apply to the objects generated by the ecdf function.
 #
 library(truncnorm)
 x  - rtruncnorm(100, 3,  25,  15,  5)
 y  - rtruncnorm(100, 5,  30,  17,  8)
 x - ecdf(x)
 y - ecdf(y)
 plot(x)
 lines(y)
 #This is not working
 polygon(x, y, xpd = xpd, col = orange, lty = 2, lwd = 2, border = red)
 #How to shade the area between the curve
 #calculate the area between the two curves
 
 
 Peter Maclean
 Department of Economics
 UDSM
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
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] Estimating parameters of 3 parameters lognormal distribution

2014-01-18 Thread peter dalgaard
Offhand, I'd say that the issue isn't so much the starting values as the risk 
of hitting the upper bound on gamma. If you get gamma set to min(x) at any 
point during the iteration, the density at the corresponding point is zero, the 
log-likelihood is -Inf, and poof, the magic smoke escapes. 

Perhaps try min(x)-1e-7 or so?

-pd

On 17 Jan 2014, at 22:46 , Rolf Turner r.tur...@auckland.ac.nz wrote:

 
 Can you please tell us (me!) how you chose starting values?
 
 Out of curiosity I tried the following:
 
 set.seed(42)
 x - rlnorm(100,1,2) + 3
 require(MASS)
 strt - list(mu=1,sigma=2,gamma=3)
 fit  - fitdistr(x,densfun=function(x,mu,sigma,gamma)
  {dlnorm(x-gamma,mu,sigma)
  },
   start=strt,lower=c(0,0,-Inf),
   upper=c(Inf,Inf,min(x)))
 
 and it ran just fine and gave sensible answers.  But when I took:
 
 strt - list(mu=0.9,sigma=1.9,gamma=2.9)
 
 (not very different from the previous starting values)
 
 I got an error:
 
 Error in stats::optim(x = c(45.178764955739, 3.87862565957867, 
 8.61957940802123,  :
  L-BFGS-B needs finite values of 'fn'
 
 
 On 18/01/14 01:00, Vito Ricci wrote:
 OK. It runs fine! Many thanks Frede.
 Regards.
 Vito
 
 
 
 Se non ora, quando?
 Se non qui, dove?
 Se non tu, chi?
 
 
 
 Il Venerdì 17 Gennaio 2014 12:38, Frede Aakmann Tøgersen fr...@vestas.com 
 ha scritto:
 
 
 In package MASS there is the fitdistr function using maximum likelihood 
 estimation to infer on the parameters of distributions based on observed 
 data.
 
 
 One of the arguments of fitdistr () allows you to specify the probability 
 density function.
 
 
 You only know how the parametrization of your three parameters lognormal 
 distribution is defined since you really haven't told us much.
 
 
 Please have a look at fitdistr() and tell us if fit your needs.
 
 __
 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.

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

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


Re: [R] Generate Variable Length Strings from Various Sources

2014-01-18 Thread Jeff Newmiller
People who subscribe to an avoid-for-loops mantra are often missing the 
point. Converting for loops to indexing can often yield speed improvements. 
Converting for loops to apply functions does not improve speed. (If you think 
it does, you are probably handling memory allocation differently.) Worse, in 
some cases it can reduce readability, so doing it because of a mantra can 
actually harm your code.

Also, posting in HTML is hardly the R-help way (see the Posting Guide).
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Burhan ul haq ulh...@gmail.com wrote:
Hi Rainer,

Thanks for the tip.

Your suggestion works perfectly, however as per the R Mantra of
avoiding
for loops,  I propose the following this alternate:

# number of strings to be created
n - 50

# random length of each string
v.length = sample( c( 2:4), n, rep = TRUE )

# letter sources
src.1 = LETTERS[ 1:10 ]
src.2 = LETTERS[ 11:20 ]
src.3 = z
src.4 = c( 1, 2 )

# turn into a list
src - list( src.1, src.2, src.3, src.4 )

my.g = function(len,src)
{
  my.s = src[[ sample( 1:4, 1 ) ]]
  tmp = sample(my.s,len,rep=TRUE)
  n1 = paste(tmp,collapse=)
  n1
} # end

sapply(v.length,my.g,src)


// Cheers.

   [[alternative HTML version deleted]]

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

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


[R] accessing an object with a variable ?

2014-01-18 Thread ce

I want access and object , its name is in an variable :

require(xts)
data(sample_matrix)

head(sample_matrix)
   Open High  LowClose
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185
 assign(a,sample_matrix)
 head(a)

   Open High  LowClose
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185


But following doesn't work:

b=sample_matrix
assign(a,b)

 a
[1] sample_matrix

how I can access sample_matrix data when I have only b variable ?

__
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] Estimating parameters of 3 parameters lognormal distribution

2014-01-18 Thread Rolf Turner

On 19/01/14 06:20, peter dalgaard wrote:

Offhand, I'd say that the issue isn't so much the starting values as the risk of 
hitting the upper bound on gamma. If you get gamma set to min(x) at any point during 
the iteration, the density at the corresponding point is zero, the log-likelihood is 
-Inf, and poof, the magic smoke escapes.

Perhaps try min(x)-1e-7 or so?


Yep, that did it.  Thanks Peter.

(Actually I used min(x) - eps where I set eps equal to 
sqrt(.Machine$double.eps) --- which seems to be a kind of standard 
construction for a small-but-not-too-small number.)


cheers,

Rolf

__
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] accessing an object with a variable ?

2014-01-18 Thread ce
Yes, it works perfect, thanks a lot. 


-Original Message-
From: Marius 't Hart [mar...@ai178182.ai.rug.nl]
Date: 01/18/2014 04:58 PM
To: ce zadi...@excite.com
CC:  r-help@r-project.org
Subject: Re: [R] accessing an object with a variable ?


Does this help you?

http://stackoverflow.com/questions/3971844/access-variable-value-where-the-name-of-variable-is-stored-in-a-string-in-r


On Sat, 18 Jan 2014, ce wrote:


 I want access and object , its name is in an variable :

 require(xts)
 data(sample_matrix)

 head(sample_matrix)
   Open High  LowClose
 2007-01-02 50.03978 50.11778 49.95041 50.11778
 2007-01-03 50.23050 50.42188 50.23050 50.39767
 2007-01-04 50.42096 50.42096 50.26414 50.33236
 2007-01-05 50.37347 50.37347 50.22103 50.33459
 2007-01-06 50.24433 50.24433 50.11121 50.18112
 2007-01-07 50.13211 50.21561 49.99185 49.99185
 assign(a,sample_matrix)
 head(a)

   Open High  LowClose
 2007-01-02 50.03978 50.11778 49.95041 50.11778
 2007-01-03 50.23050 50.42188 50.23050 50.39767
 2007-01-04 50.42096 50.42096 50.26414 50.33236
 2007-01-05 50.37347 50.37347 50.22103 50.33459
 2007-01-06 50.24433 50.24433 50.11121 50.18112
 2007-01-07 50.13211 50.21561 49.99185 49.99185


 But following doesn't work:

 b=sample_matrix
 assign(a,b)

 a
 [1] sample_matrix

 how I can access sample_matrix data when I have only b variable ?

 __
 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] accessing an object with a variable ?

2014-01-18 Thread arun
May be this helps:
 assign(a,eval(parse(text=b)))
A.K.




On Saturday, January 18, 2014 4:24 PM, ce zadi...@excite.com wrote:

I want access and object , its name is in an variable :

require(xts)
data(sample_matrix)

head(sample_matrix)
               Open     High      Low    Close
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185
 assign(a,sample_matrix)
 head(a)

               Open     High      Low    Close
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185


But following doesn't work:

b=sample_matrix
assign(a,b)

 a
[1] sample_matrix

how I can access sample_matrix data when I have only b variable ?

__
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] remove axes on barp from plotrix

2014-01-18 Thread Chrisee
Hello guys, 

I'm using the barp function from the plotrix package, which works really
really great. 
Unfortunately, I need a finer spacing of the labels on the y - axis. 
Is there any way to control this? 
Looking at the documentation of barp, it seems to be done rather
automatically.

An option would be to not plot axes at all from barp, and add them later
by using axes(), which I was not able to get to work.. 

I tried axes=FALSE, and yaxt=n, and par settings: yaxp = c(a,b,n), all of
which did not work.

Any ideas?!

Best regards
Chrisee



--
View this message in context: 
http://r.789695.n4.nabble.com/remove-axes-on-barp-from-plotrix-tp4683808.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] *** caught segfault *** :: a common problem in 3.0.2

2014-01-18 Thread Christopher T Gregg
Thank you, Frede.  I will look into these suggestions.  I did not specify the 
data type carefully…I will assess this and see if it cleans up the problem.

best wishes,
Chris

On Jan 18, 2014, at 2:23 AM, Frede Aakmann Tøgersen fr...@vestas.com
 wrote:

 I think you are trying to access memory that you are not allowed to.
 
 Or did you specify the type of all of your data to be of the right ones?
 
 The segfault message at least say so.
 
 *** caught segfault ***
 address 0x2464943a08, cause 'memory not mapped'
 
 Traceback:
 1: .Call(gyroscope, ncol(Y), nrow(Y), t(Y), as.integer(as.numeric(l) - 
 1),
 as.character(lnames), as.integer(perms), as.numeric(coloring),
 as.integer(useDensity), as.integer(showProfile), as.integer(showPatch))
 2: gyro2(data)
 
 Why don't you have as.integer for ncol(Y), nrow(Y)??
 
 So are you having ncol(Y), nrow(Y) in the right order when you use t(Y)??
 
 Why don't you have as.double for t(Y)??
 
 Is this correct: as.integer(as.numeric(l) - 1)??
 
 Should as.numeric be as.double?
 
 Have you checked that all indexes for your arrays in the C/C++ code are 
 defined correctly with the arguments of your  .Call()??
 
 
 Yours sincerely / Med venlig hilsen
 
 
 Frede Aakmann Tøgersen
 Specialist, M.Sc., Ph.D.
 Plant Performance  Modeling
 
 Technology  Service Solutions
 T +45 9730 5135
 M +45 2547 6050
 fr...@vestas.com
 http://www.vestas.com
 
 Company reg. name: Vestas Wind Systems A/S
 This e-mail is subject to our e-mail disclaimer statement.
 Please refer to www.vestas.com/legal/notice
 If you have received this e-mail in error please contact the sender. 
 
 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Christopher T Gregg
 Sent: 17. januar 2014 19:48
 To: r-help@R-project.org
 Subject: [R] *** caught segfault *** :: a common problem in 3.0.2
 
 Hi,
 
 I have struggled recently with R crashing with the following error in various
 contexts.  It has occurred when running the R package RCytoscape, a package
 we generated internally and when running the base system.  I have seen
 that this is an issue with the Mavericks OS (http://citizen-
 statistician.org/2013/10/27/warning-mac-os-10-9-mavericks-and-r-dont-play-
 nicely/), but I don't run Mavericks.  I have tried reinstalling the latest R
 version without any improvements and I am seeking a solution for this
 frustating problem.  The error and sessionInfo() are below.
 
 Thank you very much for any suggestions to overcome this problem.
 
 best wishes,
 Chris
 
 Here is the error:
 
 *** caught segfault ***
 address 0x2464943a08, cause 'memory not mapped'
 
 Traceback:
 1: .Call(gyroscope, ncol(Y), nrow(Y), t(Y), as.integer(as.numeric(l) - 
 1),
 as.character(lnames), as.integer(perms), as.numeric(coloring),
 as.integer(useDensity), as.integer(showProfile), as.integer(showPatch))
 2: gyro2(data)
 
 Possible actions:
 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace
 
 sessionInfo()
 R version 3.0.2 (2013-09-25)
 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
 
 other attached packages:
 [1] gyroscope_0.9
 
 
 Christopher Gregg, PhD.
 New York Stem Cell Foundation-Robertson Investigator
 Assistant Professor, Neurobiology and Anatomy
 Adjunct Assistant Professor, Human Genetics
 323 Wintrobe Bldg 530
 University of Utah, School of Medicine
 20 North 1900 East
 Salt Lake City, Utah 84132-3401
 
 phone: (801) 581-8212
 fax: (801) 585-9736
 
 Gregg Lab Website:
 www.neuro.utah.edu/labs/gregg/index.htmlhttp://www.neuro.utah.edu/l
 abs/gregg/index.html
 
 
  [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] Fwd: Implementing a Formula into a Column of a Data Frame

2014-01-18 Thread Norman McBride
-- Forwarded message --
From: Norman McBride npmcbride0...@gmail.com
Date: Fri, Jan 17, 2014 at 9:54 AM
Subject: Implementing a Formula into a Column of a Data Frame
To: r-help@r-project.org


Now, if I were to move the data over from an excel doc would that change
anything. I do understand that that I would have to change it to a csv
document and create a variable for it. Just to give you a more visual
understanding of what I am doing I a portion of the head of the data is
shown below.  So the formula would specifically be:  Battery Heat (Watts) /
( Surface Area (Square Meters) * ( Battery Temperature (Celsius) - Air
Temperature (Celsius) ) and that would be the value put into the Cooling
Coefficient Column currently set at one. One final note, when using
function() should I input variable such as a,b, c and then change then
change them when using the do.call function or should I just do it with the
column names the first time? Thank you for the help I really appreciate it.

structure(list(`Time (Seconds)` = c(20.318162, 21.316219, 22.316277,
23.316334, 24.316391, 25.316448, 26.316505, 27.315562, 28.315619,
29.315677, 30.315734, 31.315791, 32.315848, 33.315906, 34.315963,
35.31602, 36.316077, 37.316134, 38.316192, 39.316249), `Battery Temperature
(Celsius)` = c(12.290895,
12.331806, 12.373601, 12.424348, 12.467361, 12.522784, 12.581674,
12.642473, 12.713441, 12.760907, 12.832591, 12.90363, 12.953117,
13.037519, 13.103664, 13.193626, 13.267647, 13.340661, 13.439084,
13.512353), `Air Temperature (Celsius)` = c(12.109872, 12.130341,
12.127966, 12.126647, 12.138111, 12.13635, 12.133192, 12.137278,
12.144941, 12.140494, 12.145511, 12.143312, 12.136964, 12.15125,
12.1607, 12.162753, 12.152606, 12.148803, 12.16181, 12.151917
), `Battery Heat (Watts)` = c(1.634698, 1.634698, 1.634882, 1.634703,
1.634614, 1.634435, 1.634435, 1.634252, 1.634252, 1.634163, 1.633435,
1.633801, 1.633444, 1.63344, 1.804659, 2.013801, 2.013905, 2.013905,
2.0139, 2.013107), `Surface Area (Square Meters)` = c(0.00637115,
0.00637115, 0.00637115, 0.00637115, 0.00637115, 0.00637115, 0.00637115,
0.00637115, 0.00637115, 0.00637115, 0.00637115, 0.00637115, 0.00637115,
0.00637115, 0.00637115, 0.00637115, 0.00637115, 0.00637115, 0.00637115,
0.00637115), `Cooling Coefficient` = c(1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = c(Time (Seconds),
Battery Temperature (Celsius), Air Temperature (Celsius),
Battery Heat (Watts), Surface Area (Square Meters), Cooling
Coefficient
), row.names = c(NA, 20L), class = data.frame)

[[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] 2 phase coxian phase distribution

2014-01-18 Thread nelsonsibbs78
Can you pliz  send me the R code for estimating parameters of a 2 phase 
distribution given some data to fit. Im nelson sibanda , a final year student 
at Nust
[[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] accessing an object with a variable ?

2014-01-18 Thread Marius 't Hart


Does this help you?

http://stackoverflow.com/questions/3971844/access-variable-value-where-the-name-of-variable-is-stored-in-a-string-in-r


On Sat, 18 Jan 2014, ce wrote:



I want access and object , its name is in an variable :

require(xts)
data(sample_matrix)

head(sample_matrix)
  Open High  LowClose
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185

assign(a,sample_matrix)
head(a)


  Open High  LowClose
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185


But following doesn't work:

b=sample_matrix
assign(a,b)


a

[1] sample_matrix

how I can access sample_matrix data when I have only b variable ?

__
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] lm(y ~ group/x ) + predict.lm(...,type=terms)

2014-01-18 Thread Xing Zhao
Hi, all

I am trying to figure out the computation result for
predict.lm(...,type=terms)  when the original fitting model has a
nesting term, lm(y ~ group/x ).

A example,

 set.seed(731)
 group - factor(rep(1:2, 200))
 x - rnorm(400)

 fun1 - function(x) -3*x+8
 fun2 - function(x) 15*x-18

 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400)

 mod1 - lm(y ~ group/(x-1) ) # without intercetp
 mod2 - lm(y ~ group/x ) # with intercetp


 #data to predict
 new - data.frame(x=rep(0:2,each=2),
+   group=factor(rep(1:2,3)))
 new
  x group
1 0 1
2 0 2
3 1 1
4 1 2
5 2 1
6 2 2
 coef(mod1) # checking coefficients, both make sense to me.
group1 group2   group1:x   group2:x
  7.864981 -18.098424  -2.963931  15.051449
 coef(mod2)
(Intercept)  group2group1:xgroup2:x
   7.864981  -25.963405   -2.963931   15.051449

 predict(mod1, new,type = c(response)) # two response type predictions are 
 the same, make sense to me.
 1  2  3  4  5  6
  7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474
 predict(mod2, new,type = c(response))
 1  2  3  4  5  6
  7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474

 predict(mod1, new,type = c(terms)) # make sense to me
   group   group:x
1   7.864981  0.00
2 -18.098424  0.00
3   7.864981 -2.963931
4 -18.098424 15.051449
5   7.864981 -5.927861
6 -18.098424 30.102898
attr(,constant)
[1] 0

# I want to know the computation process for group:x below??? this is
what I am interested in
 predict(mod2, new,type = c(terms))
 groupgroup:x
1  12.9817  0.5209069
2 -12.9817  0.5209069
3  12.9817 -2.4430237
4 -12.9817 15.5723560
5  12.9817 -5.4069544
6 -12.9817 30.6238052
attr(,constant)
[1] -5.637629


Thanks in advance
Xing

__
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] lm(y ~ group/x ) + predict.lm(...,type=terms)

2014-01-18 Thread Xing Zhao
Hi, all

I am trying to figure out the computation result for
predict.lm(...,type=terms)  when the original fitting model has a
nesting term, lm(y ~ group/x ).

A example,

 set.seed(731)
 group - factor(rep(1:2, 200))
 x - rnorm(400)

 fun1 - function(x) -3*x+8
 fun2 - function(x) 15*x-18

 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400)

 mod1 - lm(y ~ group/(x-1) ) # without intercetp
 mod2 - lm(y ~ group/x ) # with intercetp


 #data to predict
 new - data.frame(x=rep(0:2,each=2),
+   group=factor(rep(1:2,3)))
 new
  x group
1 0 1
2 0 2
3 1 1
4 1 2
5 2 1
6 2 2
 coef(mod1) # checking coefficients, both make sense to me.
group1 group2   group1:x   group2:x
  7.864981 -18.098424  -2.963931  15.051449
 coef(mod2)
(Intercept)  group2group1:xgroup2:x
   7.864981  -25.963405   -2.963931   15.051449

 predict(mod1, new,type = c(response)) # two response type predictions
are the same, make sense to me.
 1  2  3  4  5  6
  7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474
 predict(mod2, new,type = c(response))
 1  2  3  4  5  6
  7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474

 predict(mod1, new,type = c(terms)) # make sense to me
   group   group:x
1   7.864981  0.00
2 -18.098424  0.00
3   7.864981 -2.963931
4 -18.098424 15.051449
5   7.864981 -5.927861
6 -18.098424 30.102898
attr(,constant)
[1] 0

# I want to know the computation process for group:x below??? this is
what I am interested in
 predict(mod2, new,type = c(terms))
 groupgroup:x
1  12.9817  0.5209069
2 -12.9817  0.5209069
3  12.9817 -2.4430237
4 -12.9817 15.5723560
5  12.9817 -5.4069544
6 -12.9817 30.6238052
attr(,constant)
[1] -5.637629


Thanks in advance
Xing

[[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] accessing an object with a variable ?

2014-01-18 Thread Marius 't Hart

Does this help you?

http://stackoverflow.com/questions/3971844/access-variable-value-where-the-name-of-variable-is-stored-in-a-string-in-r

On 14-01-18 04:21 PM, ce wrote:

I want access and object , its name is in an variable :

require(xts)
data(sample_matrix)

head(sample_matrix)
Open High  LowClose
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185

assign(a,sample_matrix)
head(a)

Open High  LowClose
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185


But following doesn't work:

b=sample_matrix
assign(a,b)


a

[1] sample_matrix

how I can access sample_matrix data when I have only b variable ?

__
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] lm(y ~ group/x ) + predict.lm(...,type=terms)

2014-01-18 Thread Xing Zhao
Hi, all

I am trying to figure out the computation result for
predict.lm(...,type=terms)  when the original fitting model has a
nesting term, lm(y ~ group/x ).

A example,

 set.seed(731)
 group - factor(rep(1:2, 200))
 x - rnorm(400)

 fun1 - function(x) -3*x+8
 fun2 - function(x) 15*x-18

 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400)

 mod1 - lm(y ~ group/(x-1) ) # without intercetp
 mod2 - lm(y ~ group/x ) # with intercetp


 #data to predict
 new - data.frame(x=rep(0:2,each=2),
+   group=factor(rep(1:2,3)))
 new
  x group
1 0 1
2 0 2
3 1 1
4 1 2
5 2 1
6 2 2
 coef(mod1) # checking coefficients, both make sense to me.
group1 group2   group1:x   group2:x
  7.864981 -18.098424  -2.963931  15.051449
 coef(mod2)
(Intercept)  group2group1:xgroup2:x
   7.864981  -25.963405   -2.963931   15.051449

 predict(mod1, new,type = c(response)) # two response type predictions
are the same, make sense to me.
 1  2  3  4  5  6
  7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474
 predict(mod2, new,type = c(response))
 1  2  3  4  5  6
  7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474

 predict(mod1, new,type = c(terms)) # make sense to me
   group   group:x
1   7.864981  0.00
2 -18.098424  0.00
3   7.864981 -2.963931
4 -18.098424 15.051449
5   7.864981 -5.927861
6 -18.098424 30.102898
attr(,constant)
[1] 0

# I want to know the computation process for group:x below??? this is
what I am interested in
 predict(mod2, new,type = c(terms))
 groupgroup:x
1  12.9817  0.5209069
2 -12.9817  0.5209069
3  12.9817 -2.4430237
4 -12.9817 15.5723560
5  12.9817 -5.4069544
6 -12.9817 30.6238052
attr(,constant)
[1] -5.637629


Thanks in advance
Xing

[[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] lm(y ~ group/x ) + predict.lm(...,type=terms)

2014-01-18 Thread Prof Brian Ripley
Please see the posting guide: posting 3 times only reduces your chance 
of an informative answer (as does posting in HTML).  Your posting is too 
vague for others to know what it is you do not understand.


R is Open Source: please read the sources for the definitive answer to 
the 'know the computation process' query.


If (as I suspect) your difficulty is rather with interpreting terms in 
formulae, study chapter 6 of MASS (Venables  Ripley, 2002).



On 18/01/2014 22:03, Xing Zhao wrote:

Hi, all

I am trying to figure out the computation result for
predict.lm(...,type=terms)  when the original fitting model has a
nesting term, lm(y ~ group/x ).


'nested' 



A example,


set.seed(731)
group - factor(rep(1:2, 200))
x - rnorm(400)

fun1 - function(x) -3*x+8
fun2 - function(x) 15*x-18

y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400)

mod1 - lm(y ~ group/(x-1) ) # without intercetp
mod2 - lm(y ~ group/x ) # with intercetp


#data to predict
new - data.frame(x=rep(0:2,each=2),

+   group=factor(rep(1:2,3)))

new

   x group
1 0 1
2 0 2
3 1 1
4 1 2
5 2 1
6 2 2

coef(mod1) # checking coefficients, both make sense to me.

 group1 group2   group1:x   group2:x
   7.864981 -18.098424  -2.963931  15.051449

coef(mod2)

(Intercept)  group2group1:xgroup2:x
7.864981  -25.963405   -2.963931   15.051449


predict(mod1, new,type = c(response)) # two response type predictions

are the same, make sense to me.
  1  2  3  4  5  6
   7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474

predict(mod2, new,type = c(response))

  1  2  3  4  5  6
   7.864981 -18.098424   4.901050  -3.046975   1.937120  12.004474


predict(mod1, new,type = c(terms)) # make sense to me

group   group:x
1   7.864981  0.00
2 -18.098424  0.00
3   7.864981 -2.963931
4 -18.098424 15.051449
5   7.864981 -5.927861
6 -18.098424 30.102898
attr(,constant)
[1] 0

# I want to know the computation process for group:x below??? this is
what I am interested in

predict(mod2, new,type = c(terms))

  groupgroup:x
1  12.9817  0.5209069
2 -12.9817  0.5209069
3  12.9817 -2.4430237
4 -12.9817 15.5723560
5  12.9817 -5.4069544
6 -12.9817 30.6238052
attr(,constant)
[1] -5.637629


Thanks in advance
Xing

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




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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