Re: [R] Questions regarding to JohnSonFit() in the R package Johnson {SuppDists}

2017-06-30 Thread William Dunlap via R-help
This happens for some inputs, e.g.,
   > JohnsonFit(c(2,3,4,5,6,7,8,30,50,300))
   Error in JohnsonFit(c(2, 3, 4, 5, 6, 7, 8, 30, 50, 300)) :
   Unbounded solution intermediate values out of range
The usual recommendation is to contact the maintainer of the package but
that isn't possible in this case
   > maintainer("SuppDists")
   [1] "ORPHANED"

You can work around the problem to some extent by replacing
   JohnsonFit
with a function that detects errrors in JohnsonFit and returns an indicator
that JohnsonFit fails and lets you move on to the next subset of data.
E.g.,
   function(x) tryCatch(JohnsonFit(x),
error=function(e)
structure(conditionMessage(e), x=x))


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Jun 30, 2017 at 9:16 AM, Shiner Yang  wrote:

> Hello,
>
> I was trying to fit a Johnson curve by first figuring out the parameter
> estimates using JohosnFit of a vector by a group ID using the aggregate
> function. I.E.
>
> aggregate(x, by = list(ID), JohnsonFit)
>
> where x is the variable I am trying to perform JohnsonFit on. It is a
> continuous random variable. However, I keep getting the following error:
>
> Error in JohnsonFit(x) :
> Unbounded solution intermediate values out of range
>
> When I run the fit individually by group ID, it works fine. However I do
> not want to do that manually as there are a large number of groups that
> would be too laborious to do so.
>
> If possible, could you shed some light on this error?
>
> Thanks!
>
> --
> Regards,
>
> Shiner Yang
> B. Sc Statistics & Economics, Commerce Minor | UBC
> Co-President, Science Co-op Students Association
>
> [[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] Questions regarding to JohnSonFit() in the R package Johnson {SuppDists}

2017-06-30 Thread Shiner Yang
Hello,

I was trying to fit a Johnson curve by first figuring out the parameter
estimates using JohosnFit of a vector by a group ID using the aggregate
function. I.E.

aggregate(x, by = list(ID), JohnsonFit)

where x is the variable I am trying to perform JohnsonFit on. It is a
continuous random variable. However, I keep getting the following error:

Error in JohnsonFit(x) :
Unbounded solution intermediate values out of range

When I run the fit individually by group ID, it works fine. However I do
not want to do that manually as there are a large number of groups that
would be too laborious to do so.

If possible, could you shed some light on this error?

Thanks!

-- 
Regards,

Shiner Yang
B. Sc Statistics & Economics, Commerce Minor | UBC
Co-President, Science Co-op Students Association

[[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] Predict

2017-06-30 Thread David Winsemius

> On Jun 30, 2017, at 9:13 AM, Sarah Goslee  wrote:
> 
> Once again, you are over-writing your variable. This time, you are overwriting
> the entirety of Stand_Height with the timeseries of height.
> 
> Perhaps you should spend some time with one of the good introductory R
> resources out there, and think a bit more about your procedure.
> 
> Sarah
> 
> On Fri, Jun 30, 2017 at 11:23 AM, Ahmed Attia  wrote:
>> Sorry for the confusion, here is the edited question.
>> 
>> The data= Stand_Height (attached) is recorded from 12/1/2009 to

Also.  Nothing attached made it back to the list readership, although it 
probably did make it to Sarah Goslee. Attachments should have the file 
extension `.txt` so that your mail client can give it the proper MIME-type. The 
only MIME-type that the server accepts for data is 'plain text".

So,  You should also spend more time reading the Mailing list Info page and 
the Posting Guide.


-- 
David.

>> 12/31/2015 (25 observations) and the other dataset (leafbiom) is
>> recorded from 10/7/2009 to 12/29/2016 (daily observations).
>> 
>> I want to use the 25 observations of stand height to predict the daily
>> stand height from 10/7/2009 to 12/29/2016. The daily stand height will
>> be multiplied by leaf biomass to produce a new variable.
>> 
>> I agree that a loop is not needed, would the forecast library help or
>> should I use predict library.
>> 
>> Stand_Height=ts(Stand_Height$height,start=2009,end = 2016,
>>frequency =365)
>> 
>> plot(forecast(ets(Stand_Height),10))
>> a=seq(as.Date("2009-12-01"),by="weeks",length=11)
>> axis(1, at = a, labels = format(a, "%Y %b %d"), cex.axis=0.6)
>> 
>> 
>> #Error :$ operator is invalid for atomic vectors
>> 
>> Thanks
>> 
>> 
>> Ahmed Attia, Ph.D.
>> Agronomist & Soil Scientist
>> 
>> 
>> 
>> 
>> 
>> 
>> On Fri, Jun 30, 2017 at 10:37 AM, Sarah Goslee  
>> wrote:
>>> There are a bunch of things wrong here, although without a
>>> reproducible example I can't really fix most of them.
>>> 
>>> - You're overwriting SH within the loop.
>>> - You're running the regression 2641 times, even though the result
>>> never changes.
>>> - You're never predicting from your linear model using the other data
>>> not in the regression.
>>> - Leaf biomass data is never used for anything. I would have thought
>>> that you would use leaf biomass as the predictor variable, not Date.
>>> - I'm not sure why you want the cumulative sum of stand height; that
>>> doesn't make sense to me.
>>> 
>>> I'm guessing you want:
>>> 
>>> height.model <- lm(height ~ leafbiomass, data = Stand_Height)
>>> pred.height <- predict(height.model, leafbiom)
>>> 
>>> # not sure about the reasoning behind this
>>> SH <- cumsum(pred.height)
>>> 
>>> You don't need a loop. Overwriting SH is the biggest R problem; the
>>> rest of my questions have to do with what your objective actually is,
>>> like what you are modeling and what you are doing with the
>>> predictions. But my sample code might be enough to get you headed in
>>> the right direction regardless.
>>> 
>>> Sarah
>>> 
>>> On Fri, Jun 30, 2017 at 9:27 AM, Ahmed Attia  wrote:
 Hi folks,
 
 I have 25 stand height observations over 7 years period and daily
 leafbiomass data during this period. I want to use the 25 plant height
 observations as inputs and predict the daily stand height during the 7
 years.
 
 
 SH=matrix(data=NA , nrow = 2641, ncol = 1)
 for (i in 1:2641) {
  SH<- predict(lm(height~Date, data=Stand_Height));
 
  dl=leafbiom$Date[i-1];
  de=leafbiom$Date[i];
 SH[i]=sum(SH[leafbiom$Date==de$Date==dl])
 
 
 }
 SH
 
 
 The SH output is the prediction of Stand height in 25 observations
 only and provides NA for the remaining 2616 iterations.
 
 Thanks for your help.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


Re: [R] Predict

2017-06-30 Thread Sarah Goslee
Once again, you are over-writing your variable. This time, you are overwriting
the entirety of Stand_Height with the timeseries of height.

Perhaps you should spend some time with one of the good introductory R
resources out there, and think a bit more about your procedure.

Sarah

On Fri, Jun 30, 2017 at 11:23 AM, Ahmed Attia  wrote:
> Sorry for the confusion, here is the edited question.
>
> The data= Stand_Height (attached) is recorded from 12/1/2009 to
> 12/31/2015 (25 observations) and the other dataset (leafbiom) is
> recorded from 10/7/2009 to 12/29/2016 (daily observations).
>
> I want to use the 25 observations of stand height to predict the daily
> stand height from 10/7/2009 to 12/29/2016. The daily stand height will
> be multiplied by leaf biomass to produce a new variable.
>
> I agree that a loop is not needed, would the forecast library help or
> should I use predict library.
>
> Stand_Height=ts(Stand_Height$height,start=2009,end = 2016,
> frequency =365)
>
> plot(forecast(ets(Stand_Height),10))
> a=seq(as.Date("2009-12-01"),by="weeks",length=11)
> axis(1, at = a, labels = format(a, "%Y %b %d"), cex.axis=0.6)
>
>
> #Error :$ operator is invalid for atomic vectors
>
> Thanks
>
>
> Ahmed Attia, Ph.D.
> Agronomist & Soil Scientist
>
>
>
>
>
>
> On Fri, Jun 30, 2017 at 10:37 AM, Sarah Goslee  wrote:
>> There are a bunch of things wrong here, although without a
>> reproducible example I can't really fix most of them.
>>
>> - You're overwriting SH within the loop.
>> - You're running the regression 2641 times, even though the result
>> never changes.
>> - You're never predicting from your linear model using the other data
>> not in the regression.
>> - Leaf biomass data is never used for anything. I would have thought
>> that you would use leaf biomass as the predictor variable, not Date.
>> - I'm not sure why you want the cumulative sum of stand height; that
>> doesn't make sense to me.
>>
>> I'm guessing you want:
>>
>> height.model <- lm(height ~ leafbiomass, data = Stand_Height)
>> pred.height <- predict(height.model, leafbiom)
>>
>> # not sure about the reasoning behind this
>> SH <- cumsum(pred.height)
>>
>> You don't need a loop. Overwriting SH is the biggest R problem; the
>> rest of my questions have to do with what your objective actually is,
>> like what you are modeling and what you are doing with the
>> predictions. But my sample code might be enough to get you headed in
>> the right direction regardless.
>>
>> Sarah
>>
>> On Fri, Jun 30, 2017 at 9:27 AM, Ahmed Attia  wrote:
>>> Hi folks,
>>>
>>> I have 25 stand height observations over 7 years period and daily
>>> leafbiomass data during this period. I want to use the 25 plant height
>>> observations as inputs and predict the daily stand height during the 7
>>> years.
>>>
>>>
>>> SH=matrix(data=NA , nrow = 2641, ncol = 1)
>>> for (i in 1:2641) {
>>>   SH<- predict(lm(height~Date, data=Stand_Height));
>>>
>>>   dl=leafbiom$Date[i-1];
>>>   de=leafbiom$Date[i];
>>> SH[i]=sum(SH[leafbiom$Date==de$Date==dl])
>>>
>>>
>>> }
>>> SH
>>>
>>>
>>> The SH output is the prediction of Stand height in 25 observations
>>> only and provides NA for the remaining 2616 iterations.
>>>
>>> Thanks for your help.

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


Re: [R] package to fit mixtures of student-t distributions

2017-06-30 Thread David Winsemius

> On Jun 29, 2017, at 10:02 AM, vare vare via R-help  
> wrote:
> 
> I don’t see how neither a) or b) applies to this question nor the technical 
> merit of the remark about  mixture models.
> 
> Do you have a suggestion for a more appropriate forum for this issue/question?

CrossValidated.com, although if you frame it in terms of "I need a language 
specific response", they often will refer questioners back to StackOverflow. 
There seems to be a widespread aversion to doing people's searching for them. 
You should read the Posting Guide and the help pages for any online forum you 
consider posting to. SO has a filter that prevents LMGTFY responses, but Rhelp 
has no such prohibition.

http://lmgtfy.com/?q=package+to+fit+mixtures+of+student-t+distributions

> (stackoverflow basically sent me here).

I question whether "stackoverflow basically sent me here" in any meaningful 
sense. There is a response yesterday on StackOverflow from Ben Bolker in which 
he constructed a working example (which should have been provided by you) and 
he then illustrated the use of a function from the `teigen` package that seemed 
to work fairly well. There were not any comments that suggested you should use 
the rhelp mailing list. You have not commented on, upvoted, or accepted that 
answer using the mechanisms given to you by the SO people to recognize the 
answerer's effort or guide the "helping" process.  So one suggestion would be 
to:

-- show what searching you have done,  (Maybe you really do need methods 
advice?)

-- and why the suggestions so far are not satisfactory.

-- 
David.


> 
> Kind regards
> 
>> On 29. Jun 2017, at 16:58, Bert Gunter  wrote:
>> 
>> Offlist, because this is (a) an opinion and (b) about statistics and
>> therefore offtopic.
>> 
>> I don't know whether any such package exists, but I would predict that
>> this is likely to be overdetermined (too many parameters) and
>> therefore unlikely to be a successful strategy. Fitting a mixture of
>> Gaussians is already difficult enough.
>> 
>> Feel free to ignore, of course, and no need to reply.
>> 
>> Cheers,
>> Bert
>> 
>> 
>> Bert Gunter
>> 
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> 
>> 
>> On Thu, Jun 29, 2017 at 5:41 AM, vare vare via R-help
>>  wrote:
>>> Hello!
>>> 
>>> I am new to R (before used python exclusively and would actually call the R 
>>> solution for this issue inside a python notebook, hope that doesn’t 
>>> disqualify me right of the batch).
>>> 
>>> Right now I am  looking for a piece of software  to fit a 1D data sample to 
>>> a mixture of t-distributions.
>>> 
>>> I searched quite a while already and it seems to be that this is a somehwat 
>>> obscure endeavor as most search results turn up for mixture of gaussians 
>>> (what I am not interested here).
>>> 
>>> The most promising candidates so far are the "AdMit" and "MitSEM" R 
>>> packages. However I do not know R and find the description of these 
>>> packages rather comlple and it seems their core objective is not the 
>>> fitting of mixtures of t’s but instead use this as a step to accomplish 
>>> something else.
>>> 
>>> This is in a nutshell what I want the software to accomplish:
>>> 
>>> Fitting a mixture of t-distributions to some data and estimate the 
>>> "location" "scale" and "degrees of freedom" for each.
>>> 
>>> I hope someone can point me to a simple package, I can’t believe that this 
>>> is such an obscure use case.
>>> 
>>> Thanks!
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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

[R] Multiple "scale_color_manual" statements in one plot (ggplot2, flexible legend challenge)

2017-06-30 Thread Jun Shen
Dear list,

I am facing an unusual situation where I need to create two sets of legends
based on the color mapping. Can't get exactly what I want and really
appreciate any advice from ggplot experts.

Let's say I have the first dataset "df1" that draws some points and based
on which a "loess" line with confidence interval is added. Then the second
dataset "df2" will produce a line and ribbon.

These are all fine. The challenge is I want to color and shape code the
points and then have two sets of legends, one for the points and one for
the lines. I have tried different ways, so far I can only get the legend
for the points but not for the lines.

Attached the sample code and sample data.

I tried to add "color" arguments to the "geom_smooth" and "geom_line" and
doesn't work. I think the problem is I need to separate the color schemes
for lines and points, but I can't use multiple scale_color_manual statement
in one ggplot.

Jun Shen

sample data#
df1 <-  structure(list(Y2 = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L), X = c(27L, 8L,
33L, 53L, 100L, 52L, 9L, 60L, 50L, 10L, 3L, 30L, 50L, 15L, 90L,
48L, 110L, 75L, 72L, 150L, 47L, 30L), GRP = structure(c(3L, 1L,
3L, 4L, 4L, 4L, 1L, 3L, 3L, 1L, 2L, 2L, 2L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 4L), .Label = c("1", "2", "3", "4"), class = "factor")), .Names
= c("Y2",
"X", "GRP"), row.names = c(NA, -22L), class = "data.frame")

df2 <-  structure(list(X = c(1L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L,
90L, 100L, 110L, 120L, 130L, 140L, 150L), P025 = c(0.000319,
0.00928, 0.0232, 0.0393, 0.0556, 0.0699, 0.0833, 0.0949, 0.104,
0.113, 0.119, 0.124, 0.129, 0.134, 0.138, 0.144), P50 = c(0.00352,
0.0262, 0.0479, 0.0681, 0.0855, 0.103, 0.118, 0.134, 0.149, 0.164,
0.178, 0.19, 0.202, 0.213, 0.224, 0.234), P975 = c(0.016, 0.0523,
0.0768, 0.0987, 0.119, 0.14, 0.159, 0.178, 0.199, 0.223, 0.247,
0.269, 0.291, 0.312, 0.338, 0.36)), .Names = c("X", "P025", "P50",
"P975"), class = "data.frame", row.names = c(NA, -16L))

code
cols.point <- c('1'="#E69F00", '2'="#56B4E9", '3'="#009E73", '4'="#CC79A7")
shape.point <- c('1'=1, '2'=4, '3'=15, '4'=19)

ggplot(data = df1, aes(x=X)) +
  geom_point(aes(y=Y2, color=GRP, shape=GRP, size=1.5)) +
  geom_smooth(aes(y=Y2),  method= 'loess', size=1.5)  +
  geom_line(data=df2, aes(y=P50), size=1.5) +
  geom_ribbon(data=df2,aes(ymin=P025, ymax=P975), alpha=0.2) +
  theme_bw() +
  scale_color_manual(name="",values=cols.point) +
  scale_shape_manual(name="",values=shape.point) +
  guides(color = guide_legend(title='Group', override.aes=list()),
 size = 'none',
 shape = guide_legend(title='Group', override.aes=list(size=2))) +
  theme(legend.position = "top")

[[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] about reading files in order

2017-06-30 Thread Jeff Newmiller
See http://en.wikipedia.org/wiki/Internet_troll
-- 
Sent from my phone. Please excuse my brevity.

On June 30, 2017 10:50:45 AM EDT, lily li  wrote:
>Who is this person and what did he/she mean?
>
>On Fri, Jun 30, 2017 at 1:48 AM, Kindell Young 
>wrote:
>
>>
>> On Jun 29, Silly FAGGOTS DICKS [R] 4 chicks not 18-40 year old dudes
>with
>> no life or reason too still live except wasting our worlds oxygen on
>> pathetic excuses of nothings that should eat a bullet for their next
>meal
>> instead of bull SHIT ( although I know they like the taste of shit) 
>(its a
>> favorite of ]r[ist subscribers )
>>
>> Show quoted text
>>
>> 15:04, "lily li"  wrote:
>> >
>> > Hi R users,
>> > I have a question about opening the txt files and putting them into
>a
>> > matrix. The txt files are in the folder01, while they have the name
>> > file.1.txt, file.2.txt, file.3.txt, etc. There are about 200 such
>text
>> > files. Each txt file contains one value inside. When I tried to use
>the
>> > code below, I found that the txt files are not in order, from 1, 2,
>3, to
>> > 200. Rather, they are in the order 1, 10, 100, 101, etc. How to
>change it
>> > so that they are in order? Thanks for your help.
>> >
>> > temp <- list.files('folder01',pattern="*.txt"
>> > name.list
><-lapply(paste('folder01',temp,sep='/'),read.table,head=F)
>> > library(data.table)
>> > files.matrix <-rbindlist(name.list)
>> >
>> > Also, when use the code below, how to complete it so that the
>values of
>> the
>> > files are stored in a matrix?
>> > lists = list.files('folder01')
>> > for (i in 1:length(lists)){
>> >   file <- read.table(paste('folder01',lists[i],sep='/'),head=F)
>> >   print(file)
>> > }
>> >
>> > [[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-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] Predict

2017-06-30 Thread Bert Gunter
Seems like you need to start by learning R. Lots of good online
tutorials exist -- have you spent time with any? And possibly also
spend some time with a basic statistics text or a statistical expert
to clarify your goals and methodology.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jun 30, 2017 at 8:23 AM, Ahmed Attia  wrote:
> Sorry for the confusion, here is the edited question.
>
> The data= Stand_Height (attached) is recorded from 12/1/2009 to
> 12/31/2015 (25 observations) and the other dataset (leafbiom) is
> recorded from 10/7/2009 to 12/29/2016 (daily observations).
>
> I want to use the 25 observations of stand height to predict the daily
> stand height from 10/7/2009 to 12/29/2016. The daily stand height will
> be multiplied by leaf biomass to produce a new variable.
>
> I agree that a loop is not needed, would the forecast library help or
> should I use predict library.
>
> Stand_Height=ts(Stand_Height$height,start=2009,end = 2016,
> frequency =365)
>
> plot(forecast(ets(Stand_Height),10))
> a=seq(as.Date("2009-12-01"),by="weeks",length=11)
> axis(1, at = a, labels = format(a, "%Y %b %d"), cex.axis=0.6)
>
>
> #Error :$ operator is invalid for atomic vectors
>
> Thanks
>
>
> Ahmed Attia, Ph.D.
> Agronomist & Soil Scientist
>
>
>
>
>
>
> On Fri, Jun 30, 2017 at 10:37 AM, Sarah Goslee  wrote:
>> There are a bunch of things wrong here, although without a
>> reproducible example I can't really fix most of them.
>>
>> - You're overwriting SH within the loop.
>> - You're running the regression 2641 times, even though the result
>> never changes.
>> - You're never predicting from your linear model using the other data
>> not in the regression.
>> - Leaf biomass data is never used for anything. I would have thought
>> that you would use leaf biomass as the predictor variable, not Date.
>> - I'm not sure why you want the cumulative sum of stand height; that
>> doesn't make sense to me.
>>
>> I'm guessing you want:
>>
>> height.model <- lm(height ~ leafbiomass, data = Stand_Height)
>> pred.height <- predict(height.model, leafbiom)
>>
>> # not sure about the reasoning behind this
>> SH <- cumsum(pred.height)
>>
>> You don't need a loop. Overwriting SH is the biggest R problem; the
>> rest of my questions have to do with what your objective actually is,
>> like what you are modeling and what you are doing with the
>> predictions. But my sample code might be enough to get you headed in
>> the right direction regardless.
>>
>> Sarah
>>
>> On Fri, Jun 30, 2017 at 9:27 AM, Ahmed Attia  wrote:
>>> Hi folks,
>>>
>>> I have 25 stand height observations over 7 years period and daily
>>> leafbiomass data during this period. I want to use the 25 plant height
>>> observations as inputs and predict the daily stand height during the 7
>>> years.
>>>
>>>
>>> SH=matrix(data=NA , nrow = 2641, ncol = 1)
>>> for (i in 1:2641) {
>>>   SH<- predict(lm(height~Date, data=Stand_Height));
>>>
>>>   dl=leafbiom$Date[i-1];
>>>   de=leafbiom$Date[i];
>>> SH[i]=sum(SH[leafbiom$Date==de$Date==dl])
>>>
>>>
>>> }
>>> SH
>>>
>>>
>>> The SH output is the prediction of Stand height in 25 observations
>>> only and provides NA for the remaining 2616 iterations.
>>>
>>> Thanks for your help.
>>>
>>>
>>>
>>> Ahmed Attia, Ph.D.
>>> Agronomist & Soil Scientist
>>>
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Predict

2017-06-30 Thread Ahmed Attia
Sorry for the confusion, here is the edited question.

The data= Stand_Height (attached) is recorded from 12/1/2009 to
12/31/2015 (25 observations) and the other dataset (leafbiom) is
recorded from 10/7/2009 to 12/29/2016 (daily observations).

I want to use the 25 observations of stand height to predict the daily
stand height from 10/7/2009 to 12/29/2016. The daily stand height will
be multiplied by leaf biomass to produce a new variable.

I agree that a loop is not needed, would the forecast library help or
should I use predict library.

Stand_Height=ts(Stand_Height$height,start=2009,end = 2016,
frequency =365)

plot(forecast(ets(Stand_Height),10))
a=seq(as.Date("2009-12-01"),by="weeks",length=11)
axis(1, at = a, labels = format(a, "%Y %b %d"), cex.axis=0.6)


#Error :$ operator is invalid for atomic vectors

Thanks


Ahmed Attia, Ph.D.
Agronomist & Soil Scientist






On Fri, Jun 30, 2017 at 10:37 AM, Sarah Goslee  wrote:
> There are a bunch of things wrong here, although without a
> reproducible example I can't really fix most of them.
>
> - You're overwriting SH within the loop.
> - You're running the regression 2641 times, even though the result
> never changes.
> - You're never predicting from your linear model using the other data
> not in the regression.
> - Leaf biomass data is never used for anything. I would have thought
> that you would use leaf biomass as the predictor variable, not Date.
> - I'm not sure why you want the cumulative sum of stand height; that
> doesn't make sense to me.
>
> I'm guessing you want:
>
> height.model <- lm(height ~ leafbiomass, data = Stand_Height)
> pred.height <- predict(height.model, leafbiom)
>
> # not sure about the reasoning behind this
> SH <- cumsum(pred.height)
>
> You don't need a loop. Overwriting SH is the biggest R problem; the
> rest of my questions have to do with what your objective actually is,
> like what you are modeling and what you are doing with the
> predictions. But my sample code might be enough to get you headed in
> the right direction regardless.
>
> Sarah
>
> On Fri, Jun 30, 2017 at 9:27 AM, Ahmed Attia  wrote:
>> Hi folks,
>>
>> I have 25 stand height observations over 7 years period and daily
>> leafbiomass data during this period. I want to use the 25 plant height
>> observations as inputs and predict the daily stand height during the 7
>> years.
>>
>>
>> SH=matrix(data=NA , nrow = 2641, ncol = 1)
>> for (i in 1:2641) {
>>   SH<- predict(lm(height~Date, data=Stand_Height));
>>
>>   dl=leafbiom$Date[i-1];
>>   de=leafbiom$Date[i];
>> SH[i]=sum(SH[leafbiom$Date==de$Date==dl])
>>
>>
>> }
>> SH
>>
>>
>> The SH output is the prediction of Stand height in 25 observations
>> only and provides NA for the remaining 2616 iterations.
>>
>> Thanks for your help.
>>
>>
>>
>> Ahmed Attia, Ph.D.
>> Agronomist & Soil Scientist
>>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
__
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] about reading files in order

2017-06-30 Thread lily li
Who is this person and what did he/she mean?

On Fri, Jun 30, 2017 at 1:48 AM, Kindell Young  wrote:

>
> On Jun 29, Silly FAGGOTS DICKS [R] 4 chicks not 18-40 year old dudes with
> no life or reason too still live except wasting our worlds oxygen on
> pathetic excuses of nothings that should eat a bullet for their next meal
> instead of bull SHIT ( although I know they like the taste of shit)  (its a
> favorite of ]r[ist subscribers )
>
> Show quoted text
>
> 15:04, "lily li"  wrote:
> >
> > Hi R users,
> > I have a question about opening the txt files and putting them into a
> > matrix. The txt files are in the folder01, while they have the name
> > file.1.txt, file.2.txt, file.3.txt, etc. There are about 200 such text
> > files. Each txt file contains one value inside. When I tried to use the
> > code below, I found that the txt files are not in order, from 1, 2, 3, to
> > 200. Rather, they are in the order 1, 10, 100, 101, etc. How to change it
> > so that they are in order? Thanks for your help.
> >
> > temp <- list.files('folder01',pattern="*.txt"
> > name.list <-lapply(paste('folder01',temp,sep='/'),read.table,head=F)
> > library(data.table)
> > files.matrix <-rbindlist(name.list)
> >
> > Also, when use the code below, how to complete it so that the values of
> the
> > files are stored in a matrix?
> > lists = list.files('folder01')
> > for (i in 1:length(lists)){
> >   file <- read.table(paste('folder01',lists[i],sep='/'),head=F)
> >   print(file)
> > }
> >
> > [[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] Predict

2017-06-30 Thread Sarah Goslee
There are a bunch of things wrong here, although without a
reproducible example I can't really fix most of them.

- You're overwriting SH within the loop.
- You're running the regression 2641 times, even though the result
never changes.
- You're never predicting from your linear model using the other data
not in the regression.
- Leaf biomass data is never used for anything. I would have thought
that you would use leaf biomass as the predictor variable, not Date.
- I'm not sure why you want the cumulative sum of stand height; that
doesn't make sense to me.

I'm guessing you want:

height.model <- lm(height ~ leafbiomass, data = Stand_Height)
pred.height <- predict(height.model, leafbiom)

# not sure about the reasoning behind this
SH <- cumsum(pred.height)

You don't need a loop. Overwriting SH is the biggest R problem; the
rest of my questions have to do with what your objective actually is,
like what you are modeling and what you are doing with the
predictions. But my sample code might be enough to get you headed in
the right direction regardless.

Sarah

On Fri, Jun 30, 2017 at 9:27 AM, Ahmed Attia  wrote:
> Hi folks,
>
> I have 25 stand height observations over 7 years period and daily
> leafbiomass data during this period. I want to use the 25 plant height
> observations as inputs and predict the daily stand height during the 7
> years.
>
>
> SH=matrix(data=NA , nrow = 2641, ncol = 1)
> for (i in 1:2641) {
>   SH<- predict(lm(height~Date, data=Stand_Height));
>
>   dl=leafbiom$Date[i-1];
>   de=leafbiom$Date[i];
> SH[i]=sum(SH[leafbiom$Date==de$Date==dl])
>
>
> }
> SH
>
>
> The SH output is the prediction of Stand height in 25 observations
> only and provides NA for the remaining 2616 iterations.
>
> Thanks for your help.
>
>
>
> Ahmed Attia, Ph.D.
> Agronomist & Soil Scientist
>
-- 
Sarah Goslee
http://www.functionaldiversity.org

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

2017-06-30 Thread Ahmed Attia
Hi folks,

I have 25 stand height observations over 7 years period and daily
leafbiomass data during this period. I want to use the 25 plant height
observations as inputs and predict the daily stand height during the 7
years.


SH=matrix(data=NA , nrow = 2641, ncol = 1)
for (i in 1:2641) {
  SH<- predict(lm(height~Date, data=Stand_Height));

  dl=leafbiom$Date[i-1];
  de=leafbiom$Date[i];
SH[i]=sum(SH[leafbiom$Date==de$Date==dl])


}
SH


The SH output is the prediction of Stand height in 25 observations
only and provides NA for the remaining 2616 iterations.

Thanks for your help.



Ahmed Attia, Ph.D.
Agronomist & Soil Scientist

__
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-es] Ordenar vector

2017-06-30 Thread Freddy Omar López Quintero
2017-06-30 5:14 GMT-04:00 Isidro Hidalgo Arellano :

> x[order(x,  decreasing = TRUE)]


​También con la función sort:

sort(x, decreasing=T)
>

¡Salud!​

-- 
«Pídeles sus títulos a los que te persiguen, pregúntales
cuándo nacieron, diles que te demuestren su existencia.»

Rafael Cadenas

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] package to fit mixtures of student-t distributions

2017-06-30 Thread Ingmar Visser
gamlss.mx can fit these I believe (although no experience with these myself)
flexmix may be (relatively easily) adaptable to accomplish this as well
hth, Ingmar

Ingmar Visser
Universitair Hoofddocent ontwikkelingspsychologie | Directeur College
Psychologie
Afdeling Psychologie | Faculteit Maatschappij- en Gedragswetenschappen |
Universiteit van Amsterdam
Bezoek | Nieuwe Achtergracht 129B | Kamer G 1.18
Post | Postbus 15933 | 1001 NK Amsterdam
Pakketpost | Valckenierstraat 59 | 1018 XE Amsterdam
T: +31205256723 | M: +31647260824 | e: i.vis...@uva.nl

On Thu, Jun 29, 2017 at 2:41 PM, vare vare via R-help 
wrote:

> Hello!
>
> I am new to R (before used python exclusively and would actually call the
> R solution for this issue inside a python notebook, hope that doesn’t
> disqualify me right of the batch).
>
> Right now I am  looking for a piece of software  to fit a 1D data sample
> to a mixture of t-distributions.
>
> I searched quite a while already and it seems to be that this is a
> somehwat obscure endeavor as most search results turn up for mixture of
> gaussians (what I am not interested here).
>
> The most promising candidates so far are the "AdMit" and "MitSEM" R
> packages. However I do not know R and find the description of these
> packages rather comlple and it seems their core objective is not the
> fitting of mixtures of t’s but instead use this as a step to accomplish
> something else.
>
> This is in a nutshell what I want the software to accomplish:
>
> Fitting a mixture of t-distributions to some data and estimate the
> "location" "scale" and "degrees of freedom" for each.
>
> I hope someone can point me to a simple package, I can’t believe that this
> is such an obscure use case.
>
> Thanks!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[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] R 3.4.1 is released

2017-06-30 Thread Peter Dalgaard
The build system rolled up R-3.4.1.tar.gz (codename "Single Candle") this 
morning.

The list below details the changes in this release.

You can get the source code from

http://cran.r-project.org/src/base/R-3/R-3.4.1.tar.gz

or wait for it to be mirrored at a CRAN site nearer to you.

Binaries for various platforms will appear in due course.


For the R Core Team,

Peter Dalgaard



These are the checksums (md5 and SHA-256) for the freshly created files, in 
case you wish
to check that they are uncorrupted:

MD5 (AUTHORS) = f12a9c3881197b20b08dd3d1f9d005e6
MD5 (COPYING) = eb723b61539feef013de476e68b5c50a
MD5 (COPYING.LIB) = a6f89e2100d9b6cdffcea4f398e37343
MD5 (FAQ) = 8c65d9a0af345a185d3770c9876f1d51
MD5 (INSTALL) = 7893f754308ca31f1ccf62055090ad7b
MD5 (NEWS) = 4cd5e22f3fffd3525a65acd7d3ed0e28
MD5 (NEWS.0) = bfcd7c147251b5474d96848c6f57e5a8
MD5 (NEWS.1) = eb78c4d053ec9c32b815cf0c2ebea801
MD5 (NEWS.2) = 71562183d75dd2080d86c42bbf733bb7
MD5 (R-latest.tar.gz) = 3a79c01dc0527c62e80ffb1c489297ea
MD5 (README) = f468f281c919665e276a1b691decbbe6
MD5 (RESOURCES) = 529223fd3ffef95731d0a87353108435
MD5 (THANKS) = f60d286bb7294cef00cb0eed4052a66f
MD5 (VERSION-INFO.dcf) = cc04bf1371ce85ec7fb32143692ead4e
MD5 (R-3/R-3.4.1.tar.gz) = 3a79c01dc0527c62e80ffb1c489297ea


6474d9791fff6a74936296bde3fcb569477f5958e4326189bd6e5ab878e0cd4f  AUTHORS
e6d6a009505e345fe949e1310334fcb0747f28dae2856759de102ab66b722cb4  COPYING
6095e9ffa777dd22839f7801aa845b31c9ed07f3d6bf8a26dc5d2dec8ccc0ef3  COPYING.LIB
f0d18e22b9bdfe1dd91547d401b4ef5c8828b2c956a51dc54e7476196b48f87e  FAQ
f87461be6cbaecc4dce44ac58e5bd52364b0491ccdadaf846cb9b452e9550f31  INSTALL
c732c6ec885f4085ba20ae837ac9bcf2ad0952e61fcf910953bdd8dd2c103d23  NEWS
4e21b62f515b749f80997063fceab626d7258c7d650e81a662ba8e0640f12f62  NEWS.0
12b30c724117b1b2b11484673906a6dcd48a361f69fc420b36194f9218692d01  NEWS.1
a10f84be31f897456a31d31690df2fdc3f21a197f28b4d04332cc85005dcd0d2  NEWS.2
shasum: R-2: 
shasum: R-3: Is a directory
02b1135d15ea969a3582caeb95594a05e830a6debcdb5b85ed2d5836a6a3fc78  
R-latest.tar.gz
2fdd3e90f23f32692d4b3a0c0452f2c219a10882033d1774f8cadf25886c3ddc  README
408737572ecc6e1135fdb2cf7a9dbb1a6cb27967c757f1771b8c39d1fd2f1ab9  RESOURCES
52f934a4e8581945cbc1ba234932749066b5744cbd3b1cb467ba6ef164975163  THANKS
e53d0641f90183fee5b7bec130b77d398634211a111fee3ceefb1536275865be  
VERSION-INFO.dcf
02b1135d15ea969a3582caeb95594a05e830a6debcdb5b85ed2d5836a6a3fc78  
R-3/R-3.4.1.tar.gz



This is the relevant part of the NEWS file

CHANGES IN R 3.4.1:

 INSTALLATION on a UNIX-ALIKE:

   * The deprecated support for PCRE versions older than 8.20 has been
 removed.

 BUG FIXES:

   * getParseData() gave incorrect column information when code
 contained multi-byte characters.  (PR#17254)

   * Asking for help using expressions like ?stats::cor() did not
 work.  (PR#17250)

   * readRDS(url()) now works.

   * R CMD Sweave again returns status = 0 on successful completion.

   * Vignettes listed in .Rbuildignore were not being ignored
 properly.  (PR#17246)

   * file.mtime() no longer returns NA on Windows when the file or
 directory is being used by another process.  This affected
 installed.packages(), which is now protected against this.

   * R CMD INSTALL Windows .zip file obeys --lock and --pkglock flags.

   * (Windows only) The choose.files() function could return incorrect
 results when called with multi = FALSE.  (PR#17270)

   * aggregate(, drop = FALSE) now also works in case of
 near-equal numbers in by.  (PR#16918)

   * fourfoldplot() could encounter integer overflow when calculating
 the odds ratio. (PR#17286)

   * parse() no longer gives spurious warnings when extracting srcrefs
 from a file not encoded in the current locale.

 This was seen from R CMD check with inst/doc/*.R files, and check
 has some additional protection for such files.

   * print.noquote(x) now always returns its argument x (invisibly).

   * Non-UTF-8 multibyte character sets were not handled properly in
 source references.  (PR#16732)

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


[R-es] Ordenar vector

2017-06-30 Thread Manuel Máquez
Estimados Colegas, tengo una pregunta, supongamos el vector x que tiene los
siguientes elementos: x<-c(15,20,11,25,0,22,22,16,13,18,16,15,18)
# y luego pongo
y <- order(x)
y # entonces obtengo:
[1]  5  3  9  1 12  8 11 10 13  2  6  7  4
que indican la posición en el vector, pero quiero obtener:
25 22 22 20 18 18 16 16 15 15 13 11 0
¿Me pueden indicar el documento que debo consultar para lograrlo?
Anticipo las gracias más cumplidas.
Atentamente,

*MANOLO MÁRQUEZ P.*

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] Unit of cellsize in 'ascgen' from adehabitatMR? Spatialpoints unit?

2017-06-30 Thread Dagmar

Hello dear all,

A simple understanding question but I cannot find the answer anywhere.

I use coordiates (longitude, latitude) in my study. I created a 
SpatialPoints class from those data and then I created a grid using the 
'ascgen' command in the package 'adehabitatMR' like:


ascgen(xy,cellsize=40).

It worked out fine and my analysis is doing great. But I don't know what 
unit the 'cellsize' is. Is it the area (squaremeter), or the length of 
the border of each rastercell (meter)? Or is it some dimension that I 
cannot grasp from a geografical sense? I can't find the information 
anywhere.


Best, Dagmar

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