[R] Get the output of a function in R GUI

2015-10-22 Thread Jesús Para Fernández
Hi,

I want to create my own RGUI, so I�m using tcltk for that. 

In a very simple example, I want to get the response of a function into a 
tktext, so I have done this:
data<-c(2,3,5,2)
tt<-tktoplevel
text<-tktext(tt)
tkpack(text)
sum(data)

How can I get the output of sum(data) in my tktext??

Thanks!
Jes�s 
  
[[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] expression evaluation during recursion

2015-10-22 Thread david . kaethner

> You seem to have ignored my explanation.

True, sorry. Thanks for sticking with me. Making sense now.


> 
> Duncan Murdoch
> 
>> 
>> 
>>> Am 22.10.2015 um 19:05 schrieb Duncan Murdoch >> >:
>>> 
>>> On 22/10/2015 10:20 AM,david.kaeth...@gmail.com 
>>> wrote:
 Hello,
 
 I’m trying to solve an exercise, where I want to walk through the search 
 path recursively 
 (http://adv-r.had.co.nz/Environments.html).
 
 I’m puzzled by a certain behavior and hope somebody can give me an 
 explanation.
 
 This code works:
 
 listenv <- function(env = parent.frame()) {
 if (identical(env, emptyenv())) {
   #stop("reached emptyenv", call. = FALSE)
   return(env)
 } else {
   print(env)
   listenv(parent.env(env))
 }
 }
 
 Here, the calling environment is determined with a default parameter in 
 the function’s formals.
 
 However, if I want to assign the calling environment within the function’s 
 body, I get the error message „infinite recursion“. Also, I never get 
 actual environments (with attributes, that is), only memory addresses like 
 this: .
>>> 
>>> I'm not sure what you were looking for, but ""
>>> is the normal way to print an environment, unless it happens to be one
>>> of the special named ones (like .GlobalEnv).
>>> 
 
 listenv <- function(env) {
 env <- parent.frame()
 if (identical(env, emptyenv())) {
   #stop("reached emptyenv", call. = FALSE)
   return(env)
 } else {
   print(env)
   listenv(parent.env(env))
 }
 }
 
 Any explanation of what’s going on here would be greatly appreciated. I 
 suspect it has to do with when exactly the parent.frame()-expression is 
 evaluated, but that’s not an actual explanation.
>>> 
>>> 
>>> Your function completely ignores the "env" argument.  It never recurses.
>>> In the first case, "parent.frame()" is only a default value, so
>>> recursion happens properly.  If you change the first line in the body to
>>> these two lines
>>> 
>>> if (missing(env))
>>>   env <- parent.frame()
>>> 
>>> it would be equivalent.
>>> 
>>> Duncan Murdoch
>> 
> 

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

[R] quantile regression: error terms

2015-10-22 Thread T.Riedle
Greetings R Community,

I am running quantile regressions using quantreg in R. I also plot the 
residuals in a QQplot which indicate fat tails. I would like to try using 
Student distribution, but I do not know if the R software allows it for my task 
in hand.

In my opinion it is very likely that there is a structural break and if that is 
not taken into consideration by the rq() function leading to QQ plots which 
display nonlinearity. Hence, the model is slightly misspecified.
I was also wondering if I can cope with the nonlinearity by using a sandwich 
estimate in the summary.rq() function such as "ker".

How can I modify the model to improve the model specification and the standard 
errors specifications? Can I modify the regression model or do I have to change 
the method used to compute the error terms in summary.rq()?

Thanks for your feedback.

[[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] expression evaluation during recursion

2015-10-22 Thread Duncan Murdoch

On 22/10/2015 2:44 PM, david.kaeth...@gmail.com wrote:

Hi,

I’m sure there’s a ton I don’t understand about environments, but I’m 
afraid your answer doesn’t make sense to me.


If it’s on the search path, the „print(env)“ should yield something like:


You never get to the search list.



attr(,"name")
[1] "package:pryr"
attr(,"path")
[1] "/Library/Frameworks/R.framework/Versions/3.2/Resources/library/pryr“

I agree that there would only be an address if it was an unnamed 
environment such as the ones constructed during function execution. 
But I’m walking the search path here, so these should all contain 
information on packages.


My question wasn’t so much about how to retrieve information on 
environments, there are plenty functions concerning that. I just don’t 
understand why it makes that much of a difference if I put the 
parent.frame() in the arguments list, or in the function body.


You seem to have ignored my explanation.

Duncan Murdoch




Am 22.10.2015 um 19:05 schrieb Duncan Murdoch 
>:


On 22/10/2015 10:20 AM,david.kaeth...@gmail.com 
wrote:

Hello,

I’m trying to solve an exercise, where I want to walk through the 
search path recursively 
(http://adv-r.had.co.nz/Environments.html).


I’m puzzled by a certain behavior and hope somebody can give me an 
explanation.


This code works:

listenv <- function(env = parent.frame()) {
 if (identical(env, emptyenv())) {
   #stop("reached emptyenv", call. = FALSE)
   return(env)
 } else {
   print(env)
   listenv(parent.env(env))
 }
}

Here, the calling environment is determined with a default parameter 
in the function’s formals.


However, if I want to assign the calling environment within the 
function’s body, I get the error message „infinite recursion“. Also, 
I never get actual environments (with attributes, that is), only 
memory addresses like this: .


I'm not sure what you were looking for, but ""
is the normal way to print an environment, unless it happens to be one
of the special named ones (like .GlobalEnv).



listenv <- function(env) {
 env <- parent.frame()
 if (identical(env, emptyenv())) {
   #stop("reached emptyenv", call. = FALSE)
   return(env)
 } else {
   print(env)
   listenv(parent.env(env))
 }
}

Any explanation of what’s going on here would be greatly 
appreciated. I suspect it has to do with when exactly the 
parent.frame()-expression is evaluated, but that’s not an actual 
explanation.



Your function completely ignores the "env" argument.  It never recurses.
In the first case, "parent.frame()" is only a default value, so
recursion happens properly.  If you change the first line in the body to
these two lines

 if (missing(env))
   env <- parent.frame()

it would be equivalent.

Duncan Murdoch




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

Re: [R] expression evaluation during recursion

2015-10-22 Thread david . kaethner
Hi,

I’m sure there’s a ton I don’t understand about environments, but I’m afraid 
your answer doesn’t make sense to me. 

If it’s on the search path, the „print(env)“ should yield something like:


attr(,"name")
[1] "package:pryr"
attr(,"path")
[1] "/Library/Frameworks/R.framework/Versions/3.2/Resources/library/pryr“

I agree that there would only be an address if it was an unnamed environment 
such as the ones constructed during function execution. But I’m walking the 
search path here, so these should all contain information on packages. 

My question wasn’t so much about how to retrieve information on environments, 
there are plenty functions concerning that. I just don’t understand why it 
makes that much of a difference if I put the parent.frame() in the arguments 
list, or in the function body.


> Am 22.10.2015 um 19:05 schrieb Duncan Murdoch :
> 
> On 22/10/2015 10:20 AM, david.kaeth...@gmail.com 
>  wrote:
>> Hello,
>> 
>> I’m trying to solve an exercise, where I want to walk through the search 
>> path recursively (http://adv-r.had.co.nz/Environments.html 
>>  
>> > >). 
>> 
>> I’m puzzled by a certain behavior and hope somebody can give me an 
>> explanation.
>> 
>> This code works:
>> 
>> listenv <- function(env = parent.frame()) {
>>  if (identical(env, emptyenv())) {
>>#stop("reached emptyenv", call. = FALSE)
>>return(env)
>>  } else {
>>print(env)
>>listenv(parent.env(env))
>>  }
>> }
>> 
>> Here, the calling environment is determined with a default parameter in the 
>> function’s formals. 
>> 
>> However, if I want to assign the calling environment within the function’s 
>> body, I get the error message „infinite recursion“. Also, I never get actual 
>> environments (with attributes, that is), only memory addresses like this: 
>> .
> 
> I'm not sure what you were looking for, but ""
> is the normal way to print an environment, unless it happens to be one
> of the special named ones (like .GlobalEnv).
> 
>> 
>> listenv <- function(env) {
>>  env <- parent.frame()
>>  if (identical(env, emptyenv())) {
>>#stop("reached emptyenv", call. = FALSE)
>>return(env)
>>  } else {
>>print(env)
>>listenv(parent.env(env))
>>  }
>> }
>> 
>> Any explanation of what’s going on here would be greatly appreciated. I 
>> suspect it has to do with when exactly the parent.frame()-expression is 
>> evaluated, but that’s not an actual explanation.
> 
> 
> Your function completely ignores the "env" argument.  It never recurses.
> In the first case, "parent.frame()" is only a default value, so
> recursion happens properly.  If you change the first line in the body to
> these two lines
> 
>  if (missing(env))
>env <- parent.frame()
> 
> it would be equivalent.
> 
> Duncan Murdoch


[[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] Error in Opening Project on R Studio

2015-10-22 Thread Duncan Murdoch
On 22/10/2015 10:18 AM, sdee...@iitk.ac.in wrote:
> Good Evening everyone,
>  I am Deepak Singh, Student I.I.T. Kanpur, INDIA, was
> working on a project on R Studio and now when I am
> trying to open my project it is showing the attached
> error. Can it be fixed? if 'Yes' then how can I do
> fix it ? Please help.

You've written to the wrong place.  You need to write to one of the
RStudio support forums at support.rstudio.com.

Duncan Murdoch

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


Re: [R] Get the output of a function in R GUI

2015-10-22 Thread Jesús Para Fernández
Thanks, but just one more question

How can I catch the response and put it on a tktext?

Imagien there is a function that the response is an error, how can i catch this 
error and manage it?

Thanks!

> From: pda...@gmail.com
> Subject: Re: [R] Get the output of a function in R GUI
> Date: Thu, 22 Oct 2015 11:17:34 +0200
> CC: r-help@r-project.org
> To: j.para.fernan...@hotmail.com
> 
> 
> On 22 Oct 2015, at 10:49 , Jesús Para Fernández 
>  wrote:
> 
> > Hi,
> > 
> > I want to create my own RGUI, so I�m using tcltk for that. 
> > 
> > In a very simple example, I want to get the response of a function into a 
> > tktext, so I have done this:
> > data<-c(2,3,5,2)
> > tt<-tktoplevel
> > text<-tktext(tt)
> > tkpack(text)
> > sum(data)
> > 
> > How can I get the output of sum(data) in my tktext??
> 
> 
> For instance with
> 
> tkinsert(text, "end", sum(data))
> 
> However, you need to reach out for a Tcl/Tk reference manual to sort out the 
> mysteries of the index argument and of the widget subcommands in general.
> 
> -pd
> 
> > 
> > Thanks!
> > Jes�s 
> >   
> > [[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
> 
> 
> 
> 
> 
> 
> 
> 
> 
  
[[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] Anina magija (r help)

2015-10-22 Thread Ana
"Anina magija" je čaj za mršavljenje.



Napravljen je od bilja koje svakodnevno koristimo u ishrani i lečenju, po
recepturi koju su generacije travarki prenosile sa kolena na koleno i koju
je svaka naredna generacija obogatila novim dodatkom i boljim efektom. 



http://djura.simpleuploader.com/int/link.php?M=2797433=432=37=T



Za razliku od mnogih proizvoda, čajeva, tableta, praškova i napitaka,
"Anina magija" zaista radi svoj posao. Topi masne naslage bez obzira na to
šta i koliko jedete.



Uputstvo za upotrebu je veoma jednostavno - pije se 1 šolja ujutru posle
doručka i 1 uveče posle večere. Jedete šta god poželite! Nema dijete!
i mršavite lako...



Više informacija možete naći na našoj stranici.





To stop receiving these
emails:http://djura.simpleuploader.com/int/unsubscribe.php?M=2797433=e30553db539f628f5010553023e12258=48=432

[[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] Linear regression with a rounded response variable

2015-10-22 Thread Jim Lemon
Hi Ravi,
And remember that the vanilla rounding procedure is biased upward. That is,
an observation of 5 actually may have ranged from 4.5 to 5.4.

Jim

On Thu, Oct 22, 2015 at 7:15 AM, peter salzman 
wrote:

> here is one thought:
>
> if you plug in your numbers into any kind of regression you will get
> prediction that are real numbers and not necessarily integers, it may be
> that you predictions are good enough with this approximate value of Y. you
> could test this by randomly shuffling your data by +- 0.5 and compare the
> results with the original result.
>
> let me add another idea:
>
> if data is not fully observed this falls under the umbrella of censored
> data, in this case you have interval censoring. if you see 5 then the
> observations is in interval [4.5, 5.5]
> i'm not familiar with the field but i'd search for 'regression with
> interval censoring'
>
>
> peter
>
>
> On Wed, Oct 21, 2015 at 10:53 AM, Ravi Varadhan 
> wrote:
>
> > Hi,
> > I am dealing with a regression problem where the response variable, time
> > (second) to walk 15 ft, is rounded to the nearest integer.  I do not care
> > for the regression coefficients per se, but my main interest is in
> getting
> > the prediction equation for walking speed, given the predictors (age,
> > height, sex, etc.), where the predictions will be real numbers, and not
> > integers.  The hope is that these predictions should provide unbiased
> > estimates of the "unrounded" walking speed. These sounds like a
> measurement
> > error problem, where the measurement error is due to rounding and hence
> > would be uniformly distributed (-0.5, 0.5).
> >
> > Are there any canonical approaches for handling this type of a problem?
> > What is wrong with just doing the standard linear regression?
> >
> > I googled and saw that this question was asked by someone else in a
> > stackexchange post, but it was unanswered.  Any suggestions?
> >
> > Thank you,
> > Ravi
> >
> > Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg)
> > Associate Professor,  Department of Oncology
> > Division of Biostatistics & Bionformatics
> > Sidney Kimmel Comprehensive Cancer Center
> > Johns Hopkins University
> > 550 N. Broadway, Suite -E
> > Baltimore, MD 21205
> > 410-502-2619
> >
> >
> > [[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 Salzman, PhD
> Department of Biostatistics and Computational Biology
> University of Rochester
>
> [[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.


[R] Need help in completing this R assignment

2015-10-22 Thread mehdiabdulla2



Sent from my T-Mobile 4G LTE Device
__
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 regression with a rounded response variable

2015-10-22 Thread Ravi Varadhan
Dear Peter, Charles, Gabor, Jim, Mark, Victor, Peter, and Harold,
You have given me plenty of ammunition.  Thank you very much for the useful 
answers. 
Gratefully,
Ravi

From: peter dalgaard 
Sent: Wednesday, October 21, 2015 8:11 PM
To: Charles C. Berry
Cc: Ravi Varadhan; r-help@r-project.org
Subject: Re: [R] Linear regression with a rounded response variable

> On 21 Oct 2015, at 19:57 , Charles C. Berry  wrote:
>
> On Wed, 21 Oct 2015, Ravi Varadhan wrote:
>
>> [snippage]
>
> If half the subjects have a value of 5 seconds and the rest are split between 
> 4 and 6, your assertion that rounding induces an error of 
> dunif(epsilon,-0.5,0.5) is surely wrong (more positive errors in the 6 second 
> group and more negative errors in the 4 second group under any plausible 
> model).

Yes, and I think that the suggestion in another post to look at censored 
regression is more in the right direction.

In general, I'd expect the bias caused by rounding the response to quite small, 
except at very high granularity. I did a few small experiments with the 
simplest possible linear model: estimating a mean based on highly rounded data,

> y <- round(rnorm(1e2,pi,.5))
> mean(y)
[1] 3.12
> table(y)
y
 2  3  4  5
13 63 23  1

Or, using a bigger sample:

> mean(round(rnorm(1e8,pi,.5)))
[1] 3.139843

in which there is a visible bias, but quite a small one:

> pi - 3.139843
[1] 0.001749654

At lower granularity (sd=1 instead of .5), the bias has almost disappeared.

> mean(round(rnorm(1e8,pi,1)))
[1] 3.141577

If the granularity is increased sufficiently, you _will_ see a sizeable bias 
(because almost all observations will be round(pi)==3):

> mean(round(rnorm(1e8,pi,.1)))
[1] 3.00017


A full ML fit (with known sigma=1) is pretty easily done:

> library(stats4)
> mll <- function(mu)-sum(log(pnorm(y+.5,mu, .5)-pnorm(y-.5, mu, .5)))
> mle(mll,start=list(mu=3))

Call:
mle(minuslogl = mll, start = list(mu = 3))

Coefficients:
  mu
3.122069
> mean(y)
[1] 3.12

As you see, the difference is only 0.002.

A small simulation (1000 repl.) gave (r[1,]==MLE ; r{2,]==mean)

> summary(r[1,]-r[2,])
 Min.   1st Qu.Median  Mean   3rd Qu.  Max.
-0.004155  0.000702  0.001495  0.001671  0.002554  0.006860

so the corrections relative to the crude mean stay within one unit in the 2nd 
place. Notice  that the corrections are pretty darn close to cancelling out the 
bias.

-pd

>
>
> HTH,
>
> Chuck
>
> __
> 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
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] SARIMA in rpy2

2015-10-22 Thread pietro chen
Hello,

Am trying to estimate a seasonal Arima by calling the R forecast package in
Rpy2:

fit = forecast.Arima(x = h02, order = order, seasonal = seasonal)

Strangely I get the estimates of the non-seasonal part, only, even if the
model is specified as (3,0,1)x(0,1,2). Can anyone tell me where the issue
is?

Regards,

P.

[[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] (no subject)

2015-10-22 Thread Xibiao YE
Hi, I am new to R and am trying to run some spatial analysis using
SpatialEpi package. Here is part of my code:

geo<-latlong2grid(cbind(MBPolygon@data$X,MBPolygon@data$Y))
population<-tapply(mydata$population,mydata$PHRAS4,sum)
cases<-tapply(mydata$case, mydata$PHRAS4,sum)
expected.cases<-mydata$expected

and then I run:
output<-bayes_cluster(expected.cases, cases, population, geo, MBPolygon,
max.prop, k, shape, rate, J, pi0, n.sim.imp, n.sim.prior, n.sim.post)
which is a function for MCMC.

I got this message:

"  Error message as.vector(data): no method for coercing this S4 class to a
vector"

I ran the author's code and got the same message. I'm guessing there maybe
some issue with my R environment. Many people online mentioned namespace,
but no idea how to fix it.  Please help.

xibiao

[[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] GARCH convergence error in for-loop

2015-10-22 Thread Hannah L. Linder
Hello,

I am using the rugarch package to fit to simulated data. I am fitting the
same garch model to 1000 simulated data sets (all very similar with
slightly different error). Within each data set I am using 10-fold CV, so I
am fitting the model to 10 training sets. When I run the code (shown below)
I occasionally receive the error:

Solver Message: Error in is.nloptr(ret) : at least one element in x0 < lb

When I re-run the exact same code starting from the iteration that caused
and error, the error goes away. Does anyone know if this may be an error
with R or if I am missing a problem in the model?

Thank-you very much for your time! I could not generate reproducible code
for this question, but am happy to supply a sample of my data if someone is
interested in helping.

Hannah Linder
M.S.c School of Aquatic and Fishery Sciences, UW

Code:


library(rugarch)

fit.spec1=array(list(),c(1000,10))
fit1=array(list(),c(1000,10))


for (j in 1:1000){
  for (i in 1:10){
fit.spec1[[j,i]]=ugarchspec(variance.model = list(model = "sGARCH",
   garchOrder = c(1,
1),external.regressors=as.matrix(train.all[[j]][[i]][,c(5,6)])),
mean.model= list(armaOrder = c(1,1),
 include.mean = T,

 external.regressors=as.matrix(train.all[[j]][[i]][,c(2,4,5,6)])),
distribution.model = "sstd")
fit1[[j,i]] <- ugarchfit(data=train.all[[j]][[i]][,c(1)],spec =
fit.spec1[[j,i]],solver="hybrid")
 }}

I am actually using the model on biological data, rather than finance. The
regressors in the model are  Julian day count (2), tidal range (4), and a
sin and cos (5,6) transform for time-of-day (24-hr period).

[[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] Get the output of a function in R GUI

2015-10-22 Thread Jesús Para Fernández
Thanks, but it does�nt do what I want.

What I wnat is to insert it into a tktext. 

Jes�s

Date: Thu, 22 Oct 2015 10:06:20 +0100
Subject: Re: [R] Get the output of a function in R GUI
From: kmezh...@gmail.com
To: j.para.fernan...@hotmail.com
CC: r-help@r-project.org

Hi, 

require(tcltk)
data<-c(2,3,5,2)
PressedOK <- function()
{
  tkmessageBox(message=sum(data))
}

tt <- tktoplevel()
OK.but <- tkbutton(tt,text="OK",command=PressedOK)
tkgrid(OK.but)
tkfocus(tt)

Please take a look in examples: 
http://mcu.edu.tw/~chenmh/teaching/project/r/reference/RTclTkExamples/
Karim

On Thu, Oct 22, 2015 at 9:49 AM, Jes�s Para Fern�ndez 
 wrote:
Hi,



I want to create my own RGUI, so I�m using tcltk for that.



In a very simple example, I want to get the response of a function into a 
tktext, so I have done this:

data<-c(2,3,5,2)

tt<-tktoplevel

text<-tktext(tt)

tkpack(text)

sum(data)



How can I get the output of sum(data) in my tktext??



Thanks!

Jes�s



[[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] Get the output of a function in R GUI

2015-10-22 Thread peter dalgaard

On 22 Oct 2015, at 10:49 , Jesús Para Fernández  
wrote:

> Hi,
> 
> I want to create my own RGUI, so I�m using tcltk for that. 
> 
> In a very simple example, I want to get the response of a function into a 
> tktext, so I have done this:
> data<-c(2,3,5,2)
> tt<-tktoplevel
> text<-tktext(tt)
> tkpack(text)
> sum(data)
> 
> How can I get the output of sum(data) in my tktext??


For instance with

tkinsert(text, "end", sum(data))

However, you need to reach out for a Tcl/Tk reference manual to sort out the 
mysteries of the index argument and of the widget subcommands in general.

-pd

> 
> Thanks!
> Jes�s 
> 
>   [[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.

Re: [R] Get the output of a function in R GUI

2015-10-22 Thread Karim Mezhoud
Hi,

require(tcltk)
data<-c(2,3,5,2)
PressedOK <- function()
{
  tkmessageBox(message=sum(data))
}

tt <- tktoplevel()
OK.but <- tkbutton(tt,text="OK",command=PressedOK)
tkgrid(OK.but)
tkfocus(tt)

Please take a look in examples:
http://mcu.edu.tw/~chenmh/teaching/project/r/reference/RTclTkExamples/
Karim

On Thu, Oct 22, 2015 at 9:49 AM, Jesús Para Fernández <
j.para.fernan...@hotmail.com> wrote:

> Hi,
>
> I want to create my own RGUI, so I´m using tcltk for that.
>
> In a very simple example, I want to get the response of a function into a
> tktext, so I have done this:
> data<-c(2,3,5,2)
> tt<-tktoplevel
> text<-tktext(tt)
> tkpack(text)
> sum(data)
>
> How can I get the output of sum(data) in my tktext??
>
> Thanks!
> Jesús
>
> [[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] Control of x-axis variable ordering in ggplot

2015-10-22 Thread Jeff Newmiller
The ggplot function has no display behaviour. You have to couple it with a geom 
function to define how the data will be displayed. Read ?geom_line and 
?geom_poly.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  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.

On October 23, 2015 3:46:02 AM GMT+02:00, sbihorel 
 wrote:
>Hi,
>
>Given a certain data.frame, the lattice xyplot function will plot the 
>data as.is and join the data point in the order of the data frame. It
>is 
>my (probably flawed) understanding that, using the same data frame, 
>ggplot orders the data by increasing order of the x-axis variable. Can 
>one control this behavior?
>
>Thanks
>
>Sebastien
>
>Code example
>
>library(lattice)
>library(ggplot2)
>
>
>data <- data.frame(x=rep(1:4,each=25),
>y=rep(1:25,times=4),
>g=rep(1:4,each=25))
>data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1
>
>col <- 3:7
>
>xyplot(y~x,data=data,groups=g,type='l',col=col)
>
>ggplot(data, aes(x,y,group=g)) + geom_point(colour=col[data$g]) +
>   geom_line(colour=col[data$g])
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


[R] Control of x-axis variable ordering in ggplot

2015-10-22 Thread sbihorel

Hi,

Given a certain data.frame, the lattice xyplot function will plot the 
data as.is and join the data point in the order of the data frame. It is 
my (probably flawed) understanding that, using the same data frame, 
ggplot orders the data by increasing order of the x-axis variable. Can 
one control this behavior?


Thanks

Sebastien

Code example

library(lattice)
library(ggplot2)


data <- data.frame(x=rep(1:4,each=25),
   y=rep(1:25,times=4),
   g=rep(1:4,each=25))
data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1

col <- 3:7

xyplot(y~x,data=data,groups=g,type='l',col=col)

ggplot(data, aes(x,y,group=g)) + geom_point(colour=col[data$g]) +
  geom_line(colour=col[data$g])

__
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] Announcement - The Use Of Nabble For Posting To R-Help Will

2015-10-22 Thread Jesús Para Fernández
Nice

  
[[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] Linear regression with a rounded response variable

2015-10-22 Thread Doran, Harold

> Yes, and I think that the suggestion in another post to look at censored 
> regression is more in the right direction.

I think this is right and perhaps the best (or at least better) pathway to 
pursue than considering this within the framework of measurement error (ME). Of 
course there *is* ME in the observed walking time since the observed value is 
only one draw from the distribution of potential times that could have been 
observed for each individual.

But, the typical econometric correction for ME requires that we have an 
observed value and then an estimate of its variance. Theoretically, I would 
imagine this variance to be heteroscedastic and to vary by individual.  In 
Ravi's regression with the observed value on the LHS, there is no bias in the 
regression coefficients because the ME is not correlated with the error term, 
but the standard errors of the coefficients would be too large. If such this 
conditional variance did exist, you could treat the reciprocal of the variance 
as a weight in WLS, such that values with less ME have greater weight in the 
estimation and there would also exists a closed form way to correct the 
standard errors.

This however, is not the problem as I understand it from Ravi. Instead, he 
observes x which lies within a known interval, x_l < x < x_u where x_l and x_u 
denote upper and lower limits for the observed values.

At first this threw me for a loop because censoring in my work is typically 
done at the extremes with left/right censored data. But, there is also a 
package in R for interval censoring (called interval), though I have not used 
it before. Some googling on this topic drew me to some good worked examples 
that I think fit within the framework Ravi is working within.

So, perhaps Ravi's question really has two issues, one of which might be 
solvable: there is ME in the outcome value, y. But, perhaps that is ignorable. 
The censoring is perhaps not ignorable, and even better yet solvable?

__
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] Bollinger Band quantmod

2015-10-22 Thread Joshua Ulrich
On Mon, Oct 19, 2015 at 4:04 PM, bgnumis bgnum  wrote:
> Hi all,
>
> When I plot Bollinger bands  with
>
> chartSeries(
> IBEX,theme="white",
>   TA = c(addBBands(50,2))
>
> )
>
> There is a "no" shadow area that it is used to obtain the levels. How can I
> plot with charSeries so that the plot start on the shadow area? I mean,
> ¿How can I say to de axis start plotting f.i. 50 steps forward on the chart
> Series?
>
This is very unclear. What's a "shadow area"?  What levels are you referring to?

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



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.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] Update dataframe based on some conditions

2015-10-22 Thread david . kaethner
Hi,

what I find a little confusing about your example: If there are several 
positions with a REF of, say, 999, why do you not just add them up to a single 
position? Because if you have the same position in several rows, than REF is 
not a unique identifier for that position. You would need the row number as 
well. Without a unique ID per position, I don’t think you can solve your 
problem.

Further: If I fill up a position from a previous row, won’t I just do the same 
thing again for the next row, thereby carrying items just down the list? 

Also, it would help if you used as for the example more useful variable names 
(such as ‚product_ID‘ or ‚number_in_stock‘). And it would help if you try to 
make your example as simple as possible, meaning that you use the smallest 
amount of data possible without changing the problem.


> Am 21.10.2015 um 22:07 schrieb Jorge I Velez :
> 
> Dear R-help,
> 
> I am working on what it seems to be a simple problem, but after several
> hours trying to come up with a solution, unfortunately I have not been able
> to.
> 
> I would like to go from "datain" to "dataout", that is, create the NEWREF
> variable according with some restrictions, and update the values for the
> remaining variables in the original data set (which is way more bigger than
> this example). The problem can be described as having products (coded as
> REF) in stock. Here, the total nomber of units in stock are named TOENDREF
> and those required for the customer are given by TIMEREF. The idea is to
> use as many units of the previous REF as possible before using a new REF.
> 
> ## input
> datain <- structure(list(REF = c("999", "999", "999", "1099", "731", "731",
> "731", "731", "1442", "1442", "1442", "1442"), TIMEREF = c(120,
> 240, 360, 30, 30, 60, 90, 120, 30, 60, 90, 120), TOENDREF = c(390,
> 270, 150, 480, 480, 450, 420, 390, 480, 450, 420, 390)), .Names = c("REF",
> "TIMEREF", "TOENDREF"), row.names = c(NA, 12L), class = "data.frame")
> datain
> 
> ## output
> dataout <- structure(list(REF = c(999L, 999L, 999L, 1099L, 731L, 731L,
> 731L,
> 731L, 1442L, 1442L, 1442L, 1442L), TIMEREF = c(120L, 240L, 360L,
> 30L, 30L, 60L, 90L, 120L, 30L, 60L, 90L, 120L), TOENDREF = c(390L,
> 270L, 150L, 120L, 90L, 30L, 420L, 300L, 270L, 210L, 120L, 0L),
>NEWREF = c(999L, 999L, 999L, 999L, 999L, 999L, 731L, 731L,
>731L, 731L, 731L, 731L)), .Names = c("REF", "TIMEREF", "TOENDREF",
> "NEWREF"), row.names = c(NA, 12L), class = "data.frame")
> dataout
> 
> 
> I what follows I will try to explain what I want to accomplish:
> 
> * Example 1
> Take rows 3 and 4 of "datain"
> 
> #REF TIMEREF TOENDREF
> #3   999 360  150
> #4  1099  30  480
> 
> As 150 units of REF 999 are available, we could substitute the 30 units of
> REF 1099 with them. Hence, the 4th row of the _updated_ "datain" becomes
> 
> #REF TIMEREF TOENDREF NEWREF
> #3   999 360  150  999
> #4  1099  30  120  999
> 
> * Example 2
> Now, let's take rows 3 to 8 of the _updated_ "datain":
> 
> #REF TIMEREF TOENDREF
> #3   999 360  150
> #4   999  30  120
> #5   731  30  480
> #6   731  60  450
> #7   731  90  420
> #8   731 120  390
> 
> In row 4, there 120 units available to be used. The number of units
> required of REF 731 is 30, which can be easily covered by the remaining 120
> units of REF 999. By doing so, the remaining units of REF 999 would then be
> 90.  Hence, the newly _updated_ "datain" becomes
> 
> #REF TIMEREF TOENDREF
> #3   999 360  150
> #4   999  30  120
> #5   999  30   90
> #6   999  60   30
> #7   731  90  420
> #8   731 120  300
> 
> Finally, the updated "datain" file after processing the remaining REF would
> be
> 
> #REF TIMEREF TOENDREF
> #9  731  30  270
> #10 731  60  210
> #11 731  90  120
> #12 731 1200
> 
> Hopefully I have explained well what I would like to end up with.  If this
> is not the case, I will be more than happy to provide more information.
> 
> Any help would be very much appreciated.  Thanks in advance.
> 
> Best regards,
> Jorge Velez.-
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

[R] expression evaluation during recursion

2015-10-22 Thread david . kaethner
Hello,

I’m trying to solve an exercise, where I want to walk through the search path 
recursively (http://adv-r.had.co.nz/Environments.html 
). 

I’m puzzled by a certain behavior and hope somebody can give me an explanation.

This code works:

listenv <- function(env = parent.frame()) {
  if (identical(env, emptyenv())) {
#stop("reached emptyenv", call. = FALSE)
return(env)
  } else {
print(env)
listenv(parent.env(env))
  }
}

Here, the calling environment is determined with a default parameter in the 
function’s formals. 

However, if I want to assign the calling environment within the function’s 
body, I get the error message „infinite recursion“. Also, I never get actual 
environments (with attributes, that is), only memory addresses like this: 
. 

listenv <- function(env) {
  env <- parent.frame()
  if (identical(env, emptyenv())) {
#stop("reached emptyenv", call. = FALSE)
return(env)
  } else {
print(env)
listenv(parent.env(env))
  }
}

Any explanation of what’s going on here would be greatly appreciated. I suspect 
it has to do with when exactly the parent.frame()-expression is evaluated, but 
that’s not an actual explanation.
[[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] Codes of Conduct at R Conferences

2015-10-22 Thread Martyn Plummer
The useR! conferences in 2014 and 2015 both had codes of conduct in
order to ensure an experience free from harassment for all participants.
After a request from some members of the R community, the R Foundation
has decided to endorse this practice. Future conferences supported by
the R Foundation must have a code of conduct.  We encourage other R
meetings not affiliated with the R Foundation to adopt the same policy.

A code of conduct serves two important purposes. Firstly, it sends a
clear message to those outside the community that an R conference is a
professional and comfortable working environment for all participants.
Secondly, it provides a mechanism for reporting and monitoring any
incidents of harassment that may occur.

We have decided not to require a particular formulation for the code of
conduct, but suggest that conference organizers use the model of the
useR! 2015 meeting ( http://user2015.math.aau.dk/behaviouR ). This will
allow the code to be adapted to local circumstances and to evolve in the
future. Conference organizers should ensure that any sanctions laid out
in the code of conduct are legally and practically enforceable. 

Vigorous debate and lively exchange are important features of R
conferences. We expect this to continue within the boundaries set by the
code of conduct.

For the R Foundation
Martyn Plummer, Co-President

---
This message and its attachments are strictly confidenti...{{dropped:8}}

___
r-annou...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
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] Scope of Axes

2015-10-22 Thread S Ellison
> fhist<-hist(Simulation,plot=FALSE)
> par(mar=c(6,0,6,6))
> barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray")

i) Unlike hist(), barplot() does not plot at histogram bin boundaries - you'll 
have noticed that you did not specify locations for the bars and in fact can 
not do so . There is no simple way of aligning a barplot with particular axis 
length and locations. But there is a useful example of usig rect() to do the 
job in ?pairs; look for the USJudgeRatings example and see the panel.hist 
function there. It should be straightforward to adapt that for horizontal use.

ii) axes= has nothing to do with the plot limits. xlim and ylim control plot 
limits.  You should set ylim and the top and bottom margins to the same values 
for both plots.

iii) Your png file includes a barplot with gridlines, so that cannot be the 
result of the exact command you used above. If you used a different plotting 
system for the bar plot the alignment would be very hard to guarantee, so stay 
with base graphics for both.



S Ellison

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] Error in Opening Project on R Studio

2015-10-22 Thread sdeepak
Good Evening everyone,
 I am Deepak Singh, Student I.I.T. Kanpur, INDIA, was
working on a project on R Studio and now when I am
trying to open my project it is showing the attached
error. Can it be fixed? if 'Yes' then how can I do
fix it ? Please help.

Thank You!
Deepak Singh
Student I.I.T. Kanpur, INDIA
__
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] expression evaluation during recursion

2015-10-22 Thread Duncan Murdoch
On 22/10/2015 10:20 AM, david.kaeth...@gmail.com wrote:
> Hello,
> 
> I’m trying to solve an exercise, where I want to walk through the search path 
> recursively (http://adv-r.had.co.nz/Environments.html 
> ). 
> 
> I’m puzzled by a certain behavior and hope somebody can give me an 
> explanation.
> 
> This code works:
> 
> listenv <- function(env = parent.frame()) {
>   if (identical(env, emptyenv())) {
> #stop("reached emptyenv", call. = FALSE)
> return(env)
>   } else {
> print(env)
> listenv(parent.env(env))
>   }
> }
> 
> Here, the calling environment is determined with a default parameter in the 
> function’s formals. 
> 
> However, if I want to assign the calling environment within the function’s 
> body, I get the error message „infinite recursion“. Also, I never get actual 
> environments (with attributes, that is), only memory addresses like this: 
> .

I'm not sure what you were looking for, but ""
is the normal way to print an environment, unless it happens to be one
of the special named ones (like .GlobalEnv).

> 
> listenv <- function(env) {
>   env <- parent.frame()
>   if (identical(env, emptyenv())) {
> #stop("reached emptyenv", call. = FALSE)
> return(env)
>   } else {
> print(env)
> listenv(parent.env(env))
>   }
> }
> 
> Any explanation of what’s going on here would be greatly appreciated. I 
> suspect it has to do with when exactly the parent.frame()-expression is 
> evaluated, but that’s not an actual explanation.


Your function completely ignores the "env" argument.  It never recurses.
 In the first case, "parent.frame()" is only a default value, so
recursion happens properly.  If you change the first line in the body to
these two lines

  if (missing(env))
env <- parent.frame()

it would be equivalent.

Duncan Murdoch

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

[R] spatial adjustment using checks

2015-10-22 Thread DIGHE, NILESH [AG/2362]
Hi,
I have yield data for several varieties and a randomly placed check (1 in every 
8 column or "cols") in a field test arranged in a rows*cols grid format (see 
image attached).  Both "rows" & "cols" are variables in the data set.  I like 
to adjust "yield" variable for each row listed as "variety" in variable 
"linecode" by dividing its yield with the average yield of four nearest "check" 
(on the rows*cols field grid) in variable "linecode".  I like to have two 
checks on the same row where one check is on the left and the other is on the 
right side of a given variety.  The other two checks should come from the two 
neighboring columns ("cols").  If a check is missing on one or more sides of a 
given variety, then I like to proceed with the calculation with only the 
available checks around that given variety.  If two checks on the neighboring 
column are equidistance from a given variety then use position of the variety 
to choose which one to use (If variety is in cols 1-8 then use check from those 
cols; if variety is in cols 9-16 then use check from cols 9-16).

Below is the function I wrote which adjust yield values for each "variety" 
(variable "linecode") by dividing its yield with the average yield of all 
checks in the field.  Instead of using average check across the whole field, I 
like to use the four neighboring checks to make this adjustment.  I am 
struggling with specifying the four nearest checks in this loop.  I played 
around using "dist" function but without any success.  I tried searching for 
any packages that can do these nearest check adjustments without any success.  
Any help will be appreciated.

---function--
function (dataset, trait, control) {
m <- c()
x <- length(trait)
chkmean <- tapply(trait, control, mean, na.rm = T)
for (i in 1:x) {
m[i] <- ifelse(control[i] == "variety", trait[i]/chkmean[1],
trait[i]/trait[i])
}
head(as.data.frame(m))
}

-data--

dput(dat)

structure(list(rows = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,

1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,

2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,

3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,

4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("1", "2", "3",

"4"), class = "factor"), cols = structure(c(1L, 2L, 3L, 4L, 5L,

6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 16L, 15L,

14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L,

1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,

15L, 16L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L,

5L, 4L, 3L, 2L, 1L), .Label = c("1", "2", "3", "4", "5", "6",

"7", "8", "9", "10", "11", "12", "13", "14", "15", "16"), class = "factor"),

plotid = c(289L, 290L, 291L, 292L, 293L, 294L, 295L, 296L,

297L, 298L, 299L, 300L, 301L, 302L, 303L, 304L, 369L, 370L,

371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L, 379L, 380L,

381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 389L, 390L,

391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L,

465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L, 473L, 474L,

475L, 476L, 477L, 478L, 479L, 480L), yield = c(5.1, 5.5,

5, 5.5, 6.2, 5.1, 5.5, 5.2, 5, 5, 3.9, 4.6, 5, 4.4, 5.1,

4.3, 4.4, 4.2, 3.9, 4.6, 4.8, 5.4, 4.7, 5.5, 5.3, 4.8, 5.8,

4.6, 5.8, 5.5, 5.3, 5.6, 5.6, 5, 4.8, 4.9, 5.2, 5.3, 4.6,

4.8, 5.3, 4.2, 4.6, 4.2, 4.2, 4, 3.9, 4.5, 5.4, 4.8, 4.6,

5.2, 4.9, 5.1, 4.5, 5.8, 5.2, 4.7, 4.8, 5.3, 5.8, 4.9, 5.9,

4.5), line = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,

9L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,

20L, 1L, 21L, 22L, 1L, 23L, 24L, 25L, 26L, 27L, 28L, 29L,

30L, 31L, 32L, 33L, 1L, 34L, 35L, 36L, 37L, 38L, 39L, 40L,

41L, 42L, 1L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 1L,

51L, 52L, 53L, 54L, 1L, 55L, 56L, 57L), .Label = c("CHK",

"V002", "V003", "V004", "V005", "V006", "V007", "V008", "V009",

"V010", "V011", "V012", "V013", "V014", "V015", "V016", "V017",

"V018", "V019", "V020", "V021", "V022", "V023", "V024", "V025",

"V026", "V027", "V028", "V029", "V030", "V031", "V032", "V033",

"V034", "V035", "V036", "V037", "V038", "V039", "V040", "V041",

"V042", "V043", "V044", "V045", "V046", "V047", "V048", "V049",

"V050", "V051", "V052", "V053", "V054", "V055", "V056", "V057"

), class = "factor"), linecode = structure(c(1L, 2L, 2L,

2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,

2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,

2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L,

2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,

2L), .Label = c("check", "variety"), class = "factor")), .Names = c("rows",

"cols", "plotid", "yield", "line", "linecode"), row.names = c(NA,