But with three lines for the three habitat types and grass length at the bottom
On Thu, Oct 10, 2013 at 5:52 PM, Rebecca Stirnemann <rstirnem...@gmail.com>wrote: > Thanks Jim for helping, > > Your sample data actually looks like my dataset. The one I put up looks > strange for some reason so please ignore that. > I have three landusenumb variables 1 2 and 3. is rep (1,2,3) correct? > > When I run the following code I am getting: > > > mod1 <- glmer(frat ~ flandusenumb + ground.cover_lo + (1|fsite) ,family > = binomial, data= mao1) > > > > #Calculate predicted values > > newdata1 <- data.frame(ground.cover_lo = c(25,50,100), flandusenumb = > rep(1,2,3)) > > pred34 <- predict(mod1,newdata=newdata1,type="response") > > Error in UseMethod("predict") : > no applicable method for 'predict' applied to an object of class "mer" > > Can you see what I am doing wrong? > What I am aiming for is a graph which looks like this. > > Thanks > Rebecca > > > > > > > On Thu, Oct 10, 2013 at 5:33 PM, Jim Lemon <j...@bitwrit.com.au> wrote: > >> On 10/10/2013 08:35 AM, Rebecca Stirnemann wrote: >> >>> Dear R wizards, >>> >>> Though I hate to do it after weeks of my code not working I need some >>> help >>> since I cant find an example which seems to work. >>> I am trying to create a graph which show the probability of predation of >>> a >>> nest on one side (either 1 to 0) or (0% to 100%) on one side >>> and grass height at the bottom. I want to then add my predicted lines >>> from >>> my glmr onto the graph for three habitat types. >>> >>> I would like to repeat this procedure 3 times for three different grass >>> heights 25- 50- 100 to see the effect size. >>> >>> My data: >>> landusenumb landuse sitename rat ground.cover_lo 1 plantation >>> far.leftroad_LHS 0 60 1 plantation far.leftroad_LHS 1 70 1 plantation >>> far.leftroad_LHS 1 10 1 plantation far.leftroad_LHS 1 30 1 plantation >>> far.leftroad_LHS 1 50 1 plantation far.leftroad_LHS 0 20 1 plantation >>> far.leftroad_LHS 0 70 1 plantation far.leftroad_LHS 0 100 1 plantation >>> far.leftroad_LHS 0 90 >>> >>> #Graph >>> >>> >>> #Fit model >>> >>> mod1<- glmer(frat ~ flandusenumb + ground.cover_lo + (1|fsite) ,family = >>> binomial, data= mao1) >>> >>> >>> #Calculate predicted values >>> >>> newdata1<- data.frame(ground.cover_lo = seq(0,10,length=100), >>> flandusenumb >>> = rep(1,2,3)) >>> >>> pred34<- predict(mod1,newdata=newdata1,**type="response") >>> >>> >>> >>> #Plot model predicted curves >>> >>> plot(c(0,100),c(0,1),type="n",**xlab="grasscover",ylab="**Probability of >>> predation") >>> >>> lines(newdata1$frat,pred34,**lwd=3,col="blue") >>> >>> >>> Hi Rebecca, >> First, your sample data are a bit mangled, and should look like this: >> >> mao1 >> >> landusenumb landuse sitename rat ground.cover_lo >> 1 plantation far.leftroad_LHS 0 60 >> 1 plantation far.leftroad_LHS 1 70 >> 1 plantation far.leftroad_LHS 1 10 >> 1 plantation far.leftroad_LHS 1 30 >> 1 plantation far.leftroad_LHS 1 50 >> 1 plantation far.leftroad_LHS 0 20 >> 1 plantation far.leftroad_LHS 0 70 >> 1 plantation far.leftroad_LHS 0 100 >> 1 plantation far.leftroad_LHS 0 90 >> >> If you want the predicted values with ground cover as above, then: >> >> ground.cover_lo = c(25,50,100) >> >> The variable names in the first model don't match those in the data >> frame, but I assume these were typos. What does "pred34" look like? This >> will tell you what function you should be using to plot it. >> >> Jim >> > > > > -- > www.samoanbirds.com > -- www.samoanbirds.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.