<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: R-Sessions 20: Plotting Multilevel Models</title>
	<atom:link href="http://www.rensenieuwenhuis.nl/r-sessions-20-plotting-multilevel-models/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rensenieuwenhuis.nl/r-sessions-20-plotting-multilevel-models/</link>
	<description>&#34;The extra-ordinary lies within the curve of normality&#34;</description>
	<lastBuildDate>Thu, 10 Jan 2019 23:23:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>By: Kate</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-20-plotting-multilevel-models/comment-page-1/#comment-4923</link>
		<dc:creator><![CDATA[Kate]]></dc:creator>
		<pubDate>Wed, 16 Apr 2014 05:01:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=573#comment-4923</guid>
		<description><![CDATA[Hello Rense,
This is a very nice example of how to visualize models with nlme, but I am having trouble manipulating it piece by piece, probably because I am not very good with the function() part. I have tried to manipulate the script  to fit by own data by first reproducing your work. If I essentially copy/paste and run the script, everything works with the dataset (Exam) and model provided. However, when going through, I keep running into errors that certain objects are not able to be found. For example:

object &#039;group&#039; not found

For example, I have tried many variations of the following line to reproduce the exam data, bu nothing works.

predictor.min &lt;- tapply(model$data[[coefficient]], model$data[[group]], min)

Changed into:
tapply(model.01$Exam[[standLRT]], model.01$Exam[[school]], min)

I have tried many variations of this, ie 1) not changing anything, removing $, or removing  $Exam, keeping the words coefficients and group etc.

Could you maybe provide an example without the function part that allows one to go step by step or alternatively, provide a bit more guidance as to what information in teh script needs to be changed to modify it to other data sets? Much appreciated!!]]></description>
		<content:encoded><![CDATA[<p>Hello Rense,<br />
This is a very nice example of how to visualize models with nlme, but I am having trouble manipulating it piece by piece, probably because I am not very good with the function() part. I have tried to manipulate the script  to fit by own data by first reproducing your work. If I essentially copy/paste and run the script, everything works with the dataset (Exam) and model provided. However, when going through, I keep running into errors that certain objects are not able to be found. For example:</p>
<p>object &#8216;group&#8217; not found</p>
<p>For example, I have tried many variations of the following line to reproduce the exam data, bu nothing works.</p>
<p>predictor.min &lt;- tapply(model$data[[coefficient]], model$data[[group]], min)</p>
<p>Changed into:<br />
tapply(model.01$Exam[[standLRT]], model.01$Exam[[school]], min)</p>
<p>I have tried many variations of this, ie 1) not changing anything, removing $, or removing  $Exam, keeping the words coefficients and group etc.</p>
<p>Could you maybe provide an example without the function part that allows one to go step by step or alternatively, provide a bit more guidance as to what information in teh script needs to be changed to modify it to other data sets? Much appreciated!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julie Falcon</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-20-plotting-multilevel-models/comment-page-1/#comment-4303</link>
		<dc:creator><![CDATA[Julie Falcon]]></dc:creator>
		<pubDate>Wed, 19 Oct 2011 15:35:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=573#comment-4303</guid>
		<description><![CDATA[Hi Rense,

As I&#039;ve already told you, thanks a lot for your R sessions. Really nice!

Here is my proposition of the same function but for lmer.
(note that it assumes that the &quot;coefficient variable&quot; is always in second position in the formula, i.e. after the tilde ~ , and the group variable in last position... cf. objects a and b in function code!)

I hope it helps.

Enjoy,

Julie

library(mlmRev)
data(Exam)
library(lme4)

visualize.lmer &lt;- function (model, coefficient, group,...)
{
r &lt;- ranef(model)
f &lt;- fixef(model)
attributes(r)[[1]] &lt;- &quot;r1&quot;
r1 &lt;- ((r)$r1)[,1]
attributes(r)[[1]] &lt;- &quot;r2&quot;
r2 &lt;- ((r)$r2)[,2]
effects &lt;- data.frame(r1+f[1], r2+f[2])
number.lines &lt;- nrow(effects)
a&lt;- unlist((attributes(model)$frame[2]))
n &lt;- ncol(attributes(model)$frame)
b&lt;- unlist((attributes(model)$frame[n]))
predictor.min &lt;- tapply(a,b,min)
predictor.max &lt;- tapply(a,b,max)
outcome.min &lt;- min(attributes(model)$eta)
outcome.max &lt;- max(attributes(model)$eta)
plot (c(min(predictor.min),max(predictor.max)),c(outcome.min,outcome.max),
type=&quot;n&quot;,...)
for (i in 1:number.lines)
{
expression &lt;- function(x) {effects[i,1] + (effects[i,2] * x) }
curve(expression, from=predictor.min[i], to=predictor.max[i], add=TRUE)
}
}

par(mar=c(2.3, 2.0, 2.5, 0.3), bg=&quot;white&quot;, las=2)
layout(matrix(c(1,2), nrow=1, ncol=2, byrow=T), heights=c(3,3), widths=c(3,3))

model.b &lt;- lmer (normexam ~ standLRT + schavg + (1 + standLRT&#124;school), data=Exam)
summary(model.b)

visualize.lmer(model.b, &quot;standLRT&quot;, &quot;school&quot;,xlab=&quot;Student test at school-entry&quot;, ylab=&quot;Result on Exam&quot;, main=&quot;Exam results for 65 schools&quot;)

model.01 &lt;-lme(fixed=normexam ~standLRT + schavg, data = Exam, random=~standLRT&#124;school)
summary(model.01)

visualize.lme(model.01, &quot;standLRT&quot;, &quot;school&quot;, xlab=&quot;Student test at school-entry&quot;, ylab=&quot;Result on Exam&quot;, main=&quot;Exam results for 65 schools&quot;)]]></description>
		<content:encoded><![CDATA[<p>Hi Rense,</p>
<p>As I&#8217;ve already told you, thanks a lot for your R sessions. Really nice!</p>
<p>Here is my proposition of the same function but for lmer.<br />
(note that it assumes that the &#8220;coefficient variable&#8221; is always in second position in the formula, i.e. after the tilde ~ , and the group variable in last position&#8230; cf. objects a and b in function code!)</p>
<p>I hope it helps.</p>
<p>Enjoy,</p>
<p>Julie</p>
<p>library(mlmRev)<br />
data(Exam)<br />
library(lme4)</p>
<p>visualize.lmer &lt;- function (model, coefficient, group,&#8230;)<br />
{<br />
r &lt;- ranef(model)<br />
f &lt;- fixef(model)<br />
attributes(r)[[1]] &lt;- &quot;r1&quot;<br />
r1 &lt;- ((r)$r1)[,1]<br />
attributes(r)[[1]] &lt;- &quot;r2&quot;<br />
r2 &lt;- ((r)$r2)[,2]<br />
effects &lt;- data.frame(r1+f[1], r2+f[2])<br />
number.lines &lt;- nrow(effects)<br />
a&lt;- unlist((attributes(model)$frame[2]))<br />
n &lt;- ncol(attributes(model)$frame)<br />
b&lt;- unlist((attributes(model)$frame[n]))<br />
predictor.min &lt;- tapply(a,b,min)<br />
predictor.max &lt;- tapply(a,b,max)<br />
outcome.min &lt;- min(attributes(model)$eta)<br />
outcome.max &lt;- max(attributes(model)$eta)<br />
plot (c(min(predictor.min),max(predictor.max)),c(outcome.min,outcome.max),<br />
type=&quot;n&quot;,&#8230;)<br />
for (i in 1:number.lines)<br />
{<br />
expression &lt;- function(x) {effects[i,1] + (effects[i,2] * x) }<br />
curve(expression, from=predictor.min[i], to=predictor.max[i], add=TRUE)<br />
}<br />
}</p>
<p>par(mar=c(2.3, 2.0, 2.5, 0.3), bg=&quot;white&quot;, las=2)<br />
layout(matrix(c(1,2), nrow=1, ncol=2, byrow=T), heights=c(3,3), widths=c(3,3))</p>
<p>model.b &lt;- lmer (normexam ~ standLRT + schavg + (1 + standLRT|school), data=Exam)<br />
summary(model.b)</p>
<p>visualize.lmer(model.b, &quot;standLRT&quot;, &quot;school&quot;,xlab=&quot;Student test at school-entry&quot;, ylab=&quot;Result on Exam&quot;, main=&quot;Exam results for 65 schools&quot;)</p>
<p>model.01 &lt;-lme(fixed=normexam ~standLRT + schavg, data = Exam, random=~standLRT|school)<br />
summary(model.01)</p>
<p>visualize.lme(model.01, &quot;standLRT&quot;, &quot;school&quot;, xlab=&quot;Student test at school-entry&quot;, ylab=&quot;Result on Exam&quot;, main=&quot;Exam results for 65 schools&quot;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T-bone</title>
		<link>http://www.rensenieuwenhuis.nl/r-sessions-20-plotting-multilevel-models/comment-page-1/#comment-2915</link>
		<dc:creator><![CDATA[T-bone]]></dc:creator>
		<pubDate>Thu, 05 Nov 2009 03:29:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.rensenieuwenhuis.nl/?p=573#comment-2915</guid>
		<description><![CDATA[I can&#039;t seem to get this code to work. 

I would really like to use the lmer function instead of lme. 

There seems to be a problem with the expression function near the bottom. The code &quot;curve(expression,&quot; does not send anything to the expression function. It also crashed when I didn&#039;t have $school after the &#039;r&#039; in the dataframe section. And, finally, the font selected causes a problem with R because of the smart quotes. 

But otherwise this is helpful.]]></description>
		<content:encoded><![CDATA[<p>I can&#8217;t seem to get this code to work. </p>
<p>I would really like to use the lmer function instead of lme. </p>
<p>There seems to be a problem with the expression function near the bottom. The code &#8220;curve(expression,&#8221; does not send anything to the expression function. It also crashed when I didn&#8217;t have $school after the &#8216;r&#8217; in the dataframe section. And, finally, the font selected causes a problem with R because of the smart quotes. </p>
<p>But otherwise this is helpful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
