Re: [R] lme4 Error Help: “maxstephalfit…pwrssUpdate”

2014-04-28 Thread Craig O'Connell
Thanks.  I used the most current version of lme4 that is why I was a bit 
concerned.  My data seems appropriate and with lme4 working last week on a very 
similar data set, I was left a bit confused.  Since I only starting 
implementing this technique, does anybody have some pointers on what I should 
look for that may potentially cause some issues?  

 
 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 Namens Craig O'Connell
 Verzonden: maandag 28 april 2014 3:20
 Aan: r-help@r-project.org
 Onderwerp: [R] lme4 Error Help: “maxstephalfit…pwrssUpdate”
 
 I am using a mixed model to assess the effects of various variables (i.e. 
 treatment, density, visibility) on bee behavior (e.g., avoidance frequency - 
 total avoidances per total visits; feeding frequency, and mating frequency).  
 Bee individuals is my random factor (n=63 different bees), whereas treatment 
 type, animal density, and air visibility are my fixed factors.
 However, when I run my models, I immediately get an error that I cannot fix.  
 Here is a sample of my data:
 Bee   TreatmentVisitsAvoid   FeedingMatingDensity   Visibility
 
 1   C   5   0   5   0  54
 2   C   4   0   3   0  54
 3   C   3   0   3   0  54
 ...
 63
 
 1   PC  2   0   1   1  54
 2   PC  3   0   0   3  54
 3   PC  1   0   0   0  54
 ...
 63
 
 1   M   5   0   1   3  54
 2   M   3   2   0   0  54
 3   M   2   0   0   2  54
 ...
 63One I create my .txt file, I being my coding in R by first loading lme4.  
 After that, my coding starts off as follows:
 barrierdat = read.table(GLMMROW.txt, header=TRUE) barrierdat 
 barrierdat$Visibility = as.factor(barrierdat$Visibility);
 barrierdat$Density= as.factor(barrierdat$Density);
 
 p01.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee),
 family=poisson,
   data=egghead);  # null model; p02.glmer = 
 glmer(Avoidance~offset(log(Visits))+(1|Bee)+Treatment,  family=poisson,
   data=egghead);
 p03.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Visibility, 
 family=poisson,
   data=egghead);
 p04.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Density,
 family=poisson,
   data=egghead);However, upon immediately running my models 
 (e.g. p01.glmer), I receive the error:
 Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in 
 pwrssUpdate
 
 Does anybody know what the issue is?  I ran similar data several weeks ago 
 and had no issues.  Any Suggestions on how to proceed?
 
 [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
 Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
 en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd 
 is door een geldig ondertekend document.
 The views expressed in this message and any annex are purely those of the 
 writer and may not be regarded as stating an official position of INBO, as 
 long as the message is not confirmed by a duly signed document.

  
[[alternative HTML version deleted]]

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


[R] lme4 Error Help: “maxstephalfit…pwrssUpdate”

2014-04-27 Thread Craig O'Connell
I am using a mixed model to assess the effects of various variables (i.e. 
treatment, density, visibility) on bee behavior (e.g., avoidance frequency - 
total avoidances per total visits; feeding frequency, and mating frequency).  
Bee individuals is my random factor (n=63 different bees), whereas treatment 
type, animal density, and air visibility are my fixed factors.  
However, when I run my models, I immediately get an error that I cannot fix.  
Here is a sample of my data:
Bee   TreatmentVisitsAvoid   FeedingMatingDensity   Visibility

1   C   5   0   5   0  54
2   C   4   0   3   0  54  
3   C   3   0   3   0  54  
...
63

1   PC  2   0   1   1  54
2   PC  3   0   0   3  54   
3   PC  1   0   0   0  54   
...
63

1   M   5   0   1   3  54
2   M   3   2   0   0  54   
3   M   2   0   0   2  54
...
63One I create my .txt file, I being my coding in R by first loading lme4.  
After that, my coding starts off as follows:
barrierdat = read.table(GLMMROW.txt, header=TRUE)
barrierdat
barrierdat$Visibility = as.factor(barrierdat$Visibility);
barrierdat$Density= as.factor(barrierdat$Density);

p01.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee),
family=poisson, 
  data=egghead);  # null model;
p02.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Treatment,  
family=poisson, 
  data=egghead);
p03.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Visibility, 
family=poisson, 
  data=egghead);
p04.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Density,
family=poisson, 
  data=egghead);However, upon immediately running my models 
(e.g. p01.glmer), I receive the error:  
Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in 
pwrssUpdate
 
Does anybody know what the issue is?  I ran similar data several weeks ago and 
had no issues.  Any Suggestions on how to proceed?
  
[[alternative HTML version deleted]]

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


[R] Need Help Plotting Line for multiple linear regression

2013-02-13 Thread Craig O'Connell
Hello,

My name is Craig and I need help plotting a line for a multiple linear
regression in R.

Here is my sample data (filename:  convis.txt)

Output of convis.txt is (vis and density being predictors of either
avoidance or entrance):

   vis den  avoid entrance
1   10   1 0.   0.
2   10   3 0.8750   0.
38   3 0.8180   0.0300
48   3 0.6670   0.0667
58   1 0.2110   0.
66   1 0.2500   0.
7   10   1 0.3000   0.
8   10   1 0.1050   0.
98   1 0.7000   0.1000
10   3   5 0.1176   0.0588
11   3   5 0.3077   0.1150
12   3   9 0.9090   0.0900
13   3   7 0.7778   0.1110
14   3   5 0.5560   0.1110
15   3   1 0.5710   0.
16   3   4 0.5710   0.

In order to do the multiple regression, I used the following coding:


double=read.table(convis.txt,header=TRUE)
attach(double)
double
stem(vis)
stem(den)
stem(avoid)
stem(entrance)
plot(entrance,vis*den)  *as means to see how the interaction between
visibility and density may impact entrance behaviors
model6=lm(entrance~vis*den)
model6
summary(model6)
*abline(model6)  *Here is the issue as I used this for my simple linear
regression technique, but do not know what to use for a multiple regression*

If anybody can provide some feedback on this, it would be greatly
appreciated.

Kind Regards,

Craig

-- 

Craig O'Connell
University of Massachusetts Dartmouth
Marine Biologist
www.youtube.com/craigpoconnell
craigosea.blogspot.com

[[alternative HTML version deleted]]

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


[R] Predator Prey Models

2010-12-11 Thread Craig O'Connell
Dear R-users,

   I am currently modifying a previously developed predator prey model and
was curious if there was a way to add in a disturbance to the model (let's
say at time t=100).  The disturbance can be the introduction of 40 prey
(N=40) and 10 predators (Pred = 10).  I would like to see my model go from a
state of equilibrium (up to t = 99), show this disturbance (at t = 100) and
then slowly work its way back to equilibrium.  Does anybody know if this
could be done?


LVmod0D - function(Time, State, Pars) {

with(as.list(c(State, Pars)), {

IngestPred - rI * N * Pred

GrowthN - rG * N * (1 - N/K)

MortPred - rM * Pred



dN - GrowthN - IngestPred

dPred - IngestPred * AE - MortPred



return(list(c(dN, dPred)))

})

}



pars - c(rI = 0.1, rG = 0.9, rM = 0.8, AE = 0.9, K = 20)

yini - c(N = 20, Pred = 20)

times - seq(0, 200, by = 1)

y(time=100)-c(N=10, Pred=5)

print(system.time)

zout - as.data.frame(lsoda(yini, y(time=100), times, LVmod0D, pars))

plot(zout[,1],zout[,2], type=l,col=black, ylim=range(0,25),
xlab=time,ylab=population)

points(zout[,1],zout[,3],type=l,col=red)

title(main=prey (black) predator (red))



Thanks much for your help!

[[alternative HTML version deleted]]

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


Re: [R] MATLAB vrs. R

2010-10-11 Thread Craig O'Connell

Thank you Peter.  That is very much helpful.  If you don't mind, I continued 
running the code to attempt to get my answer and I continue to get inf inf 
inf... (printed around 100 times).
 
Any assistance with this issue.  Here is my code (including your corrections):
 

myquadrature-function(f,a,b){
npts=length(f)
nint=npts-1
if(npts=1)
error('need at least two points to integrate')
end;
if(b=a)
error('something wrong with the interval, b should be greater than a')
else
dx=b/real(nint)
end;
npts=length(f)
int=0
int - sum(f[-npts]+f[-1])/2*dx
}
 
#Call my quadrature
x=seq(0,2000,10)
h = 10.*(cos(((2*pi)/2000)*(x-mean(x)))+1)
u = 1.*(cos(((2*pi)/2000)*(x-mean(x)))+1)
a = x[1]
b = x[length(x)] 
plot(x,-h)
a = x[1];
b = x[length(x)];
#call your quadrature function.  Hint, the answer should be 3.
f=u*h;
val =  myquadrature(f,a,b); ?  ___This is where issue arises.  
result=myquadrature(val,0,2000)  ?
print(result)   ?  
 
 
Thanks again,
 
Phil
 
 
  
[[alternative HTML version deleted]]

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


Re: [R] MATLAB vrs. R

2010-10-11 Thread Craig O'Connell

alain,
 
Perhaps i'm still entering the code wrong.  I tried using your  
result=myquadrature(f,0,2000)
print(result)
 
Instead of my:
val = myquadrature(f,a,b)
result=myquadrature(val,0,2000) 
print(result) 
 
...and I am still getting an inf inf inf inf inf...
 
Did you change any of the previous syntax in addition to changing the result 
statement?
 
Thank you so much and I think my brain is fried!  Happy Holiday.
 
Craig
 
 Date: Mon, 11 Oct 2010 09:59:17 +0200
 From: alain.guil...@uclouvain.be
 To: craigpoconn...@hotmail.com
 CC: pda...@gmail.com; r-help@r-project.org
 Subject: Re: [R] MATLAB vrs. R
 
 Hi,
 
 The first argument of myquadrature in result shouldn't be val but f I 
 guess. At least it works for me
 
  result=myquadrature(f,0,2000)
  print(result)
 [1] 3
 
 Regards,
 Alain
 
 
 On 11-Oct-10 09:37, Craig O'Connell wrote:
  Thank you Peter. That is very much helpful. If you don't mind, I continued 
  running the code to attempt to get my answer and I continue to get inf inf 
  inf... (printed around 100 times).
 
  Any assistance with this issue. Here is my code (including your 
  corrections):
 
 
  myquadrature-function(f,a,b){
  npts=length(f)
  nint=npts-1
  if(npts=1)
  error('need at least two points to integrate')
  end;
  if(b=a)
  error('something wrong with the interval, b should be greater than a')
  else
  dx=b/real(nint)
  end;
  npts=length(f)
  int=0
  int- sum(f[-npts]+f[-1])/2*dx
  }
 
  #Call my quadrature
  x=seq(0,2000,10)
  h = 10.*(cos(((2*pi)/2000)*(x-mean(x)))+1)
  u = 1.*(cos(((2*pi)/2000)*(x-mean(x)))+1)
  a = x[1]
  b = x[length(x)]
  plot(x,-h)
  a = x[1];
  b = x[length(x)];
  #call your quadrature function. Hint, the answer should be 3.
  f=u*h;
  val = myquadrature(f,a,b); ? ___This is where issue arises.
  result=myquadrature(val,0,2000) ?
  print(result) ?
 
 
  Thanks again,
 
  Phil
 
 
  
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 -- 
 Alain Guillet
 Statistician and Computer Scientist
 
 SMCS - IMMAQ - Université catholique de Louvain
 Bureau c.316
 Voie du Roman Pays, 20
 B-1348 Louvain-la-Neuve
 Belgium
 
 tel: +32 10 47 30 50
 
  
[[alternative HTML version deleted]]

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


Re: [R] MATLAB vrs. R

2010-10-11 Thread Craig O'Connell

Daniel,
 
That's it!  Thanks.  Your help is very much appreciated.  I'm hoping to 
nail down the code conversion from MATLAB to R, but it seems to be a bit more 
difficult that I had anticipated.
 
Craig
 
 From: djnordl...@frontier.com
 To: djnordl...@frontier.com; r-help@r-project.org
 Date: Mon, 11 Oct 2010 16:12:48 -0700
 Subject: Re: [R] MATLAB vrs. R
 
 I apologize for the noise. I didn't clean up the code enough. See below.
 
 snip
  
  Craig,
  
  I haven't seen an answer to this yet, so let me jump in. You seem to have
  some stuff still leftover from MATLAB. Here is some cleaned up code that
  produces the result you expect. I don't think the value of dx was being
  correctly computed in your code. I did not change the assignment operator
  you used (=), but in R the preferred operator is - (without the
  quotes).
  
  myquadrature - function(f,a,b){
  npts = length(f)
  nint = npts-1
  if(npts = 1) error('need at least two points to integrate')
  if(b = a) error('something wrong with the interval, b should be greater
  than a') else dx=b/nint
 
 The 2 'if' statements above should have been
 
 if(npts = 1) stop('need at least two points to integrate')
 if(b = a) stop('something wrong with the interval, b should be greater than 
 a') else dx=b/nint
 
  sum(f[-npts]+f[-1])/2*dx
  }
  
  #Call my quadrature
  x = seq(0,2000,10)
  h = 10*(cos(((2*pi)/2000)*(x-mean(x)))+1)
  u = (cos(((2*pi)/2000)*(x-mean(x)))+1)
  a = x[1]
  b = x[length(x)]
  plot(x,-h)
  a = x[1];
  b = x[length(x)]
  
  #call your quadrature function. Hint, the answer should be 3.
  f = u*h
  result = myquadrature(f,a,b)
  result
  
  Hope this is helpful,
  
  Dan
  
 Daniel Nordlund
 Bothell, WA USA
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
  
[[alternative HTML version deleted]]

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


[R] MATLAB vrs. R

2010-10-10 Thread Craig O'Connell

I need to find the area under a trapezoid for a research-related project.  I 
was able to find the area under the trapezoid in MATLAB using the code:
function [int] = myquadrature(f,a,b) 
% user-defined quadrature function
% integrate data f from x=a to x=b assuming f is equally spaced over the 
interval 
% use type 
% determine number of data points
npts = prod(size(f));
nint = npts -1; %number of intervals
if(npts =1)
  error('need at least two points to integrate')
end;
% set the grid spacing
if(b =a)
  error('something wrong with the interval, b should be greater than a')
else
  dx = b/real(nint);
end;
npts = prod(size(f));

% trapezoidal rule
% can code in line, hint:  sum of f is sum(f) 
% last value of f is f(end), first value is f(1)
% code below
int=0;
for i=1:(nint)
%F(i)=dx*((f(i)+f(i+1))/2);
int=int+dx*((f(i)+f(i+1))/2);
end
%int=sum(F);

Then to call myquadrature I did:
% example function call test the user-defined myquadrature function
% setup some data

% velocity profile across a channel
% remember to use ? for help, e.g. ?seq 
x = 0:10:2000; 
% you can access one element of a list of values using brackets
% x(1) is the first x value, x(2), the 2nd, etc.
% if you want the last value, a trick is x(end)  
% the function cos is cosin and mean gives the mean value
% pi is 3.1415, or pi
% another hint, if you want to multiple two series of numbers together
% for example c = a*b where c(1) = a(1)*b(1), c(2) = a(2)*b(2), etc.
% you must tell Matlab you want element by element multiplication
% e.g.:c = a.*b
% note the .
%
h = 10.*(cos(((2*pi)/2000)*(x-mean(x)))+1); %bathymetry
u = 1.*(cos(((2*pi)/2000)*(x-mean(x)))+1);  %vertically-averaged cross-transect 
velocity
plot(x,-h)
% set begin and end points for the integration 
a = x(1);
b = x(end);
% call your quadrature function.  Hint, the answer should be 3.
f=u.*h;
val =  myquadrature(f,a,b);
fprintf('the solution is %f\n',val);

This is great, I got the expected answer of 3.
 
NOW THE ISSUE IS, I HAVE NO IDEA HOW THIS CODE TRANSLATES TO R.  Here is what I 
attempted to do, and with error messages, I can tell i'm doing something wrong:
  myquadrature-function(f,a,b){
npts=length(f)
nint=npts-1
if(npts=1)
error('need at least two points to integrate')
end;
if(b=a)
error('something wrong with the interval, b should be greater than a')
else
dx=b/real(nint)
end;
npts=length(f)
_(below this line, I cannot code)
int=0
for(i in 1:(npts-1))
sum(f)=((b-a)/(2*length(f)))*(0.5*f[i]+f[i+1]+f[length(f)])}
%F(i)=dx*((f(i)+f(i+1))/2);
int=int+dx*((f(i)+f(i+1))/2);
end
%int=sum(F);
 
Thank you and any potential suggestions would be greatly appreciated.
 
Dr. Argese.   
[[alternative HTML version deleted]]

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