Re: [R] problem in saving the history file '~/.Rhistory'

2019-06-26 Thread William Dunlap via R-help
Did you (or a startup script) set the environment variable R_HISTORY to be
'~/somefile'?  R does not expand the tilde in this case so you need to let
the shell do it.  Perhaps ~ doesn't expand for the root user.  (IMO, it is
crazy to run R, or almost any other program, as root.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Jun 26, 2019 at 7:11 AM lejeczek via R-help 
wrote:

> hi guys,
>
> I'm on Centos 7.6 with R 3.6 and I see this:
>
> >
> Save workspace image? [y/n/c]: y
> Warning message:
> problem in saving the history file '~/.Rhistory'
>
> from strace:
>
> rt_sigaction(SIGWINCH, {SIG_DFL, [], SA_RESTORER, 0x7fb9dd34b5d0},
> {0x7fb9dc383820, [], SA_RESTORER|SA_RESTART, 0x7fb9dd34b5d0}, 8) = 0
> rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(1, TCXONC, TCOON) = 0
> open("~/.Rhistory", O_WRONLY|O_CREAT|O_TRUNC, 0600) = -1 ENOENT (No such
> file or directory)
> brk(NULL)   = 0x43da000
> brk(0x43fe000)  = 0x43fe000
> rt_sigaction(SIGINT, {SIG_IGN, [], SA_RESTORER, 0x7fb9dcfa2280},
> {0x7fb9dfd99ffb, [INT], SA_RESTORER|SA_RESTART, 0x7fb9dd34b5d0}, 8) = 0
> rt_sigaction(SIGQUIT, {SIG_IGN, [], SA_RESTORER, 0x7fb9dcfa2280},
> {SIG_DFL, [], SA_RESTORER, 0x7fb9dd34b5d0}, 8) = 0
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD,
> parent_tidptr=0x7ffd7d87e100) = 1367359
> wait4(1367359, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 1367359
> rt_sigaction(SIGINT, {0x7fb9dfd99ffb, [INT], SA_RESTORER|SA_RESTART,
> 0x7fb9dcfa2280}, NULL, 8) = 0
> rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER, 0x7fb9dcfa2280}, NULL,
> 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1367359,
> si_uid=0, si_status=0, si_utime=0, si_stime=1} ---
> write(2, "Warning message:\n", 17)  = 17
> write(2, "problem in saving the history fi"..., 50) = 50
> exit_group(0)   = ?
> +++ exited with 0 +++
>
>
> This only with user "root", and the some root can touch the ~/.Rhistory
> just fine.
>
> Even this works:
>
> > system(command="touch ~/.Rhistory")
>
> Would have any suggestions, ideas on how to fix it?
>
> many thanks, L.
>
> __
> 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] problem in saving the history file '~/.Rhistory'

2019-06-26 Thread lejeczek via R-help
hi guys,

I'm on Centos 7.6 with R 3.6 and I see this:

> 
Save workspace image? [y/n/c]: y
Warning message:
problem in saving the history file '~/.Rhistory' 

from strace:

rt_sigaction(SIGWINCH, {SIG_DFL, [], SA_RESTORER, 0x7fb9dd34b5d0},
{0x7fb9dc383820, [], SA_RESTORER|SA_RESTART, 0x7fb9dd34b5d0}, 8) = 0
rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
ioctl(1, TCXONC, TCOON) = 0
open("~/.Rhistory", O_WRONLY|O_CREAT|O_TRUNC, 0600) = -1 ENOENT (No such
file or directory)
brk(NULL)   = 0x43da000
brk(0x43fe000)  = 0x43fe000
rt_sigaction(SIGINT, {SIG_IGN, [], SA_RESTORER, 0x7fb9dcfa2280},
{0x7fb9dfd99ffb, [INT], SA_RESTORER|SA_RESTART, 0x7fb9dd34b5d0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN, [], SA_RESTORER, 0x7fb9dcfa2280},
{SIG_DFL, [], SA_RESTORER, 0x7fb9dd34b5d0}, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD,
parent_tidptr=0x7ffd7d87e100) = 1367359
wait4(1367359, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 1367359
rt_sigaction(SIGINT, {0x7fb9dfd99ffb, [INT], SA_RESTORER|SA_RESTART,
0x7fb9dcfa2280}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER, 0x7fb9dcfa2280}, NULL,
8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1367359,
si_uid=0, si_status=0, si_utime=0, si_stime=1} ---
write(2, "Warning message:\n", 17)  = 17
write(2, "problem in saving the history fi"..., 50) = 50
exit_group(0)   = ?
+++ exited with 0 +++


This only with user "root", and the some root can touch the ~/.Rhistory
just fine.

Even this works:

> system(command="touch ~/.Rhistory")

Would have any suggestions, ideas on how to fix it?

many thanks, L.

__
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 maximum likelihood estimation

2019-06-26 Thread peter dalgaard
Bricks fly fine with sufficient thrust, but you have lff with a mu argument 
that never gets used, so the negative log-likelihood is constant and mle() 
cannot minimize it.

You need to read up on the definition of (log-) likelihood and write a proper 
one for your problem.

-pd

> On 26 Jun 2019, at 14:01 , avadhoot velankar  
> wrote:
> 
> I am analyzing animal movement pattern using levy flight pattern and want
> to fit power function to observed data and estimate exponent using Maximum
> Likelihood Estimation.
> 
> I am using
> 
> lff<-function(mu){1-1/mean(log(x))}
> library(stats4)
> mle(lff, start = list(mu = 1))
> 
> where x is the observed data.
> 
> I am getting following error
> 
> Error in solve.default(oout$hessian) :
>  Lapack routine dgesv: system is exactly singular: U[1,1] = 0
> 
> This is first time i am writing function and I am as good at algebra
> as brick is good at flying.
> 
> Thank you in advance for your help.
> 
> -- 
> *Avadhoot D. Velankar*
> 
>   [[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

__
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] IRT discrimination value (ltm and psych package)

2019-06-26 Thread shreepad khandve
Hello Sir,

I am learning R and its syntax and  I have successfully converted
irt.item.diff.rasch into python code and pass the inputs as per the
function made in R.



In R  :-

function (items)

{

  ncases <- nrow(items)

  item.mean <- colMeans(items, na.rm = TRUE)

  item.mean[item.mean < (1/ncases)] <- 1/ncases

  irt.item.diff.rasch <- log((1/item.mean) - 1)

}



In Python :-

def diff(items):

item_mean= items.mean()

item_diff = []

for i in item_mean:

diff = np.log((1/i)-1)

item_diff.append(diff)

return item_diff





I am getting the exact same result as R output.

But I’m still unable to understand the “item.discrim” and how to and
what to pass as a input to the function,



function (item.diff, theta, items)

{

  irt.item.discrim <- function(x, diff, theta, scores) {

fit <- -1 * (log(scores/(1 + exp(x * (diff - theta))) +

  (1 - scores)/(1 + exp(x * (theta - diff)

mean(fit, na.rm = TRUE)

  }

  nitems <- length(item.diff)

  discrim <- matrix(NaN, nitems, 2)

  for (i in 1:nitems) {

item.fit <- optimize(irt.item.discrim, c(-5, 5), diff = item.diff[i],

  theta = theta, scores = items[, i])

discrim[i, 1] <- item.fit$minimum

discrim[i, 2] <- item.fit$objective

  }

  irt.discrim <- discrim



Could you please guide how do I convert the same in python, because
there are no proper explanation in documentation what to pass as
following arguments or the formulas to find the values of x and theta.

X= ?

Diff = I got the diff values

Theta = ?

Scores = = items[, i] as per mentioned in code



Unable to find theta and x, please help with this parameters ?


Thanks,
Shreepad

__
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 select max data according to week?

2019-06-26 Thread SITI AISYAH BINTI ZAKARIA
Dear All, 

Thank you very much for helping me.. i will try my best by using all 
suggestion..

thank you again.. hopefully is work.

- Original Message -
From: "Eric Berger" 
To: "Marc Schwartz" 
Cc: "Bert Gunter" , "R-help" , 
"SITI AISYAH BINTI ZAKARIA" 
Sent: Thursday, June 20, 2019 3:21:14 PM
Subject: Re: [R] How to select max data according to week?

Marc - very nice.

On Wed, Jun 19, 2019 at 6:30 PM Marc Schwartz  wrote:

> Hi All,
>
> Is there a reason that the following was not considered?
>
> > DF
>  Date O3_Conc
> 1  2000-01-01   0.033
> 2  2000-01-02   0.023
> 3  2000-01-03   0.025
> 4  2000-01-04   0.041
> 5  2000-01-05   0.063
> 6  2000-01-06   0.028
> 7  2000-01-07   0.068
> 8  2000-01-08   0.048
> 9  2000-01-09   0.037
> 10 2000-01-10   0.042
> 11 2000-01-11   0.027
> 12 2000-01-12   0.035
> 13 2000-01-13   0.063
> 14 2000-01-14   0.035
> 15 2000-01-15   0.042
> 16 2000-01-16   0.028
>
> > str(DF)
> 'data.frame':   16 obs. of  2 variables:
>  $ Date   : Date, format: "2000-01-01" ...
>  $ O3_Conc: num  0.033 0.023 0.025 0.041 0.063 0.028 0.068 0.048 0.037
> 0.042 ...
>
>
> > aggregate(O3_Conc ~ cut(Date, breaks = "14 days"), data = DF, max)
>   cut(Date, breaks = "14 days") O3_Conc
> 12000-01-01   0.068
> 22000-01-15   0.042
>
>
> See ?cut.Date
>
> Note that there is an error in Aisyah's original post, in that the value
> for the max concentration in the second 14 day window is 0.042, not 0.061.
>
> Also, if one wanted to use actual calendar weeks, with a week starting on
> Sunday, as opposed to 14 day windows starting from the minimum date, you
> could use:
>
> > aggregate(O3_Conc ~ cut(Date, breaks = "2 weeks", start.on.monday =
> FALSE), data = DF, max)
>   cut(Date, breaks = "2 weeks", start.on.monday = FALSE) O3_Conc
> 1 1999-12-26   0.068
> 2 2000-01-09   0.063
>
>
> If desired, you could pre-create a column in the DF with the result of
> cut():
>
> DF$TimeStartDays <- cut(DF$Date, breaks = "14 days")
> DF$TimeStartWks <- cut(DF$Date, breaks = "2 weeks", start.on.monday =
> FALSE)
>
> > DF
>  Date O3_Conc TimeStartDays TimeStartWks
> 1  2000-01-01   0.0332000-01-01   1999-12-26
> 2  2000-01-02   0.0232000-01-01   1999-12-26
> 3  2000-01-03   0.0252000-01-01   1999-12-26
> 4  2000-01-04   0.0412000-01-01   1999-12-26
> 5  2000-01-05   0.0632000-01-01   1999-12-26
> 6  2000-01-06   0.0282000-01-01   1999-12-26
> 7  2000-01-07   0.0682000-01-01   1999-12-26
> 8  2000-01-08   0.0482000-01-01   1999-12-26
> 9  2000-01-09   0.0372000-01-01   2000-01-09
> 10 2000-01-10   0.0422000-01-01   2000-01-09
> 11 2000-01-11   0.0272000-01-01   2000-01-09
> 12 2000-01-12   0.0352000-01-01   2000-01-09
> 13 2000-01-13   0.0632000-01-01   2000-01-09
> 14 2000-01-14   0.0352000-01-01   2000-01-09
> 15 2000-01-15   0.0422000-01-15   2000-01-09
> 16 2000-01-16   0.0282000-01-15   2000-01-09
>
> and then use:
>
> > aggregate(O3_Conc ~ TimeStartDays, data = DF, max)
>   TimeStartDays O3_Conc
> 12000-01-01   0.068
> 22000-01-15   0.042
>
> > aggregate(O3_Conc ~ TimeStartWks, data = DF, max)
>   TimeStartWks O3_Conc
> 1   1999-12-26   0.068
> 2   2000-01-09   0.063
>
>
> Regards,
>
> Marc Schwartz
>
>
>
> > On Jun 19, 2019, at 10:45 AM, Eric Berger  wrote:
> >
> > I just realized that my method as written only works if the entire date
> > range is within a single calendar year.
> > Here is a revised version that should handle the general case.
> >
> > In this version I assume that the conversion from the original numbers to
> > dates has already been done
> > e.g. it can be done using ymd() as I showed before
> >
> > library(dplyr)
> > library(lubridate)
> >
> > ## create some example data for 36 months from 2010
> > d <- seq(from=as.Date("2010-01-01"),to=as.Date("2012-12-31"),by="1 day")
> > conc <- runif(length(d)) # concentrations
> > df <- data.frame( dt=d, conc=conc)
> > df2 <- dplyr::mutate( df, wkpair=as.integer(floor((0:(nrow(df)-1))/14)) )
> > df3 <- dplyr::group_by(df2,wkpair) %>%
> >   dplyr::summarise(from=min(dt), to=max(dt), maxconc=max(conc)) %>%
> >   dplyr::select(from,to,maxconc)
> > df3
> >
> > # A tibble: 79 x 3
> >   from   to maxconc
> >   
> > 1 2010-01-01 2010-01-14   0.928
> > 2 2010-01-15 2010-01-28   0.834
> > 3 2010-01-29 2010-02-11   0.989
> > 4 2010-02-12 2010-02-25   0.983
> > 5 2010-02-26 2010-03-11   0.898
> > 6 2010-03-12 2010-03-25   0.864
> > 7 2010-03-26 2010-04-08   0.920
> > 8 2010-04-09 2010-04-22   0.925
> > 9 2010-04-23 2010-05-06   0.998
> > 10 2010-05-07 2010-05-20   0.761
> > # ... with 69 more rows
> >
> > On Wed, Jun 19, 2019 at 5:08 PM Eric Berger 
> wrote:
> >
> >> Hi Bert,
> >> I agree that our interpretation is slightly different, which is why I
> >> wrote:
> >> "If one can take the actual week of the year 

[R] Help with maximum likelihood estimation

2019-06-26 Thread avadhoot velankar
I am analyzing animal movement pattern using levy flight pattern and want
to fit power function to observed data and estimate exponent using Maximum
Likelihood Estimation.

I am using

lff<-function(mu){1-1/mean(log(x))}
library(stats4)
mle(lff, start = list(mu = 1))

where x is the observed data.

I am getting following error

Error in solve.default(oout$hessian) :
  Lapack routine dgesv: system is exactly singular: U[1,1] = 0

This is first time i am writing function and I am as good at algebra
as brick is good at flying.

Thank you in advance for your help.

-- 
*Avadhoot D. Velankar*

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