<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.socr.umich.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Imoubara</id>
	<title>SOCR - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.socr.umich.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Imoubara"/>
	<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php/Special:Contributions/Imoubara"/>
	<updated>2026-08-03T14:28:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.6</generator>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_DataSimulation&amp;diff=16187</id>
		<title>SMHS DataSimulation</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_DataSimulation&amp;diff=16187"/>
		<updated>2016-05-23T14:00:26Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Simulate New Data to Match the Properties/Characteristics of Observed Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Data Simulation ==&lt;br /&gt;
&lt;br /&gt;
===Importing observed data for exploratory analytics===&lt;br /&gt;
&lt;br /&gt;
Using the [[SOCR_Simulated_HELP_Data|SOCR Health Evaluation and Linkage to Primary (HELP) Care Dataset]] we can [https://umich.instructure.com/files/354289/download?download_frd=1 extract some sample data (00_Tiny_SOCR_HELP_Data_Simmulation.csv)].&lt;br /&gt;
&lt;br /&gt;
 # data_1 &amp;lt;- read.csv('00_Tiny_SOCR_HELP_Data_Simmulation.csv',as.is=T, header=T)&lt;br /&gt;
 # data_1 = read.csv(file.choose( ))&lt;br /&gt;
 # data_1 &amp;lt;- read.table('00_Tiny_SOCR_HELP_Data_Simmulation.csv', header=TRUE,   sep=&amp;quot;,&amp;quot;, row.names=&amp;quot;ID&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 attach(data_1)  &lt;br /&gt;
 # to ensure all variables are accessible within R, e.g., using age instead of data_1$\$$age&lt;br /&gt;
 # i2 maximum number of drinks (standard units) consumed per day (in the past 30 days range 0–184) see also i1&lt;br /&gt;
 # treat randomization group (0=usual care, 1=HELP clinic)&lt;br /&gt;
 # pcs SF-36 Physical Component Score (range 14-75)&lt;br /&gt;
 # mcs SF-36 Mental Component Score(range 7-62)&lt;br /&gt;
 # cesd Center for Epidemiologic Studies Depression scale (range 0–60)&lt;br /&gt;
 # indtot Inventory of Drug Use Con-sequences (InDUC) total score (range 4–45)&lt;br /&gt;
 # pss_fr perceived social supports (friends, range 0–14) see also dayslink&lt;br /&gt;
 # drugrisk Risk-Assessment Battery(RAB) drug risk score (range0–21)&lt;br /&gt;
 # satreat any BSAS substance abuse treatment at baseline (0=no,1=yes)&lt;br /&gt;
&lt;br /&gt;
===Fragment of the data===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ID ||i2 ||age ||treat ||homeless ||pcs ||mcs ||cesd ||indtot ||pss_fr ||drugrisk ||sexrisk ||satreat ||female ||substance ||racegrp&lt;br /&gt;
|-&lt;br /&gt;
| 1 ||0 ||25 ||0 ||0 ||49 ||7 ||46 ||37 ||0 ||1 ||6 ||0 ||0 ||cocaine ||black&lt;br /&gt;
|-&lt;br /&gt;
| 2 ||18 ||31 ||0 ||0 ||48 ||34 ||17 ||48 ||0 ||0 ||11 ||0 ||0 ||alcohol ||white&lt;br /&gt;
|-&lt;br /&gt;
| 3 ||39 ||36 ||0 ||0 ||76 ||9 ||33 ||41 ||12 ||19 ||4 ||0 ||0 ||heroin ||black&lt;br /&gt;
|-&lt;br /&gt;
| … || || || || || || || || || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| 100 ||81 ||22 ||0 ||0 ||37 ||17 ||19 ||30 ||3 ||0 ||10 ||0 ||0 ||alcohol ||other&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing section===&lt;br /&gt;
&lt;br /&gt;
 summary(data_1)&lt;br /&gt;
 &lt;br /&gt;
 x.norm &amp;lt;- rnorm(n=200, m=10, sd=20)&lt;br /&gt;
 hist(x.norm, main=&amp;quot;N(10,20) Histogram&amp;quot;)&lt;br /&gt;
 hist(x.norm, main=&amp;quot;N(10,20) Histogram&amp;quot;)&lt;br /&gt;
 mean(data_1$\$$age)&lt;br /&gt;
 sd(data_1$\$$age)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Simulate New Data to Match the Properties/Characteristics of Observed Data==&lt;br /&gt;
&lt;br /&gt;
*i2 [0: 184]&lt;br /&gt;
*age m=34,sd=12&lt;br /&gt;
*treat {0,1}&lt;br /&gt;
*homeless {0,1}&lt;br /&gt;
*pcs 14-75&lt;br /&gt;
*mcs 7-62&lt;br /&gt;
*cesd 0–60&lt;br /&gt;
*indtot 4-45&lt;br /&gt;
*pss_fr 0-14&lt;br /&gt;
*drugrisk 0-21&lt;br /&gt;
*sexrisk&lt;br /&gt;
*satreat (0=no,1=yes)&lt;br /&gt;
*female (0=no,1=yes)&lt;br /&gt;
*racegrp (black, white, other)&lt;br /&gt;
 &lt;br /&gt;
 # Demographics variables&lt;br /&gt;
 Sex &amp;lt;- ifelse(runif(NumSubj)&amp;lt;.5,0,1)&lt;br /&gt;
 Weight &amp;lt;- as.integer(rnorm(NumSubj, 80,10))&lt;br /&gt;
 Age &amp;lt;- as.integer(rnorm(NumSubj, 62,10))&lt;br /&gt;
&lt;br /&gt;
 # Diagnosis:&lt;br /&gt;
 Dx &amp;lt;- c(rep(&amp;quot;PD&amp;quot;, 100), rep(&amp;quot;HC&amp;quot;, 100), rep(&amp;quot;SWEDD&amp;quot;, 82))&lt;br /&gt;
&lt;br /&gt;
 # Genetics&lt;br /&gt;
 chr12_rs34637584_GT &amp;lt;- c(ifelse(runif(100)&amp;lt;.3,0,1), ifelse(runif(100)&amp;lt;.6,0,1), ifelse(runif(82)&amp;lt;.4,0,1))                              # NumSubj Bernoulli trials&lt;br /&gt;
 chr17_rs11868035_GT &amp;lt;- c(ifelse(runif(100)&amp;lt;.7,0,1), ifelse(runif(100)&amp;lt;.4,0,1), ifelse(runif(82)&amp;lt;.5,0,1))                              # NumSubj Bernoulli trials&lt;br /&gt;
&lt;br /&gt;
 # Clinical          # rpois(NumSubj, 15) + rpois(NumSubj, 6)&lt;br /&gt;
 UPDRS_part_I &amp;lt;- c( ifelse(runif(100)&amp;lt;.7,0,1)+ifelse(runif(100)&amp;lt;.7,0,1),&lt;br /&gt;
 ifelse(runif(100)&amp;lt;.6,0,1)+ ifelse(runif(100)&amp;lt;.6,0,1),&lt;br /&gt;
 ifelse(runif(82)&amp;lt;.4,0,1)+ ifelse(runif(82)&amp;lt;.4,0,1) )&lt;br /&gt;
 UPDRS_part_II &amp;lt;- c(sample.int(20, 100, replace=T), sample.int(14, 100, replace=T),&lt;br /&gt;
 sample.int(18, 82, replace=T) )&lt;br /&gt;
 UPDRS_part_III &amp;lt;- c(sample.int(30, 100, replace=T), sample.int(20, 100, replace=T),&lt;br /&gt;
    sample.int(25, 82, replace=T) )&lt;br /&gt;
&lt;br /&gt;
 # Time: VisitTime – done automatically below in aggregator&lt;br /&gt;
&lt;br /&gt;
 # Data (putting all components together)&lt;br /&gt;
 sim_PD_Data &amp;lt;- cbind(&lt;br /&gt;
           rep(Cases, each= NumTime),                          # Cases&lt;br /&gt;
           rep(L_caudate_ComputeArea, each= NumTime), # Imaging&lt;br /&gt;
           rep(Sex, each= NumTime),                            # Demographics&lt;br /&gt;
           rep(Weight, each= NumTime),&lt;br /&gt;
           rep(Age, each= NumTime),&lt;br /&gt;
           rep(Dx, each= NumTime),                             # Dx&lt;br /&gt;
           rep(chr12_rs34637584_GT, each= NumTime),            # Genetics&lt;br /&gt;
           rep(chr17_rs11868035_GT, each= NumTime),&lt;br /&gt;
           rep(UPDRS_part_I, each= NumTime),                   # Clinical&lt;br /&gt;
           rep(UPDRS_part_II, each= NumTime),&lt;br /&gt;
           rep(UPDRS_part_III, each= NumTime),&lt;br /&gt;
           rep(c(0,6,12,18), NumSubj)                          # Time&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # Assign the column names&lt;br /&gt;
 colnames(sim_PD_Data) &amp;lt;- c(&lt;br /&gt;
 &amp;quot;Cases&amp;quot;,&lt;br /&gt;
 &amp;quot;L_caudate_ComputeArea&amp;quot;,&lt;br /&gt;
 &amp;quot;Sex&amp;quot;, &amp;quot;Weight&amp;quot;, &amp;quot;Age&amp;quot;,&lt;br /&gt;
 &amp;quot;Dx&amp;quot;, &amp;quot;chr12_rs34637584_GT&amp;quot;, &amp;quot;chr17_rs11868035_GT&amp;quot;,&lt;br /&gt;
 &amp;quot;UPDRS_part_I&amp;quot;, &amp;quot;UPDRS_part_II&amp;quot;, &amp;quot;UPDRS_part_III&amp;quot;,&lt;br /&gt;
 &amp;quot;Time&amp;quot;&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # some QC&lt;br /&gt;
 summary(sim_PD_Data)&lt;br /&gt;
 dim(sim_PD_Data)&lt;br /&gt;
 head(sim_PD_Data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
.....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_DataSimulation_Fig1.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
....&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_DataSimulation}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM_Assumptions&amp;diff=16186</id>
		<title>SMHS LinearModeling LMM Assumptions</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM_Assumptions&amp;diff=16186"/>
		<updated>2016-05-23T13:58:56Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Example of Logistic Regression */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling_LMM| Linear mixed effects analyses]] - Mixed Effect Model Assumptions==&lt;br /&gt;
&lt;br /&gt;
First review the [[SMHS_LinearModeling_LMM | Linear mixed effects analyses section]].&lt;br /&gt;
&lt;br /&gt;
The [[SMHS_LinearModeling_MLR_VizModelCoeff |same conditions we have in the fixed effect multivariate linear model]] apply to mixed and random effect models – co-linearity, influential data points, homoscedasticity, and lack of normality. These assumptions can be checked by creating residual plots, histogram plots of the residuals or a Q-Q normal probability plots.&lt;br /&gt;
&lt;br /&gt;
The fixed effect independence condition is relaxed in mixed/random effect models, as this was the main motivation for mixed models – to resolve dependencies in the data. Mixed effect models still require independence, e.g., when ignoring independent and including just a fixed effect for a variable of interest. For instance, working with a model that does not include a random effect “Player”, we have multiple Weight responses per Player. This would violate the LME model independence assumption. Careful selection of fixed effects and random effects is necessary to resolve potential dependencies in the data.&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;b&amp;gt;&amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;dfbeta() can’t be used for assessing influential data points in mixed effects linear models &amp;lt;/span&amp;gt;&amp;lt;/b&amp;gt; the way it can for fixed effect models. To check for influential points in mixed effect models the package &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;influence.ME&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt; or a &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;leave-one-out validation&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; can be employed. &lt;br /&gt;
&lt;br /&gt;
For example, we can define a vector of size equal to the number of rows in the data. Iterating over each row (i), we estimate a new mixed model excluding the current row index (data[-i,]). The function fixef() extracts the coefficients of interest, which can be adapted to the specific analysis. Running fixef() on the linear model yields the position of the relevant coefficient. For example, position “1” refers to the intercept (which is always the first coefficient mentioned in the coefficient table) and position “2” reflects the effect of “Height” appears second in the list of coefficients.&lt;br /&gt;
&lt;br /&gt;
 df &amp;lt;- as.data.frame(data)&lt;br /&gt;
 all.res=numeric(nrow(df)) &lt;br /&gt;
 for(i in 1:nrow(df))&lt;br /&gt;
 { 		# Generic&lt;br /&gt;
 # myfullmodel=lmer(response~predictor+ (1+predictor|randomeffect))&lt;br /&gt;
 # results[i]=fixef(myfullmodel)[parameter position index]&lt;br /&gt;
 fullmodel=lmer(Weight~Height+ (1+Height|Team), data=data[-i,])&lt;br /&gt;
 results[i]=fixef(fullmodel)[2]&lt;br /&gt;
 echo (&amp;quot;Row = &amp;quot;, i)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Comments&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fixed effects represent explanatory predictors that are expected to have a systematic and predictable influence on the data (response). Whereas random effects represent covariates expected to have a non-systematic, idiosyncratic, unpredictable, or “random” influence on the response variable. Examples of such random effects in experimental studies include “subject/patient/player/unit” and “Age”, as we generally have no control over idiosyncrasies of individual subjects or their age at time of observation.&lt;br /&gt;
&lt;br /&gt;
Often fixed effects are expected to exhaust the population of interest, or the levels of a factor. In the MLB study the factor “Team” may not exhaust the space as there are other teams/leagues. However, for MLB at a fixed time, the “Team” factor may be fully exhaustive. Same with Height. Random effects represent sub-samples from the population of interest and may not “exhaust” the population as more players or teams could be included in the study. The levels of random factor may only represent a small sub-subset of all levels of the factor.&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity===&lt;br /&gt;
Use these cancer data (http://www.ats.ucla.edu/stat/data/hdp.csv), representing cancer phenotypes and predictors (e.g., &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;) and outcome measures (e.g., remission) collected on patients, nested within doctors (DID) and within hospitals (HID). To fit a mixed model (http://www.ats.ucla.edu/stat/r/dae/melogit.htm) and examine remissions as cancer outcomes.&lt;br /&gt;
&lt;br /&gt;
This lung cancer dataset includes a variety of outcomes collected on patients, nested within doctors, who are in turn nested within hospitals. Doctor level variables include experience.&lt;br /&gt;
 hdp &amp;lt;- read.csv(&amp;quot;http://www.ats.ucla.edu/stat/data/hdp.csv&amp;quot;)&lt;br /&gt;
 hdp &amp;lt;- within(hdp, {&lt;br /&gt;
 Married &amp;lt;- factor(Married, levels = 0:1, labels = c(&amp;quot;no&amp;quot;, &amp;quot;yes&amp;quot;))&lt;br /&gt;
 DID &amp;lt;- factor(DID)&lt;br /&gt;
 HID &amp;lt;- factor(HID)&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Plot several continuous predictor variables to examine the distributions and catch coding errors (e.g., if values range from 0 to 7, but we see a 999), and explore the relationship among our variables. &lt;br /&gt;
 # install.packages(&amp;quot;ggally&amp;quot;)&lt;br /&gt;
 # library(GGally)&lt;br /&gt;
 # library(&amp;quot;ggplot2&amp;quot;)&lt;br /&gt;
 # ggpairs (hdp[, c(&amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig35.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Are there strong linear relations among the continuous variables? Examine CancerStage and LengthofStay closer. The area of bubbles is proportional to the number of observations with the corresponding values. &lt;br /&gt;
&lt;br /&gt;
Violin plots may be used for continuous predictors. We can render all raw data separated by CancerStage. To reduce overlaying, we can add some random noise (along the x axis) or alternatively set the alpha opacity level. &lt;br /&gt;
Note that IL6 and CRP have skewed distributions indicating that we use a square root scale on the y axes. The distributions appear normal and symmetric with long right tails, even after square root transformation.&lt;br /&gt;
 ggplot(hdp, aes(x = CancerStage, y = LengthofStay)) +&lt;br /&gt;
 stat_sum(aes(size = ..n.., group = 1)) +&lt;br /&gt;
 scale_size_area(max_size=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig36.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;reshape&amp;quot;) &lt;br /&gt;
 # library(reshape)&lt;br /&gt;
 tmp &amp;lt;- melt(hdp[, c(&amp;quot;CancerStage&amp;quot;, &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;)], id.vars=&amp;quot;CancerStage&amp;quot;)&lt;br /&gt;
 ggplot(tmp, aes(x = CancerStage, y = value)) +&lt;br /&gt;
 geom_jitter(alpha = .1) +&lt;br /&gt;
 geom_violin(alpha = .75) +&lt;br /&gt;
 facet_grid(variable ~ .) +&lt;br /&gt;
 scale_y_sqrt()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig37.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The distribution of continuous variables at each level of the binary outcome to provide a better depiction of the change of the binary variables over levels of continuous variables.&lt;br /&gt;
 tmp &amp;lt;- melt(hdp[, c(&amp;quot;remission&amp;quot;, &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;)], id.vars=&amp;quot;remission&amp;quot;)&lt;br /&gt;
 ggplot(tmp, aes(factor(remission), y = value, fill=factor(remission)))+ geom_boxplot() + facet_wrap(~variable, scales=&amp;quot;free_y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig38.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Types of Data Analyses&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*Mixed effects logistic regression, the focus of this page. &lt;br /&gt;
*Mixed effects probit regression is very similar to mixed effects logistic regression, but it uses the normal CDF instead of the logistic CDF. Both model binary outcomes and can include fixed and random effects. (Note: This link function, aka Probit link, defined in the 1930’s by biologists studying the dosage-cure rate link, refers to the “probability unit”. It’s kind of the inverse CDF, of the model: if Y = Φ(Xβ+ ε), then Probit link = Φ^(-1) (Y). &lt;br /&gt;
*Fixed effects logistic regression is limited in this case because it may ignore necessary random effects and/or non-independence in the data.&lt;br /&gt;
*Fixed effects probit regression is limited in this case because it may ignore necessary random effects and/or non-independence in the data.&lt;br /&gt;
*Logistic regression with clustered standard errors. These can adjust for non-independence but does not allow for random effects.&lt;br /&gt;
*Probit regression with clustered standard errors. These can adjust for non-independence but does not allow for random effects.&lt;br /&gt;
&lt;br /&gt;
===Mixed Effects Logistic Regression===&lt;br /&gt;
&lt;br /&gt;
The glmer model can be used to estimate a mixed effects logistic regression model with Il6, CRP, and LengthofStay as patient level continuous predictors, CancerStage as a patient level categorical predictor (I, II, III, or IV), Experience as a doctor level continuous predictor, and a random intercept by DID, doctor ID.&lt;br /&gt;
Estimating and interpreting generalized linear mixed models (GLMMs, of which mixed effects logistic regression is one) can be quite challenging. &lt;br /&gt;
 # estimate the model and store results in m&lt;br /&gt;
 # library(&amp;quot;lme4&amp;quot;)&lt;br /&gt;
 m1 &amp;lt;- glmer(remission ~ IL6 + CRP + CancerStage + LengthofStay + Experience +&lt;br /&gt;
 (1 | DID), data = hdp, family = binomial, control = glmerControl(optimizer = &amp;quot;bobyqa&amp;quot;), nAGQ = 10)&lt;br /&gt;
&lt;br /&gt;
 # print the mod results without correlations among fixed effects&lt;br /&gt;
 print(m1, corr = FALSE)&lt;br /&gt;
&lt;br /&gt;
Generalized linear mixed model fit by maximum likelihood&lt;br /&gt;
  (Adaptive Gauss-Hermite Quadrature, nAGQ = 10) [glmerMod]&lt;br /&gt;
 Family: binomial  ( logit )&lt;br /&gt;
&lt;br /&gt;
This part conforms the estimates (based on an adaptive Gaussian Hermite approximation of the likelihood) using 10 integrations. More integration points improves the approximation (convergnce to the ML estimates), however, increase the computational requirements.&amp;lt;BR&amp;gt;&lt;br /&gt;
To avoid a warning of nonconvergence, we specify a different optimizer with the argument control=glmerControl(optimizer=&amp;quot;bobyqa&amp;quot;). Although the model will produce nearly identical results without the new argument, we prefer to use models without such warnings. &lt;br /&gt;
&lt;br /&gt;
Formula: &amp;lt;BR&amp;gt;&lt;br /&gt;
remission ~ IL6 + CRP + CancerStage + LengthofStay + Experience +  (1 | DID)&amp;lt;BR&amp;gt;&lt;br /&gt;
Data: hdp&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|AIC||BIC||LogLik||Deviance||df. resid.&lt;br /&gt;
|-&lt;br /&gt;
|7397.276||7460.733||-3689.638||7379.276||8516&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Random effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|Groups Name||Std. Deviation.&lt;br /&gt;
|-&lt;br /&gt;
|DID (Intercept)||2.015&lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 8525, groups:  DID, 407 &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section gives the basic information to compare models, and lists the random effect estimates. This represents the estimated variability in the intercept on the logit scale. When there are other random effects, e.g., random slopes, they are included here. &lt;br /&gt;
&lt;br /&gt;
The total number of observations, and the number of level 2 observations, the total number of patients (8,525) and doctors (407) are reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|(Intercept)||IL6||CRP||CancerStageII&lt;br /&gt;
|-&lt;br /&gt;
|-2.05271||-0.05677||-0.02148||-0.41393&lt;br /&gt;
|-		&lt;br /&gt;
|CancerStageIII||CancerStageIV||LengthofStay||Experience&lt;br /&gt;
|-&lt;br /&gt;
|-1.00346||-2.33703||-0.12118||7379.276||0.12009&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The part includes a table of the fixed effects estimates. The estimates represent the regression coefficients, which are raw/unstandardized on the logit scale. &lt;br /&gt;
&lt;br /&gt;
The estimates are followed by their standard errors (SEs). As is common in GLMs, the SEs are obtained by inverting the observed information matrix (negative second derivative matrix). However, for GLMMs, this is again an approximation. The approximations of the coefficient estimates likely stabilize faster than do those for the SEs. Thus if you are using fewer integration points, the estimates may be reasonable, but the approximation of the SEs may be less accurate. The Wald tests, Estimate/SE, rely on asymptotic theory, here referring to as the highest level unit size converges to infinity, these tests will be normally distributed, and from that, p values (the probability of obtaining the observed estimate or more extreme, given the true estimate is 0).&lt;br /&gt;
&lt;br /&gt;
To obtain confidence intervals (CIs) using the SE estimates:&lt;br /&gt;
&lt;br /&gt;
 se &amp;lt;- sqrt(diag(vcov(m1)))&lt;br /&gt;
 # table of estimates with 95% CI, fixef = Extract fixed-effects estimates&lt;br /&gt;
 (tab &amp;lt;- cbind(Est = fixef(m1), LL = fixef(m1) - 1.96 * se, UL = fixef(m1) + 1.96 * se))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| ||Est||LL||UL&lt;br /&gt;
|-		&lt;br /&gt;
|(Intercept)||-2.05270650||-3.09434022||-1.011072788&lt;br /&gt;
|-&lt;br /&gt;
|IL6||-0.05677184||-0.07934785||-0.034195828&lt;br /&gt;
|-&lt;br /&gt;
|CRP||-0.02148295||-0.04151100||-0.001454894&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageII||-0.41393353||-0.56243063||-0.265436433&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIII||-1.00346481||-1.19609924||-0.810830385&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIV||-2.33703403||-2.64682910||-2.027238952&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||-0.12118216||-0.18710346||-0.055260857&lt;br /&gt;
|-&lt;br /&gt;
|Experience||0.12008900||0.06628364||0.173894365&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of coefficients on the logit scale, we can report the add odds ratios by exponentiating the estimates and CIs. &amp;lt;BR&amp;gt;&lt;br /&gt;
exp(tab)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| ||Est||LL||UL&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||0.12838695||0.04530489||0.3638285&lt;br /&gt;
|-&lt;br /&gt;
|IL6||0.94480962||0.92371856||0.9663822&lt;br /&gt;
|-&lt;br /&gt;
|CRP||0.97874617||0.95933878||0.9985462&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageII||0.66104489||0.56982235||0.7668712&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIII||0.36660701||0.30237139||0.4444888&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIV||0.09661377||0.07087560||0.1316986&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||0.88587258||0.82935793||0.9462383&lt;br /&gt;
|-&lt;br /&gt;
|Experience||1.12759721||1.06852976||1.1899299&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 r1 &amp;lt;- ranef(m1)		# Extract the modes of the random effects&lt;br /&gt;
 r1.order &amp;lt;- r1[order(r1$\$$DID),]&lt;br /&gt;
 # install.packages(&amp;quot;lattice&amp;quot;)&lt;br /&gt;
 dotplot(ranef(m1,condVar=TRUE), lattice.options=list(layout=c(1,2)))&lt;br /&gt;
&lt;br /&gt;
 # Inference&lt;br /&gt;
 VarCorr(m1); anova(m1); intervals(m1)&lt;br /&gt;
&lt;br /&gt;
===Example of Logistic Regression===&lt;br /&gt;
(1)	Logistic curve:&lt;br /&gt;
$y=f(x)=\frac{1}{1+e^{-x}}$,&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;i&amp;gt;y&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;x&amp;lt;/i&amp;gt; represent probability and quantitative-predictor values, respectively.&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- seq(-10,10,1)&lt;br /&gt;
 plot(x,1/(1+exp(-x)), type=&amp;quot;l&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig39.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The point of this logistic curve is:&amp;lt;BR&amp;gt;&lt;br /&gt;
$y=\frac{1}{1+e^{-x}}$ ⇔ $x=ln(\frac{y}{1-y})$, &amp;lt;BR&amp;gt;&lt;br /&gt;
which is the '''log-odds'''&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; (when y is the probability of an event of interest)&lt;br /&gt;
&lt;br /&gt;
(2)Logistic regression equation model to estimate the probability of specific outcomes:&amp;lt;BR&amp;gt;&lt;br /&gt;
(''Estimate of'') ''P'' (''Y''=1|$x_1,x_2,...,x_1)=\frac{1}{1+e^{-(a_o+\sum_{k=1}a_kx_k)}}$ &amp;lt;BR&amp;gt;&lt;br /&gt;
the coefficients a&amp;lt;sub&amp;gt;o&amp;lt;/sub&amp;gt;,  (intercept) and $a_k, k = 1,2,...,l$, are estimated using GLM according to a maximum likelihood approach. Using this model allows us to estimate the probability of the dependent (outcome) variable ''Y''=1 (CO), i.e., surviving surgery, given the observed values of the predictors $X_k,k = 1,2,...,l.$&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Probability of Surviving a Heart Transplant Based on Surgeon’s Experience:&amp;lt;/b&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
A group of 20 patients undergo heart transplantation with different surgeons having experience in the range {0(least), 2…, 10(most)}, representing 100’s of operating/surgery hours. How does the surgeon’s experience affect the probability of the patient survival? &amp;lt;BR&amp;gt;&lt;br /&gt;
The data is shown below and represents each patient and the outcome of the surgery (1=survival) or (0=death).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|Surgeon's Experience||1||1.5||2||2.5||3||3.5||3.5||4||4.5||5||5.5||6||6.5||7||8||8.5||9||9.5||10||10&lt;br /&gt;
|-&lt;br /&gt;
|Clinical Outcome||0||0||0||0||0||0||1||0||1||0||1||0||1||0||1||1||1||1||1||1&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 mydata &amp;lt;- read.csv('https://umich.instructure.com/files/405273/download?download_frd=1&amp;amp;verifier=AOny2eq3wF7WqWAV5YsT6e9zakRTEbZpcuNYRdtM')  # 01_HeartSurgerySurvivalData.csv&lt;br /&gt;
 # estimates a logistic regression model for the clinical outcome (CO), survival, using the glm &lt;br /&gt;
 # (generalized linear model) function. &lt;br /&gt;
 # convert Surgeon’s Experience (SE) to a factor to indicate it should be treated as a categorical variable.&lt;br /&gt;
 # mydata$\$$rank &amp;lt;- factor(mydata$\$$SE)&lt;br /&gt;
 mylogit &amp;lt;- glm(CO ~ SE, data = mydata, family = &amp;quot;binomial&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 ggplot(mydata, aes(x=SE, y=CO)) + geom_point() + &lt;br /&gt;
  		stat_smooth(method=&amp;quot;glm&amp;quot;, family=&amp;quot;binomial&amp;quot;, se=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Graph of a Logistic Regression Curve Showing Probability of Surviving the Surgery versus Surgeon’s Experience.&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig40.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The graph shows the probability of the clinical outcome, survival, (Y-axis) versus the surgeon’s experience (X-axis), with the logistic regression curve fitted to the data.&lt;br /&gt;
&lt;br /&gt;
 mylogit &amp;lt;- glm(CO ~ SE, data = mydata, family = &amp;quot;binomial&amp;quot;)&lt;br /&gt;
 summary(mylogit)&lt;br /&gt;
&lt;br /&gt;
The logistic regression analysis gives the following output.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate Std.||Error||z value||Pr (&amp;gt;z) Wald&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||-4.1030||1.7629||-2.327||0.0199 *&lt;br /&gt;
|-&lt;br /&gt;
|SE||0.7583||0.3139||2.416||&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;0.0157&amp;lt;/u&amp;gt; *&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output indicates that surgeon’s experience (SE) is significantly associated with the probability of surviving the surgery (0.0157, Wald test). The output also provides the &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;coefficients&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; for:&lt;br /&gt;
&lt;br /&gt;
''Intercept'' = -4.1030 and  ''SE'' = 0.7583.&lt;br /&gt;
&lt;br /&gt;
*Probability of surviving heart surgery CO =1/(1+exp(-(-4.1030+0.7583×SE)))&lt;br /&gt;
*For example, for a patient who is operated by a surgeon with 200 hours of operating experience (SE=2), we plug in the value 2 in the equation to get an estimated probability of survival, &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;p=0.07:&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SE=2;&amp;lt;/b&amp;gt; &amp;lt;BR&amp;gt;&lt;br /&gt;
CO =1/(1+exp(-(-4.1030+0.7583*SE)))&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; CO&amp;lt;BR&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
[1] &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;0.07001884&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Similarly, a patient undergoing heart surgery with a doctor that has 400 operating hours experience (SE=4), the estimated probability of survival is &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p=0.26:&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;SE=4;&amp;lt;/b&amp;gt; CO =1/(1+exp(-(-4.1030+0.7583*SE))); CO &amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; CO&amp;lt;BR&amp;gt;&lt;br /&gt;
[1] &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;0.2554411&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The table below shows the probability of surviving surgery for several values of surgeons’ experience:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|Surgeon's Experience||Probability of Patient Survival (Clinical Outcome)&lt;br /&gt;
|-&lt;br /&gt;
|1||0.034&lt;br /&gt;
|-&lt;br /&gt;
|2||0.07&lt;br /&gt;
|-&lt;br /&gt;
|3||0.14&lt;br /&gt;
|-&lt;br /&gt;
|4||0.26&lt;br /&gt;
|-&lt;br /&gt;
|5||0.423&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output from the logistic regression analysis gives a p-value of p=0.0157, which is based on the Wald z-score. In addition to the Wald method, we can calculate the p-value for logistic regression &amp;lt;i&amp;gt;(mylogit &amp;lt;- glm(CO ~ SE,data = mydata,family = &amp;quot;binomial&amp;quot;))&amp;lt;/i&amp;gt; using the &amp;lt;b&amp;gt;Likelihood Ratio Test (LRT)&amp;lt;/b&amp;gt;, which for these data give &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;0.0006476922&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate Std.||Error||z value||Pr (&amp;gt;z) Wald&lt;br /&gt;
|-&lt;br /&gt;
|SE||0.7583||0.3139||2.416||&amp;lt;b&amp;gt;0.0157&amp;lt;/b&amp;gt; *&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logit of a number $0≤p≤1$ given by the formula: $logit(p) = log(\frac{p}{1-p})$ representing the &amp;lt;b&amp;gt;log-odds&amp;lt;/b&amp;gt; (of survival in this case).&lt;br /&gt;
&lt;br /&gt;
 confint(mylogit) &lt;br /&gt;
&lt;br /&gt;
So, why exponentiating the coefficients? Because,&lt;br /&gt;
&lt;br /&gt;
$logit(p)=log(\frac{p}{1-p})&amp;amp;#8594; e^{logit(p)}=e^{log(\frac{p}{1-p})}&amp;amp;#8594; RHS=\frac{p}{1-p}$ &amp;lt;b&amp;gt;(odds-ratio, OR)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; exp(coef(mylogit)) 	 # exponentiated logit model coefficients&amp;lt;/font&amp;gt;&lt;br /&gt;
 (Intercept)          	SE &lt;br /&gt;
 0.01652254  		2.13474149   ## == exp(0.7583456)&lt;br /&gt;
 &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; coef(mylogit)    	# raw logit model coefficients&amp;lt;/font&amp;gt; &lt;br /&gt;
 (Intercept)          	SE &lt;br /&gt;
 -4.1030298   		0.7583456&lt;br /&gt;
&lt;br /&gt;
 exp(cbind(OR = coef(mylogit), confint(mylogit)))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;OR&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;||2.5%||97.5%&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||0.01652254||0.0001825743||0.277290&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;SE&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;2.13474149&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;1.3083794719&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;4.839986&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 with(mylogit, df.null - df.residual)&lt;br /&gt;
&lt;br /&gt;
Finally, the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;LRT (likelihood-ratio test)  p-value&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; can be obtained using:&lt;br /&gt;
&lt;br /&gt;
 with(mylogit, pchisq(null.deviance - deviance, df.null - df.residual, lower.tail = FALSE))&lt;br /&gt;
&lt;br /&gt;
[1] &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;0.0006476922&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The LRT &amp;lt;i&amp;gt;p_value&amp;lt;/i&amp;gt; &amp;lt; 0.001 tells us that our model as a whole fits significantly better than an empty model. The deviance residual is -2*log likelihood, and to see the model's log likelihood:&lt;br /&gt;
&lt;br /&gt;
 logLik(mylogit)&lt;br /&gt;
 'log Lik.' -8.046117 (df=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Side-note&amp;lt;/b&amp;gt;: The LRT compares the data fit of two models. For instance, removing predictor variables from a model will reduce model quality (i.e., a model will have a lower log likelihood). To statistically assess whether the observed difference in model fit is significant, the LRT compares the difference of the log likelihoods of the two models. When this difference is statistically significant, the full model (the one with more variables) is a better fit to the data, compared to the reduced model. LRT is computed from the log likelihoods of the models:&lt;br /&gt;
&lt;br /&gt;
$LRT=-2ln\Big(\frac{L(m1)}{L(m2)}\Big)=2(ll(m2)-ll(m1)) $,&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;i&amp;gt;m1&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;m2&amp;lt;/i&amp;gt; are the reduced and the full models, respectively, &amp;lt;i&amp;gt;L(m1)&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;L(m2)&amp;lt;/i&amp;gt; denote the likelihoods of the 2 models, and &amp;lt;i&amp;gt;ll(m1)&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;ll(m2)&amp;lt;/i&amp;gt; represent the log likelihood (natural log of the model likelihood.&lt;br /&gt;
&lt;br /&gt;
The distribution of the LRT is chi-squared with degrees of freedom equal to the number of parameters that are reduced (i.e., the number of variables removed from the model). In our case,&lt;br /&gt;
&lt;br /&gt;
$LRT \sim X^2_{df=2}$ as we have an intercept and one predictor (SE), and the null model is empty (no parameters).&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
* &amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt; http://cran.r-project.org/web/packages/influence.ME/influence.ME.pdf&lt;br /&gt;
* &amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt; http://www.ats.ucla.edu/stat/mult_pkg/glmm.htm&lt;br /&gt;
* &amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; http://wiki.socr.umich.edu/index.php/SMHS_OR_RR&lt;br /&gt;
&lt;br /&gt;
==Next See==&lt;br /&gt;
[[SMHS_LinearModeling_MachineLearning|Machine Learning Algorithms section]] for data modeling, training , testing, forecasting, prediction, and simulation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM_Assumptions}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM_Assumptions&amp;diff=16184</id>
		<title>SMHS LinearModeling LMM Assumptions</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM_Assumptions&amp;diff=16184"/>
		<updated>2016-05-23T13:58:12Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Types of Data Analyses16 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling_LMM| Linear mixed effects analyses]] - Mixed Effect Model Assumptions==&lt;br /&gt;
&lt;br /&gt;
First review the [[SMHS_LinearModeling_LMM | Linear mixed effects analyses section]].&lt;br /&gt;
&lt;br /&gt;
The [[SMHS_LinearModeling_MLR_VizModelCoeff |same conditions we have in the fixed effect multivariate linear model]] apply to mixed and random effect models – co-linearity, influential data points, homoscedasticity, and lack of normality. These assumptions can be checked by creating residual plots, histogram plots of the residuals or a Q-Q normal probability plots.&lt;br /&gt;
&lt;br /&gt;
The fixed effect independence condition is relaxed in mixed/random effect models, as this was the main motivation for mixed models – to resolve dependencies in the data. Mixed effect models still require independence, e.g., when ignoring independent and including just a fixed effect for a variable of interest. For instance, working with a model that does not include a random effect “Player”, we have multiple Weight responses per Player. This would violate the LME model independence assumption. Careful selection of fixed effects and random effects is necessary to resolve potential dependencies in the data.&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;b&amp;gt;&amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;dfbeta() can’t be used for assessing influential data points in mixed effects linear models &amp;lt;/span&amp;gt;&amp;lt;/b&amp;gt; the way it can for fixed effect models. To check for influential points in mixed effect models the package &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;influence.ME&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt; or a &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;leave-one-out validation&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; can be employed. &lt;br /&gt;
&lt;br /&gt;
For example, we can define a vector of size equal to the number of rows in the data. Iterating over each row (i), we estimate a new mixed model excluding the current row index (data[-i,]). The function fixef() extracts the coefficients of interest, which can be adapted to the specific analysis. Running fixef() on the linear model yields the position of the relevant coefficient. For example, position “1” refers to the intercept (which is always the first coefficient mentioned in the coefficient table) and position “2” reflects the effect of “Height” appears second in the list of coefficients.&lt;br /&gt;
&lt;br /&gt;
 df &amp;lt;- as.data.frame(data)&lt;br /&gt;
 all.res=numeric(nrow(df)) &lt;br /&gt;
 for(i in 1:nrow(df))&lt;br /&gt;
 { 		# Generic&lt;br /&gt;
 # myfullmodel=lmer(response~predictor+ (1+predictor|randomeffect))&lt;br /&gt;
 # results[i]=fixef(myfullmodel)[parameter position index]&lt;br /&gt;
 fullmodel=lmer(Weight~Height+ (1+Height|Team), data=data[-i,])&lt;br /&gt;
 results[i]=fixef(fullmodel)[2]&lt;br /&gt;
 echo (&amp;quot;Row = &amp;quot;, i)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Comments&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fixed effects represent explanatory predictors that are expected to have a systematic and predictable influence on the data (response). Whereas random effects represent covariates expected to have a non-systematic, idiosyncratic, unpredictable, or “random” influence on the response variable. Examples of such random effects in experimental studies include “subject/patient/player/unit” and “Age”, as we generally have no control over idiosyncrasies of individual subjects or their age at time of observation.&lt;br /&gt;
&lt;br /&gt;
Often fixed effects are expected to exhaust the population of interest, or the levels of a factor. In the MLB study the factor “Team” may not exhaust the space as there are other teams/leagues. However, for MLB at a fixed time, the “Team” factor may be fully exhaustive. Same with Height. Random effects represent sub-samples from the population of interest and may not “exhaust” the population as more players or teams could be included in the study. The levels of random factor may only represent a small sub-subset of all levels of the factor.&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity===&lt;br /&gt;
Use these cancer data (http://www.ats.ucla.edu/stat/data/hdp.csv), representing cancer phenotypes and predictors (e.g., &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;) and outcome measures (e.g., remission) collected on patients, nested within doctors (DID) and within hospitals (HID). To fit a mixed model (http://www.ats.ucla.edu/stat/r/dae/melogit.htm) and examine remissions as cancer outcomes.&lt;br /&gt;
&lt;br /&gt;
This lung cancer dataset includes a variety of outcomes collected on patients, nested within doctors, who are in turn nested within hospitals. Doctor level variables include experience.&lt;br /&gt;
 hdp &amp;lt;- read.csv(&amp;quot;http://www.ats.ucla.edu/stat/data/hdp.csv&amp;quot;)&lt;br /&gt;
 hdp &amp;lt;- within(hdp, {&lt;br /&gt;
 Married &amp;lt;- factor(Married, levels = 0:1, labels = c(&amp;quot;no&amp;quot;, &amp;quot;yes&amp;quot;))&lt;br /&gt;
 DID &amp;lt;- factor(DID)&lt;br /&gt;
 HID &amp;lt;- factor(HID)&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Plot several continuous predictor variables to examine the distributions and catch coding errors (e.g., if values range from 0 to 7, but we see a 999), and explore the relationship among our variables. &lt;br /&gt;
 # install.packages(&amp;quot;ggally&amp;quot;)&lt;br /&gt;
 # library(GGally)&lt;br /&gt;
 # library(&amp;quot;ggplot2&amp;quot;)&lt;br /&gt;
 # ggpairs (hdp[, c(&amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig35.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Are there strong linear relations among the continuous variables? Examine CancerStage and LengthofStay closer. The area of bubbles is proportional to the number of observations with the corresponding values. &lt;br /&gt;
&lt;br /&gt;
Violin plots may be used for continuous predictors. We can render all raw data separated by CancerStage. To reduce overlaying, we can add some random noise (along the x axis) or alternatively set the alpha opacity level. &lt;br /&gt;
Note that IL6 and CRP have skewed distributions indicating that we use a square root scale on the y axes. The distributions appear normal and symmetric with long right tails, even after square root transformation.&lt;br /&gt;
 ggplot(hdp, aes(x = CancerStage, y = LengthofStay)) +&lt;br /&gt;
 stat_sum(aes(size = ..n.., group = 1)) +&lt;br /&gt;
 scale_size_area(max_size=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig36.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;reshape&amp;quot;) &lt;br /&gt;
 # library(reshape)&lt;br /&gt;
 tmp &amp;lt;- melt(hdp[, c(&amp;quot;CancerStage&amp;quot;, &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;)], id.vars=&amp;quot;CancerStage&amp;quot;)&lt;br /&gt;
 ggplot(tmp, aes(x = CancerStage, y = value)) +&lt;br /&gt;
 geom_jitter(alpha = .1) +&lt;br /&gt;
 geom_violin(alpha = .75) +&lt;br /&gt;
 facet_grid(variable ~ .) +&lt;br /&gt;
 scale_y_sqrt()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig37.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The distribution of continuous variables at each level of the binary outcome to provide a better depiction of the change of the binary variables over levels of continuous variables.&lt;br /&gt;
 tmp &amp;lt;- melt(hdp[, c(&amp;quot;remission&amp;quot;, &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;)], id.vars=&amp;quot;remission&amp;quot;)&lt;br /&gt;
 ggplot(tmp, aes(factor(remission), y = value, fill=factor(remission)))+ geom_boxplot() + facet_wrap(~variable, scales=&amp;quot;free_y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig38.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Types of Data Analyses&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*Mixed effects logistic regression, the focus of this page. &lt;br /&gt;
*Mixed effects probit regression is very similar to mixed effects logistic regression, but it uses the normal CDF instead of the logistic CDF. Both model binary outcomes and can include fixed and random effects. (Note: This link function, aka Probit link, defined in the 1930’s by biologists studying the dosage-cure rate link, refers to the “probability unit”. It’s kind of the inverse CDF, of the model: if Y = Φ(Xβ+ ε), then Probit link = Φ^(-1) (Y). &lt;br /&gt;
*Fixed effects logistic regression is limited in this case because it may ignore necessary random effects and/or non-independence in the data.&lt;br /&gt;
*Fixed effects probit regression is limited in this case because it may ignore necessary random effects and/or non-independence in the data.&lt;br /&gt;
*Logistic regression with clustered standard errors. These can adjust for non-independence but does not allow for random effects.&lt;br /&gt;
*Probit regression with clustered standard errors. These can adjust for non-independence but does not allow for random effects.&lt;br /&gt;
&lt;br /&gt;
===Mixed Effects Logistic Regression===&lt;br /&gt;
&lt;br /&gt;
The glmer model can be used to estimate a mixed effects logistic regression model with Il6, CRP, and LengthofStay as patient level continuous predictors, CancerStage as a patient level categorical predictor (I, II, III, or IV), Experience as a doctor level continuous predictor, and a random intercept by DID, doctor ID.&lt;br /&gt;
Estimating and interpreting generalized linear mixed models (GLMMs, of which mixed effects logistic regression is one) can be quite challenging. &lt;br /&gt;
 # estimate the model and store results in m&lt;br /&gt;
 # library(&amp;quot;lme4&amp;quot;)&lt;br /&gt;
 m1 &amp;lt;- glmer(remission ~ IL6 + CRP + CancerStage + LengthofStay + Experience +&lt;br /&gt;
 (1 | DID), data = hdp, family = binomial, control = glmerControl(optimizer = &amp;quot;bobyqa&amp;quot;), nAGQ = 10)&lt;br /&gt;
&lt;br /&gt;
 # print the mod results without correlations among fixed effects&lt;br /&gt;
 print(m1, corr = FALSE)&lt;br /&gt;
&lt;br /&gt;
Generalized linear mixed model fit by maximum likelihood&lt;br /&gt;
  (Adaptive Gauss-Hermite Quadrature, nAGQ = 10) [glmerMod]&lt;br /&gt;
 Family: binomial  ( logit )&lt;br /&gt;
&lt;br /&gt;
This part conforms the estimates (based on an adaptive Gaussian Hermite approximation of the likelihood) using 10 integrations. More integration points improves the approximation (convergnce to the ML estimates), however, increase the computational requirements.&amp;lt;BR&amp;gt;&lt;br /&gt;
To avoid a warning of nonconvergence, we specify a different optimizer with the argument control=glmerControl(optimizer=&amp;quot;bobyqa&amp;quot;). Although the model will produce nearly identical results without the new argument, we prefer to use models without such warnings. &lt;br /&gt;
&lt;br /&gt;
Formula: &amp;lt;BR&amp;gt;&lt;br /&gt;
remission ~ IL6 + CRP + CancerStage + LengthofStay + Experience +  (1 | DID)&amp;lt;BR&amp;gt;&lt;br /&gt;
Data: hdp&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|AIC||BIC||LogLik||Deviance||df. resid.&lt;br /&gt;
|-&lt;br /&gt;
|7397.276||7460.733||-3689.638||7379.276||8516&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Random effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|Groups Name||Std. Deviation.&lt;br /&gt;
|-&lt;br /&gt;
|DID (Intercept)||2.015&lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 8525, groups:  DID, 407 &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section gives the basic information to compare models, and lists the random effect estimates. This represents the estimated variability in the intercept on the logit scale. When there are other random effects, e.g., random slopes, they are included here. &lt;br /&gt;
&lt;br /&gt;
The total number of observations, and the number of level 2 observations, the total number of patients (8,525) and doctors (407) are reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|(Intercept)||IL6||CRP||CancerStageII&lt;br /&gt;
|-&lt;br /&gt;
|-2.05271||-0.05677||-0.02148||-0.41393&lt;br /&gt;
|-		&lt;br /&gt;
|CancerStageIII||CancerStageIV||LengthofStay||Experience&lt;br /&gt;
|-&lt;br /&gt;
|-1.00346||-2.33703||-0.12118||7379.276||0.12009&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The part includes a table of the fixed effects estimates. The estimates represent the regression coefficients, which are raw/unstandardized on the logit scale. &lt;br /&gt;
&lt;br /&gt;
The estimates are followed by their standard errors (SEs). As is common in GLMs, the SEs are obtained by inverting the observed information matrix (negative second derivative matrix). However, for GLMMs, this is again an approximation. The approximations of the coefficient estimates likely stabilize faster than do those for the SEs. Thus if you are using fewer integration points, the estimates may be reasonable, but the approximation of the SEs may be less accurate. The Wald tests, Estimate/SE, rely on asymptotic theory, here referring to as the highest level unit size converges to infinity, these tests will be normally distributed, and from that, p values (the probability of obtaining the observed estimate or more extreme, given the true estimate is 0).&lt;br /&gt;
&lt;br /&gt;
To obtain confidence intervals (CIs) using the SE estimates:&lt;br /&gt;
&lt;br /&gt;
 se &amp;lt;- sqrt(diag(vcov(m1)))&lt;br /&gt;
 # table of estimates with 95% CI, fixef = Extract fixed-effects estimates&lt;br /&gt;
 (tab &amp;lt;- cbind(Est = fixef(m1), LL = fixef(m1) - 1.96 * se, UL = fixef(m1) + 1.96 * se))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| ||Est||LL||UL&lt;br /&gt;
|-		&lt;br /&gt;
|(Intercept)||-2.05270650||-3.09434022||-1.011072788&lt;br /&gt;
|-&lt;br /&gt;
|IL6||-0.05677184||-0.07934785||-0.034195828&lt;br /&gt;
|-&lt;br /&gt;
|CRP||-0.02148295||-0.04151100||-0.001454894&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageII||-0.41393353||-0.56243063||-0.265436433&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIII||-1.00346481||-1.19609924||-0.810830385&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIV||-2.33703403||-2.64682910||-2.027238952&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||-0.12118216||-0.18710346||-0.055260857&lt;br /&gt;
|-&lt;br /&gt;
|Experience||0.12008900||0.06628364||0.173894365&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of coefficients on the logit scale, we can report the add odds ratios by exponentiating the estimates and CIs. &amp;lt;BR&amp;gt;&lt;br /&gt;
exp(tab)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| ||Est||LL||UL&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||0.12838695||0.04530489||0.3638285&lt;br /&gt;
|-&lt;br /&gt;
|IL6||0.94480962||0.92371856||0.9663822&lt;br /&gt;
|-&lt;br /&gt;
|CRP||0.97874617||0.95933878||0.9985462&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageII||0.66104489||0.56982235||0.7668712&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIII||0.36660701||0.30237139||0.4444888&lt;br /&gt;
|-&lt;br /&gt;
|CancerStageIV||0.09661377||0.07087560||0.1316986&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||0.88587258||0.82935793||0.9462383&lt;br /&gt;
|-&lt;br /&gt;
|Experience||1.12759721||1.06852976||1.1899299&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 r1 &amp;lt;- ranef(m1)		# Extract the modes of the random effects&lt;br /&gt;
 r1.order &amp;lt;- r1[order(r1$\$$DID),]&lt;br /&gt;
 # install.packages(&amp;quot;lattice&amp;quot;)&lt;br /&gt;
 dotplot(ranef(m1,condVar=TRUE), lattice.options=list(layout=c(1,2)))&lt;br /&gt;
&lt;br /&gt;
 # Inference&lt;br /&gt;
 VarCorr(m1); anova(m1); intervals(m1)&lt;br /&gt;
&lt;br /&gt;
===Example of Logistic Regression===&lt;br /&gt;
(1)	Logistic curve:&lt;br /&gt;
$y=f(x)=\frac{1}{1+e^{-x}}$,&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;i&amp;gt;y&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;x&amp;lt;/i&amp;gt; represent probability and quantitative-predictor values, respectively.&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- seq(-10,10,1)&lt;br /&gt;
 plot(x,1/(1+exp(-x)), type=&amp;quot;l&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig39.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The point of this logistic curve is:&amp;lt;BR&amp;gt;&lt;br /&gt;
$y=\frac{1}{1+e^{-x}}$ ⇔ $x=ln(\frac{y}{1-y})$, &amp;lt;BR&amp;gt;&lt;br /&gt;
which is the '''log-odds'''&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; (when y is the probability of an event of interest)&lt;br /&gt;
&lt;br /&gt;
(2)Logistic regression equation model to estimate the probability of specific outcomes:&amp;lt;BR&amp;gt;&lt;br /&gt;
(''Estimate of'') ''P'' (''Y''=1|$x_1,x_2,...,x_1)=\frac{1}{1+e^{-(a_o+\sum_{k=1}a_kx_k)}}$ &amp;lt;BR&amp;gt;&lt;br /&gt;
the coefficients a&amp;lt;sub&amp;gt;o&amp;lt;/sub&amp;gt;,  (intercept) and $a_k, k = 1,2,...,l$, are estimated using GLM according to a maximum likelihood approach. Using this model allows us to estimate the probability of the dependent (outcome) variable ''Y''=1 (CO), i.e., surviving surgery, given the observed values of the predictors $X_k,k = 1,2,...,l.$&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Probability of Surviving a Heart Transplant Based on Surgeon’s Experience:&amp;lt;/b&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
A group of 20 patients undergo heart transplantation with different surgeons having experience in the range {0(least), 2…, 10(most)}, representing 100’s of operating/surgery hours. How does the surgeon’s experience affect the probability of the patient survival? &amp;lt;BR&amp;gt;&lt;br /&gt;
The data is shown below and represents each patient and the outcome of the surgery (1=survival) or (0=death).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|Surgeon's Experience||1||1.5||2||2.5||3||3.5||3.5||4||4.5||5||5.5||6||6.5||7||8||8.5||9||9.5||10||10&lt;br /&gt;
|-&lt;br /&gt;
|Clinical Outcome||0||0||0||0||0||0||1||0||1||0||1||0||1||0||1||1||1||1||1||1&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 mydata &amp;lt;- read.csv('https://umich.instructure.com/files/405273/download?download_frd=1&amp;amp;verifier=AOny2eq3wF7WqWAV5YsT6e9zakRTEbZpcuNYRdtM')  # 01_HeartSurgerySurvivalData.csv&lt;br /&gt;
 # estimates a logistic regression model for the clinical outcome (CO), survival, using the glm &lt;br /&gt;
 # (generalized linear model) function. &lt;br /&gt;
 # convert Surgeon’s Experience (SE) to a factor to indicate it should be treated as a categorical variable.&lt;br /&gt;
 # mydata$\$$rank &amp;lt;- factor(mydata$\$$SE)&lt;br /&gt;
 mylogit &amp;lt;- glm(CO ~ SE, data = mydata, family = &amp;quot;binomial&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 ggplot(mydata, aes(x=SE, y=CO)) + geom_point() + &lt;br /&gt;
  		stat_smooth(method=&amp;quot;glm&amp;quot;, family=&amp;quot;binomial&amp;quot;, se=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Graph of a Logistic Regression Curve Showing Probability of Surviving the Surgery versus Surgeon’s Experience.&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig40.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The graph shows the probability of the clinical outcome, survival, (Y-axis) versus the surgeon’s experience (X-axis), with the logistic regression curve fitted to the data.&lt;br /&gt;
&lt;br /&gt;
 mylogit &amp;lt;- glm(CO ~ SE, data = mydata, family = &amp;quot;binomial&amp;quot;)&lt;br /&gt;
 summary(mylogit)&lt;br /&gt;
&lt;br /&gt;
The logistic regression analysis gives the following output.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate Std.||Error||z value||Pr (&amp;gt;z) Wald&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||-4.1030||1.7629||-2.327||0.0199 *&lt;br /&gt;
|-&lt;br /&gt;
|SE||0.7583||0.3139||2.416||&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;0.0157&amp;lt;/u&amp;gt; *&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output indicates that surgeon’s experience (SE) is significantly associated with the probability of surviving the surgery (0.0157, Wald test). The output also provides the &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;coefficients&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; for:&lt;br /&gt;
&lt;br /&gt;
''Intercept'' = -4.1030 and  ''SE'' = 0.7583.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Probability of surviving heart surgery CO =1/(1+exp(-(-4.1030+0.7583×SE)))&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;For example, for a patient who is operated by a surgeon with 200 hours of operating experience (SE=2), we plug in the value 2 in the equation to get an estimated probability of survival, &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;p=0.07:&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SE=2;&amp;lt;/b&amp;gt; &amp;lt;BR&amp;gt;&lt;br /&gt;
CO =1/(1+exp(-(-4.1030+0.7583*SE)))&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; CO&amp;lt;BR&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
[1] &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;0.07001884&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Similarly, a patient undergoing heart surgery with a doctor that has 400 operating hours experience (SE=4), the estimated probability of survival is &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p=0.26:&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;SE=4;&amp;lt;/b&amp;gt; CO =1/(1+exp(-(-4.1030+0.7583*SE))); CO &amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; CO&amp;lt;BR&amp;gt;&lt;br /&gt;
[1] &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;0.2554411&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The table below shows the probability of surviving surgery for several values of surgeons’ experience:&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|Surgeon's Experience||Probability of Patient Survival (Clinical Outcome)&lt;br /&gt;
|-&lt;br /&gt;
|1||0.034&lt;br /&gt;
|-&lt;br /&gt;
|2||0.07&lt;br /&gt;
|-&lt;br /&gt;
|3||0.14&lt;br /&gt;
|-&lt;br /&gt;
|4||0.26&lt;br /&gt;
|-&lt;br /&gt;
|5||0.423&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output from the logistic regression analysis gives a p-value of p=0.0157, which is based on the Wald z-score. In addition to the Wald method, we can calculate the p-value for logistic regression &amp;lt;i&amp;gt;(mylogit &amp;lt;- glm(CO ~ SE,data = mydata,family = &amp;quot;binomial&amp;quot;))&amp;lt;/i&amp;gt; using the &amp;lt;b&amp;gt;Likelihood Ratio Test (LRT)&amp;lt;/b&amp;gt;, which for these data give &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;0.0006476922&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate Std.||Error||z value||Pr (&amp;gt;z) Wald&lt;br /&gt;
|-&lt;br /&gt;
|SE||0.7583||0.3139||2.416||&amp;lt;b&amp;gt;0.0157&amp;lt;/b&amp;gt; *&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logit of a number $0≤p≤1$ given by the formula: $logit(p) = log(\frac{p}{1-p})$ representing the &amp;lt;b&amp;gt;log-odds&amp;lt;/b&amp;gt; (of survival in this case).&lt;br /&gt;
&lt;br /&gt;
 confint(mylogit) &lt;br /&gt;
&lt;br /&gt;
So, why exponentiating the coefficients? Because,&lt;br /&gt;
&lt;br /&gt;
$logit(p)=log(\frac{p}{1-p})&amp;amp;#8594; e^{logit(p)}=e^{log(\frac{p}{1-p})}&amp;amp;#8594; RHS=\frac{p}{1-p}$ &amp;lt;b&amp;gt;(odds-ratio, OR)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; exp(coef(mylogit)) 	 # exponentiated logit model coefficients&amp;lt;/font&amp;gt;&lt;br /&gt;
 (Intercept)          	SE &lt;br /&gt;
 0.01652254  		2.13474149   ## == exp(0.7583456)&lt;br /&gt;
 &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;&amp;gt; coef(mylogit)    	# raw logit model coefficients&amp;lt;/font&amp;gt; &lt;br /&gt;
 (Intercept)          	SE &lt;br /&gt;
 -4.1030298   		0.7583456&lt;br /&gt;
&lt;br /&gt;
 exp(cbind(OR = coef(mylogit), confint(mylogit)))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;OR&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;||2.5%||97.5%&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||0.01652254||0.0001825743||0.277290&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;SE&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;2.13474149&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;1.3083794719&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;4.839986&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 with(mylogit, df.null - df.residual)&lt;br /&gt;
&lt;br /&gt;
Finally, the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;LRT (likelihood-ratio test)  p-value&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; can be obtained using:&lt;br /&gt;
&lt;br /&gt;
 with(mylogit, pchisq(null.deviance - deviance, df.null - df.residual, lower.tail = FALSE))&lt;br /&gt;
&lt;br /&gt;
[1] &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;0.0006476922&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The LRT &amp;lt;i&amp;gt;p_value&amp;lt;/i&amp;gt; &amp;lt; 0.001 tells us that our model as a whole fits significantly better than an empty model. The deviance residual is -2*log likelihood, and to see the model's log likelihood:&lt;br /&gt;
&lt;br /&gt;
 logLik(mylogit)&lt;br /&gt;
 'log Lik.' -8.046117 (df=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Side-note&amp;lt;/b&amp;gt;: The LRT compares the data fit of two models. For instance, removing predictor variables from a model will reduce model quality (i.e., a model will have a lower log likelihood). To statistically assess whether the observed difference in model fit is significant, the LRT compares the difference of the log likelihoods of the two models. When this difference is statistically significant, the full model (the one with more variables) is a better fit to the data, compared to the reduced model. LRT is computed from the log likelihoods of the models:&lt;br /&gt;
&lt;br /&gt;
$LRT=-2ln\Big(\frac{L(m1)}{L(m2)}\Big)=2(ll(m2)-ll(m1)) $,&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;i&amp;gt;m1&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;m2&amp;lt;/i&amp;gt; are the reduced and the full models, respectively, &amp;lt;i&amp;gt;L(m1)&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;L(m2)&amp;lt;/i&amp;gt; denote the likelihoods of the 2 models, and &amp;lt;i&amp;gt;ll(m1)&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;ll(m2)&amp;lt;/i&amp;gt; represent the log likelihood (natural log of the model likelihood.&lt;br /&gt;
&lt;br /&gt;
The distribution of the LRT is chi-squared with degrees of freedom equal to the number of parameters that are reduced (i.e., the number of variables removed from the model). In our case,&lt;br /&gt;
&lt;br /&gt;
$LRT \sim X^2_{df=2}$ as we have an intercept and one predictor (SE), and the null model is empty (no parameters).&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
* &amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt; http://cran.r-project.org/web/packages/influence.ME/influence.ME.pdf&lt;br /&gt;
* &amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt; http://www.ats.ucla.edu/stat/mult_pkg/glmm.htm&lt;br /&gt;
* &amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; http://wiki.socr.umich.edu/index.php/SMHS_OR_RR&lt;br /&gt;
&lt;br /&gt;
==Next See==&lt;br /&gt;
[[SMHS_LinearModeling_MachineLearning|Machine Learning Algorithms section]] for data modeling, training , testing, forecasting, prediction, and simulation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM_Assumptions}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR_VizModelCoeff&amp;diff=16183</id>
		<title>SMHS LinearModeling MLR VizModelCoeff</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR_VizModelCoeff&amp;diff=16183"/>
		<updated>2016-05-23T13:57:02Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Protocols for Rectifying Residual Plots Indicating Nonlinearity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling_MLR|Multiple Linear Regression]] - Visualizing the Regression-Model coefficients==&lt;br /&gt;
&lt;br /&gt;
First see the [[SMHS_LinearModeling_MLR|Multiple Linear Regression section]], where we discuss linear modeling, review, and demonstrate computing and visualizing the regression-model coefficients (effect-sizes), (fixed-effect) linear model assumptions, examination of residual plots, and independence.&lt;br /&gt;
&lt;br /&gt;
To visualize the Regression-Model coefficients (effect-sizes) we can use the '''arm''' package: &lt;br /&gt;
 #library(&amp;quot;arm&amp;quot;)&lt;br /&gt;
 # data &amp;lt;- read.table('01a_data.txt',as.is=T, header=T)&lt;br /&gt;
 data &amp;lt;- read.table('01a_data.txt',as.is=T, header=T)	&lt;br /&gt;
 attach(data)&lt;br /&gt;
&lt;br /&gt;
 df.2 = data.frame(Age, Weight, Height, Position, Team) &lt;br /&gt;
 lm.2 = lm(Weight ~ Age + Height+ Position + Team, df.2)&lt;br /&gt;
 lm.3 = lm(Weight ~ Age*Height+ Position*Team, df.2)&lt;br /&gt;
 lm.4 = lm(Weight ~ Age*Team + Position*Height, df.2) &lt;br /&gt;
&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # coefplot(lm.2, xlim=c(-2, 2),  intercept=TRUE)&lt;br /&gt;
 coefplot(lm.2, vertical=FALSE, col.pts=&amp;quot;green&amp;quot;)&lt;br /&gt;
 coefplot(lm.3, vertical=FALSE, add=TRUE, col.pts=&amp;quot;red&amp;quot;, offset=0.2)&lt;br /&gt;
 coefplot(lm.3a, vertical=FALSE, add=TRUE, col.pts=&amp;quot;black&amp;quot;, offset=0.4)&lt;br /&gt;
 coefplot(lm.4, vertical=FALSE, add=TRUE, col.pts=&amp;quot;blue&amp;quot;, offset=0.6)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig16.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===(Fixed-Effect) Linear Model Assumptions===&lt;br /&gt;
&lt;br /&gt;
The linear modeling approach (above) is referred to as a linear  model, as opposed to another type of model (e.g., non-linear, exponential, etc.) for 2 reasons. First, functional analytic representation of the model involves linear terms of the predictive variables. Second, the model assumptions dictate linear relationships among the covariates and between covariates and response.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Linearity&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The response variable (Y=Weight, in our case) can be expressed via a linear combination formula of the independent variable (e.g., Height, Age, etc.). If its assumption is invalid, the residual plot may include patterns (e.g., quadratic curve or non-linear trend) indicating another type of model may be appropriate. For instance, the residuals may include a pair of lines when we have dichotomous categorical data. Similarly, the QQ Normal Probability Plot may not be perfectly linear (e.g., S-shaped), which again indicates the distribution of the residuals (observed minus fitted (predicted) values) may not be IID Normal (Gaussian distributed).&lt;br /&gt;
&lt;br /&gt;
This plot shows the age/pitch relationship along with the depiction of the residuals:&lt;br /&gt;
 # Weight ~ Age + Height + Position + Team + e&lt;br /&gt;
 # lm.4 = lm(Weight ~ Age.centered + Height+ Position + Team, df.2)&lt;br /&gt;
&lt;br /&gt;
 lm.4.res = resid(lm.4) &lt;br /&gt;
 plot(Height, lm.4.res, ylab=&amp;quot;(Weight) Residuals&amp;quot;, xlab=&amp;quot;Height&amp;quot;, main=&amp;quot;MLB (lm.4) model residuals&amp;quot;)  &lt;br /&gt;
 abline(0, 0)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig17.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Weight ~ Age + Height + Position + Team + e&lt;br /&gt;
 # lm.4 = lm(Weight ~ Age.centered + Height+ Position + Team, df.2)&lt;br /&gt;
 # lm.4.res = resid(lm.4)&lt;br /&gt;
 qqnorm(lm.4.res) 	# A quantile normal plot - good for checking normality&lt;br /&gt;
 qqline(lm.4.res)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig18.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mind that now, for illustrative purposes, we change the model to (lm.2: Weight ~ Age)!&lt;br /&gt;
&lt;br /&gt;
 # lm.2 = lm(Weight ~ Age, df.2)&lt;br /&gt;
 # calculate residuals and predicted values &lt;br /&gt;
 lm.2.res = resid(lm.2)&lt;br /&gt;
 residuals &amp;lt;- signif(lm.2.res, 5)&lt;br /&gt;
 predicted &amp;lt;- predict(lm.2)&lt;br /&gt;
&lt;br /&gt;
 plot(Age, Weight, main=&amp;quot;Visualization of the Residuals of Model: Weight ~ Age&amp;quot;, xlab=&amp;quot;Age&amp;quot;, ylab=&amp;quot;Weight&amp;quot;, pch=19) &lt;br /&gt;
 abline(lm(Weight ~ Age), col=&amp;quot;red&amp;quot;)&lt;br /&gt;
 # plot distances between points and the regression line&lt;br /&gt;
 segments(Age, Weight, Age, predicted, col=&amp;quot;blue&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # add residual-value labels to (Age) points&lt;br /&gt;
 # install.packages(&amp;quot;calibrate&amp;quot;)&lt;br /&gt;
 # library(&amp;quot;calibrate&amp;quot;, lib.loc=&amp;quot;~/R/win-library/3.1&amp;quot;)&lt;br /&gt;
 library(calibrate)&lt;br /&gt;
 textxy(Age, Weight, residuals, cx=0.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig19.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;U&amp;gt;blue&amp;lt;/U&amp;gt; lines indicate the (magnitude of the) residuals and represent the deviations of the observed data points from the model-predicted values (fitted values). The sum of all residuals (positive and negative) is zero, ensured by the least-squares method for estimating the linear model parameters (intercept and slope).&lt;br /&gt;
&lt;br /&gt;
An alternative view is to plot the fitted values (predicted means) on the horizontal line and the residuals, as deviations, on the vertical line.&lt;br /&gt;
&lt;br /&gt;
 plot(fitted(lm.2),residuals(lm.2))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig20.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Protocols for Rectifying Residual Plots Indicating Nonlinearity===&lt;br /&gt;
&lt;br /&gt;
Model may be excluding important fixed effects that interact with fixed effects already accounted for in the model. If new fixed effects are added, the pattern in the residual plot may disappear.&lt;br /&gt;
*Variable transformation – Perform a nonlinear transformation of the response, e.g., log, or reciprocal transform. See this SOCR Activity&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;.&lt;br /&gt;
*Perform a nonlinear transformation to explanatory variables. For instance, if Age is related to Weight in a U-shaped way (e.g., quadratic relation), then the model could include Age and Age&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; as predictors.&lt;br /&gt;
*If residual plots include stripes, then there may be categorical variables playing role, which may necessitate alternative class of models, such as logistic or multinomial models.&lt;br /&gt;
&lt;br /&gt;
===Lack of Collinearity===&lt;br /&gt;
&lt;br /&gt;
A pair of (linearly) correlated predictors are also called collinear. Suppose Age and Height are correlated (which is certainly to be expected!), then including both as predictors of Weight presents a collinearity problem. In the presence of significant variable collinearity, the interpretation of the model becomes challenging. Depending on which correlated predictors are included in the model, the fixed effects may (incorrectly) become significant or insignificant. Significant findings for these correlated or collinear fixed effects is difficult to interpret as there may be trading-off between the &amp;quot;explanatory power&amp;quot; of the pair of covariates. Multiple predictors that are very similar (linearly correlated) inhibit our ability to decide what plays a big role and what has only marginal impact on the response.&lt;br /&gt;
&lt;br /&gt;
Collinearity may be avoided early during the study-design/data-collection phase of the study to collect fewer fixed effects known to not be linearly correlated. Alternatively, we can selectively include/exclude predictors (e.g., only include in model the most meaningful independent variable and drop the others). Dimensionality reduction methods (e.g., Principal/Independent Component Analyses) also identify (fuse) linearly correlated variables into factors (representing linear combinations transforming several correlated variables into one component variable, which can be used as new fixed effect).&lt;br /&gt;
&lt;br /&gt;
===Heteroskedasticity (lack of homoscedasticity)===&lt;br /&gt;
&lt;br /&gt;
If the variance of the data is (approximately) stable across the range of the predicted values, then the process is homoscedastic (equal variance assumption). Otherwise, when the homoscedasticity criterion is violated, the process is called heteroskedastic (unequal variances).&lt;br /&gt;
&lt;br /&gt;
Satisfying the homoscedasticity assumption requires the model residuals to roughly have a similar amount of deviation from the predicted values. This can be checked by examining the residual plot. &lt;br /&gt;
&lt;br /&gt;
 # lm.2 = lm(Weight ~ Age, df.2)&lt;br /&gt;
 lm.2.res = resid(lm.2) &lt;br /&gt;
 plot(Age, lm.2.res, ylab=&amp;quot;(Weight) Residuals&amp;quot;, xlab=&amp;quot;Age&amp;quot;, main=&amp;quot;MLB (lm.2) model residuals&amp;quot;)  &lt;br /&gt;
 abline(0, 0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig21.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Overall, these data are mostly homoscedastic. A good residual plot essentially looks like a random blob cluster. For instance, using real (simulated) random data, we can see the expectation for the residuals under the linear model assumptions:&lt;br /&gt;
&lt;br /&gt;
 plot(rnorm(1000), rbeta(1000, 1,1)-0.5)&lt;br /&gt;
 abline(0, 0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig22.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates two sets of 1,000 random numbers (x and y axes representing Normal(mean=0,SD=1) and Beta(1,1) distributions, respectively&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;). Redoing this simulation multiple times and recreating the residual plots will *not* change the appearance of the scatter!&lt;br /&gt;
&lt;br /&gt;
However, there are many situations where the residual plots may show clear heteroskedasticity:&lt;br /&gt;
&lt;br /&gt;
 set.seed(11)		# see the random generator with some integer&lt;br /&gt;
 n &amp;lt;- 256		# define sample size&lt;br /&gt;
 X &amp;lt;- (1:n)/n           # The set of the predictor X values (uniform steps of 1/n from 0 to 1)&lt;br /&gt;
 E &amp;lt;- rnorm(n, sd=1)         # A set of *normally distributed* random noise E values&lt;br /&gt;
 i &amp;lt;- order(runif(n, max=dnorm(E))) # Reorder E, by putting larger errors at the end, on average&lt;br /&gt;
 Y &amp;lt;- 1 + 5 * X + E[rev(i)]   # Simulate new (observed responses) Y values, X plus &amp;quot;error&amp;quot; `E`.&lt;br /&gt;
 lm.5 &amp;lt;- lm(Y ~ X)             # Regress `Y` against `X`.&lt;br /&gt;
 par(mfrow=c(1,3))             # Set up 1 row of 3 plots for drawing the graphs&lt;br /&gt;
 plot(X,Y, main=&amp;quot;Simulated Noisy Data (Y) across time/index&amp;quot;, cex=0.8)&lt;br /&gt;
 abline(coef(lm.5), col=&amp;quot;Red&amp;quot;) &lt;br /&gt;
 hist(residuals(lm.5), main=&amp;quot;Linear Model Residuals&amp;quot;)&lt;br /&gt;
 plot(predict(lm.5), residuals(lm.5), cex=0.8, main=&amp;quot;Residuals vs. Predicted (Heteroskedasticity)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig23.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, larger fitted values correspond with larger residuals (the opposite may be true as well). Transforming the data often helps resolve such Heteroskedasticity.&lt;br /&gt;
&lt;br /&gt;
===Normality of residuals===&lt;br /&gt;
&lt;br /&gt;
The normality of residuals assumption (parametric assumptions) is also important. Linear models may be robust and gracefully handle certain some violations of the normality assumption. &lt;br /&gt;
&lt;br /&gt;
 # lm.2 = lm(Weight ~ Age, df.2) &lt;br /&gt;
 par(mfrow=c(1,2))&lt;br /&gt;
 hist(residuals(lm.2))&lt;br /&gt;
 qqnorm(residuals(lm.2))&lt;br /&gt;
 qqline(lm.2.res, col=&amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig24.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The histogram (left) is relatively bell-shaped and the Q-Q normal probability plot (right) indicates the residuals are mostly on a straight line (suggesting errors (observed-predicted) are similar to a normal distribution). Thus, there is no strong evidence suggesting possible violation of the normality assumption.&lt;br /&gt;
&lt;br /&gt;
===Outliers (influential data points)===&lt;br /&gt;
&lt;br /&gt;
Data should not include extreme influential points, otherwise the linear model may be heavily biased. Outliers (influential data points) can drastically change the interpretation of model results and inference, similarly to variable collinearity.&lt;br /&gt;
&lt;br /&gt;
The R function dfbeta() computes some of the regression (leave-one-out deletion) diagnostics for linear models and allows us to check for outliers. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Coefficients&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[SMHS_LinearModeling_LMM|Linear mixed effects analyses]] for scientific inference based on fixed and random effect models, assumptions, and mixed effects logistic regression. &lt;br /&gt;
&lt;br /&gt;
 #lm.2 = lm(Weight ~ Age, df.2) &lt;br /&gt;
 df.results &amp;lt;- dfbeta (lm.2)&lt;br /&gt;
 head(df.results)&lt;br /&gt;
&lt;br /&gt;
 #lm.2 = lm(Weight ~ Age, df.2) &lt;br /&gt;
 Coefficients:&lt;br /&gt;
            Estimate Std. Error t value Pr(&amp;gt;|t|)    &lt;br /&gt;
 (Intercept) 179.6684     4.3418  41.381  &amp;lt; 2e-16 ***&lt;br /&gt;
 Age           0.7672     0.1494   5.135 3.37e-07 ***&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Intercept||Age&lt;br /&gt;
|-&lt;br /&gt;
|1||-0.1654198377||0.0051723556&lt;br /&gt;
|-&lt;br /&gt;
|2||-0.0690980186||0.0026986682&lt;br /&gt;
|-&lt;br /&gt;
|3||-0.0139731950||0.0007125283&lt;br /&gt;
|-&lt;br /&gt;
|4||-0.0284523604||0.0010963970&lt;br /&gt;
|-&lt;br /&gt;
|5||0.1803531368||-0.0069199855&lt;br /&gt;
|-&lt;br /&gt;
|6||0.0001719468||-0.0008892050	&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each coefficient of the lm.2 model (intercept, Age, etc.), dfbeta gives the DFbeta values. The first row means that the coefficient for Age (0.7672) has to be adjusted by 0.0051723556 if data point 1 is excluded. In other words, the Age coefficient of the model without the first data point would be -­‐0.7723724 (=0.7672 + 0.0051723556). If the slope is negative, DFbeta values are subtracted; if the slope is positive, DFbeta values are added.&lt;br /&gt;
&lt;br /&gt;
Interpretation of large or a small DFbeta values is similarly &amp;quot;open&amp;quot; as the interpretation of p-values (case-specific). However, if the DFbeta value changes, the sign of the coefficient slope, then this data point is an outlier candidate (influential point) that needs special attention. Excluding that 1 point would change the interpretation of the model results. &lt;br /&gt;
&lt;br /&gt;
For small to medium size (''n'') data, |DFbeta| &amp;gt; 1 is generally suspicious (outlier).  For larger datasets, a rule of thumb criterion is |''DFbeta''| &amp;gt; &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;amp;frasl;&amp;lt;sub&amp;gt;&amp;amp;radic;&amp;lt;span style=&amp;quot;text-decoration: overline&amp;quot;&amp;gt;n&amp;lt;/span&amp;gt;&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 par(mfrow=c(1,1))&lt;br /&gt;
 plot(df.results, pch=23, bg= 'orange', cex=2, ylab=&amp;quot;BFBeta(Weight)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig25.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Excluding outliers and reporting results using the reduced data set is not an optimal solution. Running and reporting both the analyses with/without the influential points may be a better strategy. We can exclude influential points when there evidence that these represent technical errors.&lt;br /&gt;
&lt;br /&gt;
===Independence===&lt;br /&gt;
&lt;br /&gt;
The independence linear model assumption is the most important limitation (which plays role in most statistical tests). Each data point is supposed to be independent from all the others (e.g., observations come from different subjects). &lt;br /&gt;
&lt;br /&gt;
Violations of the independence assumption make the interpretation of the model results impractical. All assumptions are important; however, the independence assumption is critical. Violating independence may inflate the chance of finding spurious effects, bias the results and generate meaningless p‐values.&lt;br /&gt;
&lt;br /&gt;
Independence is mostly a question of the experimental design which is tightly intertwined with the subsequent statistical analyses. When the study design demands collection of more data per subject, repeated measure designs, the data will have (time) dependencies and the appropriate statistical methodologies for interrogating such data involve mixed linear models.&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt; http://wiki.socr.umich.edu/index.php/SOCR_EduMaterials_Activities_PowerTransformFamily_Graphs&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt; http://socr.umich.edu/html/dist/&lt;br /&gt;
&lt;br /&gt;
===See next===&lt;br /&gt;
&lt;br /&gt;
* [[SMHS_LinearModeling_LMM|Linear mixed effects analyses]] where we present scientific inference based on fixed and random effect models, assumptions, and mixed effects logistic regression. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR_VizModelCoeff}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1&amp;diff=16181</id>
		<title>SMHS BigDataBigSci SEM Ex1</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1&amp;diff=16181"/>
		<updated>2016-05-23T13:51:27Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] - Hands-on Example 1 (School Kids Mental Abilities) ==&lt;br /&gt;
&lt;br /&gt;
These data (Holzinger &amp;amp; Swineford 1939) include mental ability test scores of 7 &amp;amp; 8 grade children from two schools (Pasteur and Grant-White). This version of the dataset includes only 9 (out of the 26) tests. We can build and test a confirmatory factor analysis (CFA) SEM model for 3 correlated latent variables (or factors), each with three indicators:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;u&amp;gt;'''visual'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x1, x2 and x3,&lt;br /&gt;
*&amp;lt;u&amp;gt;'''textual'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x4, x5 and x6,&lt;br /&gt;
*&amp;lt;u&amp;gt;'''speed'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x7, x8 and x9.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;lhs&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;op&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;rhs&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;user&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;free&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;ustart&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1 ||Visual||=~||x1||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|2 ||Visual||=~||x2||1||1||NA&lt;br /&gt;
|-&lt;br /&gt;
|3 ||Visual||=~||x3||1||2||NA&lt;br /&gt;
|-&lt;br /&gt;
|4 ||Textual||=~||x4||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|5||Textual||=~||x5||1||3||NA&lt;br /&gt;
|-&lt;br /&gt;
|6||Textual||=~||x6||1||4||NA&lt;br /&gt;
|-&lt;br /&gt;
|7 ||Speed||=~||x7||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|8 ||Speed||=~||x8||1||5||NA&lt;br /&gt;
|-&lt;br /&gt;
|9 ||Speed||=~||x9||1||6||NA&lt;br /&gt;
|-&lt;br /&gt;
|10 ||x1||~~||x1||0||7||NA&lt;br /&gt;
|-&lt;br /&gt;
|11||x2||~~||x2||0||8||NA&lt;br /&gt;
|-&lt;br /&gt;
|12||x3||~~||x3||0||9||NA&lt;br /&gt;
|-&lt;br /&gt;
|13||x4||~~||x4||0||10||NA&lt;br /&gt;
|-&lt;br /&gt;
|14||x5||~~||x5||0||11||NA&lt;br /&gt;
|-&lt;br /&gt;
|15||x6||~~||x6||0||12||NA&lt;br /&gt;
|-&lt;br /&gt;
|16||x7||~~||x7||0||13||NA&lt;br /&gt;
|-&lt;br /&gt;
|17||x8||~~||x8||0||14||NA&lt;br /&gt;
|-&lt;br /&gt;
|18||x9||~~||x9||0||15||47.8&lt;br /&gt;
|-&lt;br /&gt;
|19||Visual||~~||Visual||0||16||NA&lt;br /&gt;
|-&lt;br /&gt;
|20||Textual||~~||Textual||0||17||NA&lt;br /&gt;
|-&lt;br /&gt;
|21||Speed||~~||Speed||boy||18||NA&lt;br /&gt;
|-&lt;br /&gt;
|22||Visual||~~||Textual||girl||19||NA&lt;br /&gt;
|-&lt;br /&gt;
|23||Visual||~~||Speed||girl||20||NA&lt;br /&gt;
|-&lt;br /&gt;
|24||Textual||~~||Speed||boy||21||NA&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are 3 latent variables (factors) in this model, each with 3 indicators, resulting in 9 factor loadings that need to be estimated. There are also 3 covariances among the latent variables {another three parameters}. &lt;br /&gt;
&lt;br /&gt;
These &amp;lt;b&amp;gt;12 parameters&amp;lt;/b&amp;gt; are represented in the path diagram as single-headed and double-headed arrows, respectively. We also need to estimate the residual variances of the 9 observed variables and the variances of the 3 latent variables, resulting in &amp;lt;b&amp;gt;12 additional free parameters&amp;lt;/b&amp;gt;. In total, we have &amp;lt;b&amp;gt;24 parameters.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci2.png|200px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To fully identify the model we need to set the metric of the latent variables. There are 2 ways to do this: &lt;br /&gt;
*for each latent variable, fix the factor loading of one of the indicators (typically the first) to a constant (e.g., 1.0), or&lt;br /&gt;
*standardize the variances of the 3 latent variables. &lt;br /&gt;
&lt;br /&gt;
Either way, we fix 3 of these 24 parameters, and 21 parameters remain free. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;parTable(fit)&amp;lt;/b&amp;gt; method, generates this table output.&lt;br /&gt;
&lt;br /&gt;
The `rhs', `op' and `lhs' columns define the parameters of the model. &lt;br /&gt;
All parameters with the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;`=~'&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; operator are factor loadings, whereas all parameters with the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;`~~'&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; operator are variances or covariances. Nonzero elements in the `free' column are the free parameters of the model. Zero elements in the `free' column correspond to fixed parameters, whose value is found in the `start' column.&lt;br /&gt;
&lt;br /&gt;
Lavaan’s user-friendly model-specification approach is implemented in the fitting functions: cfa() and sem(). &lt;br /&gt;
&lt;br /&gt;
Since these data contain 3 latent variables, and no regressions, the minimalist syntax is:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;data.model &amp;lt;- 'visual 	        =~ x1 + x2 + x3&lt;br /&gt;
 textual 	                =~ x4 + x5 + x6&lt;br /&gt;
 speed 	                        =~ x7 + x8 + x9'&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fit the CFA model:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.1 &amp;lt;- cfa(data.model, data = HolzingerSwineford1939)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The `user' column (parTabale) shows which parameters were explicitly contained in the user-specified model syntax (= 1), and which parameters were added by the cfa() function (= 0). &lt;br /&gt;
 &amp;lt;b&amp;gt;parTable(fit.1)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we prefer &amp;lt;b&amp;gt;not to fix the factor loadings&amp;lt;/b&amp;gt; of the first indicator, but instead want to fix the variances of the latent variances, the model syntax would be changed to:&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.2 &amp;lt;- 'visual =~ NA*x1 + x2 + x3&lt;br /&gt;
 textual =~ NA*x4 + x5 + x6&lt;br /&gt;
 speed =~ NA*x7 + x8 + x9&lt;br /&gt;
 visual ~~ 1*visual&lt;br /&gt;
 textual ~~ 1*textual&lt;br /&gt;
 speed ~~ 1*speed'&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complex model specifications can be made using the full '''lavaan''' model syntax:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.full &amp;lt;- '			# latent variables&lt;br /&gt;
 visual 	=~ 1*x1 + x2 + x3&lt;br /&gt;
 textual =~ 1*x4 + x5 + x6&lt;br /&gt;
 speed 	=~ 1*x7 + x8 + x9&lt;br /&gt;
 # residual variances observed variables&lt;br /&gt;
 x1 	~~ x1&lt;br /&gt;
 x2 	~~ x2&lt;br /&gt;
 x3 	~~ x3&lt;br /&gt;
 x4 	~~ x4&lt;br /&gt;
 x5 	~~ x5&lt;br /&gt;
 x6 	~~ x6&lt;br /&gt;
 x7 	~~ x7&lt;br /&gt;
 x8 	~~ x8&lt;br /&gt;
 x9 	~~ x9&lt;br /&gt;
 # factor variances&lt;br /&gt;
 visual 	~~ visual&lt;br /&gt;
 textual ~~ textual&lt;br /&gt;
 speed 	~~ speed&lt;br /&gt;
 # factor covariances&lt;br /&gt;
 visual 	~~ textual + speed&lt;br /&gt;
 textual ~~ speed'&lt;br /&gt;
 fit.3 &amp;lt;- lavaan(fit.full, data = HolzingerSwineford1939)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can specify the model where the first factor loadings are explicitly fixed to one, and the covariances among the factors are added manually.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.mixed &amp;lt;- '		# latent variables&lt;br /&gt;
 visual =~ 1*x1 + x2 + x3&lt;br /&gt;
 textual =~ 1*x4 + x5 + x6&lt;br /&gt;
 speed =~ 1*x7 + x8 + x9&lt;br /&gt;
 # factor covariances&lt;br /&gt;
 visual ~~ textual + speed&lt;br /&gt;
 textual ~~ speed'&lt;br /&gt;
 fit &amp;lt;- lavaan(fit.mixed, data = HolzingerSwineford1939, auto.var = TRUE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The best method to view results from a SEM fitted with lavaan is &amp;lt;b&amp;gt;summary()&amp;lt;/b&amp;gt;, which can be called with optional arguments like fit.measures, standardized, and rsquare.&lt;br /&gt;
&lt;br /&gt;
===Core Lavaan Methods===&lt;br /&gt;
*&amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() print a long summary of the model results&lt;br /&gt;
*&amp;lt;b&amp;gt;show&amp;lt;/b&amp;gt;() print a short summary of the model results&lt;br /&gt;
*&amp;lt;b&amp;gt;coef&amp;lt;/b&amp;gt;() returns the estimates of the free parameters in the model as a named numeric vector&lt;br /&gt;
*&amp;lt;b&amp;gt;fitted&amp;lt;/b&amp;gt;() returns the implied moments (covariance matrix and mean vector) of the model&lt;br /&gt;
*&amp;lt;b&amp;gt;resid&amp;lt;/b&amp;gt;() returns the raw, normalized or standardized residuals (difference between implied and observed moments)&lt;br /&gt;
*&amp;lt;b&amp;gt;vcov&amp;lt;/b&amp;gt;() returns the covariance matrix of the estimated parameters&lt;br /&gt;
*&amp;lt;b&amp;gt;predict&amp;lt;/b&amp;gt;() compute factor scores&lt;br /&gt;
*&amp;lt;b&amp;gt;logLik&amp;lt;/b&amp;gt;() returns the log-likelihood of the fitted model (if maximum likelihood estimation was used)&lt;br /&gt;
*&amp;lt;b&amp;gt;AIC&amp;lt;/b&amp;gt;(), BIC() compute information criteria (if maximum likelihood estimation is used)&lt;br /&gt;
*&amp;lt;b&amp;gt;update&amp;lt;/b&amp;gt;() update a fitted lavaan object&lt;br /&gt;
*&amp;lt;b&amp;gt;inspect&amp;lt;/b&amp;gt;() peek into the internal representation of the model; by default, it returns a list of model matrices counting the free parameters in the model; can also be used to extract starting values, gradient values, and much more&lt;br /&gt;
&lt;br /&gt;
If these args are set to TRUE, the output includes additional fit measures, standardized estimates, and R2 values for the dependent variables, respectively&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.model &amp;lt;- 'visual =~ x1 + x2 + x3&lt;br /&gt;
 textual =~ x4 + x5 + x6&lt;br /&gt;
  speed =~ x7 + x8 + x9'&lt;br /&gt;
 fit &amp;lt;- cfa(fit.model, data = HolzingerSwineford1939)&lt;br /&gt;
 summary(fit, fit.measures = TRUE)&lt;br /&gt;
&lt;br /&gt;
 fit &amp;lt;- cfa(fit.model, data=HolzingerSwineford1939, estimator=&amp;quot;GLS&amp;quot;, group=&amp;quot;sex&amp;quot;)&lt;br /&gt;
 fit.4 &amp;lt;- cfa(fit.model, data=HolzingerSwineford1939, estimator=&amp;quot;GLD&amp;quot;, group=&amp;quot;sex&amp;quot;, group.equal=&amp;quot;regressions&amp;quot;) &lt;br /&gt;
 anova(fit, fit.4)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Output===&lt;br /&gt;
The output consists of three sections. &lt;br /&gt;
&lt;br /&gt;
*The &amp;lt;b&amp;gt;first section&amp;lt;/b&amp;gt; (first 6 lines) contains the package version number, an indication whether the model has converged (and in how many iterations), and the effective number of observations used in the analysis.&lt;br /&gt;
	&lt;br /&gt;
*The &amp;lt;b&amp;gt;second section&amp;lt;/b&amp;gt; contains the model χ^2 test statistic, degrees of freedom, and a p value are printed. If fit.measures = TRUE, it also prints the test statistic of the baseline model (where all observed variables are assumed to be uncorrelated) and several popular fit indices. If maximum likelihood estimation is used, this section will also contain information about the log-likelihood, the AIC, and the BIC.&lt;br /&gt;
	&lt;br /&gt;
*The &amp;lt;b&amp;gt;third section&amp;lt;/b&amp;gt; provides an overview of the parameter estimates, including the type of standard errors used and whether the observed or expected information matrix was used to compute standard errors. Then, for each model parameter, the estimate and the standard error are displayed, and if appropriate, a z value based on the Wald test and a corresponding two-sided p value are also shown. To ease the reading of the parameter estimates, they are grouped into three blocks:&lt;br /&gt;
*factor loadings, &lt;br /&gt;
*factor covariances, and &lt;br /&gt;
*residual variances of both observed variables and factors.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() method provides a nice summary of the model results for visualization purposes. The &amp;lt;b&amp;gt;parameterEstimates&amp;lt;/b&amp;gt;() method returns the actual parameter estimates as a &amp;lt;b&amp;gt;data.frame&amp;lt;/b&amp;gt;, which can be processed further.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;parameterEstimates(fit)&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||lhs||op||rhs||est||se||z||pvalue||ci.lower||ci.upper&lt;br /&gt;
|-&lt;br /&gt;
|1||visual||=~||x1||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|2||visual||=~||x2||0.553||0.1||5.554||0||0.358||0.749&lt;br /&gt;
|-&lt;br /&gt;
|3||visual||=~||x3||0.729||0.109||6.685||0||0.516||0.943&lt;br /&gt;
|-&lt;br /&gt;
|4||textual||=~||x4||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|5||textual||=~||x5||1.113||0.065||17.014||0||0.985||1.241&lt;br /&gt;
|-&lt;br /&gt;
|6||textual||=~||x6||0.926||0.055||16.703||0||0.817||1.035&lt;br /&gt;
|-&lt;br /&gt;
|7||speed||=~||x7||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|8||speed||=~||x8||1.18||0.165||7.152||0||0.857||1.503&lt;br /&gt;
|-&lt;br /&gt;
|9||speed||=~||x9||1.082||0.151||7.155||0||0.785||1.378&lt;br /&gt;
|-&lt;br /&gt;
|10||x1||~~||x1||0.549||0.114||4.833||0||0.326||0.772&lt;br /&gt;
|-&lt;br /&gt;
|11||x2||~~||x2||1.134||0.102||11.146||0||0.934||1.333&lt;br /&gt;
|-&lt;br /&gt;
|12||x3||~~||x3||0.844||0.091||9.317||0||0.667||1.022&lt;br /&gt;
|-&lt;br /&gt;
|13||x4||~~||x4||0.371||0.048||7.779||0||0.278||0.465&lt;br /&gt;
|-&lt;br /&gt;
|14||x5||~~||x5||0.446||0.058||7.642||0||0.332||0.561&lt;br /&gt;
|-&lt;br /&gt;
|15||x6||~~||x6||0.356||0.043||8.277||0||0.272||0.441&lt;br /&gt;
|-&lt;br /&gt;
|16||x7||~~||x7||0.799||0.081||9.823||0||0.64||0.959&lt;br /&gt;
|-&lt;br /&gt;
|17||x8||~~||x8||0.488||0.074||6.573||0||0.342||0.633&lt;br /&gt;
|-&lt;br /&gt;
|18||x9||~~||x9||0.566||0.071||8.003||0||0.427||0.705&lt;br /&gt;
|-&lt;br /&gt;
|19||visual||~~||visual||0.809||0.145||5.564||0||0.524||1.094&lt;br /&gt;
|-&lt;br /&gt;
|20||textual||~~||textual||0.979||0.112||8.737||0||0.76||1.199&lt;br /&gt;
|-&lt;br /&gt;
|21||speed||~~||speed||0.384||0.086||4.451||0||0.215||0.553&lt;br /&gt;
|-&lt;br /&gt;
|22||visual||~~||textual||0.408||0.074||5.552||0||0.264||0.552&lt;br /&gt;
|-&lt;br /&gt;
|23||visual||~~||speed||0.262||0.056||4.66||0||0.152||0.373&lt;br /&gt;
|-&lt;br /&gt;
|24||textual||~~||speed||0.173||0.049||3.518||0||0.077||0.27&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The confidence level can be changed by setting the level argument. To obtain several standardized versions of the estimates, we can use standardized = TRUE:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;est &amp;lt;- parameterEstimates(fit, ci = FALSE, standardized = TRUE)&lt;br /&gt;
subset(est, op == &amp;quot;=~&amp;quot;) &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||lhs||op||rhs||est||se||z||pvalue||std.lv||std.all||std.nox&lt;br /&gt;
|-&lt;br /&gt;
|1||visual||=~||x1||1||0||NA||NA||0.9||0.772||0.772&lt;br /&gt;
|-&lt;br /&gt;
|2||visual||=~||x2||0.553||0.1||5.554||0||0.498||0.424||0.424&lt;br /&gt;
|-&lt;br /&gt;
|3||visual||=~||x3||0.729||0.109||6.685||0||0.656||0.581||0.581&lt;br /&gt;
|-&lt;br /&gt;
|4||textual||=~||x4||1||0||NA||NA||0.99||0.852||0.852&lt;br /&gt;
|-&lt;br /&gt;
|5||textual||=~||x5||1.113||0.065||17.014||0||1.102||0.855||0.855&lt;br /&gt;
|-&lt;br /&gt;
|6||textual||=~||x6||0.926||0.055||16.703||0||0.917||0.838||0.838&lt;br /&gt;
|-&lt;br /&gt;
|7||speed||=~||x7||1||0||NA||NA||0.619||0.57||0.57&lt;br /&gt;
|-&lt;br /&gt;
|8||speed||=~||x8||1.18||0.165||7.152||0||0.731||0.723||0.723&lt;br /&gt;
|-&lt;br /&gt;
|9||speed||=~||x9||1.082||0.151||7.155||0||0.67||0.665||0.665&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This only shows the factor loadings are shown but 3 additional columns with standardized values are added. &lt;br /&gt;
*In the first column &amp;lt;b&amp;gt;(std.lv)&amp;lt;/b&amp;gt;, only the latent variables have been standardized;&lt;br /&gt;
*In the second column &amp;lt;b&amp;gt;(std.all)&amp;lt;/b&amp;gt;, both the latent and the observed variables have been standardized;&lt;br /&gt;
* In the third column &amp;lt;b&amp;gt;(std.nox)&amp;lt;/b&amp;gt;, both the latent and the observed variables have been standardized, except for the exogenous observed variables. This option may be useful if the standardization of exogenous observed variables has little meaning (for example, binary covariates). Since there are no exogenous covariates in this model, the last two columns are identical in this output.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;semPlot&amp;quot;)&lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, &amp;quot;show&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0) &lt;br /&gt;
 # get the margines right:&lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0, mar = c(10, 3, 10, 3)) &lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0, mar = c(10, 3, 10, 3), as.expression = c(&amp;quot;nodes&amp;quot;, &lt;br /&gt;
 # 	&amp;quot;edges&amp;quot;), sizeMan = 3, sizeInt = 1, sizeLat = 4)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci3.png|500px]]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Back to Structural Equation Modeling (SEM)]]&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM_Ex2| Next Section: SEM Example 2: Parkinson’s Disease data]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis&amp;diff=16180</id>
		<title>SMHS TimeSeriesAnalysis</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis&amp;diff=16180"/>
		<updated>2016-05-23T13:49:44Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Exponential Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Time Series Analysis ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
* Why are trends, patterns or predictions from models/data important?&lt;br /&gt;
* How to detect, model and utilize trends in longitudinal data?&lt;br /&gt;
&lt;br /&gt;
Time series analysis represents a class of statistical methods applicable for series data aiming to extract meaningful information, trend and characterization of the process using observed longitudinal data. These trends may be used for time series forecasting and for prediction of future values based on retrospective observations. Note that classical linear modeling (e.g., regression analysis) may also be employed for prediction &amp;amp; testing of associations using the values of one or more independent variables and their effect on the value of another variable. However, time series analysis allows dependencies (e.g., seasonal effects to be accounted for).&lt;br /&gt;
&lt;br /&gt;
===Time-series representation===&lt;br /&gt;
&lt;br /&gt;
There are 3 (distinct and complementary) types of &amp;lt;b&amp;gt;time series patterns&amp;lt;/b&amp;gt; that most time-series analyses are trying to identify, model and analyze. These include: &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Trend&amp;lt;/b&amp;gt;: A trend is a long-term increase or decrease in the data that may be linear or non-linear, but is generally continuous (mostly monotonic). The trend may be referred to as direction.&lt;br /&gt;
* &amp;lt;b&amp;gt;Seasonal&amp;lt;/b&amp;gt;: A seasonal pattern is influence in the data, like seasonal factors (e.g., the quarter of the year, the month, or day of the week), which is always of a fixed known period.&lt;br /&gt;
* &amp;lt;b&amp;gt;Cyclic&amp;lt;/b&amp;gt;:  A cyclic pattern of fluctuations corresponds to rises and falls that are &amp;lt;i&amp;gt;not of fixed period.&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries1.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, the following code shows several time series with different types of time series patterns.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;par&amp;lt;/b&amp;gt;(mfrow=c(3,2))&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;n &amp;lt;- 98&amp;lt;/b&amp;gt;&lt;br /&gt;
 X &amp;lt;- cbind(1:n)   # time points (annually)&lt;br /&gt;
 &amp;lt;u&amp;gt;Trend1&amp;lt;/u&amp;gt; &amp;lt;- LakeHuron+0.2*X  # series 1&lt;br /&gt;
 Trend2 &amp;lt;- LakeHuron-0.5*X  # series 2&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;u&amp;gt;Season1&amp;lt;/u&amp;gt; &amp;lt;- X; Season2 &amp;lt;- X;  # series 1 &amp;amp; 2&lt;br /&gt;
 for(i in 1:n) {&lt;br /&gt;
     &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] + 5*(i%%4)&lt;br /&gt;
     &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] -2*(i%%10)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;u&amp;gt;Cyclic1&amp;lt;/u&amp;gt; &amp;lt;- X; Cyclic2 &amp;lt;- X;  # series 1 &amp;amp; 2&lt;br /&gt;
 for(i in 1:n) {&lt;br /&gt;
 rand1 &amp;lt;- as.integer(runif(1, 1, 10))&lt;br /&gt;
     &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] + 3*(i%%rand1)&lt;br /&gt;
     &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] - 1*(i%%rand1)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, Trend1, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; Trend1&amp;quot;, main=&amp;quot;Trend1 (LakeHuron+0.2*X)&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, Trend2, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; Trend2&amp;quot; , main=&amp;quot;Trend2 (LakeHuron-0.5*X)&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;=Trend1 (LakeHuron+5(i%%4))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;=Trend1 (LakeHuron-2(i%%10))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;=Trend1 (LakeHuron+3*(i%%rand1))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt; = Trend1 (LakeHuron-(i%%rand1))&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note: If you get this run-time graphics error:&lt;br /&gt;
“&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Error in plot.new() : figure margins too large&amp;lt;/font&amp;gt;” &amp;lt;BR&amp;gt;&lt;br /&gt;
You need to make sure your graphics window is large enough or print to PDF:&lt;br /&gt;
&lt;br /&gt;
 pdf(&amp;quot;myplot.pdf&amp;quot;); plot(x); dev.off()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries2.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s look at the delta (Δ) changes - Lagged Differences, using &amp;lt;b&amp;gt;diff&amp;lt;/b&amp;gt;, which returns suitably lagged and iterated differences.&lt;br /&gt;
&lt;br /&gt;
 ## Default lag = 1&lt;br /&gt;
 &amp;lt;b&amp;gt;par&amp;lt;/b&amp;gt;(mfrow=c(1,1))&lt;br /&gt;
 hist(diff(Trend1), prob=T, col=&amp;quot;red&amp;quot;) # Plot histogram&lt;br /&gt;
 lines(density(diff(Trend1)),lwd=2)	# plot density estimate&lt;br /&gt;
 x&amp;lt;-seq(-4,4,length=100); y&amp;lt;-dnorm(x, mean(diff(Trend1)), sd(diff(Trend1)))&lt;br /&gt;
 lines(x,y,lwd=2,col=&amp;quot;blue&amp;quot;)	# plot MLE Normal Fit&lt;br /&gt;
&lt;br /&gt;
===Time series decomposition===&lt;br /&gt;
&lt;br /&gt;
Denote the time series $yt$ including the three components: a seasonal effect, a trend-cycle effect (containing both trend and cycle), and a remainder component (containing the residual variability in the time series).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Additive model&amp;lt;/b&amp;gt;: &lt;br /&gt;
$yt=St+Tt+Et,$ where $yt$ is the data at period $t, St$ is the seasonal component at period $t, Tt$ is the trend-cycle component at period $t$ and $Et$ is the remainder (error) component at period $t$. This &amp;lt;u&amp;gt;additive model&amp;lt;/u&amp;gt; is appropriate if the magnitude of the seasonal fluctuations or the variation around the trend-cycle does not vary with the level of the time series.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Multiplicative model&amp;lt;/b&amp;gt;:  $yt=St×Tt×Et$. When the variation in the seasonal pattern, or the variation around the trend-cycle, are proportional to the level of the time series, then a multiplicative model is more appropriate. Note that when using a multiplicative model, we can transform the data to stabilize the variation in the series over time, and then use an additive model. For instance, a log transformation decomposes the multiplicative model from:&lt;br /&gt;
&lt;br /&gt;
$yt=St×Tt×Et$ &amp;lt;BR&amp;gt;&lt;br /&gt;
to the additive model: &amp;lt;BR&amp;gt;&lt;br /&gt;
$log(yt)=log(St)+log(Tt)+log(Et).$&lt;br /&gt;
&lt;br /&gt;
We can examine the Seasonal trends by decomposing the Time Series by &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;loess&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt; (Local Polynomial Regression) Fitting into &amp;lt;b&amp;gt;S&amp;lt;/b&amp;gt;easonal, &amp;lt;b&amp;gt;T&amp;lt;/b&amp;gt;rend and irregular components using &amp;lt;b&amp;gt;L&amp;lt;/b&amp;gt;oess - Local Polynomial Regression Fitting (&amp;lt;b&amp;gt;stl&amp;lt;/b&amp;gt; function, in the default “stats” package):&lt;br /&gt;
&lt;br /&gt;
 # using Monthly Males Deaths from Lung Diseases in UK from bronchitis, emphysema and asthma, 1974–1979&lt;br /&gt;
 mdeaths  # is.ts(mdeaths)&lt;br /&gt;
 fit &amp;lt;- stl(mdeaths, s.window=5)&lt;br /&gt;
 plot(mdeaths, col=&amp;quot;gray&amp;quot;,   main=&amp;quot; Lung Diseases in UK &amp;quot;, ylab=&amp;quot; Lung Diseases Deaths&amp;quot;, xlab=&amp;quot;&amp;quot;)&lt;br /&gt;
 lines(fit\$\$$time.series[,2],col=&amp;quot;red&amp;quot;,ylab=&amp;quot;Trend&amp;quot;)&lt;br /&gt;
 plot(fit) # data, seasonal, trend, residuals&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;“stl” function parameters&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|x||Univariate time series to be decomposed. This should be an object of class &amp;quot;ts&amp;quot; with a frequency greater than one.&lt;br /&gt;
|-&lt;br /&gt;
|s.window||either the character string &amp;quot;periodic&amp;quot; or the span (in lags) of the loess window for seasonal extraction, which should be odd and at least 7, according to Cleveland et al. This has no default.&lt;br /&gt;
|-&lt;br /&gt;
|s.degree||degree of locally-fitted polynomial in seasonal extraction. Should be zero or one.&lt;br /&gt;
|-&lt;br /&gt;
|t.window||the span (in lags) of the loess window for trend extraction, which should be odd. If NULL, the default, nextodd(ceiling((1.5*period) / (1-(1.5/s.window)))), is taken.&lt;br /&gt;
|-&lt;br /&gt;
|t.degree||degree of locally-fitted polynomial in trend extraction. Should be zero or one.&lt;br /&gt;
|-&lt;br /&gt;
|l.window||the span (in lags) of the loess window of the low-pass filter used for each subseries. Defaults to the smallest odd integer greater than or equal to frequency(x) which is recommended since it prevents competition between the trend and seasonal components. If not an odd integer its given value is increased to the next odd one.&lt;br /&gt;
|-&lt;br /&gt;
|l.degree||degree of locally-fitted polynomial for the subseries low-pass filter. Must be 0 or 1.&lt;br /&gt;
|-&lt;br /&gt;
|s.jump, t.jump, l.jump||integers at least one to increase speed of the respective smoother. Linear interpolation happens between every *.jump&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; value.&lt;br /&gt;
|-&lt;br /&gt;
|robust||logical indicating if robust fitting be used in the loess procedure.&lt;br /&gt;
|-&lt;br /&gt;
|inner||integer; the number of ‘inner’ (backfitting) iterations; usually very few (2) iterations suffice.&lt;br /&gt;
|-&lt;br /&gt;
|outer||integer; the number of ‘outer’ robustness iterations.&lt;br /&gt;
|-&lt;br /&gt;
|na.action||action on missing values.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries3.png|400px]] [[Image:SMHS_TimeSeries4.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;monthplot&amp;lt;/b&amp;gt;(fit$\$$time.series[,&amp;quot;seasonal&amp;quot;], main=&amp;quot;&amp;quot;, ylab=&amp;quot;Seasonal&amp;quot;, lwd=5)&lt;br /&gt;
 &amp;amp;#35;As the “fit &amp;lt;- stl(mdeaths, s.window=5)” object has 3 time-series components (seasonal; trend; remainder)&lt;br /&gt;
 &amp;amp;#35;we can alternatively plot them separately:&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;seasonal&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, cex.axis = 0.8)&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;trend&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, cex.axis = 0.8)&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;remainder&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, type = &amp;quot;h&amp;quot;, cex.axis = 1.2)    # histogramatic&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries5.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the seasonal plots and seasonal sub-series plots of the seasonal component illustrating the variation in the seasonal component over time (over the years).&lt;br /&gt;
&lt;br /&gt;
Using historical weather (average daily temperature at the University of Michigan, Ann Arbor):&lt;br /&gt;
[http://weather-warehouse.com/WeatherHistory/PastWeatherData_AnnArborUnivOfMi_AnnArbor_MI_January.html]&lt;br /&gt;
(See meta-data description and provenance online: [http://weather-warehouse.com/WxWfaqs.html]).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Mean Temperature, (F), UMich, Ann Arbor (1900-2015)&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Year||Jan||Feb||Mar||Apr||May||Jun||Jul||Aug||Sep||Oct||Nov||Dec&lt;br /&gt;
|-&lt;br /&gt;
|2015||26.3||14.4||34.9||49||64.2||68||71.2||70.2||68.7||53.9||NR||NR&lt;br /&gt;
|-&lt;br /&gt;
|2014||24.4||19.4||29||48.9||60.7||69.7||68.8||70.8||63.2||52.1||35.4||33.3&lt;br /&gt;
|-&lt;br /&gt;
|2013||22.7||26.1||33.3||46||63.1||68.5||72.9||70.2||64.6||53.2||37.6||26.7&lt;br /&gt;
|-&lt;br /&gt;
|2012||22.4||32.8||50.7||49.2||65.2||71.4||78.9||72.2||63.9||51.7||39.6||34.8&lt;br /&gt;
|-&lt;br /&gt;
|...|| || || || || || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|...||17||15.3||31.4||47.3||57||69||76.6||72||63.4||52.2||35.2||23.7&lt;br /&gt;
|-&lt;br /&gt;
|1900||21.4||19.2||24.7||47.8||60.2||66.3||72||75.4||67.2||59||37.6||29.2&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # data: 07_UMich_AnnArbor_MI_TempPrecipitation_HistData_1900_2015.csv&lt;br /&gt;
 # more complete data is available here: 07_UMich_AnnArbor_MI_TempPrecipitation_HistData_1900_2015.xls umich_data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/702739/download?download_frd=1&amp;quot;, header=TRUE)&lt;br /&gt;
 &lt;br /&gt;
 head(umich_data)&lt;br /&gt;
 &lt;br /&gt;
 # https://cran.r-project.org/web/packages/mgcv/mgcv.pdf &lt;br /&gt;
 # install.packages(&amp;quot;mgcv&amp;quot;);  require(mgcv) &lt;br /&gt;
 &lt;br /&gt;
 # install.packages(&amp;quot;gamair&amp;quot;); require(gamair)&lt;br /&gt;
 par(mfrow=c(1,1))&lt;br /&gt;
&lt;br /&gt;
The data are in wide format – convert to long format for plotting&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;reshape2&amp;quot;)&lt;br /&gt;
 long_data &amp;lt;- melt(umich_data, id.vars = c(&amp;quot;Year&amp;quot;), value.name = &amp;quot;temperature&amp;quot;)&lt;br /&gt;
 l.sort &amp;lt;- long_data[order(long_data$\$$Year),]&lt;br /&gt;
 head(l.sort); tail(l.sort)&lt;br /&gt;
 &lt;br /&gt;
 plot(l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit the GAMM Model&amp;lt;/b&amp;gt; (Generalized Additive Mixed Model)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries6.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit a model with trend and seasonal components&amp;lt;/b&amp;gt; --- computation may be slow:&lt;br /&gt;
&lt;br /&gt;
 # define the parameters controlling the process of model-fitting/parameter-estimation&lt;br /&gt;
 ctrl &amp;lt;- list(niterEM = 0, msVerbose = TRUE, optimMethod=&amp;quot;L-BFGS-B&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # First try this model&lt;br /&gt;
 mod &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year)) + s(as.numeric(variable)), data = l.sort, method = &amp;quot;REML&amp;quot;,  correlation=corAR1(form = ~ 1|Year), knots=list(Variable = c(1, 12)), na.action=na.omit, control = ctrl)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;&amp;lt;u&amp;gt;Correlation&amp;lt;/u&amp;gt;: &amp;lt;b&amp;gt;corStruct&amp;lt;/b&amp;gt; object defineing correlation structures in &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt;. Grouping factors in the formula for this&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;object are assumed to be nested within any random effect grouping factors, without the need to make this&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;explicit in the formula (somewhat different from the behavior of &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt;).&amp;lt;BR&amp;gt; &lt;br /&gt;
&amp;amp;#35;This is similar to the GEE approach to correlation in the generalized case.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;&amp;lt;u&amp;gt;Knots&amp;lt;/u&amp;gt;: an optional list of user specified knot values to be used for basis construction --&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;different terms can use different numbers of knots, unless they share a covariate.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;If you revise the model like this (below), it will compare nicely with 3 ARMA models (later)&amp;lt;BR&amp;gt;&lt;br /&gt;
 mod &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corAR1(form = ~ 1|Year),  control = ctrl)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Summary of the fitted model:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(mod$\$$gam)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visualize the model trend (year) and seasonal terms (months)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(mod$\$$gam, pages = 1)&lt;br /&gt;
 t &amp;lt;- cbind(1: 1392)	# define the time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries7.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot the trend on the observed data -- with prediction:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pred2 &amp;lt;- predict(mod$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 ptemp2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,1]&amp;lt;/u&amp;gt;    &lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;# pred2[,1] = trend; 	pred2[,2] = seasonal effects&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;# mod$\$$gam&amp;lt;/b&amp;gt; is a GAM object containing information to use predict, summary and print methods, but not to use e.g. the anova method function to compare models&lt;br /&gt;
 plot(temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;, xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(ptemp2 ~ t, data = l.sort, col = &amp;quot;blue&amp;quot;, lwd = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries8.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot the seasonal model&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pred &amp;lt;- predict(mod$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 ptemp &amp;lt;- attr(pred, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred[,2]&amp;lt;/u&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 plot(l.sort$\$$temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;,  xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(ptemp, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 0.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries9.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Zoom in first 100 temps (1:100)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(l.sort$\$$temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;,  &amp;lt;b&amp;gt;xlim=c(0, 120)&amp;lt;/b&amp;gt;, xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F))); lines(ptemp, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 0.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries10.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To examine how much the estimated trend has changed over the 116 year period, we can use the data contained in &amp;lt;b&amp;gt;pred&amp;lt;/b&amp;gt; to compute the difference between the start (Jan 1900) and the end (Dec 2015) of the series in the &amp;lt;i&amp;gt;&amp;lt;u&amp;gt;trend&amp;lt;/u&amp;gt;&amp;lt;/i&amp;gt; component only:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;tail(pred[,1], 1) - head(pred[,1], 1)&amp;lt;/b&amp;gt; # subtract the predicted temp [,1] in 1900 (head) from the temp in 2015 (tail)&lt;br /&gt;
 &lt;br /&gt;
 # names(attributes(pred)); str(pred)    # to see the components of the GAM prediction model object (pred)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Assess autocorrelation in residuals&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # head(umich_data); tail(umich_data)&lt;br /&gt;
 acf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;ACF&amp;quot;)&lt;br /&gt;
 # &amp;lt;b&amp;gt;acf&amp;lt;/b&amp;gt; = Auto-correlation and Cross-Covariance Function computes and plots the estimates of the autocovariance or autocorrelation function.&lt;br /&gt;
 # &amp;lt;b&amp;gt;pacf&amp;lt;/b&amp;gt; is the function used for the partial autocorrelations.&lt;br /&gt;
 # &amp;lt;b&amp;gt;ccf&amp;lt;/b&amp;gt; computes the cross-correlation or cross-covariance of two univariate series.&lt;br /&gt;
 pacf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;pACF&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Looking at the residuals of this model, using the (partial) autocorrelation function, we see that there may be some residual autocorrelation in the data that the trend term didn’t account for. The shapes of the ACF and the pACF suggest an &amp;lt;b&amp;gt;AR(p)&amp;lt;/b&amp;gt; model might be appropriate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit and compare 4 alternative autoregressive models (original mod, AR1, AR2 and AR3)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ## AR(1)&lt;br /&gt;
 m1 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
   data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 1&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
&lt;br /&gt;
 ## AR(2)&lt;br /&gt;
 m2 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 2&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
&lt;br /&gt;
 ## AR(3)&lt;br /&gt;
 m3 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 3&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;),  control = ctrl)&lt;br /&gt;
&lt;br /&gt;
Note that the correlation argument is specified by &amp;lt;b&amp;gt;corARMA(form = ~ 1|Year, p = x)&amp;lt;/b&amp;gt;, which fits an ARMA (auto-regressive moving average) process to the residuals, where &amp;lt;b&amp;gt;p&amp;lt;/b&amp;gt; indicates the order for the &amp;lt;b&amp;gt;AR&amp;lt;/b&amp;gt; part of the ARMA model, and &amp;lt;b&amp;gt;form = ~ 1|Year&amp;lt;/b&amp;gt; specifies that the ARMA is nested within each year. This may expedite the model fitting but may also hide potential residual variation from one year to another.&lt;br /&gt;
&lt;br /&gt;
Let’s compare the candidate models by using the generalized likelihood ratio test via the &amp;lt;b&amp;gt;anova()&amp;lt;/b&amp;gt; method for &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt; objects; see our previous mixed effects modeling notes &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; , &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;. This model selection is justified as we work with nested models -- going from the AR(3) to the AR(1) by setting some of the AR coefficients to 0. The models also vary in terms of the coefficient estimates for the splines terms which may require fixing some values while choosing the AR structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;center&amp;gt;anova(mod$\$$lme, m1$\$$lme, m2$\$$lme, m3$\$$lme)&amp;lt;/center&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
|||Model||df||AIC||BIC||logLik||Test||L.Ratio||p-value&lt;br /&gt;
|-&lt;br /&gt;
|mod$\$$lme||1||7||7455.609||7492.228|| -3720.805|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|m1$\$$lme||2|| 7||7455.609||7492.228|| -3720.805|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|m2$\$$lme||3|| 8||7453.982||7495.832|| -3718.991||2 vs 3||3.627409||0.0568&lt;br /&gt;
|-&lt;br /&gt;
|m3$\$$lme||4|| 9||7455.966||7503.048|| -3718.983|| 3 vs 4||0.015687||0.9003&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Interpretation &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The AR(1) model (m1) does not provide a substantial increase in fit over the naive model (mod), and the AR(2) model (m2) only provides a marginal increase in the AR(1) model fit (m1). There is no improvement in moving from m2 to AR(3) model (m3).&lt;br /&gt;
&lt;br /&gt;
Let’s plot the AR(2) model (m2) to inspect how over-fitted the naive model with uncorrelated errors was in terms of the trend term, which shows similar smoothness compared to the initial (mod) model.&lt;br /&gt;
&lt;br /&gt;
 plot(m2$\$$gam, scale = 0)     #  plot(mod2$\$$gam, scale = 0)   # “scale=0” ensures optimal y-axis cropping of plot&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries11.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Investigation of residual patterns&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 layout(matrix(1:2, ncol = 2))&lt;br /&gt;
 # original (mod) model&lt;br /&gt;
 acf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;ACF&amp;quot;); pacf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;pACF&amp;quot;)&lt;br /&gt;
 # pACF controls for the values of the time series at all shorter lags, which contrasts the ACF which does not control for other lags.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries12.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This illustrates that there is some (month=1) Auto-correlation (ACF) and partial auto correlation in the residuals.&lt;br /&gt;
&lt;br /&gt;
 # ARM(2) model (m2)&lt;br /&gt;
 layout(matrix(1:2, ncol = 2))&lt;br /&gt;
 res &amp;lt;- resid(m2$\$$lme, type = &amp;quot;normalized&amp;quot;); &lt;br /&gt;
 acf(res, lag.max = 36, main = &amp;quot;ACF - AR(2) errors&amp;quot;); pacf(res, lag.max = 36, main = &amp;quot;pACF- AR(2) errors&amp;quot;)&lt;br /&gt;
 layout(1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries13.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No residual auto-correlation remains in &amp;lt;b&amp;gt;m2&amp;lt;/b&amp;gt;. The resulting fitted Generalized Additive Mixed Model (GAMM) object contains information about the trend and the contributions to the fitted values. The package '''mgcv'''&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; can spit the information using &amp;lt;b&amp;gt;predict()&amp;lt;/b&amp;gt; for each of the 4 models.&lt;br /&gt;
&lt;br /&gt;
 # require(mgcv); require(gamair)&lt;br /&gt;
 # m2 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 2&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
 &lt;br /&gt;
 pred2 &amp;lt;- predict(m2$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 pred_trend2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,1]&amp;lt;/u&amp;gt; &amp;lt;b&amp;gt;# trend&amp;lt;/b&amp;gt;&lt;br /&gt;
 pred_season2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,2]&amp;lt;/u&amp;gt; &amp;lt;b&amp;gt;# seasonal&amp;lt;/b&amp;gt; effects&lt;br /&gt;
 # plot(m2$\$$gam, scale = 0) # plot pure effects&lt;br /&gt;
 &lt;br /&gt;
 # Convert the 2 columns (Year and Month/variable) to R Date object&lt;br /&gt;
 # df_time &amp;lt;- as.Date(paste(as.numeric(l.sort$\$$Year), as.numeric(l.sort$\$$variable), &amp;quot;1&amp;quot;, sep=&amp;quot;-&amp;quot;)); df_time&lt;br /&gt;
 &lt;br /&gt;
 plot(x=df_time, y=l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;,  xlim=c(as.Date(&amp;quot;1950-02-01&amp;quot;),as.Date(&amp;quot;1960-01-01&amp;quot;)), xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(x=df_time, y=pred_trend2, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 2);&lt;br /&gt;
 lines(x=df_time, y=pred_season2, data = l.sort, col = &amp;quot;blue&amp;quot;, lwd = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries14.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Moving average smoothing===&lt;br /&gt;
&lt;br /&gt;
A moving average of order $m=2k+1$ can be expressed as:&lt;br /&gt;
$T_{t}=\frac{1}{2k+1}\sum_{j=-k}^{k}Y_{t+j}$ .&lt;br /&gt;
&lt;br /&gt;
The ''m''-MA represents an order m moving average, $T_t$, or the estimate of the trend-cycle at time ''t'', obtained by averaging values of the time series within ''k'' periods (left and right) of ''t''. This averaging process denoises the data (eliminates randomness in the data) and produces a smoother trend-cycle component.&lt;br /&gt;
&lt;br /&gt;
The 5-MA contains the values of $T_t$ with ''k''=2. To see what the trend-cycle estimate looks like, we plot it along with the original data&lt;br /&gt;
&lt;br /&gt;
 # print the moving average results (k=3 &amp;amp;#8596; m=7)&lt;br /&gt;
 # library(&amp;quot;forecast&amp;quot;)&lt;br /&gt;
 plot(l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;, main=&amp;quot; UMich/AA Temp (1900-2015) &amp;quot;, ylab=&amp;quot; Temperature (F)&amp;quot;, xlab=&amp;quot;Year&amp;quot;)&lt;br /&gt;
 lines(ma(l.sort$\$$temperature, 12), col=&amp;quot;red&amp;quot;, lwd=5)&lt;br /&gt;
 lines(ma(l.sort$\$$temperature, 36), col=&amp;quot;blue&amp;quot;, lwd=3)&lt;br /&gt;
 &lt;br /&gt;
 legend(0, 80, 					# places a legend at the appropriate place &lt;br /&gt;
 c(&amp;quot;Raw&amp;quot;, &amp;quot;k=12 smoother&amp;quot;, &amp;quot;k=36 smoothest&amp;quot;), 	# puts text in the legend&lt;br /&gt;
 lty=c(1,1,1), 					# gives the legend appropriate symbols (lines)&lt;br /&gt;
 cex=1.0,  					# label sizes&lt;br /&gt;
 lwd=c(2.5,2.5), col=c(&amp;quot;black&amp;quot;, &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;)) 	# gives the legend lines the correct color and width&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries15.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The blue trend (''k''=36) (3 yrs) is smoother than the original (raw) data (black) and the 1-yr average (''k''=12). It captures the main movement of the time series without all the minor fluctuations. We can’t estimate $T_t$ where ''t'' is close to the ends as there is not enough data there to compute the averages. The red trend (''k''=12) is smoother than the original (raw) data (black) but more jagged than the 3-yr average. The order of the moving average (''m'') determines the smoothness of the trend-cycle estimate. A larger order implies a smoother curve.&lt;br /&gt;
&lt;br /&gt;
===Simulation of a time-series analysis and prediction===&lt;br /&gt;
&lt;br /&gt;
 (1) Simulate a time series&lt;br /&gt;
 &lt;br /&gt;
 # the ts() function converts a numeric vector into an R time series object. &lt;br /&gt;
 # format is ts(vector, start=, end=, frequency=) where start and end are the times of the first and last observation&lt;br /&gt;
 # and frequency is the number of observations per unit time (1=annual, 4=quarterly, 12=monthly, etc.)&lt;br /&gt;
 Note that ''ling Rate'' = $\frac{1}{Frequency}$ &lt;br /&gt;
 &lt;br /&gt;
 # save a numeric vector containing 16-years (192 monthly) observations  &lt;br /&gt;
 # from Jan 2000 to Dec 2015 as a time series object&lt;br /&gt;
 sim_ts &amp;lt;- ts(as.integer(runif(192,0,10)), start=c(2000, 1), end=c(2015, 12), frequency=12)&lt;br /&gt;
 sim_ts&lt;br /&gt;
 &lt;br /&gt;
 # subset the time series (June 2014 to December 2015)&lt;br /&gt;
 sim_ts2 &amp;lt;- window(sim_ts, start=c(2014, 6), end=c(2015, 12))&lt;br /&gt;
 sim_ts2&lt;br /&gt;
 &lt;br /&gt;
 # plot series &lt;br /&gt;
 plot(sim_ts)&lt;br /&gt;
 lines(sim_ts2, col=&amp;quot;blue&amp;quot;, lwd=3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries16.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Seasonal Decomposition====&lt;br /&gt;
&lt;br /&gt;
*The additive and seasonal trends, and irregular components, of time-series may be decomposed using the stl() function. Series with multiplicative effects can by transformed into series with additive effects through a log transformation (i.e., '''ln_sim_ts &amp;lt;- log(sim_ts)).&lt;br /&gt;
 # Seasonal decomposition&lt;br /&gt;
 fit_stl &amp;lt;- stl(sim_ts, s.window=&amp;quot;period&amp;quot;)   '''# Seasonal Decomposition of Time Series by Loess'''&lt;br /&gt;
 plot(fit_stl)&lt;br /&gt;
 &lt;br /&gt;
 # inspect the distribution of the residuals&lt;br /&gt;
 hist(fit_stl$\$$time.series[,3]);  #   this contains the residuals: fit_stl$\$$time.series  [,&amp;quot;remainder&amp;quot;], or  seasonal, trend&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries17.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # additional plots &lt;br /&gt;
 monthplot(sim_ts)	# plots the seasonal subseries of a time series. For each season, a time series is plotted.&lt;br /&gt;
 &lt;br /&gt;
 # library(forecast)&lt;br /&gt;
 seasonplot(sim_ts)&lt;br /&gt;
&lt;br /&gt;
====Exponential Models====&lt;br /&gt;
&lt;br /&gt;
*The '''HoltWinters()''' function ('''stats''' package), and the '''ets()''' function ('''forecast''' package) can fit exponential models.&lt;br /&gt;
 # simple exponential - models level&lt;br /&gt;
 fit_HW &amp;lt;- HoltWinters(sim_ts, beta=FALSE, gamma=FALSE)&lt;br /&gt;
 &lt;br /&gt;
 # double exponential - models level and trend&lt;br /&gt;
 fit_HW2&amp;lt;- HoltWinters(sim_ts, gamma=FALSE) &lt;br /&gt;
 &lt;br /&gt;
 # triple exponential - models level, trend, and seasonal components&lt;br /&gt;
 fit_HW3 &amp;lt;- HoltWinters(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 plot(fit_HW, col='black')&lt;br /&gt;
 par(new=TRUE)&lt;br /&gt;
 plot(fit_HW2, ann=FALSE, axes=FALSE, col='blue')&lt;br /&gt;
 par(new=TRUE)&lt;br /&gt;
 plot(fit_HW3, axes=FALSE, col='red')&lt;br /&gt;
 # clear plot: &lt;br /&gt;
 # dev.off()&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries18.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Auto-regressive Integrated Moving Average (ARIMA) Models&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
There are 2 types of ARIMA time-series models: &amp;lt;BR&amp;gt;&lt;br /&gt;
$ X_t= \mu+ \underbrace{\sum_{i=1}^{p}{φ_iX_{t-i}}}_\text{auto-regressive (p) part} +&lt;br /&gt;
\underbrace{\sum_{j=1}^{q}{θ_jε_{t-j}}}_\text{moving-average (q) part} + &lt;br /&gt;
\underbrace{ ε_t }_\text{error term}.$&lt;br /&gt;
&lt;br /&gt;
====Non-seasonal ARIMA models====&lt;br /&gt;
The Non-seasonal ARIMA models are denoted by ARIMA(p, d, q), where parameters p, d, and q are positive integers, &lt;br /&gt;
* p = order of the auto-regressive model,&lt;br /&gt;
* d = degree of differencing, when ''d''=2, the '''''d&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt;'' difference''' is $(X_t-X_{t-1})-(X_{t-1}-X_{t-2})= X_t-2X_{t-1}+X_{t-2}$. That is, the second difference of ''X'' (d=2) is not the difference between the current period and the value 2 periods ago.  It is the first-difference-of-the-first difference, the discrete analog of a second derivative, representing the local acceleration of the series rather than its local trend (first derivative).&lt;br /&gt;
* q = order of the moving-average model.&lt;br /&gt;
&lt;br /&gt;
====Seasonal ARIMA models====&lt;br /&gt;
The Seasonal AMIMA models are denoted by ''ARIMA(p, d, q)(P, D, Q)&amp;lt;sub&amp;gt;m&amp;lt;/sub&amp;gt;,'' &lt;br /&gt;
* m = number of periods in each season, &lt;br /&gt;
* uppercase P, D, Q represent the auto-regressive, differencing, and moving average terms for the seasonal part of the ARIMA model, and the lower case (p,d,q) are as with non-seasonal ARIMA.&lt;br /&gt;
&lt;br /&gt;
If 2 of the 3 terms are trivial, the model is abbreviated using the non-zero parameter, skipping the &amp;quot;AR&amp;quot;, &amp;quot;I&amp;quot; or &amp;quot;MA&amp;quot; from the acronym. For example, &lt;br /&gt;
&lt;br /&gt;
*ARIMA(1,0,0) = AR(1), a stationary and auto-correlated series can be predicted as a multiple of its own previous value, plus a constant. $X_t=μ + φ_1 × X_{t-1}+ \epsilon_t.$ Note that $ε_t=X_t-\hat{X}_t.$&lt;br /&gt;
&lt;br /&gt;
*An ARIMA(0,1,0) = I(1) model, not stationary series, a limiting case of an AR(1) model, the auto-regressive coefficient is equal to 1, i.e., a series with infinitely slow mean reversion,  $X_t=μ+X_{t-1}+ε_t,$ a 1-step random walk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;For more complex models:&amp;lt;/B&amp;gt;&lt;br /&gt;
*An ARIMA(1,1,0), differenced first-order auto-regressive model.  $X_t=μ+X_{t-1}+α×(X_{t-1}-X_{t-2})+ε_t.$  &lt;br /&gt;
&lt;br /&gt;
*An ARIMA(0,2,2) model is given by $X_t=2X_{t-1}-X_{t-2}+α×ε_{t-1}+β×ε_{t-2}+ ε_t,$ where $α$ and $β$ are the MA(1) and MA(2) coefficients (sometimes these are defined with negative signs). This is a general linear exponential smoothing model that uses exponentially weighted moving averages to estimate both a local level and a local trend in the series.  The long-term forecasts from this model converge to a straight line whose slope depends on the average trend observed toward the end of the series.&lt;br /&gt;
&lt;br /&gt;
*ARIMA(1,1,2), $X_t=μ+X_{t-1}+(X_{t-1}+X_{t-2})+α×ε{t}+β×ε_{t-1}$&lt;br /&gt;
&lt;br /&gt;
The '''arima'''() function ('''stats''' package) can be used to fit an &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;auto-regressive integrated moving averages&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; model. Other useful functions include:&lt;br /&gt;
* lag(sim_ts, k) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; lagged version of time series, shifted back k observations&lt;br /&gt;
* diff(sim_ts, differences=d) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; difference the time series d times&lt;br /&gt;
* ndiffs(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Number of differences required to achieve stationarity (from the forecast package)&lt;br /&gt;
* acf(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; auto-correlation function&lt;br /&gt;
* pacf(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; partial auto-correlation function&lt;br /&gt;
* adf.test(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Augmented Dickey-Fuller test. Rejecting the null hypothesis suggests that a time series is stationary (from the tseries package)&amp;lt;/li&amp;gt;&lt;br /&gt;
* Box.test(x, type=&amp;quot;Ljung-Box&amp;quot;) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Portmanteau test that observations in vector or time series x are independent.&lt;br /&gt;
&lt;br /&gt;
The '''forecast''' package has alternative versions of '''acf()''' and '''pacf()''' called '''Acf()''' and '''Pacf()''' respectively. &lt;br /&gt;
&amp;amp;#35; fit an '''ARIMA(P, D, Q) model''' of order:&lt;br /&gt;
* P, represents the AR order&amp;lt;&lt;br /&gt;
* D, represents the degree of differencing&lt;br /&gt;
* Q, represents the MA order.&lt;br /&gt;
&lt;br /&gt;
 fit_arima1 &amp;lt;- arima(sim_ts, order=c(3, 1, 2))  &lt;br /&gt;
 # predictive accuracy &lt;br /&gt;
 library(forecast) &lt;br /&gt;
 accuracy(fit_arima1)  &lt;br /&gt;
 &lt;br /&gt;
 # predict next 20 observations &lt;br /&gt;
 library(forecast) &lt;br /&gt;
 forecast(fit_arima1, 20) &lt;br /&gt;
 plot(forecast(fit_arima1, 20)) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries19.png|600px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Forecasting===&lt;br /&gt;
&lt;br /&gt;
The '''forecast''' package provides functions for the automatic selection of exponential and ARIMA models. The '''ets()''' (exponential TS) function supports both additive and multiplicative models. The '''auto.arima()''' function accounts for seasonal and nonseasonal ARIMA models according to criteria maximizing a cost function.&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;#35; library(forecast)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Automated forecasting using an exponential model&lt;br /&gt;
  fit_ets &amp;lt;- ets(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Automated forecasting using an ARIMA model&lt;br /&gt;
 fit_arima2 &amp;lt;- auto.arima(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Compare the AIC (model quality) for both models&lt;br /&gt;
 fit_ets$\$$aic; fit_arima2$\$$aic&lt;br /&gt;
 accuracy(fit_ets); accuracy(fit_arima2);&lt;br /&gt;
&lt;br /&gt;
'''Akaike’s Information Criterion (AIC)''' = ''-2Log(Likelihood)+2p,'' where ''p'' is he number of estimated parameters.&lt;br /&gt;
 summary(fit_ets); summary(fit_arima2)&lt;br /&gt;
&lt;br /&gt;
ACF plot of the residuals from the ARIMA(3,1,2) model shows all correlations within the threshold limits indicating that the residuals are behaving like white noise. A portmanteau test returns a large p-value, also suggesting the  residuals are white noise.&lt;br /&gt;
 &amp;amp;#35; acf computes (and by default plots) estimates of the autocovariance or autocorrelation function&lt;br /&gt;
 acf(residuals(fit_ets)) &lt;br /&gt;
&lt;br /&gt;
 &amp;amp;#35; Box–Pierce or Ljung–Box test statistic for examining the null hypothesis of independence in a given time series. &lt;br /&gt;
 &amp;amp;#35; These are sometimes known as ‘portmanteau’ tests.&lt;br /&gt;
 Box.test(residuals(fit_ets), lag=24, fitdf=4, type=&amp;quot;Ljung&amp;quot;)&lt;br /&gt;
 &amp;amp;#35; plot forecast&lt;br /&gt;
 &lt;br /&gt;
 plot(forecast(fit_arima2))&lt;br /&gt;
 &amp;amp;#35; more on ARIMA https://www.otexts.org/fpp/8/7&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
* &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; https://umich.instructure.com/files/689861/download?download_frd=1  &lt;br /&gt;
* &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; https://umich.instructure.com/courses/38100/files  &lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; https://cran.r-project.org/web/packages/mgcv/mgcv.pdf&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_TimeSeriesAnalysis_LOS| Applications of Time-series]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.ucla.edu&lt;br /&gt;
{{translate|pageName=http://wiki.stat.ucla.edu/socr/index.php?title=SMHS_TimeSeriesAnalysis}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis&amp;diff=16179</id>
		<title>SMHS TimeSeriesAnalysis</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis&amp;diff=16179"/>
		<updated>2016-05-23T13:49:32Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Seasonal Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Time Series Analysis ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
* Why are trends, patterns or predictions from models/data important?&lt;br /&gt;
* How to detect, model and utilize trends in longitudinal data?&lt;br /&gt;
&lt;br /&gt;
Time series analysis represents a class of statistical methods applicable for series data aiming to extract meaningful information, trend and characterization of the process using observed longitudinal data. These trends may be used for time series forecasting and for prediction of future values based on retrospective observations. Note that classical linear modeling (e.g., regression analysis) may also be employed for prediction &amp;amp; testing of associations using the values of one or more independent variables and their effect on the value of another variable. However, time series analysis allows dependencies (e.g., seasonal effects to be accounted for).&lt;br /&gt;
&lt;br /&gt;
===Time-series representation===&lt;br /&gt;
&lt;br /&gt;
There are 3 (distinct and complementary) types of &amp;lt;b&amp;gt;time series patterns&amp;lt;/b&amp;gt; that most time-series analyses are trying to identify, model and analyze. These include: &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Trend&amp;lt;/b&amp;gt;: A trend is a long-term increase or decrease in the data that may be linear or non-linear, but is generally continuous (mostly monotonic). The trend may be referred to as direction.&lt;br /&gt;
* &amp;lt;b&amp;gt;Seasonal&amp;lt;/b&amp;gt;: A seasonal pattern is influence in the data, like seasonal factors (e.g., the quarter of the year, the month, or day of the week), which is always of a fixed known period.&lt;br /&gt;
* &amp;lt;b&amp;gt;Cyclic&amp;lt;/b&amp;gt;:  A cyclic pattern of fluctuations corresponds to rises and falls that are &amp;lt;i&amp;gt;not of fixed period.&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries1.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, the following code shows several time series with different types of time series patterns.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;par&amp;lt;/b&amp;gt;(mfrow=c(3,2))&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;n &amp;lt;- 98&amp;lt;/b&amp;gt;&lt;br /&gt;
 X &amp;lt;- cbind(1:n)   # time points (annually)&lt;br /&gt;
 &amp;lt;u&amp;gt;Trend1&amp;lt;/u&amp;gt; &amp;lt;- LakeHuron+0.2*X  # series 1&lt;br /&gt;
 Trend2 &amp;lt;- LakeHuron-0.5*X  # series 2&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;u&amp;gt;Season1&amp;lt;/u&amp;gt; &amp;lt;- X; Season2 &amp;lt;- X;  # series 1 &amp;amp; 2&lt;br /&gt;
 for(i in 1:n) {&lt;br /&gt;
     &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] + 5*(i%%4)&lt;br /&gt;
     &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] -2*(i%%10)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;u&amp;gt;Cyclic1&amp;lt;/u&amp;gt; &amp;lt;- X; Cyclic2 &amp;lt;- X;  # series 1 &amp;amp; 2&lt;br /&gt;
 for(i in 1:n) {&lt;br /&gt;
 rand1 &amp;lt;- as.integer(runif(1, 1, 10))&lt;br /&gt;
     &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] + 3*(i%%rand1)&lt;br /&gt;
     &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] - 1*(i%%rand1)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, Trend1, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; Trend1&amp;quot;, main=&amp;quot;Trend1 (LakeHuron+0.2*X)&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, Trend2, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; Trend2&amp;quot; , main=&amp;quot;Trend2 (LakeHuron-0.5*X)&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;=Trend1 (LakeHuron+5(i%%4))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;=Trend1 (LakeHuron-2(i%%10))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;=Trend1 (LakeHuron+3*(i%%rand1))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt; = Trend1 (LakeHuron-(i%%rand1))&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note: If you get this run-time graphics error:&lt;br /&gt;
“&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Error in plot.new() : figure margins too large&amp;lt;/font&amp;gt;” &amp;lt;BR&amp;gt;&lt;br /&gt;
You need to make sure your graphics window is large enough or print to PDF:&lt;br /&gt;
&lt;br /&gt;
 pdf(&amp;quot;myplot.pdf&amp;quot;); plot(x); dev.off()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries2.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s look at the delta (Δ) changes - Lagged Differences, using &amp;lt;b&amp;gt;diff&amp;lt;/b&amp;gt;, which returns suitably lagged and iterated differences.&lt;br /&gt;
&lt;br /&gt;
 ## Default lag = 1&lt;br /&gt;
 &amp;lt;b&amp;gt;par&amp;lt;/b&amp;gt;(mfrow=c(1,1))&lt;br /&gt;
 hist(diff(Trend1), prob=T, col=&amp;quot;red&amp;quot;) # Plot histogram&lt;br /&gt;
 lines(density(diff(Trend1)),lwd=2)	# plot density estimate&lt;br /&gt;
 x&amp;lt;-seq(-4,4,length=100); y&amp;lt;-dnorm(x, mean(diff(Trend1)), sd(diff(Trend1)))&lt;br /&gt;
 lines(x,y,lwd=2,col=&amp;quot;blue&amp;quot;)	# plot MLE Normal Fit&lt;br /&gt;
&lt;br /&gt;
===Time series decomposition===&lt;br /&gt;
&lt;br /&gt;
Denote the time series $yt$ including the three components: a seasonal effect, a trend-cycle effect (containing both trend and cycle), and a remainder component (containing the residual variability in the time series).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Additive model&amp;lt;/b&amp;gt;: &lt;br /&gt;
$yt=St+Tt+Et,$ where $yt$ is the data at period $t, St$ is the seasonal component at period $t, Tt$ is the trend-cycle component at period $t$ and $Et$ is the remainder (error) component at period $t$. This &amp;lt;u&amp;gt;additive model&amp;lt;/u&amp;gt; is appropriate if the magnitude of the seasonal fluctuations or the variation around the trend-cycle does not vary with the level of the time series.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Multiplicative model&amp;lt;/b&amp;gt;:  $yt=St×Tt×Et$. When the variation in the seasonal pattern, or the variation around the trend-cycle, are proportional to the level of the time series, then a multiplicative model is more appropriate. Note that when using a multiplicative model, we can transform the data to stabilize the variation in the series over time, and then use an additive model. For instance, a log transformation decomposes the multiplicative model from:&lt;br /&gt;
&lt;br /&gt;
$yt=St×Tt×Et$ &amp;lt;BR&amp;gt;&lt;br /&gt;
to the additive model: &amp;lt;BR&amp;gt;&lt;br /&gt;
$log(yt)=log(St)+log(Tt)+log(Et).$&lt;br /&gt;
&lt;br /&gt;
We can examine the Seasonal trends by decomposing the Time Series by &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;loess&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt; (Local Polynomial Regression) Fitting into &amp;lt;b&amp;gt;S&amp;lt;/b&amp;gt;easonal, &amp;lt;b&amp;gt;T&amp;lt;/b&amp;gt;rend and irregular components using &amp;lt;b&amp;gt;L&amp;lt;/b&amp;gt;oess - Local Polynomial Regression Fitting (&amp;lt;b&amp;gt;stl&amp;lt;/b&amp;gt; function, in the default “stats” package):&lt;br /&gt;
&lt;br /&gt;
 # using Monthly Males Deaths from Lung Diseases in UK from bronchitis, emphysema and asthma, 1974–1979&lt;br /&gt;
 mdeaths  # is.ts(mdeaths)&lt;br /&gt;
 fit &amp;lt;- stl(mdeaths, s.window=5)&lt;br /&gt;
 plot(mdeaths, col=&amp;quot;gray&amp;quot;,   main=&amp;quot; Lung Diseases in UK &amp;quot;, ylab=&amp;quot; Lung Diseases Deaths&amp;quot;, xlab=&amp;quot;&amp;quot;)&lt;br /&gt;
 lines(fit\$\$$time.series[,2],col=&amp;quot;red&amp;quot;,ylab=&amp;quot;Trend&amp;quot;)&lt;br /&gt;
 plot(fit) # data, seasonal, trend, residuals&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;“stl” function parameters&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|x||Univariate time series to be decomposed. This should be an object of class &amp;quot;ts&amp;quot; with a frequency greater than one.&lt;br /&gt;
|-&lt;br /&gt;
|s.window||either the character string &amp;quot;periodic&amp;quot; or the span (in lags) of the loess window for seasonal extraction, which should be odd and at least 7, according to Cleveland et al. This has no default.&lt;br /&gt;
|-&lt;br /&gt;
|s.degree||degree of locally-fitted polynomial in seasonal extraction. Should be zero or one.&lt;br /&gt;
|-&lt;br /&gt;
|t.window||the span (in lags) of the loess window for trend extraction, which should be odd. If NULL, the default, nextodd(ceiling((1.5*period) / (1-(1.5/s.window)))), is taken.&lt;br /&gt;
|-&lt;br /&gt;
|t.degree||degree of locally-fitted polynomial in trend extraction. Should be zero or one.&lt;br /&gt;
|-&lt;br /&gt;
|l.window||the span (in lags) of the loess window of the low-pass filter used for each subseries. Defaults to the smallest odd integer greater than or equal to frequency(x) which is recommended since it prevents competition between the trend and seasonal components. If not an odd integer its given value is increased to the next odd one.&lt;br /&gt;
|-&lt;br /&gt;
|l.degree||degree of locally-fitted polynomial for the subseries low-pass filter. Must be 0 or 1.&lt;br /&gt;
|-&lt;br /&gt;
|s.jump, t.jump, l.jump||integers at least one to increase speed of the respective smoother. Linear interpolation happens between every *.jump&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; value.&lt;br /&gt;
|-&lt;br /&gt;
|robust||logical indicating if robust fitting be used in the loess procedure.&lt;br /&gt;
|-&lt;br /&gt;
|inner||integer; the number of ‘inner’ (backfitting) iterations; usually very few (2) iterations suffice.&lt;br /&gt;
|-&lt;br /&gt;
|outer||integer; the number of ‘outer’ robustness iterations.&lt;br /&gt;
|-&lt;br /&gt;
|na.action||action on missing values.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries3.png|400px]] [[Image:SMHS_TimeSeries4.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;monthplot&amp;lt;/b&amp;gt;(fit$\$$time.series[,&amp;quot;seasonal&amp;quot;], main=&amp;quot;&amp;quot;, ylab=&amp;quot;Seasonal&amp;quot;, lwd=5)&lt;br /&gt;
 &amp;amp;#35;As the “fit &amp;lt;- stl(mdeaths, s.window=5)” object has 3 time-series components (seasonal; trend; remainder)&lt;br /&gt;
 &amp;amp;#35;we can alternatively plot them separately:&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;seasonal&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, cex.axis = 0.8)&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;trend&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, cex.axis = 0.8)&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;remainder&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, type = &amp;quot;h&amp;quot;, cex.axis = 1.2)    # histogramatic&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries5.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the seasonal plots and seasonal sub-series plots of the seasonal component illustrating the variation in the seasonal component over time (over the years).&lt;br /&gt;
&lt;br /&gt;
Using historical weather (average daily temperature at the University of Michigan, Ann Arbor):&lt;br /&gt;
[http://weather-warehouse.com/WeatherHistory/PastWeatherData_AnnArborUnivOfMi_AnnArbor_MI_January.html]&lt;br /&gt;
(See meta-data description and provenance online: [http://weather-warehouse.com/WxWfaqs.html]).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Mean Temperature, (F), UMich, Ann Arbor (1900-2015)&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Year||Jan||Feb||Mar||Apr||May||Jun||Jul||Aug||Sep||Oct||Nov||Dec&lt;br /&gt;
|-&lt;br /&gt;
|2015||26.3||14.4||34.9||49||64.2||68||71.2||70.2||68.7||53.9||NR||NR&lt;br /&gt;
|-&lt;br /&gt;
|2014||24.4||19.4||29||48.9||60.7||69.7||68.8||70.8||63.2||52.1||35.4||33.3&lt;br /&gt;
|-&lt;br /&gt;
|2013||22.7||26.1||33.3||46||63.1||68.5||72.9||70.2||64.6||53.2||37.6||26.7&lt;br /&gt;
|-&lt;br /&gt;
|2012||22.4||32.8||50.7||49.2||65.2||71.4||78.9||72.2||63.9||51.7||39.6||34.8&lt;br /&gt;
|-&lt;br /&gt;
|...|| || || || || || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|...||17||15.3||31.4||47.3||57||69||76.6||72||63.4||52.2||35.2||23.7&lt;br /&gt;
|-&lt;br /&gt;
|1900||21.4||19.2||24.7||47.8||60.2||66.3||72||75.4||67.2||59||37.6||29.2&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # data: 07_UMich_AnnArbor_MI_TempPrecipitation_HistData_1900_2015.csv&lt;br /&gt;
 # more complete data is available here: 07_UMich_AnnArbor_MI_TempPrecipitation_HistData_1900_2015.xls umich_data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/702739/download?download_frd=1&amp;quot;, header=TRUE)&lt;br /&gt;
 &lt;br /&gt;
 head(umich_data)&lt;br /&gt;
 &lt;br /&gt;
 # https://cran.r-project.org/web/packages/mgcv/mgcv.pdf &lt;br /&gt;
 # install.packages(&amp;quot;mgcv&amp;quot;);  require(mgcv) &lt;br /&gt;
 &lt;br /&gt;
 # install.packages(&amp;quot;gamair&amp;quot;); require(gamair)&lt;br /&gt;
 par(mfrow=c(1,1))&lt;br /&gt;
&lt;br /&gt;
The data are in wide format – convert to long format for plotting&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;reshape2&amp;quot;)&lt;br /&gt;
 long_data &amp;lt;- melt(umich_data, id.vars = c(&amp;quot;Year&amp;quot;), value.name = &amp;quot;temperature&amp;quot;)&lt;br /&gt;
 l.sort &amp;lt;- long_data[order(long_data$\$$Year),]&lt;br /&gt;
 head(l.sort); tail(l.sort)&lt;br /&gt;
 &lt;br /&gt;
 plot(l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit the GAMM Model&amp;lt;/b&amp;gt; (Generalized Additive Mixed Model)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries6.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit a model with trend and seasonal components&amp;lt;/b&amp;gt; --- computation may be slow:&lt;br /&gt;
&lt;br /&gt;
 # define the parameters controlling the process of model-fitting/parameter-estimation&lt;br /&gt;
 ctrl &amp;lt;- list(niterEM = 0, msVerbose = TRUE, optimMethod=&amp;quot;L-BFGS-B&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # First try this model&lt;br /&gt;
 mod &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year)) + s(as.numeric(variable)), data = l.sort, method = &amp;quot;REML&amp;quot;,  correlation=corAR1(form = ~ 1|Year), knots=list(Variable = c(1, 12)), na.action=na.omit, control = ctrl)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;&amp;lt;u&amp;gt;Correlation&amp;lt;/u&amp;gt;: &amp;lt;b&amp;gt;corStruct&amp;lt;/b&amp;gt; object defineing correlation structures in &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt;. Grouping factors in the formula for this&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;object are assumed to be nested within any random effect grouping factors, without the need to make this&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;explicit in the formula (somewhat different from the behavior of &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt;).&amp;lt;BR&amp;gt; &lt;br /&gt;
&amp;amp;#35;This is similar to the GEE approach to correlation in the generalized case.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;&amp;lt;u&amp;gt;Knots&amp;lt;/u&amp;gt;: an optional list of user specified knot values to be used for basis construction --&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;different terms can use different numbers of knots, unless they share a covariate.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;If you revise the model like this (below), it will compare nicely with 3 ARMA models (later)&amp;lt;BR&amp;gt;&lt;br /&gt;
 mod &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corAR1(form = ~ 1|Year),  control = ctrl)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Summary of the fitted model:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(mod$\$$gam)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visualize the model trend (year) and seasonal terms (months)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(mod$\$$gam, pages = 1)&lt;br /&gt;
 t &amp;lt;- cbind(1: 1392)	# define the time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries7.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot the trend on the observed data -- with prediction:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pred2 &amp;lt;- predict(mod$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 ptemp2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,1]&amp;lt;/u&amp;gt;    &lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;# pred2[,1] = trend; 	pred2[,2] = seasonal effects&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;# mod$\$$gam&amp;lt;/b&amp;gt; is a GAM object containing information to use predict, summary and print methods, but not to use e.g. the anova method function to compare models&lt;br /&gt;
 plot(temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;, xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(ptemp2 ~ t, data = l.sort, col = &amp;quot;blue&amp;quot;, lwd = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries8.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot the seasonal model&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pred &amp;lt;- predict(mod$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 ptemp &amp;lt;- attr(pred, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred[,2]&amp;lt;/u&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 plot(l.sort$\$$temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;,  xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(ptemp, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 0.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries9.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Zoom in first 100 temps (1:100)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(l.sort$\$$temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;,  &amp;lt;b&amp;gt;xlim=c(0, 120)&amp;lt;/b&amp;gt;, xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F))); lines(ptemp, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 0.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries10.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To examine how much the estimated trend has changed over the 116 year period, we can use the data contained in &amp;lt;b&amp;gt;pred&amp;lt;/b&amp;gt; to compute the difference between the start (Jan 1900) and the end (Dec 2015) of the series in the &amp;lt;i&amp;gt;&amp;lt;u&amp;gt;trend&amp;lt;/u&amp;gt;&amp;lt;/i&amp;gt; component only:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;tail(pred[,1], 1) - head(pred[,1], 1)&amp;lt;/b&amp;gt; # subtract the predicted temp [,1] in 1900 (head) from the temp in 2015 (tail)&lt;br /&gt;
 &lt;br /&gt;
 # names(attributes(pred)); str(pred)    # to see the components of the GAM prediction model object (pred)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Assess autocorrelation in residuals&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # head(umich_data); tail(umich_data)&lt;br /&gt;
 acf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;ACF&amp;quot;)&lt;br /&gt;
 # &amp;lt;b&amp;gt;acf&amp;lt;/b&amp;gt; = Auto-correlation and Cross-Covariance Function computes and plots the estimates of the autocovariance or autocorrelation function.&lt;br /&gt;
 # &amp;lt;b&amp;gt;pacf&amp;lt;/b&amp;gt; is the function used for the partial autocorrelations.&lt;br /&gt;
 # &amp;lt;b&amp;gt;ccf&amp;lt;/b&amp;gt; computes the cross-correlation or cross-covariance of two univariate series.&lt;br /&gt;
 pacf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;pACF&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Looking at the residuals of this model, using the (partial) autocorrelation function, we see that there may be some residual autocorrelation in the data that the trend term didn’t account for. The shapes of the ACF and the pACF suggest an &amp;lt;b&amp;gt;AR(p)&amp;lt;/b&amp;gt; model might be appropriate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit and compare 4 alternative autoregressive models (original mod, AR1, AR2 and AR3)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ## AR(1)&lt;br /&gt;
 m1 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
   data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 1&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
&lt;br /&gt;
 ## AR(2)&lt;br /&gt;
 m2 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 2&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
&lt;br /&gt;
 ## AR(3)&lt;br /&gt;
 m3 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 3&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;),  control = ctrl)&lt;br /&gt;
&lt;br /&gt;
Note that the correlation argument is specified by &amp;lt;b&amp;gt;corARMA(form = ~ 1|Year, p = x)&amp;lt;/b&amp;gt;, which fits an ARMA (auto-regressive moving average) process to the residuals, where &amp;lt;b&amp;gt;p&amp;lt;/b&amp;gt; indicates the order for the &amp;lt;b&amp;gt;AR&amp;lt;/b&amp;gt; part of the ARMA model, and &amp;lt;b&amp;gt;form = ~ 1|Year&amp;lt;/b&amp;gt; specifies that the ARMA is nested within each year. This may expedite the model fitting but may also hide potential residual variation from one year to another.&lt;br /&gt;
&lt;br /&gt;
Let’s compare the candidate models by using the generalized likelihood ratio test via the &amp;lt;b&amp;gt;anova()&amp;lt;/b&amp;gt; method for &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt; objects; see our previous mixed effects modeling notes &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; , &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;. This model selection is justified as we work with nested models -- going from the AR(3) to the AR(1) by setting some of the AR coefficients to 0. The models also vary in terms of the coefficient estimates for the splines terms which may require fixing some values while choosing the AR structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;center&amp;gt;anova(mod$\$$lme, m1$\$$lme, m2$\$$lme, m3$\$$lme)&amp;lt;/center&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
|||Model||df||AIC||BIC||logLik||Test||L.Ratio||p-value&lt;br /&gt;
|-&lt;br /&gt;
|mod$\$$lme||1||7||7455.609||7492.228|| -3720.805|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|m1$\$$lme||2|| 7||7455.609||7492.228|| -3720.805|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|m2$\$$lme||3|| 8||7453.982||7495.832|| -3718.991||2 vs 3||3.627409||0.0568&lt;br /&gt;
|-&lt;br /&gt;
|m3$\$$lme||4|| 9||7455.966||7503.048|| -3718.983|| 3 vs 4||0.015687||0.9003&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Interpretation &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The AR(1) model (m1) does not provide a substantial increase in fit over the naive model (mod), and the AR(2) model (m2) only provides a marginal increase in the AR(1) model fit (m1). There is no improvement in moving from m2 to AR(3) model (m3).&lt;br /&gt;
&lt;br /&gt;
Let’s plot the AR(2) model (m2) to inspect how over-fitted the naive model with uncorrelated errors was in terms of the trend term, which shows similar smoothness compared to the initial (mod) model.&lt;br /&gt;
&lt;br /&gt;
 plot(m2$\$$gam, scale = 0)     #  plot(mod2$\$$gam, scale = 0)   # “scale=0” ensures optimal y-axis cropping of plot&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries11.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Investigation of residual patterns&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 layout(matrix(1:2, ncol = 2))&lt;br /&gt;
 # original (mod) model&lt;br /&gt;
 acf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;ACF&amp;quot;); pacf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;pACF&amp;quot;)&lt;br /&gt;
 # pACF controls for the values of the time series at all shorter lags, which contrasts the ACF which does not control for other lags.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries12.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This illustrates that there is some (month=1) Auto-correlation (ACF) and partial auto correlation in the residuals.&lt;br /&gt;
&lt;br /&gt;
 # ARM(2) model (m2)&lt;br /&gt;
 layout(matrix(1:2, ncol = 2))&lt;br /&gt;
 res &amp;lt;- resid(m2$\$$lme, type = &amp;quot;normalized&amp;quot;); &lt;br /&gt;
 acf(res, lag.max = 36, main = &amp;quot;ACF - AR(2) errors&amp;quot;); pacf(res, lag.max = 36, main = &amp;quot;pACF- AR(2) errors&amp;quot;)&lt;br /&gt;
 layout(1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries13.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No residual auto-correlation remains in &amp;lt;b&amp;gt;m2&amp;lt;/b&amp;gt;. The resulting fitted Generalized Additive Mixed Model (GAMM) object contains information about the trend and the contributions to the fitted values. The package '''mgcv'''&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; can spit the information using &amp;lt;b&amp;gt;predict()&amp;lt;/b&amp;gt; for each of the 4 models.&lt;br /&gt;
&lt;br /&gt;
 # require(mgcv); require(gamair)&lt;br /&gt;
 # m2 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 2&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
 &lt;br /&gt;
 pred2 &amp;lt;- predict(m2$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 pred_trend2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,1]&amp;lt;/u&amp;gt; &amp;lt;b&amp;gt;# trend&amp;lt;/b&amp;gt;&lt;br /&gt;
 pred_season2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,2]&amp;lt;/u&amp;gt; &amp;lt;b&amp;gt;# seasonal&amp;lt;/b&amp;gt; effects&lt;br /&gt;
 # plot(m2$\$$gam, scale = 0) # plot pure effects&lt;br /&gt;
 &lt;br /&gt;
 # Convert the 2 columns (Year and Month/variable) to R Date object&lt;br /&gt;
 # df_time &amp;lt;- as.Date(paste(as.numeric(l.sort$\$$Year), as.numeric(l.sort$\$$variable), &amp;quot;1&amp;quot;, sep=&amp;quot;-&amp;quot;)); df_time&lt;br /&gt;
 &lt;br /&gt;
 plot(x=df_time, y=l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;,  xlim=c(as.Date(&amp;quot;1950-02-01&amp;quot;),as.Date(&amp;quot;1960-01-01&amp;quot;)), xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(x=df_time, y=pred_trend2, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 2);&lt;br /&gt;
 lines(x=df_time, y=pred_season2, data = l.sort, col = &amp;quot;blue&amp;quot;, lwd = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries14.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Moving average smoothing===&lt;br /&gt;
&lt;br /&gt;
A moving average of order $m=2k+1$ can be expressed as:&lt;br /&gt;
$T_{t}=\frac{1}{2k+1}\sum_{j=-k}^{k}Y_{t+j}$ .&lt;br /&gt;
&lt;br /&gt;
The ''m''-MA represents an order m moving average, $T_t$, or the estimate of the trend-cycle at time ''t'', obtained by averaging values of the time series within ''k'' periods (left and right) of ''t''. This averaging process denoises the data (eliminates randomness in the data) and produces a smoother trend-cycle component.&lt;br /&gt;
&lt;br /&gt;
The 5-MA contains the values of $T_t$ with ''k''=2. To see what the trend-cycle estimate looks like, we plot it along with the original data&lt;br /&gt;
&lt;br /&gt;
 # print the moving average results (k=3 &amp;amp;#8596; m=7)&lt;br /&gt;
 # library(&amp;quot;forecast&amp;quot;)&lt;br /&gt;
 plot(l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;, main=&amp;quot; UMich/AA Temp (1900-2015) &amp;quot;, ylab=&amp;quot; Temperature (F)&amp;quot;, xlab=&amp;quot;Year&amp;quot;)&lt;br /&gt;
 lines(ma(l.sort$\$$temperature, 12), col=&amp;quot;red&amp;quot;, lwd=5)&lt;br /&gt;
 lines(ma(l.sort$\$$temperature, 36), col=&amp;quot;blue&amp;quot;, lwd=3)&lt;br /&gt;
 &lt;br /&gt;
 legend(0, 80, 					# places a legend at the appropriate place &lt;br /&gt;
 c(&amp;quot;Raw&amp;quot;, &amp;quot;k=12 smoother&amp;quot;, &amp;quot;k=36 smoothest&amp;quot;), 	# puts text in the legend&lt;br /&gt;
 lty=c(1,1,1), 					# gives the legend appropriate symbols (lines)&lt;br /&gt;
 cex=1.0,  					# label sizes&lt;br /&gt;
 lwd=c(2.5,2.5), col=c(&amp;quot;black&amp;quot;, &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;)) 	# gives the legend lines the correct color and width&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries15.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The blue trend (''k''=36) (3 yrs) is smoother than the original (raw) data (black) and the 1-yr average (''k''=12). It captures the main movement of the time series without all the minor fluctuations. We can’t estimate $T_t$ where ''t'' is close to the ends as there is not enough data there to compute the averages. The red trend (''k''=12) is smoother than the original (raw) data (black) but more jagged than the 3-yr average. The order of the moving average (''m'') determines the smoothness of the trend-cycle estimate. A larger order implies a smoother curve.&lt;br /&gt;
&lt;br /&gt;
===Simulation of a time-series analysis and prediction===&lt;br /&gt;
&lt;br /&gt;
 (1) Simulate a time series&lt;br /&gt;
 &lt;br /&gt;
 # the ts() function converts a numeric vector into an R time series object. &lt;br /&gt;
 # format is ts(vector, start=, end=, frequency=) where start and end are the times of the first and last observation&lt;br /&gt;
 # and frequency is the number of observations per unit time (1=annual, 4=quarterly, 12=monthly, etc.)&lt;br /&gt;
 Note that ''ling Rate'' = $\frac{1}{Frequency}$ &lt;br /&gt;
 &lt;br /&gt;
 # save a numeric vector containing 16-years (192 monthly) observations  &lt;br /&gt;
 # from Jan 2000 to Dec 2015 as a time series object&lt;br /&gt;
 sim_ts &amp;lt;- ts(as.integer(runif(192,0,10)), start=c(2000, 1), end=c(2015, 12), frequency=12)&lt;br /&gt;
 sim_ts&lt;br /&gt;
 &lt;br /&gt;
 # subset the time series (June 2014 to December 2015)&lt;br /&gt;
 sim_ts2 &amp;lt;- window(sim_ts, start=c(2014, 6), end=c(2015, 12))&lt;br /&gt;
 sim_ts2&lt;br /&gt;
 &lt;br /&gt;
 # plot series &lt;br /&gt;
 plot(sim_ts)&lt;br /&gt;
 lines(sim_ts2, col=&amp;quot;blue&amp;quot;, lwd=3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries16.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Seasonal Decomposition====&lt;br /&gt;
&lt;br /&gt;
*The additive and seasonal trends, and irregular components, of time-series may be decomposed using the stl() function. Series with multiplicative effects can by transformed into series with additive effects through a log transformation (i.e., '''ln_sim_ts &amp;lt;- log(sim_ts)).&lt;br /&gt;
 # Seasonal decomposition&lt;br /&gt;
 fit_stl &amp;lt;- stl(sim_ts, s.window=&amp;quot;period&amp;quot;)   '''# Seasonal Decomposition of Time Series by Loess'''&lt;br /&gt;
 plot(fit_stl)&lt;br /&gt;
 &lt;br /&gt;
 # inspect the distribution of the residuals&lt;br /&gt;
 hist(fit_stl$\$$time.series[,3]);  #   this contains the residuals: fit_stl$\$$time.series  [,&amp;quot;remainder&amp;quot;], or  seasonal, trend&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries17.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # additional plots &lt;br /&gt;
 monthplot(sim_ts)	# plots the seasonal subseries of a time series. For each season, a time series is plotted.&lt;br /&gt;
 &lt;br /&gt;
 # library(forecast)&lt;br /&gt;
 seasonplot(sim_ts)&lt;br /&gt;
&lt;br /&gt;
====Exponential Models====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The '''HoltWinters()''' function ('''stats''' package), and the '''ets()''' function ('''forecast''' package) can fit exponential models.&amp;lt;/li&amp;gt;&lt;br /&gt;
 # simple exponential - models level&lt;br /&gt;
 fit_HW &amp;lt;- HoltWinters(sim_ts, beta=FALSE, gamma=FALSE)&lt;br /&gt;
 &lt;br /&gt;
 # double exponential - models level and trend&lt;br /&gt;
 fit_HW2&amp;lt;- HoltWinters(sim_ts, gamma=FALSE) &lt;br /&gt;
 &lt;br /&gt;
 # triple exponential - models level, trend, and seasonal components&lt;br /&gt;
 fit_HW3 &amp;lt;- HoltWinters(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 plot(fit_HW, col='black')&lt;br /&gt;
 par(new=TRUE)&lt;br /&gt;
 plot(fit_HW2, ann=FALSE, axes=FALSE, col='blue')&lt;br /&gt;
 par(new=TRUE)&lt;br /&gt;
 plot(fit_HW3, axes=FALSE, col='red')&lt;br /&gt;
 # clear plot: &lt;br /&gt;
 # dev.off()&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries18.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Auto-regressive Integrated Moving Average (ARIMA) Models&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
There are 2 types of ARIMA time-series models: &amp;lt;BR&amp;gt;&lt;br /&gt;
$ X_t= \mu+ \underbrace{\sum_{i=1}^{p}{φ_iX_{t-i}}}_\text{auto-regressive (p) part} +&lt;br /&gt;
\underbrace{\sum_{j=1}^{q}{θ_jε_{t-j}}}_\text{moving-average (q) part} + &lt;br /&gt;
\underbrace{ ε_t }_\text{error term}.$&lt;br /&gt;
&lt;br /&gt;
====Non-seasonal ARIMA models====&lt;br /&gt;
The Non-seasonal ARIMA models are denoted by ARIMA(p, d, q), where parameters p, d, and q are positive integers, &lt;br /&gt;
* p = order of the auto-regressive model,&lt;br /&gt;
* d = degree of differencing, when ''d''=2, the '''''d&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt;'' difference''' is $(X_t-X_{t-1})-(X_{t-1}-X_{t-2})= X_t-2X_{t-1}+X_{t-2}$. That is, the second difference of ''X'' (d=2) is not the difference between the current period and the value 2 periods ago.  It is the first-difference-of-the-first difference, the discrete analog of a second derivative, representing the local acceleration of the series rather than its local trend (first derivative).&lt;br /&gt;
* q = order of the moving-average model.&lt;br /&gt;
&lt;br /&gt;
====Seasonal ARIMA models====&lt;br /&gt;
The Seasonal AMIMA models are denoted by ''ARIMA(p, d, q)(P, D, Q)&amp;lt;sub&amp;gt;m&amp;lt;/sub&amp;gt;,'' &lt;br /&gt;
* m = number of periods in each season, &lt;br /&gt;
* uppercase P, D, Q represent the auto-regressive, differencing, and moving average terms for the seasonal part of the ARIMA model, and the lower case (p,d,q) are as with non-seasonal ARIMA.&lt;br /&gt;
&lt;br /&gt;
If 2 of the 3 terms are trivial, the model is abbreviated using the non-zero parameter, skipping the &amp;quot;AR&amp;quot;, &amp;quot;I&amp;quot; or &amp;quot;MA&amp;quot; from the acronym. For example, &lt;br /&gt;
&lt;br /&gt;
*ARIMA(1,0,0) = AR(1), a stationary and auto-correlated series can be predicted as a multiple of its own previous value, plus a constant. $X_t=μ + φ_1 × X_{t-1}+ \epsilon_t.$ Note that $ε_t=X_t-\hat{X}_t.$&lt;br /&gt;
&lt;br /&gt;
*An ARIMA(0,1,0) = I(1) model, not stationary series, a limiting case of an AR(1) model, the auto-regressive coefficient is equal to 1, i.e., a series with infinitely slow mean reversion,  $X_t=μ+X_{t-1}+ε_t,$ a 1-step random walk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;For more complex models:&amp;lt;/B&amp;gt;&lt;br /&gt;
*An ARIMA(1,1,0), differenced first-order auto-regressive model.  $X_t=μ+X_{t-1}+α×(X_{t-1}-X_{t-2})+ε_t.$  &lt;br /&gt;
&lt;br /&gt;
*An ARIMA(0,2,2) model is given by $X_t=2X_{t-1}-X_{t-2}+α×ε_{t-1}+β×ε_{t-2}+ ε_t,$ where $α$ and $β$ are the MA(1) and MA(2) coefficients (sometimes these are defined with negative signs). This is a general linear exponential smoothing model that uses exponentially weighted moving averages to estimate both a local level and a local trend in the series.  The long-term forecasts from this model converge to a straight line whose slope depends on the average trend observed toward the end of the series.&lt;br /&gt;
&lt;br /&gt;
*ARIMA(1,1,2), $X_t=μ+X_{t-1}+(X_{t-1}+X_{t-2})+α×ε{t}+β×ε_{t-1}$&lt;br /&gt;
&lt;br /&gt;
The '''arima'''() function ('''stats''' package) can be used to fit an &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;auto-regressive integrated moving averages&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; model. Other useful functions include:&lt;br /&gt;
* lag(sim_ts, k) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; lagged version of time series, shifted back k observations&lt;br /&gt;
* diff(sim_ts, differences=d) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; difference the time series d times&lt;br /&gt;
* ndiffs(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Number of differences required to achieve stationarity (from the forecast package)&lt;br /&gt;
* acf(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; auto-correlation function&lt;br /&gt;
* pacf(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; partial auto-correlation function&lt;br /&gt;
* adf.test(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Augmented Dickey-Fuller test. Rejecting the null hypothesis suggests that a time series is stationary (from the tseries package)&amp;lt;/li&amp;gt;&lt;br /&gt;
* Box.test(x, type=&amp;quot;Ljung-Box&amp;quot;) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Portmanteau test that observations in vector or time series x are independent.&lt;br /&gt;
&lt;br /&gt;
The '''forecast''' package has alternative versions of '''acf()''' and '''pacf()''' called '''Acf()''' and '''Pacf()''' respectively. &lt;br /&gt;
&amp;amp;#35; fit an '''ARIMA(P, D, Q) model''' of order:&lt;br /&gt;
* P, represents the AR order&amp;lt;&lt;br /&gt;
* D, represents the degree of differencing&lt;br /&gt;
* Q, represents the MA order.&lt;br /&gt;
&lt;br /&gt;
 fit_arima1 &amp;lt;- arima(sim_ts, order=c(3, 1, 2))  &lt;br /&gt;
 # predictive accuracy &lt;br /&gt;
 library(forecast) &lt;br /&gt;
 accuracy(fit_arima1)  &lt;br /&gt;
 &lt;br /&gt;
 # predict next 20 observations &lt;br /&gt;
 library(forecast) &lt;br /&gt;
 forecast(fit_arima1, 20) &lt;br /&gt;
 plot(forecast(fit_arima1, 20)) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries19.png|600px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Forecasting===&lt;br /&gt;
&lt;br /&gt;
The '''forecast''' package provides functions for the automatic selection of exponential and ARIMA models. The '''ets()''' (exponential TS) function supports both additive and multiplicative models. The '''auto.arima()''' function accounts for seasonal and nonseasonal ARIMA models according to criteria maximizing a cost function.&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;#35; library(forecast)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Automated forecasting using an exponential model&lt;br /&gt;
  fit_ets &amp;lt;- ets(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Automated forecasting using an ARIMA model&lt;br /&gt;
 fit_arima2 &amp;lt;- auto.arima(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Compare the AIC (model quality) for both models&lt;br /&gt;
 fit_ets$\$$aic; fit_arima2$\$$aic&lt;br /&gt;
 accuracy(fit_ets); accuracy(fit_arima2);&lt;br /&gt;
&lt;br /&gt;
'''Akaike’s Information Criterion (AIC)''' = ''-2Log(Likelihood)+2p,'' where ''p'' is he number of estimated parameters.&lt;br /&gt;
 summary(fit_ets); summary(fit_arima2)&lt;br /&gt;
&lt;br /&gt;
ACF plot of the residuals from the ARIMA(3,1,2) model shows all correlations within the threshold limits indicating that the residuals are behaving like white noise. A portmanteau test returns a large p-value, also suggesting the  residuals are white noise.&lt;br /&gt;
 &amp;amp;#35; acf computes (and by default plots) estimates of the autocovariance or autocorrelation function&lt;br /&gt;
 acf(residuals(fit_ets)) &lt;br /&gt;
&lt;br /&gt;
 &amp;amp;#35; Box–Pierce or Ljung–Box test statistic for examining the null hypothesis of independence in a given time series. &lt;br /&gt;
 &amp;amp;#35; These are sometimes known as ‘portmanteau’ tests.&lt;br /&gt;
 Box.test(residuals(fit_ets), lag=24, fitdf=4, type=&amp;quot;Ljung&amp;quot;)&lt;br /&gt;
 &amp;amp;#35; plot forecast&lt;br /&gt;
 &lt;br /&gt;
 plot(forecast(fit_arima2))&lt;br /&gt;
 &amp;amp;#35; more on ARIMA https://www.otexts.org/fpp/8/7&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
* &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; https://umich.instructure.com/files/689861/download?download_frd=1  &lt;br /&gt;
* &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; https://umich.instructure.com/courses/38100/files  &lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; https://cran.r-project.org/web/packages/mgcv/mgcv.pdf&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_TimeSeriesAnalysis_LOS| Applications of Time-series]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.ucla.edu&lt;br /&gt;
{{translate|pageName=http://wiki.stat.ucla.edu/socr/index.php?title=SMHS_TimeSeriesAnalysis}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis_LOS&amp;diff=16178</id>
		<title>SMHS TimeSeriesAnalysis LOS</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis_LOS&amp;diff=16178"/>
		<updated>2016-05-23T13:48:42Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_TimeSeriesAnalysis| SMHS: Time-series Analysis]] - Applications ==&lt;br /&gt;
&lt;br /&gt;
===Time series regression studies in environmental epidemiology (London Ozone Study 2002-2006)===&lt;br /&gt;
A time series regression analysis of a London ozone dataset including daily observations from 1 January 2002 to 31 December 2006. Each day has records of (mean) '''ozone''' levels that day, and the total number of '''deaths''' that occurred in the city. &lt;br /&gt;
&lt;br /&gt;
====Questions====&lt;br /&gt;
*Is there an association between day-to-day variation in ozone levels and daily risk of death?&lt;br /&gt;
*Is ozone exposure associated with the outcome is death or other confounders - temperature and relative humidity?&lt;br /&gt;
&lt;br /&gt;
'''Reference:''' Bhaskaran K, Gasparrini A, Hajat S, Smeeth L, Armstrong B. Time series regression studies in environmental epidemiology. ''International Journal of Epidemiology''. 2013;42(4):1187-1195. doi:10.1093/ije/dyt092.&lt;br /&gt;
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3780998/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Load the Data&amp;lt;/b&amp;gt;&lt;br /&gt;
 library(foreign)&lt;br /&gt;
 &amp;amp;#35;07_LondonOzonPolutionData_2006_TS.csv&lt;br /&gt;
 &amp;amp;#35;data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/720873/download?download_frd=1&amp;quot;)&lt;br /&gt;
 data &amp;lt;- read.dta(&amp;quot;https://umich.instructure.com/files/721042/download?download_frd=1&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35;Set the Default Action for Missing Data to &amp;lt;b&amp;gt;na.exclude&amp;lt;/b&amp;gt;&lt;br /&gt;
 options(na.action=&amp;quot;na.exclude&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Exploratory Analyses&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;set the plotting parameters for the plot &lt;br /&gt;
&lt;br /&gt;
 oldpar &amp;lt;- par(no.readonly=TRUE)&lt;br /&gt;
 par(mex=0.8,mfrow=c(2,1))&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;sub-plot for daily deaths, with vertical lines defining years&lt;br /&gt;
&lt;br /&gt;
 plot(data$\$$date,data$\$$numdeaths,pch=&amp;quot;.&amp;quot;,main=&amp;quot;Daily deaths over time&amp;quot;,  &lt;br /&gt;
    ylab=&amp;quot;Daily number of deaths&amp;quot;,xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 abline(v=data$\$$date[grep(&amp;quot;-01-01&amp;quot;,data$\$$date)],col=grey(0.6),lty=2)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;plot for ozone levels&lt;br /&gt;
&lt;br /&gt;
 plot(data$\$$date,data$\$$ozone,pch=&amp;quot;.&amp;quot;,main=&amp;quot;Ozone levels over time&amp;quot;,&lt;br /&gt;
     ylab=&amp;quot;Daily mean ozone level(ug/m3)&amp;quot;,xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 abline(v=data$\$$date[grep(&amp;quot;-01-01&amp;quot;,data$\$$date)],col=grey(0.6),lty=2)&lt;br /&gt;
 par(oldpar)&lt;br /&gt;
 layout(1)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;descriptive statistics&lt;br /&gt;
 &lt;br /&gt;
 summary(data)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;correlations&lt;br /&gt;
 &lt;br /&gt;
 cor(data[,2:4])&lt;br /&gt;
 &amp;amp;#35;scale exposure&lt;br /&gt;
 data$\$$ozone10 &amp;lt;- data$\$$ozone/10&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modelling Seasonality and Long-Term Trend&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;option 1: time-stratified model &amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;generate month and year&lt;br /&gt;
&lt;br /&gt;
 data$\$$month &amp;lt;- as.factor(months(data$\$$date,abbr=TRUE))&lt;br /&gt;
 data$\$$year &amp;lt;- as.factor(substr(data$\$$date,1,4))&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;fit a Poisson model with a stratum for each month nested in year&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;(use of quasi-Poisson family for scaling the standard errors)&lt;br /&gt;
&lt;br /&gt;
 model1 &amp;lt;- glm(numdeaths ~ month/year,data,family=quasipoisson) &lt;br /&gt;
 summary(model1)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;compute predicted number of deaths from this model&lt;br /&gt;
 pred1 &amp;lt;- predict(model1,type=&amp;quot;response&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Figure 2a: Three alternative ways of modelling long-term patterns in the data (seasonality and trends)&lt;br /&gt;
&lt;br /&gt;
 plot(data$\$$date,data$\$$numdeaths,ylim=c(100,300),pch=19,cex=0.2,col=grey(0.6),&lt;br /&gt;
     main=&amp;quot;Time-stratified model (month strata)&amp;quot;,ylab=&amp;quot;Daily number of deaths&amp;quot;, xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 lines(data$\$$date, pred1,lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Option 2: periodic functions model (fourier terms)&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;use function harmonic, in package '''tsModel''' &lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;tsModel&amp;quot;); library(tsModel)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;4 sine-cosine pairs representing different harmonics with period 1 year&lt;br /&gt;
&lt;br /&gt;
 data$\$$time &amp;lt;- seq(nrow(data))&lt;br /&gt;
 fourier &amp;lt;- harmonic(data$\$$time,nfreq=4,period=365.25)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;fit a Poisson model Fourier terms + linear term for trend &amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;(use of quasi-Poisson family for scaling the standard errors)&lt;br /&gt;
&lt;br /&gt;
 model2 &amp;lt;- glm(numdeaths ~ fourier +time,data,family=quasipoisson) &lt;br /&gt;
 summary(model2)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;compute predicted number of deaths from this model&lt;br /&gt;
&lt;br /&gt;
 pred2 &amp;lt;- predict(model2,type=&amp;quot;response&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Figure 2b&lt;br /&gt;
&lt;br /&gt;
 plot(data$\$$date, data$\$$numdeaths,ylim=c(100,300),pch=19,cex=0.2,col=grey(0.6),&lt;br /&gt;
     main=&amp;quot;Sine-cosine functions (Fourier terms)&amp;quot;,ylab=&amp;quot;Daily number of deaths&amp;quot;, xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 lines(data$\$$date, pred2,lwd=2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Option 3: Spline Model: Flexible Spline Functions&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;generate spline terms,  use function '''bs''' in package '''splines'''&lt;br /&gt;
 library(splines)&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;A CUBIC B-SPLINE WITH 32 EQUALLY-SPACED KNOTS + 2 BOUNDARY KNOTS&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;Note: the 35 basis variables are set as df, with default knots placement. see '''?bs'''&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;other types of splines can be produced with the function ns. see '''?ns'''&lt;br /&gt;
 spl &amp;lt;- bs(data$\$$time,degree=3,df=35)&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;Fit a Poisson Model Fourier Terms + Linear Term for Trend&lt;br /&gt;
&lt;br /&gt;
 model3 &amp;lt;- glm(numdeaths ~ spl,data,family=quasipoisson)&lt;br /&gt;
 summary(model3)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;compute predicted number of deaths from this model&lt;br /&gt;
&lt;br /&gt;
 pred3 &amp;lt;- predict(model3,type=&amp;quot;response&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;FIGURE 2C&lt;br /&gt;
&lt;br /&gt;
 plot(data$\$$date,data$\$$numdeaths,ylim=c(100,300),pch=19,cex=0.2,col=grey(0.6), &lt;br /&gt;
     main=&amp;quot;Flexible cubic spline model&amp;quot;,ylab=&amp;quot;Daily number of deaths&amp;quot;, xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 lines(data$\$$date,pred3,lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot Response Residuals Over Time From Model 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;GENERATE RESIDUALS&lt;br /&gt;
 res3 &amp;lt;- residuals(model3,type=&amp;quot;response&amp;quot;)&lt;br /&gt;
&amp;amp;#35;Figure 3: Residual variation in daily deaths after ‘removing’ (i.e. modelling) season and long-term trend.&lt;br /&gt;
 plot(data$\$$date,res3,ylim=c(-50,150),pch=19,cex=0.4,col=grey(0.6),&lt;br /&gt;
     main=&amp;quot;Residuals over time&amp;quot;,ylab=&amp;quot;Residuals (observed-fitted)&amp;quot;,xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 abline(h=1,lty=2,lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Estimate ozone-mortality association - controlling for confounders&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;compare the RR (and CI using '''ci.lin''' in package '''Epi''')&lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;Epi&amp;quot;); library(Epi)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;unadjusted model&lt;br /&gt;
&lt;br /&gt;
 model4 &amp;lt;- glm(numdeaths ~ ozone10,data,family=quasipoisson)&lt;br /&gt;
 summary(model4)&lt;br /&gt;
 (eff4 &amp;lt;- ci.lin(model4,subset=&amp;quot;ozone10&amp;quot;,Exp=T))&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;control for seasonality (with spline as in model 3)&lt;br /&gt;
&lt;br /&gt;
 model5 &amp;lt;- update(model4, .~. + spl)&lt;br /&gt;
 summary(model5)&lt;br /&gt;
 (eff5 &amp;lt;- ci.lin(model5,subset=&amp;quot;ozone10&amp;quot;,Exp=T))&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;control for temperature - temperature modelled with categorical variables for deciles&lt;br /&gt;
 &lt;br /&gt;
 cutoffs &amp;lt;- quantile(data$\$$temperature,probs=0:10/10)&lt;br /&gt;
 tempdecile &amp;lt;- cut(data$\$$temperature,breaks=cutoffs,include.lowest=TRUE)&lt;br /&gt;
 model6 &amp;lt;- update(model5,.~.+tempdecile)&lt;br /&gt;
 summary(model6)&lt;br /&gt;
 (eff6 &amp;lt;- ci.lin(model6,subset=&amp;quot;ozone10&amp;quot;,Exp=T))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Build a summary table with effect as percent increase&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 tabeff &amp;lt;- rbind(eff4,eff5,eff6)[,5:7]&lt;br /&gt;
 tabeff &amp;lt;- (tabeff-1)*100&lt;br /&gt;
 dimnames(tabeff) &amp;lt;- list(c(&amp;quot;Unadjusted&amp;quot;,&amp;quot;Plus season/trend&amp;quot;,&amp;quot;Plus temperature&amp;quot;), c(&amp;quot;RR&amp;quot;,&amp;quot;ci.low&amp;quot;,&amp;quot;ci.hi&amp;quot;))&lt;br /&gt;
 round(tabeff,2)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;explore the lagged (delayed) effects&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;SINGLE-LAG MODELS&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;prepare the table with estimates&lt;br /&gt;
&lt;br /&gt;
 tablag &amp;lt;- matrix(NA,7+1,3,dimnames=list(paste(&amp;quot;Lag&amp;quot;,0:7),  c(&amp;quot;RR&amp;quot;,&amp;quot;ci.low&amp;quot;,&amp;quot;ci.hi&amp;quot;)))&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;iterate&lt;br /&gt;
&lt;br /&gt;
 for(i in 0:7) {&lt;br /&gt;
     &amp;amp;#35;lag ozone and temperature variables&lt;br /&gt;
     ozone10lag &amp;lt;- Lag(data$\$$ozone10,i)&lt;br /&gt;
     tempdecilelag &amp;lt;- cut(Lag(data$\$$temperature,i),breaks=cutoffs,   include.lowest=TRUE)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;define the transformation for temperature&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;lag same as above, but with strata terms instead than linear&lt;br /&gt;
 &lt;br /&gt;
     mod &amp;lt;- glm(numdeaths ~ ozone10lag + tempdecilelag + spl,data,   family=quasipoisson)&lt;br /&gt;
     tablag[i+1,] &amp;lt;- ci.lin(mod,subset=&amp;quot;ozone10lag&amp;quot;,Exp=T)[5:7]&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 }&lt;br /&gt;
 tablag&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Figure 4A: Modelling lagged (delayed) associations between ozone exposure and survival/death outcome.&lt;br /&gt;
&lt;br /&gt;
 plot(0:7,0:7,type=&amp;quot;n&amp;quot;,ylim=c(0.99,1.03),main=&amp;quot;Lag terms modelled one at a time&amp;quot;, xlab=&amp;quot;Lag (days)&amp;quot;,&lt;br /&gt;
     ylab=&amp;quot;RR and 95%CI per 10ug/m3 ozone increase&amp;quot;)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 abline(h=1)&lt;br /&gt;
 arrows(0:7,tablag[,2],0:7,tablag[,3],length=0.05,angle=90,code=3)&lt;br /&gt;
 points(0:7,tablag[,1],pch=19)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Model Checking&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;generate deviance residuals from unconstrained distributed lag model&lt;br /&gt;
&lt;br /&gt;
 res6 &amp;lt;- residuals(model6,type=&amp;quot;deviance&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Figure A1: Plot of deviance residuals over time (London data)&lt;br /&gt;
&lt;br /&gt;
 plot(data$\$$date,res6,ylim=c(-5,10),pch=19,cex=0.7,col=grey(0.6),&lt;br /&gt;
      main=&amp;quot;Residuals over time&amp;quot;,ylab=&amp;quot;Deviance residuals&amp;quot;,xlab=&amp;quot;Date&amp;quot;)&lt;br /&gt;
 abline(h=0,lty=2,lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Figure A2a: Residual plot for Model6: the residuals relate to the unconstrained distributed lag model with ozone&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;(lag days 0 to 7 inclusive), adjusted for temperature at the same lags. The spike in the plot of residuals relate to&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;the 2003 European heat wave, and indicate that the current model does not explain the data over this period well.&lt;br /&gt;
&lt;br /&gt;
 pacf(res6,na.action=na.omit,main=&amp;quot;From original model&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Include the 1-Day Lagged Residual in the Model&lt;br /&gt;
&lt;br /&gt;
 model9 &amp;lt;- update(model6,.~.+Lag(res6,1))&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;Figure A2b: residuals related to the unconstrained distributed lag model with ozone (lag days 0 to 7 inclusive),&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;adjusted for temperature at the same lags&lt;br /&gt;
&lt;br /&gt;
 pacf(residuals(model9,type=&amp;quot;deviance&amp;quot;),na.action=na.omit,   &lt;br /&gt;
     main=&amp;quot;From model adjusted for residual autocorrelation&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
====Irish Longitudinal Study on Ageing Example====&lt;br /&gt;
&lt;br /&gt;
The Irish Longitudinal Study on Ageing (TILDA), 2009-2011 &amp;lt;BR&amp;gt;&lt;br /&gt;
http://www.icpsr.umich.edu/icpsrweb/ICPSR/studies/34315&amp;lt;BR&amp;gt;&lt;br /&gt;
Kenny, Rose Anne. The Irish Longitudinal Study on Ageing (TILDA),&amp;lt;BR&amp;gt;&lt;br /&gt;
2009-2011. ICPSR34315-v1. Ann Arbor, MI: Inter-university Consortium&amp;lt;BR&amp;gt;&lt;br /&gt;
Bibliographic Citation: for Political and Social Research [distributor], 2014-07-16.&amp;lt;BR&amp;gt;&lt;br /&gt;
http://doi.org/10.3886/ICPSR34315.v1&lt;br /&gt;
&lt;br /&gt;
The Irish Longitudinal Study on Ageing (TILDA) is a major inter-institutional initiative led by Trinity College, Dublin, to improve in the quantity and quality of data, research and information related to aging in Ireland. Eligible respondents for this study include individuals aged ≥ 50 and their spouses or partners of any age. Annual interviews on a two yearly basis (N=8,504 people) in Ireland, collecting detailed information on all aspects of their lives, including the economic (pensions, employment, living standards), health (physical, mental, service needs and usage) and social aspects (contact with friends and kin, formal and informal care, social participation). Survey interviews, physical, and biological data are collected along with demographic variables (e.g., age, sex, marital status, household composition, education, and employment), and activities of daily living (ADL), aging, childhood, depression (psychology), education, employment, exercise, eyesight, families, family life, etc.&lt;br /&gt;
&lt;br /&gt;
 # download the RDA data object (ICPSR_34315.zip)&lt;br /&gt;
 # load in the data into RStudio&lt;br /&gt;
 dataURL &amp;lt;- &amp;quot;https://umich.instructure.com/files/703606/download?download_frd=1&amp;quot;&lt;br /&gt;
 load(url(dataURL))&lt;br /&gt;
 head(da34315.0001); data_colnames &amp;lt;- colnames(da34315.0001)&lt;br /&gt;
 vars &amp;lt;- da34315.0001&lt;br /&gt;
&lt;br /&gt;
 vars; head(vars); summary(vars); data_colnames&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1]||”ID&amp;quot;||”HOUSEHOLD”&lt;br /&gt;
|-&lt;br /&gt;
|[3]|| &amp;quot;CLUSTER&amp;quot;||&amp;quot;STRATUM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[5]||”REGION”|| &amp;quot;CAPIWEIGHT&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[7]|| &amp;quot;IN_SCQ&amp;quot;||&amp;quot;SCQ_WEIGHT&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[9]|| &amp;quot;AGE&amp;quot;||&amp;quot;SEX&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[11]|| &amp;quot;NML&amp;quot;||&amp;quot;CM003&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|...||||&lt;br /&gt;
|-&lt;br /&gt;
|[1673]||&amp;quot;HA_WEIGHT&amp;quot;||&amp;quot;IN_HA&amp;quot;&lt;br /&gt;
|-                                             &lt;br /&gt;
|[1675]|| &amp;quot;SR_HEIGHT_CENTIMETRES&amp;quot;||&amp;quot;HEIGHT&amp;quot;                          &lt;br /&gt;
|-&lt;br /&gt;
|[1677]|| &amp;quot;SR_WEIGHT_KILOGRAMMES&amp;quot;||&amp;quot;WEIGHT&amp;quot;                          &lt;br /&gt;
|-&lt;br /&gt;
|[1679]||&amp;quot;COGMMSE&amp;quot;||&amp;quot;FRGRIPSTRENGTHD&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1681]||&amp;quot;FRGRIPSTRENGTHND&amp;quot;||&amp;quot;VISUALACUITYLEFT&amp;quot;   &lt;br /&gt;
|-&lt;br /&gt;
|[1683]||&amp;quot;VISUALACUITYRIGHT&amp;quot; ||&amp;quot;BPSEATEDSYSTOLIC1&amp;quot;  &lt;br /&gt;
|-&lt;br /&gt;
|[1685]||&amp;quot;BPSEATEDSYSTOLIC2&amp;quot;||&amp;quot;BPSEATEDDIASTOLIC1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1687]||&amp;quot;BPSEATEDDIASTOLIC2&amp;quot;||&amp;quot;BPSEATEDSYSTOLICMEAN&amp;quot;  &lt;br /&gt;
|-&lt;br /&gt;
|[1689]||&amp;quot;BPSEATEDDIASTOLICMEAN&amp;quot;||&amp;quot;BPHYPERTENSION&amp;quot;            &lt;br /&gt;
|-&lt;br /&gt;
|[1691]||&amp;quot;FRBMI&amp;quot;||&amp;quot;FRWAIST&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|[1693]||&amp;quot;FRHIP&amp;quot;||&amp;quot;FRWHR&amp;quot;  &lt;br /&gt;
|-&lt;br /&gt;
|[1695]||&amp;quot;WEARGLASSES&amp;quot;||&amp;quot;WOREGLASSESDURINGTEST&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1697]||&amp;quot;BLOODS_CHOL&amp;quot;||&amp;quot;BLOODS_HDL&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|[1699]||&amp;quot;BLOODS_LDL&amp;quot;||&amp;quot;BLOODS_TRIG&amp;quot;  &lt;br /&gt;
|-&lt;br /&gt;
|[1701]||&amp;quot;BLOODS_TIMEBETWEENLASTMEALANDASS&amp;quot;||&amp;quot;DELAY_HA&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1703]||&amp;quot;PICMEMSCORE&amp;quot;||&amp;quot;PICRECALLSCORE&amp;quot;  &lt;br /&gt;
|-&lt;br /&gt;
|[1705]||&amp;quot;PICRECOGSCORE&amp;quot;||&amp;quot;VISREASONING&amp;quot;  &lt;br /&gt;
|-&lt;br /&gt;
|[1707]||&amp;quot;GRIPTEST1D&amp;quot;||&amp;quot;GRIPTEST2D&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1709]||&amp;quot;GRIPTEST1ND&amp;quot;||&amp;quot;GRIPTEST2ND&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1711]||&amp;quot;GRIPTESTDOMINANT&amp;quot;||&amp;quot;GRIPTESTSITTING&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|[1713]||&amp;quot;TEMPERATURE&amp;quot;||&amp;quot;SCQSOCACT1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|...||||&lt;br /&gt;
|-&lt;br /&gt;
|[1981]||&amp;quot;SOCPROXCHLD4&amp;quot;||&amp;quot;SCRFLU&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1983]||&amp;quot;SCRCHOL&amp;quot;||&amp;quot;SCRPROSTATE&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1985]||&amp;quot;SCRBREASTLUMPS&amp;quot;||&amp;quot;SCRMAMMOGRAM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1987]||&amp;quot;BEHALC_FREQ_WEEK&amp;quot;||&amp;quot;BEHALC_DRINKSPERDAY&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1989]||&amp;quot;BEHALC_DRINKSPERWEEK&amp;quot;||&amp;quot;BEHALC_DOH_LIMIT&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|[1991]||&amp;quot;BEHSMOKER&amp;quot;||&amp;quot;BEHCAGE&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # extract some data elements&lt;br /&gt;
 df1 &amp;lt;- data.frame(vars)&lt;br /&gt;
&lt;br /&gt;
 df_Irish_small &amp;lt;- df1[, c(&amp;quot;ID&amp;quot;,  &amp;quot;HOUSEHOLD&amp;quot;,  &amp;quot;AGE&amp;quot;, &amp;quot;SEX&amp;quot;  , &amp;quot;HA_WEIGHT&amp;quot;, &amp;quot;HEIGHT&amp;quot; ,                         &lt;br /&gt;
    &amp;quot;WEIGHT&amp;quot;, &amp;quot;COGMMSE&amp;quot;, &amp;quot;FRGRIPSTRENGTHD&amp;quot;, &amp;quot;VISUALACUITYLEFT&amp;quot;,       &lt;br /&gt;
    &amp;quot;VISUALACUITYRIGHT&amp;quot;,    &amp;quot;BPSEATEDSYSTOLIC1&amp;quot;,      &lt;br /&gt;
    &amp;quot;BPSEATEDSYSTOLIC2&amp;quot;,       &amp;quot;BPSEATEDDIASTOLIC1&amp;quot;,     &lt;br /&gt;
    &amp;quot;BPSEATEDDIASTOLIC2&amp;quot;,      &amp;quot;BPSEATEDSYSTOLICMEAN&amp;quot;,   &lt;br /&gt;
    &amp;quot;BPSEATEDDIASTOLICMEAN&amp;quot;,   &amp;quot;BPHYPERTENSION&amp;quot;,&lt;br /&gt;
    &amp;quot;WEARGLASSES&amp;quot;,   &amp;quot;WOREGLASSESDURINGTEST&amp;quot;,  &lt;br /&gt;
    &amp;quot;BLOODS_CHOL&amp;quot;,   &amp;quot;BLOODS_HDL&amp;quot;,    &lt;br /&gt;
    &amp;quot;BLOODS_LDL&amp;quot;,  &amp;quot;BLOODS_TRIG&amp;quot;,   &lt;br /&gt;
    &amp;quot;PICMEMSCORE&amp;quot;,   &amp;quot;PICRECALLSCORE&amp;quot;,&lt;br /&gt;
    &amp;quot;PICRECOGSCORE&amp;quot;, &amp;quot;VISREASONING&amp;quot;,  &lt;br /&gt;
    &amp;quot;TEMPERATURE&amp;quot;,  &amp;quot;SOCPROXCHLD4&amp;quot;,   &amp;quot;SCRFLU&amp;quot;, &amp;quot;SCRCHOL&amp;quot;,        &amp;quot;SCRPROSTATE&amp;quot;,   &lt;br /&gt;
    &amp;quot;SCRBREASTLUMPS&amp;quot;, &amp;quot;SCRMAMMOGRAM&amp;quot;,  &lt;br /&gt;
    &amp;quot;BEHALC_FREQ_WEEK&amp;quot;,        &amp;quot;BEHALC_DRINKSPERDAY&amp;quot;,    &lt;br /&gt;
    &amp;quot;BEHALC_DRINKSPERWEEK&amp;quot;,    &amp;quot;BEHALC_DOH_LIMIT&amp;quot;,       &lt;br /&gt;
    &amp;quot;BEHSMOKER&amp;quot;,      &amp;quot;BEHCAGE&amp;quot; )&lt;br /&gt;
    ]&lt;br /&gt;
&lt;br /&gt;
 summary(df_Irish_small); head(df_Irish_small)&lt;br /&gt;
 write.table(df_Irish_small , &amp;quot;data.csv&amp;quot;, sep=&amp;quot;,&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
===Applications===&lt;br /&gt;
&lt;br /&gt;
====Frailty associations with sustained attention measures&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
Multinomial logistic regression analyses were used to examine frailty as the outcome variable were performed to determine associations between the sustained attention measures and prefrailty or frailty. Binary logistic regression analyses determined significant associations between the sustained attention measures and the individual frailty components. The regression models included age and gender and were also extended to include additional measures of cognitive processing speed (cognitive RT from CRT), executive function (Delta CTT), number of chronic conditions, and number of medications. We also included the quadratic term age2 to allow for any potential nonlinear effects of age on frailty in each regression model. For the independent variables in the multinomial logistic regression models, relative risk (RR) ratios with 95% confidence intervals (CIs) were provided. For the independent variables in the binary logistic regression models, OR with 95% CI were provided.&lt;br /&gt;
&lt;br /&gt;
====Multivariable logistic regression examining the association between social relationships and depression, anxiety, and suicidal ideation&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;http://psychsocgerontology.oxfordjournals.org/content/early/2013/03/13/geronb.gbt009.full&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;http://www.jad-journal.com/article/S0165-0327%2815%2900145-7/fulltext&lt;br /&gt;
&lt;br /&gt;
===Appendix===&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_TimeSeriesAnalysis| Previous Section on Time-series analysis]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.ucla.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.stat.ucla.edu/socr/index.php?title=SMHS_TimeSeriesAnalysis_LOS}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis&amp;diff=16177</id>
		<title>SMHS TimeSeriesAnalysis</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_TimeSeriesAnalysis&amp;diff=16177"/>
		<updated>2016-05-23T13:47:59Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Seasonal ARIMA models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Time Series Analysis ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
* Why are trends, patterns or predictions from models/data important?&lt;br /&gt;
* How to detect, model and utilize trends in longitudinal data?&lt;br /&gt;
&lt;br /&gt;
Time series analysis represents a class of statistical methods applicable for series data aiming to extract meaningful information, trend and characterization of the process using observed longitudinal data. These trends may be used for time series forecasting and for prediction of future values based on retrospective observations. Note that classical linear modeling (e.g., regression analysis) may also be employed for prediction &amp;amp; testing of associations using the values of one or more independent variables and their effect on the value of another variable. However, time series analysis allows dependencies (e.g., seasonal effects to be accounted for).&lt;br /&gt;
&lt;br /&gt;
===Time-series representation===&lt;br /&gt;
&lt;br /&gt;
There are 3 (distinct and complementary) types of &amp;lt;b&amp;gt;time series patterns&amp;lt;/b&amp;gt; that most time-series analyses are trying to identify, model and analyze. These include: &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Trend&amp;lt;/b&amp;gt;: A trend is a long-term increase or decrease in the data that may be linear or non-linear, but is generally continuous (mostly monotonic). The trend may be referred to as direction.&lt;br /&gt;
* &amp;lt;b&amp;gt;Seasonal&amp;lt;/b&amp;gt;: A seasonal pattern is influence in the data, like seasonal factors (e.g., the quarter of the year, the month, or day of the week), which is always of a fixed known period.&lt;br /&gt;
* &amp;lt;b&amp;gt;Cyclic&amp;lt;/b&amp;gt;:  A cyclic pattern of fluctuations corresponds to rises and falls that are &amp;lt;i&amp;gt;not of fixed period.&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries1.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, the following code shows several time series with different types of time series patterns.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;par&amp;lt;/b&amp;gt;(mfrow=c(3,2))&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;n &amp;lt;- 98&amp;lt;/b&amp;gt;&lt;br /&gt;
 X &amp;lt;- cbind(1:n)   # time points (annually)&lt;br /&gt;
 &amp;lt;u&amp;gt;Trend1&amp;lt;/u&amp;gt; &amp;lt;- LakeHuron+0.2*X  # series 1&lt;br /&gt;
 Trend2 &amp;lt;- LakeHuron-0.5*X  # series 2&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;u&amp;gt;Season1&amp;lt;/u&amp;gt; &amp;lt;- X; Season2 &amp;lt;- X;  # series 1 &amp;amp; 2&lt;br /&gt;
 for(i in 1:n) {&lt;br /&gt;
     &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] + 5*(i%%4)&lt;br /&gt;
     &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] -2*(i%%10)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;u&amp;gt;Cyclic1&amp;lt;/u&amp;gt; &amp;lt;- X; Cyclic2 &amp;lt;- X;  # series 1 &amp;amp; 2&lt;br /&gt;
 for(i in 1:n) {&lt;br /&gt;
 rand1 &amp;lt;- as.integer(runif(1, 1, 10))&lt;br /&gt;
     &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] + 3*(i%%rand1)&lt;br /&gt;
     &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;[i] &amp;lt;- LakeHuron[i] - 1*(i%%rand1)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, Trend1, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; Trend1&amp;quot;, main=&amp;quot;Trend1 (LakeHuron+0.2*X)&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, Trend2, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; Trend2&amp;quot; , main=&amp;quot;Trend2 (LakeHuron-0.5*X)&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Season1&amp;lt;/b&amp;gt;=Trend1 (LakeHuron+5(i%%4))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Season2&amp;lt;/b&amp;gt;=Trend1 (LakeHuron-2(i%%10))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Cyclic1&amp;lt;/b&amp;gt;=Trend1 (LakeHuron+3*(i%%rand1))&amp;quot;)&lt;br /&gt;
 &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt;(X, &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;, xlab=&amp;quot;Year&amp;quot;,ylab=&amp;quot; &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt;&amp;quot;, main=&amp;quot; &amp;lt;b&amp;gt;Cyclic2&amp;lt;/b&amp;gt; = Trend1 (LakeHuron-(i%%rand1))&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note: If you get this run-time graphics error:&lt;br /&gt;
“&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Error in plot.new() : figure margins too large&amp;lt;/font&amp;gt;” &amp;lt;BR&amp;gt;&lt;br /&gt;
You need to make sure your graphics window is large enough or print to PDF:&lt;br /&gt;
&lt;br /&gt;
 pdf(&amp;quot;myplot.pdf&amp;quot;); plot(x); dev.off()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries2.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s look at the delta (Δ) changes - Lagged Differences, using &amp;lt;b&amp;gt;diff&amp;lt;/b&amp;gt;, which returns suitably lagged and iterated differences.&lt;br /&gt;
&lt;br /&gt;
 ## Default lag = 1&lt;br /&gt;
 &amp;lt;b&amp;gt;par&amp;lt;/b&amp;gt;(mfrow=c(1,1))&lt;br /&gt;
 hist(diff(Trend1), prob=T, col=&amp;quot;red&amp;quot;) # Plot histogram&lt;br /&gt;
 lines(density(diff(Trend1)),lwd=2)	# plot density estimate&lt;br /&gt;
 x&amp;lt;-seq(-4,4,length=100); y&amp;lt;-dnorm(x, mean(diff(Trend1)), sd(diff(Trend1)))&lt;br /&gt;
 lines(x,y,lwd=2,col=&amp;quot;blue&amp;quot;)	# plot MLE Normal Fit&lt;br /&gt;
&lt;br /&gt;
===Time series decomposition===&lt;br /&gt;
&lt;br /&gt;
Denote the time series $yt$ including the three components: a seasonal effect, a trend-cycle effect (containing both trend and cycle), and a remainder component (containing the residual variability in the time series).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Additive model&amp;lt;/b&amp;gt;: &lt;br /&gt;
$yt=St+Tt+Et,$ where $yt$ is the data at period $t, St$ is the seasonal component at period $t, Tt$ is the trend-cycle component at period $t$ and $Et$ is the remainder (error) component at period $t$. This &amp;lt;u&amp;gt;additive model&amp;lt;/u&amp;gt; is appropriate if the magnitude of the seasonal fluctuations or the variation around the trend-cycle does not vary with the level of the time series.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Multiplicative model&amp;lt;/b&amp;gt;:  $yt=St×Tt×Et$. When the variation in the seasonal pattern, or the variation around the trend-cycle, are proportional to the level of the time series, then a multiplicative model is more appropriate. Note that when using a multiplicative model, we can transform the data to stabilize the variation in the series over time, and then use an additive model. For instance, a log transformation decomposes the multiplicative model from:&lt;br /&gt;
&lt;br /&gt;
$yt=St×Tt×Et$ &amp;lt;BR&amp;gt;&lt;br /&gt;
to the additive model: &amp;lt;BR&amp;gt;&lt;br /&gt;
$log(yt)=log(St)+log(Tt)+log(Et).$&lt;br /&gt;
&lt;br /&gt;
We can examine the Seasonal trends by decomposing the Time Series by &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;loess&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt; (Local Polynomial Regression) Fitting into &amp;lt;b&amp;gt;S&amp;lt;/b&amp;gt;easonal, &amp;lt;b&amp;gt;T&amp;lt;/b&amp;gt;rend and irregular components using &amp;lt;b&amp;gt;L&amp;lt;/b&amp;gt;oess - Local Polynomial Regression Fitting (&amp;lt;b&amp;gt;stl&amp;lt;/b&amp;gt; function, in the default “stats” package):&lt;br /&gt;
&lt;br /&gt;
 # using Monthly Males Deaths from Lung Diseases in UK from bronchitis, emphysema and asthma, 1974–1979&lt;br /&gt;
 mdeaths  # is.ts(mdeaths)&lt;br /&gt;
 fit &amp;lt;- stl(mdeaths, s.window=5)&lt;br /&gt;
 plot(mdeaths, col=&amp;quot;gray&amp;quot;,   main=&amp;quot; Lung Diseases in UK &amp;quot;, ylab=&amp;quot; Lung Diseases Deaths&amp;quot;, xlab=&amp;quot;&amp;quot;)&lt;br /&gt;
 lines(fit\$\$$time.series[,2],col=&amp;quot;red&amp;quot;,ylab=&amp;quot;Trend&amp;quot;)&lt;br /&gt;
 plot(fit) # data, seasonal, trend, residuals&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;“stl” function parameters&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|x||Univariate time series to be decomposed. This should be an object of class &amp;quot;ts&amp;quot; with a frequency greater than one.&lt;br /&gt;
|-&lt;br /&gt;
|s.window||either the character string &amp;quot;periodic&amp;quot; or the span (in lags) of the loess window for seasonal extraction, which should be odd and at least 7, according to Cleveland et al. This has no default.&lt;br /&gt;
|-&lt;br /&gt;
|s.degree||degree of locally-fitted polynomial in seasonal extraction. Should be zero or one.&lt;br /&gt;
|-&lt;br /&gt;
|t.window||the span (in lags) of the loess window for trend extraction, which should be odd. If NULL, the default, nextodd(ceiling((1.5*period) / (1-(1.5/s.window)))), is taken.&lt;br /&gt;
|-&lt;br /&gt;
|t.degree||degree of locally-fitted polynomial in trend extraction. Should be zero or one.&lt;br /&gt;
|-&lt;br /&gt;
|l.window||the span (in lags) of the loess window of the low-pass filter used for each subseries. Defaults to the smallest odd integer greater than or equal to frequency(x) which is recommended since it prevents competition between the trend and seasonal components. If not an odd integer its given value is increased to the next odd one.&lt;br /&gt;
|-&lt;br /&gt;
|l.degree||degree of locally-fitted polynomial for the subseries low-pass filter. Must be 0 or 1.&lt;br /&gt;
|-&lt;br /&gt;
|s.jump, t.jump, l.jump||integers at least one to increase speed of the respective smoother. Linear interpolation happens between every *.jump&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; value.&lt;br /&gt;
|-&lt;br /&gt;
|robust||logical indicating if robust fitting be used in the loess procedure.&lt;br /&gt;
|-&lt;br /&gt;
|inner||integer; the number of ‘inner’ (backfitting) iterations; usually very few (2) iterations suffice.&lt;br /&gt;
|-&lt;br /&gt;
|outer||integer; the number of ‘outer’ robustness iterations.&lt;br /&gt;
|-&lt;br /&gt;
|na.action||action on missing values.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries3.png|400px]] [[Image:SMHS_TimeSeries4.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;monthplot&amp;lt;/b&amp;gt;(fit$\$$time.series[,&amp;quot;seasonal&amp;quot;], main=&amp;quot;&amp;quot;, ylab=&amp;quot;Seasonal&amp;quot;, lwd=5)&lt;br /&gt;
 &amp;amp;#35;As the “fit &amp;lt;- stl(mdeaths, s.window=5)” object has 3 time-series components (seasonal; trend; remainder)&lt;br /&gt;
 &amp;amp;#35;we can alternatively plot them separately:&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;seasonal&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, cex.axis = 0.8)&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;trend&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, cex.axis = 0.8)&lt;br /&gt;
 &amp;amp;#35;monthplot(fit, choice = &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;&amp;quot;remainder&amp;quot;&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;, type = &amp;quot;h&amp;quot;, cex.axis = 1.2)    # histogramatic&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries5.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the seasonal plots and seasonal sub-series plots of the seasonal component illustrating the variation in the seasonal component over time (over the years).&lt;br /&gt;
&lt;br /&gt;
Using historical weather (average daily temperature at the University of Michigan, Ann Arbor):&lt;br /&gt;
[http://weather-warehouse.com/WeatherHistory/PastWeatherData_AnnArborUnivOfMi_AnnArbor_MI_January.html]&lt;br /&gt;
(See meta-data description and provenance online: [http://weather-warehouse.com/WxWfaqs.html]).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Mean Temperature, (F), UMich, Ann Arbor (1900-2015)&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Year||Jan||Feb||Mar||Apr||May||Jun||Jul||Aug||Sep||Oct||Nov||Dec&lt;br /&gt;
|-&lt;br /&gt;
|2015||26.3||14.4||34.9||49||64.2||68||71.2||70.2||68.7||53.9||NR||NR&lt;br /&gt;
|-&lt;br /&gt;
|2014||24.4||19.4||29||48.9||60.7||69.7||68.8||70.8||63.2||52.1||35.4||33.3&lt;br /&gt;
|-&lt;br /&gt;
|2013||22.7||26.1||33.3||46||63.1||68.5||72.9||70.2||64.6||53.2||37.6||26.7&lt;br /&gt;
|-&lt;br /&gt;
|2012||22.4||32.8||50.7||49.2||65.2||71.4||78.9||72.2||63.9||51.7||39.6||34.8&lt;br /&gt;
|-&lt;br /&gt;
|...|| || || || || || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|...||17||15.3||31.4||47.3||57||69||76.6||72||63.4||52.2||35.2||23.7&lt;br /&gt;
|-&lt;br /&gt;
|1900||21.4||19.2||24.7||47.8||60.2||66.3||72||75.4||67.2||59||37.6||29.2&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # data: 07_UMich_AnnArbor_MI_TempPrecipitation_HistData_1900_2015.csv&lt;br /&gt;
 # more complete data is available here: 07_UMich_AnnArbor_MI_TempPrecipitation_HistData_1900_2015.xls umich_data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/702739/download?download_frd=1&amp;quot;, header=TRUE)&lt;br /&gt;
 &lt;br /&gt;
 head(umich_data)&lt;br /&gt;
 &lt;br /&gt;
 # https://cran.r-project.org/web/packages/mgcv/mgcv.pdf &lt;br /&gt;
 # install.packages(&amp;quot;mgcv&amp;quot;);  require(mgcv) &lt;br /&gt;
 &lt;br /&gt;
 # install.packages(&amp;quot;gamair&amp;quot;); require(gamair)&lt;br /&gt;
 par(mfrow=c(1,1))&lt;br /&gt;
&lt;br /&gt;
The data are in wide format – convert to long format for plotting&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;reshape2&amp;quot;)&lt;br /&gt;
 long_data &amp;lt;- melt(umich_data, id.vars = c(&amp;quot;Year&amp;quot;), value.name = &amp;quot;temperature&amp;quot;)&lt;br /&gt;
 l.sort &amp;lt;- long_data[order(long_data$\$$Year),]&lt;br /&gt;
 head(l.sort); tail(l.sort)&lt;br /&gt;
 &lt;br /&gt;
 plot(l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit the GAMM Model&amp;lt;/b&amp;gt; (Generalized Additive Mixed Model)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries6.png|400px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit a model with trend and seasonal components&amp;lt;/b&amp;gt; --- computation may be slow:&lt;br /&gt;
&lt;br /&gt;
 # define the parameters controlling the process of model-fitting/parameter-estimation&lt;br /&gt;
 ctrl &amp;lt;- list(niterEM = 0, msVerbose = TRUE, optimMethod=&amp;quot;L-BFGS-B&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # First try this model&lt;br /&gt;
 mod &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year)) + s(as.numeric(variable)), data = l.sort, method = &amp;quot;REML&amp;quot;,  correlation=corAR1(form = ~ 1|Year), knots=list(Variable = c(1, 12)), na.action=na.omit, control = ctrl)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;#35;&amp;lt;u&amp;gt;Correlation&amp;lt;/u&amp;gt;: &amp;lt;b&amp;gt;corStruct&amp;lt;/b&amp;gt; object defineing correlation structures in &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt;. Grouping factors in the formula for this&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;object are assumed to be nested within any random effect grouping factors, without the need to make this&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;explicit in the formula (somewhat different from the behavior of &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt;).&amp;lt;BR&amp;gt; &lt;br /&gt;
&amp;amp;#35;This is similar to the GEE approach to correlation in the generalized case.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;&amp;lt;u&amp;gt;Knots&amp;lt;/u&amp;gt;: an optional list of user specified knot values to be used for basis construction --&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;different terms can use different numbers of knots, unless they share a covariate.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35;If you revise the model like this (below), it will compare nicely with 3 ARMA models (later)&amp;lt;BR&amp;gt;&lt;br /&gt;
 mod &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corAR1(form = ~ 1|Year),  control = ctrl)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Summary of the fitted model:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(mod$\$$gam)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visualize the model trend (year) and seasonal terms (months)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(mod$\$$gam, pages = 1)&lt;br /&gt;
 t &amp;lt;- cbind(1: 1392)	# define the time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries7.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot the trend on the observed data -- with prediction:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pred2 &amp;lt;- predict(mod$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 ptemp2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,1]&amp;lt;/u&amp;gt;    &lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;# pred2[,1] = trend; 	pred2[,2] = seasonal effects&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;# mod$\$$gam&amp;lt;/b&amp;gt; is a GAM object containing information to use predict, summary and print methods, but not to use e.g. the anova method function to compare models&lt;br /&gt;
 plot(temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;, xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(ptemp2 ~ t, data = l.sort, col = &amp;quot;blue&amp;quot;, lwd = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries8.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Plot the seasonal model&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pred &amp;lt;- predict(mod$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 ptemp &amp;lt;- attr(pred, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred[,2]&amp;lt;/u&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 plot(l.sort$\$$temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;,  xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(ptemp, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 0.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries9.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Zoom in first 100 temps (1:100)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(l.sort$\$$temperature ~ t, data = l.sort, type = &amp;quot;l&amp;quot;,  &amp;lt;b&amp;gt;xlim=c(0, 120)&amp;lt;/b&amp;gt;, xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F))); lines(ptemp, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 0.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries10.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To examine how much the estimated trend has changed over the 116 year period, we can use the data contained in &amp;lt;b&amp;gt;pred&amp;lt;/b&amp;gt; to compute the difference between the start (Jan 1900) and the end (Dec 2015) of the series in the &amp;lt;i&amp;gt;&amp;lt;u&amp;gt;trend&amp;lt;/u&amp;gt;&amp;lt;/i&amp;gt; component only:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;tail(pred[,1], 1) - head(pred[,1], 1)&amp;lt;/b&amp;gt; # subtract the predicted temp [,1] in 1900 (head) from the temp in 2015 (tail)&lt;br /&gt;
 &lt;br /&gt;
 # names(attributes(pred)); str(pred)    # to see the components of the GAM prediction model object (pred)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Assess autocorrelation in residuals&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # head(umich_data); tail(umich_data)&lt;br /&gt;
 acf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;ACF&amp;quot;)&lt;br /&gt;
 # &amp;lt;b&amp;gt;acf&amp;lt;/b&amp;gt; = Auto-correlation and Cross-Covariance Function computes and plots the estimates of the autocovariance or autocorrelation function.&lt;br /&gt;
 # &amp;lt;b&amp;gt;pacf&amp;lt;/b&amp;gt; is the function used for the partial autocorrelations.&lt;br /&gt;
 # &amp;lt;b&amp;gt;ccf&amp;lt;/b&amp;gt; computes the cross-correlation or cross-covariance of two univariate series.&lt;br /&gt;
 pacf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;pACF&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Looking at the residuals of this model, using the (partial) autocorrelation function, we see that there may be some residual autocorrelation in the data that the trend term didn’t account for. The shapes of the ACF and the pACF suggest an &amp;lt;b&amp;gt;AR(p)&amp;lt;/b&amp;gt; model might be appropriate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Fit and compare 4 alternative autoregressive models (original mod, AR1, AR2 and AR3)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ## AR(1)&lt;br /&gt;
 m1 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
   data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 1&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
&lt;br /&gt;
 ## AR(2)&lt;br /&gt;
 m2 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 2&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
&lt;br /&gt;
 ## AR(3)&lt;br /&gt;
 m3 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), &lt;br /&gt;
    data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 3&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;),  control = ctrl)&lt;br /&gt;
&lt;br /&gt;
Note that the correlation argument is specified by &amp;lt;b&amp;gt;corARMA(form = ~ 1|Year, p = x)&amp;lt;/b&amp;gt;, which fits an ARMA (auto-regressive moving average) process to the residuals, where &amp;lt;b&amp;gt;p&amp;lt;/b&amp;gt; indicates the order for the &amp;lt;b&amp;gt;AR&amp;lt;/b&amp;gt; part of the ARMA model, and &amp;lt;b&amp;gt;form = ~ 1|Year&amp;lt;/b&amp;gt; specifies that the ARMA is nested within each year. This may expedite the model fitting but may also hide potential residual variation from one year to another.&lt;br /&gt;
&lt;br /&gt;
Let’s compare the candidate models by using the generalized likelihood ratio test via the &amp;lt;b&amp;gt;anova()&amp;lt;/b&amp;gt; method for &amp;lt;b&amp;gt;lme&amp;lt;/b&amp;gt; objects; see our previous mixed effects modeling notes &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; , &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;. This model selection is justified as we work with nested models -- going from the AR(3) to the AR(1) by setting some of the AR coefficients to 0. The models also vary in terms of the coefficient estimates for the splines terms which may require fixing some values while choosing the AR structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;center&amp;gt;anova(mod$\$$lme, m1$\$$lme, m2$\$$lme, m3$\$$lme)&amp;lt;/center&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
|||Model||df||AIC||BIC||logLik||Test||L.Ratio||p-value&lt;br /&gt;
|-&lt;br /&gt;
|mod$\$$lme||1||7||7455.609||7492.228|| -3720.805|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|m1$\$$lme||2|| 7||7455.609||7492.228|| -3720.805|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|m2$\$$lme||3|| 8||7453.982||7495.832|| -3718.991||2 vs 3||3.627409||0.0568&lt;br /&gt;
|-&lt;br /&gt;
|m3$\$$lme||4|| 9||7455.966||7503.048|| -3718.983|| 3 vs 4||0.015687||0.9003&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Interpretation &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The AR(1) model (m1) does not provide a substantial increase in fit over the naive model (mod), and the AR(2) model (m2) only provides a marginal increase in the AR(1) model fit (m1). There is no improvement in moving from m2 to AR(3) model (m3).&lt;br /&gt;
&lt;br /&gt;
Let’s plot the AR(2) model (m2) to inspect how over-fitted the naive model with uncorrelated errors was in terms of the trend term, which shows similar smoothness compared to the initial (mod) model.&lt;br /&gt;
&lt;br /&gt;
 plot(m2$\$$gam, scale = 0)     #  plot(mod2$\$$gam, scale = 0)   # “scale=0” ensures optimal y-axis cropping of plot&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries11.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Investigation of residual patterns&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 layout(matrix(1:2, ncol = 2))&lt;br /&gt;
 # original (mod) model&lt;br /&gt;
 acf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;ACF&amp;quot;); pacf(resid(mod$\$$lme), lag.max = 36, main = &amp;quot;pACF&amp;quot;)&lt;br /&gt;
 # pACF controls for the values of the time series at all shorter lags, which contrasts the ACF which does not control for other lags.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries12.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This illustrates that there is some (month=1) Auto-correlation (ACF) and partial auto correlation in the residuals.&lt;br /&gt;
&lt;br /&gt;
 # ARM(2) model (m2)&lt;br /&gt;
 layout(matrix(1:2, ncol = 2))&lt;br /&gt;
 res &amp;lt;- resid(m2$\$$lme, type = &amp;quot;normalized&amp;quot;); &lt;br /&gt;
 acf(res, lag.max = 36, main = &amp;quot;ACF - AR(2) errors&amp;quot;); pacf(res, lag.max = 36, main = &amp;quot;pACF- AR(2) errors&amp;quot;)&lt;br /&gt;
 layout(1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries13.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No residual auto-correlation remains in &amp;lt;b&amp;gt;m2&amp;lt;/b&amp;gt;. The resulting fitted Generalized Additive Mixed Model (GAMM) object contains information about the trend and the contributions to the fitted values. The package '''mgcv'''&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; can spit the information using &amp;lt;b&amp;gt;predict()&amp;lt;/b&amp;gt; for each of the 4 models.&lt;br /&gt;
&lt;br /&gt;
 # require(mgcv); require(gamair)&lt;br /&gt;
 # m2 &amp;lt;- gamm(as.numeric(temperature) ~ s(as.numeric(Year), k=116) + s(as.numeric(variable), k=12), data = l.sort, correlation = corARMA(form = ~ 1|Year, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;p = 2&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;), control = ctrl)&lt;br /&gt;
 &lt;br /&gt;
 pred2 &amp;lt;- predict(m2$\$$gam, newdata = l.sort, type = &amp;quot;terms&amp;quot;)&lt;br /&gt;
 pred_trend2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,1]&amp;lt;/u&amp;gt; &amp;lt;b&amp;gt;# trend&amp;lt;/b&amp;gt;&lt;br /&gt;
 pred_season2 &amp;lt;- attr(pred2, &amp;quot;constant&amp;quot;) + &amp;lt;u&amp;gt;pred2[,2]&amp;lt;/u&amp;gt; &amp;lt;b&amp;gt;# seasonal&amp;lt;/b&amp;gt; effects&lt;br /&gt;
 # plot(m2$\$$gam, scale = 0) # plot pure effects&lt;br /&gt;
 &lt;br /&gt;
 # Convert the 2 columns (Year and Month/variable) to R Date object&lt;br /&gt;
 # df_time &amp;lt;- as.Date(paste(as.numeric(l.sort$\$$Year), as.numeric(l.sort$\$$variable), &amp;quot;1&amp;quot;, sep=&amp;quot;-&amp;quot;)); df_time&lt;br /&gt;
 &lt;br /&gt;
 plot(x=df_time, y=l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;,  xlim=c(as.Date(&amp;quot;1950-02-01&amp;quot;),as.Date(&amp;quot;1960-01-01&amp;quot;)), xlab = &amp;quot;year&amp;quot;, ylab = expression(Temperature ~ (degree*F)))&lt;br /&gt;
 lines(x=df_time, y=pred_trend2, data = l.sort, col = &amp;quot;red&amp;quot;, lwd = 2);&lt;br /&gt;
 lines(x=df_time, y=pred_season2, data = l.sort, col = &amp;quot;blue&amp;quot;, lwd = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries14.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Moving average smoothing===&lt;br /&gt;
&lt;br /&gt;
A moving average of order $m=2k+1$ can be expressed as:&lt;br /&gt;
$T_{t}=\frac{1}{2k+1}\sum_{j=-k}^{k}Y_{t+j}$ .&lt;br /&gt;
&lt;br /&gt;
The ''m''-MA represents an order m moving average, $T_t$, or the estimate of the trend-cycle at time ''t'', obtained by averaging values of the time series within ''k'' periods (left and right) of ''t''. This averaging process denoises the data (eliminates randomness in the data) and produces a smoother trend-cycle component.&lt;br /&gt;
&lt;br /&gt;
The 5-MA contains the values of $T_t$ with ''k''=2. To see what the trend-cycle estimate looks like, we plot it along with the original data&lt;br /&gt;
&lt;br /&gt;
 # print the moving average results (k=3 &amp;amp;#8596; m=7)&lt;br /&gt;
 # library(&amp;quot;forecast&amp;quot;)&lt;br /&gt;
 plot(l.sort$\$$temperature, data = l.sort, type = &amp;quot;l&amp;quot;, main=&amp;quot; UMich/AA Temp (1900-2015) &amp;quot;, ylab=&amp;quot; Temperature (F)&amp;quot;, xlab=&amp;quot;Year&amp;quot;)&lt;br /&gt;
 lines(ma(l.sort$\$$temperature, 12), col=&amp;quot;red&amp;quot;, lwd=5)&lt;br /&gt;
 lines(ma(l.sort$\$$temperature, 36), col=&amp;quot;blue&amp;quot;, lwd=3)&lt;br /&gt;
 &lt;br /&gt;
 legend(0, 80, 					# places a legend at the appropriate place &lt;br /&gt;
 c(&amp;quot;Raw&amp;quot;, &amp;quot;k=12 smoother&amp;quot;, &amp;quot;k=36 smoothest&amp;quot;), 	# puts text in the legend&lt;br /&gt;
 lty=c(1,1,1), 					# gives the legend appropriate symbols (lines)&lt;br /&gt;
 cex=1.0,  					# label sizes&lt;br /&gt;
 lwd=c(2.5,2.5), col=c(&amp;quot;black&amp;quot;, &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;)) 	# gives the legend lines the correct color and width&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries15.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The blue trend (''k''=36) (3 yrs) is smoother than the original (raw) data (black) and the 1-yr average (''k''=12). It captures the main movement of the time series without all the minor fluctuations. We can’t estimate $T_t$ where ''t'' is close to the ends as there is not enough data there to compute the averages. The red trend (''k''=12) is smoother than the original (raw) data (black) but more jagged than the 3-yr average. The order of the moving average (''m'') determines the smoothness of the trend-cycle estimate. A larger order implies a smoother curve.&lt;br /&gt;
&lt;br /&gt;
===Simulation of a time-series analysis and prediction===&lt;br /&gt;
&lt;br /&gt;
 (1) Simulate a time series&lt;br /&gt;
 &lt;br /&gt;
 # the ts() function converts a numeric vector into an R time series object. &lt;br /&gt;
 # format is ts(vector, start=, end=, frequency=) where start and end are the times of the first and last observation&lt;br /&gt;
 # and frequency is the number of observations per unit time (1=annual, 4=quarterly, 12=monthly, etc.)&lt;br /&gt;
 Note that ''ling Rate'' = $\frac{1}{Frequency}$ &lt;br /&gt;
 &lt;br /&gt;
 # save a numeric vector containing 16-years (192 monthly) observations  &lt;br /&gt;
 # from Jan 2000 to Dec 2015 as a time series object&lt;br /&gt;
 sim_ts &amp;lt;- ts(as.integer(runif(192,0,10)), start=c(2000, 1), end=c(2015, 12), frequency=12)&lt;br /&gt;
 sim_ts&lt;br /&gt;
 &lt;br /&gt;
 # subset the time series (June 2014 to December 2015)&lt;br /&gt;
 sim_ts2 &amp;lt;- window(sim_ts, start=c(2014, 6), end=c(2015, 12))&lt;br /&gt;
 sim_ts2&lt;br /&gt;
 &lt;br /&gt;
 # plot series &lt;br /&gt;
 plot(sim_ts)&lt;br /&gt;
 lines(sim_ts2, col=&amp;quot;blue&amp;quot;, lwd=3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries16.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Seasonal Decomposition====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The additive and seasonal trends, and irregular components, of time-series may be decomposed using the stl() function. Series with multiplicative effects can by transformed into series with additive effects through a log transformation (i.e., '''ln_sim_ts &amp;lt;- log(sim_ts)).&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Seasonal decomposition&lt;br /&gt;
 fit_stl &amp;lt;- stl(sim_ts, s.window=&amp;quot;period&amp;quot;)   '''# Seasonal Decomposition of Time Series by Loess'''&lt;br /&gt;
 plot(fit_stl)&lt;br /&gt;
 &lt;br /&gt;
 # inspect the distribution of the residuals&lt;br /&gt;
 hist(fit_stl$\$$time.series[,3]);  #   this contains the residuals: fit_stl$\$$time.series  [,&amp;quot;remainder&amp;quot;], or  seasonal, trend&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries17.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # additional plots &lt;br /&gt;
 monthplot(sim_ts)	# plots the seasonal subseries of a time series. For each season, a time series is plotted.&lt;br /&gt;
 &lt;br /&gt;
 # library(forecast)&lt;br /&gt;
 seasonplot(sim_ts)&lt;br /&gt;
&lt;br /&gt;
====Exponential Models====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The '''HoltWinters()''' function ('''stats''' package), and the '''ets()''' function ('''forecast''' package) can fit exponential models.&amp;lt;/li&amp;gt;&lt;br /&gt;
 # simple exponential - models level&lt;br /&gt;
 fit_HW &amp;lt;- HoltWinters(sim_ts, beta=FALSE, gamma=FALSE)&lt;br /&gt;
 &lt;br /&gt;
 # double exponential - models level and trend&lt;br /&gt;
 fit_HW2&amp;lt;- HoltWinters(sim_ts, gamma=FALSE) &lt;br /&gt;
 &lt;br /&gt;
 # triple exponential - models level, trend, and seasonal components&lt;br /&gt;
 fit_HW3 &amp;lt;- HoltWinters(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 plot(fit_HW, col='black')&lt;br /&gt;
 par(new=TRUE)&lt;br /&gt;
 plot(fit_HW2, ann=FALSE, axes=FALSE, col='blue')&lt;br /&gt;
 par(new=TRUE)&lt;br /&gt;
 plot(fit_HW3, axes=FALSE, col='red')&lt;br /&gt;
 # clear plot: &lt;br /&gt;
 # dev.off()&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries18.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Auto-regressive Integrated Moving Average (ARIMA) Models&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
There are 2 types of ARIMA time-series models: &amp;lt;BR&amp;gt;&lt;br /&gt;
$ X_t= \mu+ \underbrace{\sum_{i=1}^{p}{φ_iX_{t-i}}}_\text{auto-regressive (p) part} +&lt;br /&gt;
\underbrace{\sum_{j=1}^{q}{θ_jε_{t-j}}}_\text{moving-average (q) part} + &lt;br /&gt;
\underbrace{ ε_t }_\text{error term}.$&lt;br /&gt;
&lt;br /&gt;
====Non-seasonal ARIMA models====&lt;br /&gt;
The Non-seasonal ARIMA models are denoted by ARIMA(p, d, q), where parameters p, d, and q are positive integers, &lt;br /&gt;
* p = order of the auto-regressive model,&lt;br /&gt;
* d = degree of differencing, when ''d''=2, the '''''d&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt;'' difference''' is $(X_t-X_{t-1})-(X_{t-1}-X_{t-2})= X_t-2X_{t-1}+X_{t-2}$. That is, the second difference of ''X'' (d=2) is not the difference between the current period and the value 2 periods ago.  It is the first-difference-of-the-first difference, the discrete analog of a second derivative, representing the local acceleration of the series rather than its local trend (first derivative).&lt;br /&gt;
* q = order of the moving-average model.&lt;br /&gt;
&lt;br /&gt;
====Seasonal ARIMA models====&lt;br /&gt;
The Seasonal AMIMA models are denoted by ''ARIMA(p, d, q)(P, D, Q)&amp;lt;sub&amp;gt;m&amp;lt;/sub&amp;gt;,'' &lt;br /&gt;
* m = number of periods in each season, &lt;br /&gt;
* uppercase P, D, Q represent the auto-regressive, differencing, and moving average terms for the seasonal part of the ARIMA model, and the lower case (p,d,q) are as with non-seasonal ARIMA.&lt;br /&gt;
&lt;br /&gt;
If 2 of the 3 terms are trivial, the model is abbreviated using the non-zero parameter, skipping the &amp;quot;AR&amp;quot;, &amp;quot;I&amp;quot; or &amp;quot;MA&amp;quot; from the acronym. For example, &lt;br /&gt;
&lt;br /&gt;
*ARIMA(1,0,0) = AR(1), a stationary and auto-correlated series can be predicted as a multiple of its own previous value, plus a constant. $X_t=μ + φ_1 × X_{t-1}+ \epsilon_t.$ Note that $ε_t=X_t-\hat{X}_t.$&lt;br /&gt;
&lt;br /&gt;
*An ARIMA(0,1,0) = I(1) model, not stationary series, a limiting case of an AR(1) model, the auto-regressive coefficient is equal to 1, i.e., a series with infinitely slow mean reversion,  $X_t=μ+X_{t-1}+ε_t,$ a 1-step random walk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;For more complex models:&amp;lt;/B&amp;gt;&lt;br /&gt;
*An ARIMA(1,1,0), differenced first-order auto-regressive model.  $X_t=μ+X_{t-1}+α×(X_{t-1}-X_{t-2})+ε_t.$  &lt;br /&gt;
&lt;br /&gt;
*An ARIMA(0,2,2) model is given by $X_t=2X_{t-1}-X_{t-2}+α×ε_{t-1}+β×ε_{t-2}+ ε_t,$ where $α$ and $β$ are the MA(1) and MA(2) coefficients (sometimes these are defined with negative signs). This is a general linear exponential smoothing model that uses exponentially weighted moving averages to estimate both a local level and a local trend in the series.  The long-term forecasts from this model converge to a straight line whose slope depends on the average trend observed toward the end of the series.&lt;br /&gt;
&lt;br /&gt;
*ARIMA(1,1,2), $X_t=μ+X_{t-1}+(X_{t-1}+X_{t-2})+α×ε{t}+β×ε_{t-1}$&lt;br /&gt;
&lt;br /&gt;
The '''arima'''() function ('''stats''' package) can be used to fit an &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;auto-regressive integrated moving averages&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; model. Other useful functions include:&lt;br /&gt;
* lag(sim_ts, k) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; lagged version of time series, shifted back k observations&lt;br /&gt;
* diff(sim_ts, differences=d) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; difference the time series d times&lt;br /&gt;
* ndiffs(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Number of differences required to achieve stationarity (from the forecast package)&lt;br /&gt;
* acf(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; auto-correlation function&lt;br /&gt;
* pacf(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; partial auto-correlation function&lt;br /&gt;
* adf.test(sim_ts) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Augmented Dickey-Fuller test. Rejecting the null hypothesis suggests that a time series is stationary (from the tseries package)&amp;lt;/li&amp;gt;&lt;br /&gt;
* Box.test(x, type=&amp;quot;Ljung-Box&amp;quot;) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; Portmanteau test that observations in vector or time series x are independent.&lt;br /&gt;
&lt;br /&gt;
The '''forecast''' package has alternative versions of '''acf()''' and '''pacf()''' called '''Acf()''' and '''Pacf()''' respectively. &lt;br /&gt;
&amp;amp;#35; fit an '''ARIMA(P, D, Q) model''' of order:&lt;br /&gt;
* P, represents the AR order&amp;lt;&lt;br /&gt;
* D, represents the degree of differencing&lt;br /&gt;
* Q, represents the MA order.&lt;br /&gt;
&lt;br /&gt;
 fit_arima1 &amp;lt;- arima(sim_ts, order=c(3, 1, 2))  &lt;br /&gt;
 # predictive accuracy &lt;br /&gt;
 library(forecast) &lt;br /&gt;
 accuracy(fit_arima1)  &lt;br /&gt;
 &lt;br /&gt;
 # predict next 20 observations &lt;br /&gt;
 library(forecast) &lt;br /&gt;
 forecast(fit_arima1, 20) &lt;br /&gt;
 plot(forecast(fit_arima1, 20)) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_TimeSeries19.png|600px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Forecasting===&lt;br /&gt;
&lt;br /&gt;
The '''forecast''' package provides functions for the automatic selection of exponential and ARIMA models. The '''ets()''' (exponential TS) function supports both additive and multiplicative models. The '''auto.arima()''' function accounts for seasonal and nonseasonal ARIMA models according to criteria maximizing a cost function.&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;#35; library(forecast)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Automated forecasting using an exponential model&lt;br /&gt;
  fit_ets &amp;lt;- ets(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Automated forecasting using an ARIMA model&lt;br /&gt;
 fit_arima2 &amp;lt;- auto.arima(sim_ts)&lt;br /&gt;
 &lt;br /&gt;
 &amp;amp;#35; Compare the AIC (model quality) for both models&lt;br /&gt;
 fit_ets$\$$aic; fit_arima2$\$$aic&lt;br /&gt;
 accuracy(fit_ets); accuracy(fit_arima2);&lt;br /&gt;
&lt;br /&gt;
'''Akaike’s Information Criterion (AIC)''' = ''-2Log(Likelihood)+2p,'' where ''p'' is he number of estimated parameters.&lt;br /&gt;
 summary(fit_ets); summary(fit_arima2)&lt;br /&gt;
&lt;br /&gt;
ACF plot of the residuals from the ARIMA(3,1,2) model shows all correlations within the threshold limits indicating that the residuals are behaving like white noise. A portmanteau test returns a large p-value, also suggesting the  residuals are white noise.&lt;br /&gt;
 &amp;amp;#35; acf computes (and by default plots) estimates of the autocovariance or autocorrelation function&lt;br /&gt;
 acf(residuals(fit_ets)) &lt;br /&gt;
&lt;br /&gt;
 &amp;amp;#35; Box–Pierce or Ljung–Box test statistic for examining the null hypothesis of independence in a given time series. &lt;br /&gt;
 &amp;amp;#35; These are sometimes known as ‘portmanteau’ tests.&lt;br /&gt;
 Box.test(residuals(fit_ets), lag=24, fitdf=4, type=&amp;quot;Ljung&amp;quot;)&lt;br /&gt;
 &amp;amp;#35; plot forecast&lt;br /&gt;
 &lt;br /&gt;
 plot(forecast(fit_arima2))&lt;br /&gt;
 &amp;amp;#35; more on ARIMA https://www.otexts.org/fpp/8/7&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
* &amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; https://umich.instructure.com/files/689861/download?download_frd=1  &lt;br /&gt;
* &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; https://umich.instructure.com/courses/38100/files  &lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; https://cran.r-project.org/web/packages/mgcv/mgcv.pdf&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_TimeSeriesAnalysis_LOS| Applications of Time-series]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.ucla.edu&lt;br /&gt;
{{translate|pageName=http://wiki.stat.ucla.edu/socr/index.php?title=SMHS_TimeSeriesAnalysis}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MissingData&amp;diff=16176</id>
		<title>SMHS MissingData</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MissingData&amp;diff=16176"/>
		<updated>2016-05-23T13:46:06Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Missing Data ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
*Why is data usually incomplete?&lt;br /&gt;
*What are the best strategies for dealing with missing data- ignore cases, replace them by some population derived values, or impute them?&lt;br /&gt;
*What is the impact of data manipulations on the core scientific inference?&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Many research studies encounter incomplete (missing) data that require special handling (e.g., processing, statistical analysis, visualization). There are a variety of methods (e.g., multiple imputation) to deal with missing data, detect missingness, impute the data, analyze the completed data-set and compare the characteristics of the raw and imputed data.&lt;br /&gt;
&lt;br /&gt;
Multiple imputation involves 3 steps: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1) Impute&amp;lt;/b&amp;gt;: Create sets of plausible values for the missing observations that reflect uncertainty about the non-response model. Each of these sets of plausible values can be used to “fill-in” or complete the data-set. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2) Analyze&amp;lt;/b&amp;gt;: process each of these imputed data-sets using complete-data methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3) Combine&amp;lt;/b&amp;gt;: synthesize the results accounting for the uncertainty within each imputation round.&lt;br /&gt;
&lt;br /&gt;
In a general regression setting, let’s denote the scalar, or vector valued, outcomes by &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt;, and the corresponding vector of predictors by &amp;lt;i&amp;gt;X&amp;lt;/i&amp;gt;. For a given case (e.g., subject, unit), these quantities are either observed (&amp;lt;i&amp;gt;obs&amp;lt;/i&amp;gt;) or missing (&amp;lt;i&amp;gt;mis&amp;lt;/i&amp;gt;). Thus, Y&amp;lt;sub&amp;gt;obs&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;obs&amp;lt;/sub&amp;gt; represent the observed component of the outcome and the predictors; and Y&amp;lt;sub&amp;gt;mis&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;mis&amp;lt;/sub&amp;gt; denote the unobserved components of the outcome and predictors, respectively. Imputation involves the estimation of the regression parameters β governing the conditional distribution of Y given X: f(Y|X,β). The efficiency, bias and precision of the estimates are important in this process.&lt;br /&gt;
&lt;br /&gt;
The type of missingness in the data is an important factor in the imputation process. The basic patterns of missingness include:&lt;br /&gt;
&lt;br /&gt;
*Missing completely at random (MCAR) assumes that the missing data is not related to any factor, known or unknown, in the study.&lt;br /&gt;
&lt;br /&gt;
*Missingness at random (MAR) assumes that the missingness depends only on observed quantities, which may include outcomes and/or predictors.&lt;br /&gt;
&lt;br /&gt;
*Non-ignorable missingness occurs when the missing data depends on unobserved quantities.&lt;br /&gt;
&lt;br /&gt;
===Multiple Imputation Protocol===&lt;br /&gt;
&lt;br /&gt;
====(1) Imputation:====&lt;br /&gt;
&lt;br /&gt;
Generate a set of $m &amp;gt; 1$ plausible values for $Z_{mis}=(Y_{mis},X_{mis})$.&lt;br /&gt;
&lt;br /&gt;
The imputation step relies upon assumptions regarding the cause of missingness in the dataset. The goal of the imputation is to account for the relationships between the unobserved and observed variables, while taking into account the uncertainty of the imputation. The commonly made MAR assumption for missing data is untestable without additional information. With MAR assumption we can generate imputations (Z&amp;lt;sub&amp;gt;{1}&amp;lt;/sub&amp;gt;,Z&amp;lt;sub&amp;gt;{2}&amp;lt;/sub&amp;gt;,...Z&amp;lt;sub&amp;gt;{m}&amp;lt;/sub&amp;gt;) from the distribution $f(Z_{mis}|Z_{obs})$, since after conditioning on $Z_{obs}$ the missingness is assumed to be random.&lt;br /&gt;
&lt;br /&gt;
The missingness is &amp;lt;b&amp;gt;monotone&amp;lt;/b&amp;gt; when the data matrix can be rearranged so that there is a hierarchy of missingness where observing a particular variable $Z_b$ for a subject implies that $Z_a$  is observed, for $a &amp;lt; b$. &amp;lt;i&amp;gt;In monotone condition settings many imputation methods may be employed including (for continuous variables) propensity methods, predictive mean matching, and (for discrete variables) discriminant analysis or logistic regression&amp;lt;/i&amp;gt;. For non-monotonic missingness, Markov Chain Monte Carlo (MCMC) approaches may be used.&lt;br /&gt;
&lt;br /&gt;
Each method has its own assumptions. For instance, predictive mean matching and MCMC approaches require multivariate normality. Predictive mean matching approach employs linear regression for the distribution of a partially observed variable, conditional on other factors. To impute the data using the &amp;lt;b&amp;gt;predictive mean matching approach&amp;lt;/b&amp;gt; for a variable $Z_i$ with missing values, we fit a model using complete observations for $Z_1, . . . , Z_{i-1}$ (not monotonicity assumption!):&lt;br /&gt;
&lt;br /&gt;
$E[Z_i|φ]=φ_0+φ_1Z_1+φ_2Z_2+...+φ_{i-1}Z_{i-1}$&lt;br /&gt;
&lt;br /&gt;
Next, new parameters φ&amp;lt;sup&amp;gt;*&amp;lt;/sup&amp;gt; are randomly drawn from the distribution of the parameters (since these values are estimated instead of exactly known). For the 1≤l≤m imputation, the missing values are replaced by:&lt;br /&gt;
&lt;br /&gt;
$Z_i^l= φ_0^* +φ_1^*Z_1 +φ_2^*Z_2+...+φ_{i-1}^*Z_{i-1}+σ^*ϵ$,&lt;br /&gt;
&lt;br /&gt;
where σ&amp;lt;sup&amp;gt;*&amp;lt;/sup&amp;gt; is the estimate of variance from the model and ϵ is a Gaussian, &amp;lt;i&amp;gt;N&amp;lt;/i&amp;gt;(0,1). This is the simple regression method. We can impute the &amp;lt;u&amp;gt;observed value of $Z_i$&amp;lt;/u&amp;gt; that is closest to predicted $\hat{Z}_i=Z_i^l$ in the dataset – this is the &amp;lt;b&amp;gt;predictive mean matching method.&amp;lt;/b&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;propensity score&amp;lt;/b&amp;gt; method uses an alternative model for imputation where the values are imputed from observations that are equally likely to be missing, by fitting a &amp;lt;u&amp;gt;logistic regression model for the missingness indicators&amp;lt;/u&amp;gt;. In some situations, propensity score imputation may lead to serious bias for missing covariates. For discrete incomplete variables, discriminant analysis or dichotomous logistic regression may be employed to impute values based on the estimated probability that a missing observation takes on a certain value.&lt;br /&gt;
&lt;br /&gt;
====(2) Analysis:====&lt;br /&gt;
&lt;br /&gt;
Analyze the &amp;lt;i&amp;gt;m&amp;lt;/i&amp;gt; datasets using complete-case methods. This second step in the protocol involves carrying out the analysis of interest for each of the m imputed complete-observation datasets and storing the parameter vectors (e.g., effect-size coefficients, β’s) and their standard error estimates.&lt;br /&gt;
&lt;br /&gt;
====(3) Combination:==== &lt;br /&gt;
&lt;br /&gt;
Combine the results from the &amp;lt;i&amp;gt;m&amp;lt;/i&amp;gt; analyses and calculate the estimates of the &amp;lt;i&amp;gt;within imputation and between imputation&amp;lt;/i&amp;gt; variability. If the imputation model is correct (assumptions are valid), these statistics account for the variability of the imputations and provide consistent estimates of the parameters and their standard errors.&lt;br /&gt;
&lt;br /&gt;
===Simulated Example===&lt;br /&gt;
&lt;br /&gt;
 set.seed(123)&lt;br /&gt;
 # create MCAR missing-data generator&lt;br /&gt;
 create.missing &amp;lt;- function (data, pct.mis = 10)&lt;br /&gt;
 {&lt;br /&gt;
 n &amp;lt;- nrow(data)&lt;br /&gt;
 J &amp;lt;- ncol(data)&lt;br /&gt;
 if (length(pct.mis) == 1) {&lt;br /&gt;
 n.mis &amp;lt;- rep((n * (pct.mis/100)), J)&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
 else {&lt;br /&gt;
 if (length(pct.mis) &amp;lt; J) &lt;br /&gt;
 stop(&amp;quot;The length of missing does not equal to the column of the data&amp;quot;)&lt;br /&gt;
 n.mis &amp;lt;- n * (pct.mis/100)&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
    for (i in 1:ncol(data)) {&lt;br /&gt;
        if (n.mis[i] == 0) { # if column has nothing missing, do nothing.&lt;br /&gt;
            data[, i] &amp;lt;- data[, i]&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
            data[sample(1:n, n.mis[i], replace = FALSE), i] &amp;lt;- NA&lt;br /&gt;
 # For each given column (i), sample the row indices (1:n), &lt;br /&gt;
 # a number of indices to replace as “missing”, n.mis[i], “NA”,&lt;br /&gt;
  	  # without replacement&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return(as.data.frame(data))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 # Simulate some real multivariate data &amp;lt;b&amp;gt;sim_data&amp;lt;/b&amp;gt;={y,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10}&lt;br /&gt;
 # &lt;br /&gt;
 n &amp;lt;- 1000; u1 &amp;lt;- rbinom(n, 1, .5); v1 &amp;lt;- log(rnorm(n, 5, 1)); x1 &amp;lt;- u1*exp(v1)&lt;br /&gt;
 u2 &amp;lt;- rbinom(n, 1, .5); v2 &amp;lt;- log(rnorm(n, 5, 1)); x2 &amp;lt;- u2*exp(v2)&lt;br /&gt;
 x3 &amp;lt;- rbinom(n, 1, prob=0.45); x4 &amp;lt;- ordered(rep(seq(1, 5),n)[sample(1:n, n)]); x5 &amp;lt;- rep(letters[1:10],n)[sample(1:n, n)]; x6 &amp;lt;- trunc(runif(n, 1, 10)); x7 &amp;lt;- rnorm(n); x8 &amp;lt;- factor(rep(seq(1,10),n)[sample(1:n, n)]); x9 &amp;lt;-   runif(n, 0.1, .99); x10 &amp;lt;- rpois(n, 4); y &amp;lt;- x1 + x2 + x7 + x9 + rnorm(n)&lt;br /&gt;
&lt;br /&gt;
 # package the simulated data as a data frame object&lt;br /&gt;
 sim_data &amp;lt;- cbind.data.frame(y, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)&lt;br /&gt;
&lt;br /&gt;
 # randomly create missing values&lt;br /&gt;
 sim_data_30pct_missing &amp;lt;- create.missing(sim_data, pct.mis=30); &lt;br /&gt;
 head(sim_data_30pct_missing); summary(sim_data_30pct_missing)&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;mi&amp;quot;)&lt;br /&gt;
 # install.packages(&amp;quot;betareg&amp;quot;)&lt;br /&gt;
 library(&amp;quot;betareg&amp;quot;); library(&amp;quot;mi&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # get show the missing information matrix			&lt;br /&gt;
 mdf &amp;lt;- missing_data.frame(sim_data_30pct_missing) &lt;br /&gt;
 show(mdf); mdf@patterns; image(mdf)   # remember the visual pattern of this MCAR&lt;br /&gt;
&lt;br /&gt;
 # Next try to impute the missing values …&lt;br /&gt;
 imputations &amp;lt;- mi(sim_data_30pct_missing, n.iter=10, n.chains=3, verbose=TRUE)&lt;br /&gt;
 hist(imputations)&lt;br /&gt;
&lt;br /&gt;
 # Extracts several multiply imputed data.frames from “imputations” object&lt;br /&gt;
 data.frames &amp;lt;- complete(imputations, 3)&lt;br /&gt;
&lt;br /&gt;
 # Compare the summary stats for the original data (prior to introducing missing&lt;br /&gt;
 # values) with missing data and the re-completed data following imputation&lt;br /&gt;
 summary(sim_data); summary(sim_data_30pct_missing); summary(data.frames[[1]]);&lt;br /&gt;
 lapply(data.frames, summary)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;22&amp;quot; |&amp;lt;b&amp;gt;Original&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|||y||||x1||x2||x3||x4||x5||x6||x7||||x8||x9||x10|| || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|Min||:-3.046||Min||:0.000||Min.||:0.000||Min||:0.000||0.180555556||a||:100||Min||:1.000||Min.||:-2.880570||1||:100||Min.||:0.1024||Min.||:0.000||&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.:2.788||1st Qu.:0.000||1st Qu.:0.000||1st Qu.:0.000||0.222222222||b||:100||1st Qu.:3.000||1st Qu.:-0.687578||2||:100||1st Qu.:0.3356||1st Qu.:2.000||||||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
|Median :5.613||Median :3.186||Median :2.024||Median :0.000||0.263888889||c||:100||Median :5.000||Median :0.000836||3||:100||Median :0.5546||Median :4.000||||||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
|Mean||:5.658||Mean||:2.626||Mean||:2.480||Mean||:0.459||0.305555556||d||:100||Mean||:4.998||Mean||:-0.020541||4||:100||Mean||:0.5542||Mean||:3.898||&lt;br /&gt;
|-&lt;br /&gt;
| 3rd Qu.:8.525||3rd Qu.:5.101||3rd Qu.:4.962||3rd Qu.:1.000||0.347222222||e||:100||3rd Qu.:7.000||3rd Qu.:0.635832||5||:100||3rd Qu.:0.7829||3rd Qu.:5.000||||||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
| Max.||:17.263||Max.||:8.774||Max.||:8.085||Max||:1.000||f||:100||Max.||:9.000||Max.||:3.281171||6||:100||Max.||:0.9887||Max.||:12.000||||&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;22&amp;quot; |&amp;lt;b&amp;gt;Missing Data&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|||y||||x1||x2||x3||x4||x5||x6||x7||||x8||x9||x10||6||:100||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
| Min.||:-3.046||Min||:0.000||Min.||:0.000||Min.||:0.0000||1||:144||h||:76||Min.||:1.000||Min.||:-2.8806||8||:77||Min.||:0.1024||Min.||:0.000&lt;br /&gt;
|-&lt;br /&gt;
| 1st Qu.:2.768||1st Qu.:0.000||1st Qu.:0.000||1st Qu.:0.0000||2||:128||a||:72||1st Qu.:3.000||1st Qu.:-0.6974||4||:75||1st Qu.:0.3504||1st Qu.:2.000|| || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Median :5.650||Median :3.127||Median :0.000||Median :0.0000||3||:143||d||:72||Median :5.000||Median :-0.0490||9||:72||Median :0.5590||Median :4.000|| || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mean||:5.699||Mean||:2.633||Mean||:2.455||Mean||:0.4586||4||:138||f||:72||Mean||:4.994||Mean||:-0.0261||6||:71||Mean||:0.5619||Mean||:3.853&lt;br /&gt;
|-&lt;br /&gt;
| 3rd Qu.:8.552||3rd Qu.:5.088||3rd Qu.:4.966||3rd Qu.:1.0000||5||:147||g||:72||3rd Qu.:7.000||3rd Qu.:0.6379||10||:71||3rd Qu.:0.7843||3rd Qu.:5.000|| || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Max.||:17.263||Max.||:8.774||Max.||:8.085||Max.||:1.0000||NA's:300||(Other):336||Max.||:9.000||Max.||:2.7863||(Other):334||Max.||:0.9887||Max.||:12.000||||||&lt;br /&gt;
|-&lt;br /&gt;
| NA's||:300||NA's||:300||NA's||:300||NA's||:300||||NA's||:300||NA's||:300||NA's||:300||NA's||:300||NA's||300||NA's||:300||&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;22&amp;quot; |&amp;lt;b&amp;gt;Imputed&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|||y||||x1||x2||x3||x4||x5||x6||x7||||x8||x9||x10||missing y||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
| Min.||:-4.646||Min.||:-3.687||Min.||:-4.672||0.381944444||0.199305556||a||:108||Min.||:-1.005||Min.||:-2.88057||4||:114||Min.||:0.04046||Min.||:-2.009||Mode: logical||&lt;br /&gt;
|-&lt;br /&gt;
| 1st Qu.:3.015||1st Qu.:0.000||1st Qu.:0.000||0.354166667||0.211111111||h||:108||1st Qu.:3.000||1st Qu.:-0.70985||9||:105||1st Qu.:0.36273||1st Qu.:2.352||FALSE:700||||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
|  Median :5.741||Median :2.836||Median :2.564||0.259722222||d||:107||Median :5.000||Median :-0.03695||5||:103||Median :0.57188||Median :4.000||TRUE :300||||||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
| Mean||:5.846||Mean||:2.649||Mean||:2.533||0.297916667||c||:104||Mean||:5.012||Mean||:-0.01444||3||:102||Mean||:0.56607||Mean||:3.858||NA's :0||||&lt;br /&gt;
|-&lt;br /&gt;
| 3rd Qu.:8.667||3rd Qu.:4.978||3rd Qu.:4.871||0.351388889||j||:100||3rd Qu.:7.000||3rd Qu.:0.70157||6||:102||3rd Qu.:0.78259||3rd Qu.:5.000||||||||||||||||||||&lt;br /&gt;
|-&lt;br /&gt;
| Max.||:17.263||Max.||:9.979||Max.||:12.833||||f||:99||Max.||:12.178||Max.||:2.78629||8||:102||Max.||:0.99670||Max.||:12.000||||||&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Check imputation convergence (details provided below)&lt;br /&gt;
 round(mipply(imputations, mean, to.matrix = TRUE), 3)&lt;br /&gt;
 Rhats(imputations, statistic = &amp;quot;moments&amp;quot;) # assess the convergence of MI algorithm&lt;br /&gt;
&lt;br /&gt;
 plot(imputations); hist(imputations); image(imputations); summary(imputations)&lt;br /&gt;
&lt;br /&gt;
 # Finally, pool over the m = 5 imputed datasets when we fit the “model”&lt;br /&gt;
 # Pool from across the 4 chains – in order to estimate a linear regression model&lt;br /&gt;
 model_results &amp;lt;- pool(y ~ x1+x2+x3+x4+x5+x6+x7+x8+x9+x10, data=imputations,  m=5 )&lt;br /&gt;
 display (model_results); summary (model_results)  &lt;br /&gt;
 # Report the summaries of the imputations&lt;br /&gt;
 data.frames &amp;lt;- complete(imputations, 3)  	# extract the first 3 chains&lt;br /&gt;
 lapply(data.frames, summary)&lt;br /&gt;
&lt;br /&gt;
===TBI Data Example===&lt;br /&gt;
&lt;br /&gt;
See these traumatic brain injury (TBI) data: http://wiki.socr.umich.edu/index.php/SMHS_MissingData#Raw_TBI_data&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Ind||ID||Age ||Sex ||TBI||field.gcs||er.gcs||icu.gcs||worst.gcs||X6m.gose||X2013.gose||skull.fx||temp.injury||surgery||spikes.hr||min.hr||max.hr||acute.sz||late.sz||ever.sz&lt;br /&gt;
|-&lt;br /&gt;
|1 ||1||19||M||Fall||10||10||10||10||5||5||0||1||1||NA||NA||NA||1||1||1&lt;br /&gt;
|-&lt;br /&gt;
|2 ||2||55||M||Blunt||NA||3||3||3||5||7||1||1||1||168.74||14||757||0||1||1&lt;br /&gt;
|-&lt;br /&gt;
|3 ||3||24||M||Fall||12||12||8||8||7||7||1||0||0||37.37||0||351||0||0||0&lt;br /&gt;
|-&lt;br /&gt;
|4 ||4||57||F||Fall||4||4||6||4||3||3||1||1||1||4.35||0||59||0||0||0&lt;br /&gt;
|-&lt;br /&gt;
|5||5||54||F||Peds_vs_Auto||14||11||8||8||5||7||0||1||1||54.59||0||284||0||0||0&lt;br /&gt;
|-&lt;br /&gt;
|6||6||16||F||MVA||13||7||7||7||7||8||1||1||1||75.92||7||180||0||1||1&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Load the (raw) data from the table into a plain text file &amp;quot;08_EpiBioSData_Incomplete.csv&amp;quot;&lt;br /&gt;
 TBI_Data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/720782/download?download_frd=1&amp;quot;, na.strings=c(&amp;quot;&amp;quot;,&amp;quot;.&amp;quot;,&amp;quot;NA&amp;quot;))&lt;br /&gt;
 summary(TBI_Data)&lt;br /&gt;
&lt;br /&gt;
 # Get information matrix of the data&lt;br /&gt;
 # (1) Convert to a missing_data.frame&lt;br /&gt;
 # library(&amp;quot;betareg&amp;quot;); library(&amp;quot;mi&amp;quot;)			&lt;br /&gt;
 mdf &amp;lt;- missing_data.frame(TBI_Data) # warnings about missingness patterns&lt;br /&gt;
 show(mdf); mdf@patterns&lt;br /&gt;
&lt;br /&gt;
 # (2) change things: '''mi::change()''' method changes the family, imputation method,&lt;br /&gt;
 # size, type, and so forth of a missing variable. It’s called &lt;br /&gt;
 # before calling '''mi''' to affect how the conditional expectation of each &lt;br /&gt;
 # missing variable is modeled.&lt;br /&gt;
 mdf &amp;lt;- '''change'''(mdf, y = &amp;quot;spikes.hr&amp;quot;, what = &amp;quot;transformation&amp;quot;, to = &amp;quot;identity&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:left; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Arg||Description&lt;br /&gt;
|-&lt;br /&gt;
|y||A character vector naming one or more missing variables within the missing_data.frame specified by the &amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; argument, or a vector of integers or a logical vector indicating which missing_variables to change.&lt;br /&gt;
|-&lt;br /&gt;
|what||A character string naming what is to be changed, such as &amp;quot;family&amp;quot;, &amp;quot;imputation_method&amp;quot;, &amp;quot;size&amp;quot;,&amp;quot;transformation&amp;quot;, &amp;quot;type&amp;quot;, &amp;quot;link&amp;quot;, or &amp;quot;model.&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|to||A character string naming what y should be changed to, such as one of the admissible families, imputation methods, transformations, or types. If missing, then possible choices for the &amp;quot;to&amp;quot; argument will be helpfully printed on the screen.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (3) examine missingness patterns&lt;br /&gt;
 summary(mdf); hist(mdf); &lt;br /&gt;
 image(mdf)&lt;br /&gt;
&lt;br /&gt;
 # (4) Perform initial imputation&lt;br /&gt;
 imputations &amp;lt;- mi(mdf, n.iter=30, n.chains=5, verbose=TRUE)&lt;br /&gt;
 hist(imputations)&lt;br /&gt;
&lt;br /&gt;
 # (5) Extracts several multiply imputed data.frames from “imputations” object&lt;br /&gt;
 data.frames &amp;lt;- complete(imputations, 5)&lt;br /&gt;
&lt;br /&gt;
 # (6) Report a list of “summaries” for each element (imputation instance)&lt;br /&gt;
 lapply(data.frames, summary)&lt;br /&gt;
&lt;br /&gt;
 # (6.a) To cast the imputed numbers as integers (not necessary, but may be useful)&lt;br /&gt;
 indx &amp;lt;- sapply(data.frames[[5]], is.numeric)  # get the indices of numeric columns&lt;br /&gt;
 data.frames[[5]][indx] &amp;lt;- lapply(data.frames[[5]][indx], function(x) as.numeric(as.integer(x))) 		    # cast each value as integer&lt;br /&gt;
&lt;br /&gt;
 # (7) Save results out&lt;br /&gt;
 write.csv(data.frames[[5]], &amp;quot;C:\\Users\\Dinov\\Desktop\\TBI_MIData.csv&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (8) Complete Data analytics functions:&lt;br /&gt;
 # library(&amp;quot;mi&amp;quot;)&lt;br /&gt;
 #lm.mi(); glm.mi(); polr.mi(); bayesglm.mi(); bayespolr.mi(); lmer.mi(); glmer.mi()&lt;br /&gt;
&lt;br /&gt;
 # (8.1) Define Linear Regression for multiply imputed dataset – Also see Step (10)&lt;br /&gt;
 ##linear regression for each imputed data set - 5 regression models are fit&lt;br /&gt;
 &amp;lt;b&amp;gt;fit_lm1&amp;lt;/b&amp;gt; &amp;lt;- glm(ever.sz ~ surgery + worst.gcs + factor(sex) + age, data.frames$\$$`chain:1`, family = &amp;quot;binomial&amp;quot;); summary(fit_lm1); display(fit_lm1)&lt;br /&gt;
&lt;br /&gt;
 # Fit the appropriate model and pool the results (estimates over MI chains)&lt;br /&gt;
 model_results &amp;lt;- pool(ever.sz ~ surgery + worst.gcs + factor(sex) + age, family = &amp;quot;binomial&amp;quot;, data=imputations,  m=5)&lt;br /&gt;
 display (model_results); summary (model_results)  &lt;br /&gt;
&lt;br /&gt;
 # Report the summaries of the imputations&lt;br /&gt;
 data.frames &amp;lt;- complete(imputations, 3)  	# extract the first 3 chains&lt;br /&gt;
 lapply(data.frames, summary)&lt;br /&gt;
&lt;br /&gt;
 # (9) Validation: we now verify whether enough iterations were conducted. &lt;br /&gt;
 # Validation criteria demands that the mean of each completed variable should&lt;br /&gt;
 # be similar for each of the k chains (in this case k=5).&lt;br /&gt;
 # &amp;lt;b&amp;gt;mipply&amp;lt;/b&amp;gt; is wrapper for &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; invoked on mi-class objects to compute the col means&lt;br /&gt;
 round(mipply(imputations, mean, to.matrix = TRUE), 3)&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;Rhat&amp;lt;/b&amp;gt; convergence statistics compares the variance between chains to the variance&lt;br /&gt;
 # across chains. &lt;br /&gt;
 # &amp;lt;b&amp;gt;Rhat Values ~ 1.0&amp;lt;/b&amp;gt; indicate likely convergence, &lt;br /&gt;
 # &amp;lt;b&amp;gt;Rhat Values &amp;gt; 1.1&amp;lt;/b&amp;gt; indicate that the chains should be run longer &lt;br /&gt;
 # (use large number of iterations)&lt;br /&gt;
 Rhats(imputations, statistic = &amp;quot;moments&amp;quot;) # assess the convergence of MI algorithm&lt;br /&gt;
&lt;br /&gt;
 # When convergence is unstable, we can continue the iterations for all chains, e.g.&lt;br /&gt;
 imputations &amp;lt;- mi(imputations, n.iter=20) # add additional 20 iterations&lt;br /&gt;
&lt;br /&gt;
 # To &amp;lt;b&amp;gt;plot&amp;lt;/b&amp;gt; the produced mi results, for all missing_variables we can generate&lt;br /&gt;
 # a histogram of the observed, imputed, and completed data.&lt;br /&gt;
 # We can compare of the completed data to the fitted values implied by the model&lt;br /&gt;
 # for the completed data, by plotting binned residuals. &lt;br /&gt;
 # &amp;lt;b&amp;gt;hist&amp;lt;/b&amp;gt; function works similarly as plot. &lt;br /&gt;
 # &amp;lt;b&amp;gt;image&amp;lt;/b&amp;gt; function gives a sense of the missingness patterns in the data&lt;br /&gt;
 plot(imputations); hist(imputations); image(imputations); summary(imputations)&lt;br /&gt;
&lt;br /&gt;
 # (10) Finally, pool over the m = 5 imputed datasets when we fit the “model”&lt;br /&gt;
 # Pool from across the 4 chains – in order to estimate a linear regression model&lt;br /&gt;
 # and impact ov various predictors&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;background-color: #37FDFC&amp;quot;&amp;gt;model_results &amp;lt;- &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;pool&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;(ever.sz ~ surgery + worst.gcs + factor(sex) + age, data =  imputations,  m =  5 ); display (model_results); summary (model_results)  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Report the summaries of the imputations&lt;br /&gt;
 data.frames &amp;lt;- complete(imputations, 3)  	# extract the first 3 chains&lt;br /&gt;
 lapply(data.frames, summary)			# report summaries&lt;br /&gt;
&lt;br /&gt;
===Parkinson's Disease Case Study===&lt;br /&gt;
&lt;br /&gt;
Background: See: http://wiki.socr.umich.edu/index.php/SOCR_Data_PD_BiomedBigMetadata&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;#imputation for logistic regression&amp;lt;/b&amp;gt;&lt;br /&gt;
 # load the data: &amp;lt;b&amp;gt;08_PPMI_GSA_clinical.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 ppmi_new&amp;lt;-read.csv(&amp;quot;https://umich.instructure.com/files/330401/download?download_frd=1&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;psych&amp;quot;)&lt;br /&gt;
 library(psych)&lt;br /&gt;
 # report descriptive statistics&lt;br /&gt;
&lt;br /&gt;
 ppmi_new$\$$ResearchGroup &amp;lt;- ifelse(ppmi_new$\$$ResearchGroup == &amp;quot;Control&amp;quot;, &amp;quot;Control&amp;quot;, &amp;quot;Patient&amp;quot;)&lt;br /&gt;
 ppmi_new$\$$ResearchGroup &amp;lt;- as.factor(ppmi_new$\$$ResearchGroup): table(ppmi_new$\$$ResearchGroup)&lt;br /&gt;
&lt;br /&gt;
 # Reduce the Dataset: extract only the columns of interest (to ensure real time calculations)&lt;br /&gt;
 ppmi_new_1 &amp;lt;- as.data.frame(ppmi_new)[,   c(&amp;quot;ResearchGroup&amp;quot;,&amp;quot;R_fusiform_gyrus_Curvedness&amp;quot;,&amp;quot;Sex&amp;quot;,&amp;quot;Age&amp;quot;,&amp;quot;chr12_rs34637584_GT&amp;quot;,&amp;quot;UPDRS_Part_I_Summary_Score_Baseline&amp;quot;,&amp;quot;UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline&amp;quot;,&amp;quot;UPDRS_Part_III_Summary_Score_Baseline&amp;quot;,  &amp;quot;UPDRS_Part_IV_Summary_Score_Baseline&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
 descript &amp;lt;- &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;describe&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;(ppmi_new_1); descript	# reports means, SE’s, etc.&lt;br /&gt;
&lt;br /&gt;
 dim(ppmi_new); dim(ppmi_new_1)	# check dimensions before &lt;br /&gt;
&lt;br /&gt;
 # imputation 1&lt;br /&gt;
 # install.packages(&amp;quot;mi&amp;quot;); install.packages(&amp;quot;betareg&amp;quot;)&lt;br /&gt;
 library(mi); library(betareg)&lt;br /&gt;
&lt;br /&gt;
 mdf&amp;lt;-missing_data.frame(ppmi_new_1[-1,])&lt;br /&gt;
 apply(ppmi_new_1[-1,],1,mean)&lt;br /&gt;
 imputations&amp;lt;-mi(mdf, seed=900);   summary(imputations)&lt;br /&gt;
 ppmi_complete&amp;lt;-complete(imputations)&lt;br /&gt;
&lt;br /&gt;
 # Save the imputation&lt;br /&gt;
 # again you may want to cast imputed numerical values as integers, perhaps&lt;br /&gt;
 # (indx &amp;lt;- sapply(data.frames[[5]], is.numeric)  # get the indices of numeric columns&lt;br /&gt;
 # data.frames[[5]][indx] &amp;lt;- lapply(data.frames[[5]][indx], function(x) as.numeric(as.integer(x)))   # cast each value&lt;br /&gt;
 # write.csv(ppmi_complete,&amp;quot;C:\\Users\\Dinov\\Desktop\\ppmi_new_1_complete.csv&amp;quot;)&lt;br /&gt;
 write.csv(ppmi_complete,&amp;quot;ppmi_new_1_complete.csv&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Get the imputations of 4 iterations&lt;br /&gt;
 ppmi_complete_1&amp;lt;- ppmi_complete[[1]]; ppmi_complete_2&amp;lt;- ppmi_complete[[2]]; &lt;br /&gt;
 ppmi_complete_3&amp;lt;- ppmi_complete[[3]]; ppmi_complete_4&amp;lt;- ppmi_complete[[4]]&lt;br /&gt;
&lt;br /&gt;
 # average the imputations &lt;br /&gt;
 ppmi_updrs &amp;lt;- (ppmi_complete_1+ppmi_complete_2+ppmi_complete_4+ppmi_complete_3)/4&lt;br /&gt;
 # ppmi_top&amp;lt;-cbind(ppmi_new_1[-1,1:335], ppmi_updrs) #delete the first observation&lt;br /&gt;
 # colnames(ppmi_top)&amp;lt;-colnames(ppmi_new[,1:393])&lt;br /&gt;
&lt;br /&gt;
 # Save results – complete dataset&lt;br /&gt;
 #  write.csv(ppmi_top,&amp;quot;C:\\Users\\Dinov\\Desktop\\ppmi_top_complete_1.csv&amp;quot;)&lt;br /&gt;
 # write.csv(ppmi_top,&amp;quot;ppmi_top_complete_1.csv&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Now, run some Data analytics on complete data:&lt;br /&gt;
 # library(&amp;quot;mi&amp;quot;)&lt;br /&gt;
 #lm.mi(); glm.mi(); polr.mi(); bayesglm.mi(); bayespolr.mi(); lmer.mi(); glmer.mi()&lt;br /&gt;
 # Define Linear Regression for multiply imputed dataset&lt;br /&gt;
 ##linear regression for each imputed data set - 5 regression models are fit&lt;br /&gt;
&lt;br /&gt;
 model_results &amp;lt;- pool(ResearchGroup ~  R_fusiform_gyrus_Curvedness + factor(Sex) + Age + &lt;br /&gt;
 factor(chr12_rs34637584_GT) + UPDRS_Part_I_Summary_Score_Baseline + UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + UPDRS_Part_III_Summary_Score_Baseline, family = &amp;quot;binomial&amp;quot;, data=imputations,  m=3)&lt;br /&gt;
 display (model_results); summary (model_results)&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MissingData_Appendix|Appendix]]===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===See also===&lt;br /&gt;
* [[SOCR_Simulated_HELP_Data_Activity#Multiple_imputation| The SOCR Simulated HELP data activity provides additional missing data management examples]].&lt;br /&gt;
* [http://sites.stat.psu.edu/~jls/mifaq.html Multiple Imputation FAQs].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_MissingData}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GEE&amp;diff=16175</id>
		<title>SMHS BigDataBigSci GEE</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GEE&amp;diff=16175"/>
		<updated>2016-05-23T13:44:20Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci| Model-based Analytics]] - Generalized Estimating Equation (GEE) Modeling ==&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
*How to represent dependencies in linear models and examine causal effects?&lt;br /&gt;
*Is there a way to study population average effects of a covariate against specific individual effects?&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
GEE is a marginal longitudinal method that directly assesses the mean relations of interest (i.e., how the mean dependent variable changes over time), accounting for covariances among the observations within subjects, and getting a better estimate and valid significance tests of the relations. Thus, GEE estimates two different equations, (1) for the mean relations, and (2) for the covariance structure. An advantage of GEE over random-effect models is that it does not require the dependent variable to be normally distributed. However, a disadvantage of GEE is that it is less flexible and versatile – commonly employed algorithms for it require a small-to-moderate number of time points evenly (or approximately evenly) spaced, and similarly spaced across subjects. Nevertheless, it is a little more flexible than repeated-measure ANOVA because it permits some missing values and has an easy way to test for and model away the specific form of autocorrelation within subjects.&lt;br /&gt;
&lt;br /&gt;
GEE is mostly used when the study is focused on uncovering the population average effect of a covariate vs. the individual specific effect. These two things are only equivalent for linear models, but not in non-linear models.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[SMHS_BigDataBigSci| Back to Model-based Analytics]] &lt;br /&gt;
*[[SMHS_BigDataBigSci_GCM| Back to Growth Curve Modeling ]]&lt;br /&gt;
*[[SMHS_BigDataBigSci_SEM| Back to Structural Equation Modeling (SEM)]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GEE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16174</id>
		<title>SMHS BigDataBigSci GCM</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16174"/>
		<updated>2016-05-23T13:44:02Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Appendix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci| Model-based Analytics]] - Growth Curve Models==&lt;br /&gt;
&lt;br /&gt;
Latent growth curve models may be used to analyze longitudinal or temporal data where the outcome measure is assessed on multiple occasions, and we examine its change over time, e.g., the trajectory over time can be&lt;br /&gt;
modeled as a linear or quadratic function.  Random effects are used to capture individual differences by conveniently representing (continuous) latent variables, aka growth factors.  To fit a linear growth model we may specify a model with two latent variables:  a random intercept, and a random slope:&lt;br /&gt;
&lt;br /&gt;
 #load data   &amp;lt;b&amp;gt;05_PPMI_top_UPDRS_Integrated_LongFormat.csv ( dim(myData) 661  71), wide&amp;lt;/b&amp;gt; &lt;br /&gt;
 # setwd(&amp;quot;/dir/&amp;quot;)&lt;br /&gt;
 myData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330395/download?download_frd=1&amp;amp;verifier=v6jBvV4x94ka3EYcGKuXXg5BZNaOLBVp0xkJih0H&amp;quot;,header=TRUE)&lt;br /&gt;
 attach(myData)&lt;br /&gt;
&lt;br /&gt;
 # dichotomize the &amp;quot;ResearchGroup&amp;quot; variable&lt;br /&gt;
 table(myData$\$$ResearchGroup)&lt;br /&gt;
 myData$\$$ResearchGroup &amp;lt;- ifelse(myData$\$$ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # linear growth model with 4 timepoints&lt;br /&gt;
 # intercept (i) and slope (s) with fixed coefficients&lt;br /&gt;
 # i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4 (intercept/constant)&lt;br /&gt;
 # s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (slope/linear term)&lt;br /&gt;
 # ??? =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (quadratic term)&lt;br /&gt;
&lt;br /&gt;
In this model, we have fixed all the coefficients of the linear growth functions:&lt;br /&gt;
&lt;br /&gt;
 model4 &amp;lt;-&lt;br /&gt;
 ' &lt;br /&gt;
 i =~ 1*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_06 + 1*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_12 + 1*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +&lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_06 + 1*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_12 + 1*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 +&lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24 &lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_I_Summary_Score_Month_06 + 3*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_I_Summary_Score_Month_12 + 5*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_I_Summary_Score_Month_24 +&lt;br /&gt;
 0*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 3*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 5*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +         &lt;br /&gt;
 6*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 0*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_III_Summary_Score_Month_06 + 3*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_III_Summary_Score_Month_12 + 5*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 0*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 +&lt;br /&gt;
 6*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 +&lt;br /&gt;
 0*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 6*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit4 &amp;lt;- growth(model4, data=myData)&lt;br /&gt;
 summary(fit4)&lt;br /&gt;
 parameterEstimates(fit4)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame	&lt;br /&gt;
 fitted(fit4)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit4)&lt;br /&gt;
&lt;br /&gt;
==Measures of model quality (Comparative Fit Index (CFI), Root Mean Square Error of Approximation (RMSEA))==&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector: Comparative Fit Index (CFI), Root Mean Square Error of &lt;br /&gt;
 # Approximation (RMSEA)&lt;br /&gt;
 fitMeasures(fit4, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
====Comparative Fit Index====&lt;br /&gt;
&lt;br /&gt;
(CFI) is an incremental measure directly based on the non-centrality measure.  If d = χ2(df) where df are the degrees of freedom of the model, the Comparative Fit Index is:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{(Null Model)-d(Proposed Model)}{d(Null Model)}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
$0≤CFI≤1$ (by definition). It is interpreted as:&lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;lt;0.9$  - model fitting is poor.&lt;br /&gt;
&lt;br /&gt;
*$0.9≤CFI≤0.95$  is considered marginal, &lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;gt;0.95$   is good. &lt;br /&gt;
&lt;br /&gt;
CFI is a relative index of model fit – it compare the fit of your model to the fit of (the worst) fitting null model.&lt;br /&gt;
&lt;br /&gt;
====Root Mean Square Error of Approximation====&lt;br /&gt;
(RMSEA) - “Ramsey”&lt;br /&gt;
&lt;br /&gt;
An absolute measure of fit based on the non-centrality parameter: &lt;br /&gt;
&lt;br /&gt;
$\sqrt{\frac{X^2-df}{df×(N - 1)}}$,&lt;br /&gt;
&lt;br /&gt;
where N the sample size and df the degrees of freedom of the model.  If χ&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  &amp;lt; df, then the RMSEA∶=0.  It has a penalty for complexity via the chi square to df ratio.  The RMSEA is a popular measure of model fit. &lt;br /&gt;
&lt;br /&gt;
*RMSEA &amp;lt; 0.01, excellent, &lt;br /&gt;
&lt;br /&gt;
*RMSEA  &amp;lt; 0.05, good &lt;br /&gt;
&lt;br /&gt;
*RMSEA &amp;gt; 0.10 cutoff for poor fitting models&lt;br /&gt;
&lt;br /&gt;
====Standardized Root Mean Square Residual==== &lt;br /&gt;
(SRMR) is an absolute measure of fit defined as the standardized difference between the observed correlation and the predicted correlation.  A value of zero indicates perfect fit.  The SRMR has no penalty for model complexity.  SRMR &amp;lt;0.08 is considered a good fit.&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit4)&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
 # library(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;A Simpler Model (fit5)&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 model5 &amp;lt;- '&lt;br /&gt;
  # intercept and slope with fixed coefficients&lt;br /&gt;
 i =~ UPDRS_Part_I_Summary_Score_Baseline + UPDRS_Part_I_Summary_Score_Month_03 + UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + 6*UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
  # regressions&lt;br /&gt;
 i ~  R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT                                                              &lt;br /&gt;
 s ~ R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT&lt;br /&gt;
  # time-varying covariates&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Baseline ~ Weight&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Month_03  ~ ResearchGroup &lt;br /&gt;
     UPDRS_Part_I_Summary_Score_Month_24 ~ Age&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit5 &amp;lt;- growth(model5, data=myData)&lt;br /&gt;
 summary(fit5); fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
 parameterEstimates(fit5)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame&lt;br /&gt;
&lt;br /&gt;
 lavaan (0.5-18) converged normally after  99 iterations&lt;br /&gt;
  Number of observations                           661&lt;br /&gt;
  Estimator                                         ML&lt;br /&gt;
  Minimum Function Test Statistic                3.703&lt;br /&gt;
  Degrees of freedom                                 1&lt;br /&gt;
  P-value (Chi-square)                           0.054&lt;br /&gt;
 Parameter estimates:&lt;br /&gt;
  Information                                 Expected&lt;br /&gt;
  Standard Errors                             Standard&lt;br /&gt;
                    Estimate  Std.err  Z-value  P(&amp;gt;|z|)&lt;br /&gt;
 Latent variables:&lt;br /&gt;
  i =~&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.074&lt;br /&gt;
    UPDRS_P_I_S_S     1.172&lt;br /&gt;
  s =~&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     6.000&lt;br /&gt;
 &lt;br /&gt;
 Regressions:&lt;br /&gt;
  i ~&lt;br /&gt;
    R_fsfrm_gyr_V     0.000&lt;br /&gt;
    Weight            0.003&lt;br /&gt;
    ResearchGroup    -0.880&lt;br /&gt;
    Age              -0.009&lt;br /&gt;
    c12_34637584_    -0.907&lt;br /&gt;
  s ~&lt;br /&gt;
    R_fsfrm_gyr_V    -0.000&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
    ResearchGroup    -0.084&lt;br /&gt;
    Age               0.002&lt;br /&gt;
    c12_34637584_    -0.047&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Baseline ~&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_03 ~&lt;br /&gt;
    ResearchGroup     0.693&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_24 ~&lt;br /&gt;
    Age              -0.002&lt;br /&gt;
 &lt;br /&gt;
 Covariances:&lt;br /&gt;
  i ~~&lt;br /&gt;
    s                 0.074&lt;br /&gt;
 &lt;br /&gt;
 Intercepts:&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    i                 1.633&lt;br /&gt;
    s                -0.023&lt;br /&gt;
 &lt;br /&gt;
 Variances:&lt;br /&gt;
    UPDRS_P_I_S_S     1.017&lt;br /&gt;
    UPDRS_P_I_S_S     1.093&lt;br /&gt;
    UPDRS_P_I_S_S     2.993&lt;br /&gt;
    i                 1.019&lt;br /&gt;
    s                -0.025&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;b&amp;gt;cfi rmsea  srmr&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;0.996 0.064 0.008&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 fitted(fit5)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
 # write.table(fitted(fit5), file=&amp;quot;C:\\Users\\Dinov\\Desktop\\test1.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit5)&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector&lt;br /&gt;
 fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))   # comparative fit index (CFI)&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; See discussion of SEM modeling pros/cons &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Generalized Estimating Equation (GEE) Modeling==&lt;br /&gt;
&lt;br /&gt;
Generalized Estimating Equations (GEE) modeling&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; is used for analyzing data with the following characteristics:&lt;br /&gt;
(1) the observations within a group may be correlated, (2) observations in separate clusters are independent, (3) a monotone transformation of the expectation is linearly related to the explanatory variables, and (4) the variance is a function of the expectation. The expectation (#3) and the variance (# 4) are conditional given group-level or individual-level covariates.&lt;br /&gt;
&lt;br /&gt;
GEE is applied to handle correlated discrete and continuous outcome variables. For the outcome variables, it only requires specification   of the first 2 moments and   correlation   among   them.    The   goal   is   to estimate fixed parameters    without    specifying    their    joint    distribution.  The correlation is specified by one of these 4 alternatives (which is specified in the R call: geeglm(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, &amp;lt;b&amp;gt;corstr = &amp;quot; exchangeable&amp;quot;&amp;lt;/b&amp;gt;, scale.fix = TRUE):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci8.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Respiratory Illness GEE R example===&lt;br /&gt;
&lt;br /&gt;
This example is based on a data set on respiratory illness &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; and the &amp;lt;b&amp;gt;geepack&amp;lt;/b&amp;gt; package. The data is from a clinical study of the treatment effects on patients with respiratory illness. N=111 patients from 2 clinical centers randomized to receive either placebo or active treatments. 4 temporal examinations assessed the &amp;lt;b&amp;gt;respiratory state&amp;lt;/b&amp;gt; of patients as good (=1) or poor (=0). Explanatory variables characterizing a patient were: &amp;lt;b&amp;gt;center&amp;lt;/b&amp;gt; (1,2), treatment (A=active, P=placebo), &amp;lt;b&amp;gt;sex&amp;lt;/b&amp;gt; (M=male, F=female), &amp;lt;b&amp;gt;age&amp;lt;/b&amp;gt; (in years) at baseline. The values of the covariates were constant for the repeated elementary observations on each patient.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt; shows the number of patients for the response patterns across the 4 visits split by baseline-status and treatment. Baseline respiratory status = 0 appear to have either low or high number of positive responses. Baseline respiratory status = 1 tend to respond positively. &amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt; describes the distribution of the number of positive responses per patient for sex and center.&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt;: Distribution of patients for &amp;lt;b&amp;gt;different response patterns&amp;lt;/b&amp;gt; classified by &amp;lt;b&amp;gt;baseline-respiratory&amp;lt;/b&amp;gt; response and &amp;lt;b&amp;gt;treatment&amp;lt;/b&amp;gt;. The patterns are ordered according to increasing numbers of positive responses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ||Visit|| colspan=&amp;quot;15&amp;quot;| All Possible Response Patterns (2*2*2*2=16 permutation patterns)||&lt;br /&gt;
|-&lt;br /&gt;
|||1||0||1||0||0||0||1||1||1||0||0||1||1||1||0||1||&lt;br /&gt;
|-&lt;br /&gt;
|||2||0||0||1||0||0||1||0||0||1||0||1||1||0||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||3||0||0||0||1||0||0||1||0||1||1||1||0||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||4||0||0||0||0||1||0||0||1||0||1||0||1||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
!Baseline||Treatment||||||||||||||||||||||||||||||||Sum&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;|0||A||7||2||2||2||1||0||1||0||1||0||1||2||0||4||7||30&lt;br /&gt;
|-&lt;br /&gt;
|P||18||1||0||2||1||2||0||0||1||0||0||1||2||0||3||31&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|1||A||0||0||0||0||0||0||1||1||0||0||4||0||1||0||17||24&lt;br /&gt;
|-&lt;br /&gt;
|P||1||4||1||0||0||0||0||1||1||3||1||1||2||1||10||26&lt;br /&gt;
|-&lt;br /&gt;
|Sum||||26||7||3||4||2||2||2||2||3||3||6||4||5||5||37||111&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt;: Distribution of patients for the number of positive responses across the 4 visits for &amp;lt;b&amp;gt;Sex&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;Center&amp;lt;/b&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; rowspan=&amp;quot;2&amp;quot;| ||colspan=&amp;quot;5&amp;quot;|Number of positive responses&lt;br /&gt;
|-&lt;br /&gt;
| 0||1||2||3||4&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Sex || F||7||3||3||3||7&lt;br /&gt;
|-&lt;br /&gt;
|M||19||13||9||17||30&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Center|| 1||18||9||6||11||12&lt;br /&gt;
|-&lt;br /&gt;
|2||8||7||6||9||25&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Figure 1&amp;lt;/b&amp;gt; shows a plot of age against the proportion of positive responses for each patient. It indicates a quadratic relationship between the proportions and the age. Fitting a logistic model to the data (which would be appropriate if there were &amp;lt;i&amp;gt;no time effects&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;no spread in the response probabilities&amp;lt;/i&amp;gt; for patients with the same covariate values).&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
 library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # data include a clinical trial of 111 patients with respiratory illness from two different clinics were randomized to receive either &lt;br /&gt;
 # placebo (P) or an active (A) treatment. Patients were examined at baseline and at four visits during treatment. &lt;br /&gt;
 # At each examination, respiratory status (categorized as 1 = good, 0 = poor)&lt;br /&gt;
 data(&amp;quot;respiratory&amp;quot;)&lt;br /&gt;
 head(respiratory)&lt;br /&gt;
 myData &amp;lt;- respiratory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(myData)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Center||ID||Treat||Sex||Age||Baseline||Visit||Outcome&lt;br /&gt;
|-&lt;br /&gt;
|1 ||1||1||P||M||46||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|2 ||1||1||P||M||46||0||2||0&lt;br /&gt;
|-&lt;br /&gt;
|3 ||1||1||P||M||46||0||3||0&lt;br /&gt;
|-&lt;br /&gt;
|4 ||1||1||P||M||46||0||4||0&lt;br /&gt;
|-&lt;br /&gt;
|5||1||2||P||M||28||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|6||1||2||P||M||28||0||2||0&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Get proportions of positive responses&lt;br /&gt;
 responses &amp;lt;- factor(myData$\$$outcome, labels = c(&amp;quot;OutcomePositive&amp;quot;, &amp;quot;OutcomeNegative&amp;quot;))&lt;br /&gt;
 data.frame &amp;lt;- data.frame(responses, myData$\$$age)&lt;br /&gt;
 head(data.frame)&lt;br /&gt;
 tab &amp;lt;- prop.table(table(data.frame), 1); tab	# compute proportions&lt;br /&gt;
 sum(tab[1,])				# check proportions (sums to 1.0)?&lt;br /&gt;
 prop &amp;lt;- tab[1,]				# save the proportions of positive responses for each patient&lt;br /&gt;
 plot(as.numeric(dimnames(tab)$\$$myData.age), tab[1,], xlab = &amp;quot;Age&amp;quot;, ylab = &amp;quot;Proportion of Positive Outcomes&amp;quot;)&lt;br /&gt;
 # dimnames(tab)				# to see/inspect positive/negative outcomes&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci9.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- as.numeric(dimnames(tab)$\$$myData.age)&lt;br /&gt;
 poly &amp;lt;- loess( prop ~ x)	# fit a Local Polynomial Regression Fitting&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(predict(poly), col='red', lwd=2)&lt;br /&gt;
&lt;br /&gt;
 smoothingSpline &amp;lt;- smooth.spline(x, prop, spar=0.6)&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(smoothingSpline, col='red', lwd=1.5)&lt;br /&gt;
 smoothPolySpline &amp;lt;- smooth.spline(x, predict(poly), spar=0.6)&lt;br /&gt;
 lines(smoothPolySpline, col='blue', lwd=2)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, inset=.05, title=&amp;quot;Polynomial regression models&amp;quot;,  c(&amp;quot;Raw Poly&amp;quot;,&amp;quot;Smooth Poly&amp;quot;), fill=c('red', 'blue'), horiz=TRUE)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci10.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 model.glm &amp;lt;- &amp;lt;b&amp;gt;glm&amp;lt;/b&amp;gt;(outcome ~ baseline + center + sex + treat + age + I(age^2), data = respiratory, family = binomial)&lt;br /&gt;
&lt;br /&gt;
 summary(model.glm)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Deviance Residuals: &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
| -2.5951||-0.9108||0.4034||0.8336||2.0951&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Estimate||Std. Error||z value||$Pr( \gt |z|)$  &lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||3.3579727||1.0285292||3.265||0.0011 **&lt;br /&gt;
|-&lt;br /&gt;
|baseline||1.8850421||0.2482959||7.592||3.15e-14 ***&lt;br /&gt;
|-&lt;br /&gt;
|center||0.5099244||0.2453982||2.078||0.0377 *&lt;br /&gt;
|-&lt;br /&gt;
|sexM||-0.4510595||0.3166570||-1.424||0.1543&lt;br /&gt;
|-&lt;br /&gt;
|Treatp||-1.3231587||0.2431603||-5.442||5.28e-08 ***&lt;br /&gt;
|-&lt;br /&gt;
|age||-0.2072815||0.0472538||-4.387||1.15e-05 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||0.0025650||0.0006324||4.056||4.99e-05 ***&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
(Dispersion parameter for binomial family taken to be 1)&lt;br /&gt;
&lt;br /&gt;
Null deviance: 609.41  on 443  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
Residual deviance: 468.62  on 437  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
AIC: 482.62&lt;br /&gt;
&lt;br /&gt;
The correlation matrix of the of the outcome measures across visits is shown in &amp;lt;b&amp;gt;Table 3.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 attach(myData)&lt;br /&gt;
 mat1 &amp;lt;- matrix(c(outcome[visit==1], outcome [visit==2], outcome [visit==3], &lt;br /&gt;
	outcome[visit==4]), ncol = 4)&lt;br /&gt;
 cor(mat1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 3&amp;lt;/b&amp;gt;: Correlation matrix for the outcome measurements at different visits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||[,1]||[,2]||[,3]||[,4]&lt;br /&gt;
|-&lt;br /&gt;
|[,1]||1.0000000||0.5087944||0.4431438||0.5139016&lt;br /&gt;
|-&lt;br /&gt;
|[,2]||0.5087944||1.0000000||0.5821877||0.5301611&lt;br /&gt;
|-&lt;br /&gt;
|[,3]||0.4431438||0.5821877||1.0000000||0.5871276&lt;br /&gt;
|-&lt;br /&gt;
|[,4]||0.5139016||0.5301611||0.5871276||1.0000000&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # We can also examine for multicollinearity problem, using the correlation matrix for X&lt;br /&gt;
 cor(model.matrix(model.glm)[,-1])&lt;br /&gt;
&lt;br /&gt;
 # GEE modeling: R function arguments/options&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;corstr&amp;lt;/b&amp;gt;= for defining the correlation structure within groups in a GEE model&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;= is used to identify the grouping variable in a GEE model&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;scale.fix&amp;lt;/b&amp;gt;= when TRUE causes the scale parameter to be fixed (by default at 1) rather than estimated&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;waves&amp;lt;/b&amp;gt;= names a positive integer-valued variable that is used to identify the order and spacing of observations within groups in a GEE model. This argument is crucial when there are missing values and gaps in the data&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, corstr = &amp;quot;exchangeable&amp;quot;, scale.fix = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # The column labeled &amp;lt;b&amp;gt;Wald&amp;lt;/b&amp;gt; in the summary table is the square of the z-statistic. The reported p-values are the &lt;br /&gt;
 # upper tailed probabilities from a chisq1 distribution and test whether the true parameter value ≠0.&lt;br /&gt;
 summary(gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # To test the effect of ''treatment'' using anova()&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;treat&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id = id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 gee.model2 &amp;lt;- geeglm(outcome ~ center + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id=id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 anova(gee.model1, gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # To test whether a categorical predictor with more than two levels should be retained in a GEE model we need &lt;br /&gt;
 # to test the entire set of dummy variables simultaneously as a single construct. &lt;br /&gt;
 # The geepack package provides a method for the anova function for a multivariate Wald test&lt;br /&gt;
 # When the anova function is applied to a single geeglm object it returns sequential Wald tests for &lt;br /&gt;
 # individual predictors with the tests carried out in the order the predictors are listed in the model formula.&lt;br /&gt;
 anova(gee.model1)&lt;br /&gt;
&lt;br /&gt;
===PD GEE example===&lt;br /&gt;
&lt;br /&gt;
This example used the PPMI/PD data to show GEE analysis.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;# 05_PPMI_top_UPDRS_Integrated_LongFormat1.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 longData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330397/download?download_frd=1&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Data Elements: FID_IID	L_insular_cortex_ComputeArea	L_insular_cortex_Volume	R_insular_cortex_ComputeArea	R_insular_cortex_Volume	L_cingulate_gyrus_ComputeArea	L_cingulate_gyrus_Volume	 R_cingulate_gyrus_ComputeArea	R_cingulate_gyrus_Volume	L_caudate_ComputeArea	L_caudate_Volume	R_caudate_ComputeArea	R_caudate_Volume	L_putamen_ComputeArea	L_putamen_Volume	R_putamen_ComputeArea	 R_putamen_Volume	Sex	Weight	ResearchGroup	Age	chr12_rs34637584_GT	chr17_rs11868035_GT	chr17_rs11012_GT	chr17_rs393152_GT	chr17_rs12185268_GT	chr17_rs199533_GT	UPDRS_part_I	 UPDRS_part_II	UPDRS_part_III	time_visit&lt;br /&gt;
&lt;br /&gt;
 dim(longData) &lt;br /&gt;
&lt;br /&gt;
 data1 = na.omit(longData)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 ControlGroup &amp;lt;- ifelse(ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # these calculations take a long time!!!&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca,  : &lt;br /&gt;
 # nrow(zsca) and length(y)&amp;lt;/i&amp;gt; not match” – this indicates some of the variables are of different lengths&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“glm.fit: algorithm did not converge”&amp;lt;/i&amp;gt; – see this discussion: http://goo.gl/lrjBjB &lt;br /&gt;
&lt;br /&gt;
 gee.model0 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1,  family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II +   time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # compare 2 gee models&lt;br /&gt;
 # anova(gee.model0,gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # you can try the “family = poisson(link = &amp;quot;log&amp;quot;)” model for the ResearchGroup response, as well&lt;br /&gt;
&lt;br /&gt;
 gee.model2 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(ControlGroup &lt;br /&gt;
 ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+R_insular_cortex_ComputeArea+ R_insular_cortex_Volume +L_cingulate_gyrus_ComputeArea + L_cingulate_gyrus_Volume + R_cingulate_gyrus_ComputeArea  + R_cingulate_gyrus_Volume +  L_caudate_ComputeArea + L_caudate_Volume + R_caudate_ComputeArea + R_caudate_Volume + L_putamen_ComputeArea + L_putamen_Volume + R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age +  chr12_rs34637584_GT +   chr17_rs11868035_GT + chr17_rs11012_GT + chr17_rs393152_GT + chr17_rs12185268_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr  = &amp;quot;unstructured&amp;quot;,  std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Remember that we do not interpret GEE coefficients as relating to individuals – GEE models are marginal models and the conclusions drawn are interpreted as population-based. Also, the time element in the model (time_visit) is just another controlling factor. &amp;lt;b&amp;gt;The effect-sizes (betas) associated with each variable/predictor represent the slopes associated with the corresponding covariate, while holding time constant&amp;lt;/b&amp;gt;. If we need to examine interactions (e.g., Weight change over Time), we need to include an interaction term in model: (i.e. + Weight*time_visit).&lt;br /&gt;
&lt;br /&gt;
 summary (gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # Individual Wald test and &amp;lt;b&amp;gt;confidence intervals&amp;lt;/b&amp;gt; for each covariate&lt;br /&gt;
 predictors2 &amp;lt;- coef(summary(gee.model2))&lt;br /&gt;
 CI2 &amp;lt;- with(as.data.frame(predictors2), cbind(lwr=Estimate-1.96*Std.err, est=Estimate, upr=Estimate+1.96*Std.err))&lt;br /&gt;
 rownames(CI2) &amp;lt;- rownames(predictors2)&lt;br /&gt;
 CI2&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
SEM References&lt;br /&gt;
&lt;br /&gt;
*http://socserv.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf &lt;br /&gt;
&lt;br /&gt;
GEE References&lt;br /&gt;
&lt;br /&gt;
*https://cran.r-project.org/web/packages/geepack/geepack.pdf&lt;br /&gt;
&lt;br /&gt;
*http://www.jstatsoft.org/v15/i02/paper&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; http://www.jstatsoft.org/v15/i02/ &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; https://books.google.com/books?id=mdEqBgAAQBAJ&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci| Back to Model-based Analytics]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_GEE| Next Section: Generalized Estimating Equation (GEE) Modeling]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16173</id>
		<title>SMHS BigDataBigSci GCM</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16173"/>
		<updated>2016-05-23T13:43:31Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Respiratory Illness GEE R example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci| Model-based Analytics]] - Growth Curve Models==&lt;br /&gt;
&lt;br /&gt;
Latent growth curve models may be used to analyze longitudinal or temporal data where the outcome measure is assessed on multiple occasions, and we examine its change over time, e.g., the trajectory over time can be&lt;br /&gt;
modeled as a linear or quadratic function.  Random effects are used to capture individual differences by conveniently representing (continuous) latent variables, aka growth factors.  To fit a linear growth model we may specify a model with two latent variables:  a random intercept, and a random slope:&lt;br /&gt;
&lt;br /&gt;
 #load data   &amp;lt;b&amp;gt;05_PPMI_top_UPDRS_Integrated_LongFormat.csv ( dim(myData) 661  71), wide&amp;lt;/b&amp;gt; &lt;br /&gt;
 # setwd(&amp;quot;/dir/&amp;quot;)&lt;br /&gt;
 myData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330395/download?download_frd=1&amp;amp;verifier=v6jBvV4x94ka3EYcGKuXXg5BZNaOLBVp0xkJih0H&amp;quot;,header=TRUE)&lt;br /&gt;
 attach(myData)&lt;br /&gt;
&lt;br /&gt;
 # dichotomize the &amp;quot;ResearchGroup&amp;quot; variable&lt;br /&gt;
 table(myData$\$$ResearchGroup)&lt;br /&gt;
 myData$\$$ResearchGroup &amp;lt;- ifelse(myData$\$$ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # linear growth model with 4 timepoints&lt;br /&gt;
 # intercept (i) and slope (s) with fixed coefficients&lt;br /&gt;
 # i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4 (intercept/constant)&lt;br /&gt;
 # s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (slope/linear term)&lt;br /&gt;
 # ??? =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (quadratic term)&lt;br /&gt;
&lt;br /&gt;
In this model, we have fixed all the coefficients of the linear growth functions:&lt;br /&gt;
&lt;br /&gt;
 model4 &amp;lt;-&lt;br /&gt;
 ' &lt;br /&gt;
 i =~ 1*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_06 + 1*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_12 + 1*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +&lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_06 + 1*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_12 + 1*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 +&lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24 &lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_I_Summary_Score_Month_06 + 3*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_I_Summary_Score_Month_12 + 5*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_I_Summary_Score_Month_24 +&lt;br /&gt;
 0*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 3*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 5*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +         &lt;br /&gt;
 6*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 0*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_III_Summary_Score_Month_06 + 3*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_III_Summary_Score_Month_12 + 5*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 0*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 +&lt;br /&gt;
 6*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 +&lt;br /&gt;
 0*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 6*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit4 &amp;lt;- growth(model4, data=myData)&lt;br /&gt;
 summary(fit4)&lt;br /&gt;
 parameterEstimates(fit4)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame	&lt;br /&gt;
 fitted(fit4)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit4)&lt;br /&gt;
&lt;br /&gt;
==Measures of model quality (Comparative Fit Index (CFI), Root Mean Square Error of Approximation (RMSEA))==&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector: Comparative Fit Index (CFI), Root Mean Square Error of &lt;br /&gt;
 # Approximation (RMSEA)&lt;br /&gt;
 fitMeasures(fit4, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
====Comparative Fit Index====&lt;br /&gt;
&lt;br /&gt;
(CFI) is an incremental measure directly based on the non-centrality measure.  If d = χ2(df) where df are the degrees of freedom of the model, the Comparative Fit Index is:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{(Null Model)-d(Proposed Model)}{d(Null Model)}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
$0≤CFI≤1$ (by definition). It is interpreted as:&lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;lt;0.9$  - model fitting is poor.&lt;br /&gt;
&lt;br /&gt;
*$0.9≤CFI≤0.95$  is considered marginal, &lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;gt;0.95$   is good. &lt;br /&gt;
&lt;br /&gt;
CFI is a relative index of model fit – it compare the fit of your model to the fit of (the worst) fitting null model.&lt;br /&gt;
&lt;br /&gt;
====Root Mean Square Error of Approximation====&lt;br /&gt;
(RMSEA) - “Ramsey”&lt;br /&gt;
&lt;br /&gt;
An absolute measure of fit based on the non-centrality parameter: &lt;br /&gt;
&lt;br /&gt;
$\sqrt{\frac{X^2-df}{df×(N - 1)}}$,&lt;br /&gt;
&lt;br /&gt;
where N the sample size and df the degrees of freedom of the model.  If χ&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  &amp;lt; df, then the RMSEA∶=0.  It has a penalty for complexity via the chi square to df ratio.  The RMSEA is a popular measure of model fit. &lt;br /&gt;
&lt;br /&gt;
*RMSEA &amp;lt; 0.01, excellent, &lt;br /&gt;
&lt;br /&gt;
*RMSEA  &amp;lt; 0.05, good &lt;br /&gt;
&lt;br /&gt;
*RMSEA &amp;gt; 0.10 cutoff for poor fitting models&lt;br /&gt;
&lt;br /&gt;
====Standardized Root Mean Square Residual==== &lt;br /&gt;
(SRMR) is an absolute measure of fit defined as the standardized difference between the observed correlation and the predicted correlation.  A value of zero indicates perfect fit.  The SRMR has no penalty for model complexity.  SRMR &amp;lt;0.08 is considered a good fit.&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit4)&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
 # library(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;A Simpler Model (fit5)&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 model5 &amp;lt;- '&lt;br /&gt;
  # intercept and slope with fixed coefficients&lt;br /&gt;
 i =~ UPDRS_Part_I_Summary_Score_Baseline + UPDRS_Part_I_Summary_Score_Month_03 + UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + 6*UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
  # regressions&lt;br /&gt;
 i ~  R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT                                                              &lt;br /&gt;
 s ~ R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT&lt;br /&gt;
  # time-varying covariates&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Baseline ~ Weight&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Month_03  ~ ResearchGroup &lt;br /&gt;
     UPDRS_Part_I_Summary_Score_Month_24 ~ Age&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit5 &amp;lt;- growth(model5, data=myData)&lt;br /&gt;
 summary(fit5); fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
 parameterEstimates(fit5)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame&lt;br /&gt;
&lt;br /&gt;
 lavaan (0.5-18) converged normally after  99 iterations&lt;br /&gt;
  Number of observations                           661&lt;br /&gt;
  Estimator                                         ML&lt;br /&gt;
  Minimum Function Test Statistic                3.703&lt;br /&gt;
  Degrees of freedom                                 1&lt;br /&gt;
  P-value (Chi-square)                           0.054&lt;br /&gt;
 Parameter estimates:&lt;br /&gt;
  Information                                 Expected&lt;br /&gt;
  Standard Errors                             Standard&lt;br /&gt;
                    Estimate  Std.err  Z-value  P(&amp;gt;|z|)&lt;br /&gt;
 Latent variables:&lt;br /&gt;
  i =~&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.074&lt;br /&gt;
    UPDRS_P_I_S_S     1.172&lt;br /&gt;
  s =~&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     6.000&lt;br /&gt;
 &lt;br /&gt;
 Regressions:&lt;br /&gt;
  i ~&lt;br /&gt;
    R_fsfrm_gyr_V     0.000&lt;br /&gt;
    Weight            0.003&lt;br /&gt;
    ResearchGroup    -0.880&lt;br /&gt;
    Age              -0.009&lt;br /&gt;
    c12_34637584_    -0.907&lt;br /&gt;
  s ~&lt;br /&gt;
    R_fsfrm_gyr_V    -0.000&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
    ResearchGroup    -0.084&lt;br /&gt;
    Age               0.002&lt;br /&gt;
    c12_34637584_    -0.047&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Baseline ~&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_03 ~&lt;br /&gt;
    ResearchGroup     0.693&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_24 ~&lt;br /&gt;
    Age              -0.002&lt;br /&gt;
 &lt;br /&gt;
 Covariances:&lt;br /&gt;
  i ~~&lt;br /&gt;
    s                 0.074&lt;br /&gt;
 &lt;br /&gt;
 Intercepts:&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    i                 1.633&lt;br /&gt;
    s                -0.023&lt;br /&gt;
 &lt;br /&gt;
 Variances:&lt;br /&gt;
    UPDRS_P_I_S_S     1.017&lt;br /&gt;
    UPDRS_P_I_S_S     1.093&lt;br /&gt;
    UPDRS_P_I_S_S     2.993&lt;br /&gt;
    i                 1.019&lt;br /&gt;
    s                -0.025&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;b&amp;gt;cfi rmsea  srmr&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;0.996 0.064 0.008&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 fitted(fit5)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
 # write.table(fitted(fit5), file=&amp;quot;C:\\Users\\Dinov\\Desktop\\test1.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit5)&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector&lt;br /&gt;
 fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))   # comparative fit index (CFI)&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; See discussion of SEM modeling pros/cons &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Generalized Estimating Equation (GEE) Modeling==&lt;br /&gt;
&lt;br /&gt;
Generalized Estimating Equations (GEE) modeling&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; is used for analyzing data with the following characteristics:&lt;br /&gt;
(1) the observations within a group may be correlated, (2) observations in separate clusters are independent, (3) a monotone transformation of the expectation is linearly related to the explanatory variables, and (4) the variance is a function of the expectation. The expectation (#3) and the variance (# 4) are conditional given group-level or individual-level covariates.&lt;br /&gt;
&lt;br /&gt;
GEE is applied to handle correlated discrete and continuous outcome variables. For the outcome variables, it only requires specification   of the first 2 moments and   correlation   among   them.    The   goal   is   to estimate fixed parameters    without    specifying    their    joint    distribution.  The correlation is specified by one of these 4 alternatives (which is specified in the R call: geeglm(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, &amp;lt;b&amp;gt;corstr = &amp;quot; exchangeable&amp;quot;&amp;lt;/b&amp;gt;, scale.fix = TRUE):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci8.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Respiratory Illness GEE R example===&lt;br /&gt;
&lt;br /&gt;
This example is based on a data set on respiratory illness &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; and the &amp;lt;b&amp;gt;geepack&amp;lt;/b&amp;gt; package. The data is from a clinical study of the treatment effects on patients with respiratory illness. N=111 patients from 2 clinical centers randomized to receive either placebo or active treatments. 4 temporal examinations assessed the &amp;lt;b&amp;gt;respiratory state&amp;lt;/b&amp;gt; of patients as good (=1) or poor (=0). Explanatory variables characterizing a patient were: &amp;lt;b&amp;gt;center&amp;lt;/b&amp;gt; (1,2), treatment (A=active, P=placebo), &amp;lt;b&amp;gt;sex&amp;lt;/b&amp;gt; (M=male, F=female), &amp;lt;b&amp;gt;age&amp;lt;/b&amp;gt; (in years) at baseline. The values of the covariates were constant for the repeated elementary observations on each patient.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt; shows the number of patients for the response patterns across the 4 visits split by baseline-status and treatment. Baseline respiratory status = 0 appear to have either low or high number of positive responses. Baseline respiratory status = 1 tend to respond positively. &amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt; describes the distribution of the number of positive responses per patient for sex and center.&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt;: Distribution of patients for &amp;lt;b&amp;gt;different response patterns&amp;lt;/b&amp;gt; classified by &amp;lt;b&amp;gt;baseline-respiratory&amp;lt;/b&amp;gt; response and &amp;lt;b&amp;gt;treatment&amp;lt;/b&amp;gt;. The patterns are ordered according to increasing numbers of positive responses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ||Visit|| colspan=&amp;quot;15&amp;quot;| All Possible Response Patterns (2*2*2*2=16 permutation patterns)||&lt;br /&gt;
|-&lt;br /&gt;
|||1||0||1||0||0||0||1||1||1||0||0||1||1||1||0||1||&lt;br /&gt;
|-&lt;br /&gt;
|||2||0||0||1||0||0||1||0||0||1||0||1||1||0||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||3||0||0||0||1||0||0||1||0||1||1||1||0||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||4||0||0||0||0||1||0||0||1||0||1||0||1||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
!Baseline||Treatment||||||||||||||||||||||||||||||||Sum&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;|0||A||7||2||2||2||1||0||1||0||1||0||1||2||0||4||7||30&lt;br /&gt;
|-&lt;br /&gt;
|P||18||1||0||2||1||2||0||0||1||0||0||1||2||0||3||31&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|1||A||0||0||0||0||0||0||1||1||0||0||4||0||1||0||17||24&lt;br /&gt;
|-&lt;br /&gt;
|P||1||4||1||0||0||0||0||1||1||3||1||1||2||1||10||26&lt;br /&gt;
|-&lt;br /&gt;
|Sum||||26||7||3||4||2||2||2||2||3||3||6||4||5||5||37||111&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt;: Distribution of patients for the number of positive responses across the 4 visits for &amp;lt;b&amp;gt;Sex&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;Center&amp;lt;/b&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; rowspan=&amp;quot;2&amp;quot;| ||colspan=&amp;quot;5&amp;quot;|Number of positive responses&lt;br /&gt;
|-&lt;br /&gt;
| 0||1||2||3||4&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Sex || F||7||3||3||3||7&lt;br /&gt;
|-&lt;br /&gt;
|M||19||13||9||17||30&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Center|| 1||18||9||6||11||12&lt;br /&gt;
|-&lt;br /&gt;
|2||8||7||6||9||25&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Figure 1&amp;lt;/b&amp;gt; shows a plot of age against the proportion of positive responses for each patient. It indicates a quadratic relationship between the proportions and the age. Fitting a logistic model to the data (which would be appropriate if there were &amp;lt;i&amp;gt;no time effects&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;no spread in the response probabilities&amp;lt;/i&amp;gt; for patients with the same covariate values).&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
 library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # data include a clinical trial of 111 patients with respiratory illness from two different clinics were randomized to receive either &lt;br /&gt;
 # placebo (P) or an active (A) treatment. Patients were examined at baseline and at four visits during treatment. &lt;br /&gt;
 # At each examination, respiratory status (categorized as 1 = good, 0 = poor)&lt;br /&gt;
 data(&amp;quot;respiratory&amp;quot;)&lt;br /&gt;
 head(respiratory)&lt;br /&gt;
 myData &amp;lt;- respiratory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(myData)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Center||ID||Treat||Sex||Age||Baseline||Visit||Outcome&lt;br /&gt;
|-&lt;br /&gt;
|1 ||1||1||P||M||46||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|2 ||1||1||P||M||46||0||2||0&lt;br /&gt;
|-&lt;br /&gt;
|3 ||1||1||P||M||46||0||3||0&lt;br /&gt;
|-&lt;br /&gt;
|4 ||1||1||P||M||46||0||4||0&lt;br /&gt;
|-&lt;br /&gt;
|5||1||2||P||M||28||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|6||1||2||P||M||28||0||2||0&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Get proportions of positive responses&lt;br /&gt;
 responses &amp;lt;- factor(myData$\$$outcome, labels = c(&amp;quot;OutcomePositive&amp;quot;, &amp;quot;OutcomeNegative&amp;quot;))&lt;br /&gt;
 data.frame &amp;lt;- data.frame(responses, myData$\$$age)&lt;br /&gt;
 head(data.frame)&lt;br /&gt;
 tab &amp;lt;- prop.table(table(data.frame), 1); tab	# compute proportions&lt;br /&gt;
 sum(tab[1,])				# check proportions (sums to 1.0)?&lt;br /&gt;
 prop &amp;lt;- tab[1,]				# save the proportions of positive responses for each patient&lt;br /&gt;
 plot(as.numeric(dimnames(tab)$\$$myData.age), tab[1,], xlab = &amp;quot;Age&amp;quot;, ylab = &amp;quot;Proportion of Positive Outcomes&amp;quot;)&lt;br /&gt;
 # dimnames(tab)				# to see/inspect positive/negative outcomes&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci9.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- as.numeric(dimnames(tab)$\$$myData.age)&lt;br /&gt;
 poly &amp;lt;- loess( prop ~ x)	# fit a Local Polynomial Regression Fitting&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(predict(poly), col='red', lwd=2)&lt;br /&gt;
&lt;br /&gt;
 smoothingSpline &amp;lt;- smooth.spline(x, prop, spar=0.6)&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(smoothingSpline, col='red', lwd=1.5)&lt;br /&gt;
 smoothPolySpline &amp;lt;- smooth.spline(x, predict(poly), spar=0.6)&lt;br /&gt;
 lines(smoothPolySpline, col='blue', lwd=2)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, inset=.05, title=&amp;quot;Polynomial regression models&amp;quot;,  c(&amp;quot;Raw Poly&amp;quot;,&amp;quot;Smooth Poly&amp;quot;), fill=c('red', 'blue'), horiz=TRUE)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci10.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 model.glm &amp;lt;- &amp;lt;b&amp;gt;glm&amp;lt;/b&amp;gt;(outcome ~ baseline + center + sex + treat + age + I(age^2), data = respiratory, family = binomial)&lt;br /&gt;
&lt;br /&gt;
 summary(model.glm)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Deviance Residuals: &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
| -2.5951||-0.9108||0.4034||0.8336||2.0951&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Estimate||Std. Error||z value||$Pr( \gt |z|)$  &lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||3.3579727||1.0285292||3.265||0.0011 **&lt;br /&gt;
|-&lt;br /&gt;
|baseline||1.8850421||0.2482959||7.592||3.15e-14 ***&lt;br /&gt;
|-&lt;br /&gt;
|center||0.5099244||0.2453982||2.078||0.0377 *&lt;br /&gt;
|-&lt;br /&gt;
|sexM||-0.4510595||0.3166570||-1.424||0.1543&lt;br /&gt;
|-&lt;br /&gt;
|Treatp||-1.3231587||0.2431603||-5.442||5.28e-08 ***&lt;br /&gt;
|-&lt;br /&gt;
|age||-0.2072815||0.0472538||-4.387||1.15e-05 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||0.0025650||0.0006324||4.056||4.99e-05 ***&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
(Dispersion parameter for binomial family taken to be 1)&lt;br /&gt;
&lt;br /&gt;
Null deviance: 609.41  on 443  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
Residual deviance: 468.62  on 437  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
AIC: 482.62&lt;br /&gt;
&lt;br /&gt;
The correlation matrix of the of the outcome measures across visits is shown in &amp;lt;b&amp;gt;Table 3.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 attach(myData)&lt;br /&gt;
 mat1 &amp;lt;- matrix(c(outcome[visit==1], outcome [visit==2], outcome [visit==3], &lt;br /&gt;
	outcome[visit==4]), ncol = 4)&lt;br /&gt;
 cor(mat1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 3&amp;lt;/b&amp;gt;: Correlation matrix for the outcome measurements at different visits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||[,1]||[,2]||[,3]||[,4]&lt;br /&gt;
|-&lt;br /&gt;
|[,1]||1.0000000||0.5087944||0.4431438||0.5139016&lt;br /&gt;
|-&lt;br /&gt;
|[,2]||0.5087944||1.0000000||0.5821877||0.5301611&lt;br /&gt;
|-&lt;br /&gt;
|[,3]||0.4431438||0.5821877||1.0000000||0.5871276&lt;br /&gt;
|-&lt;br /&gt;
|[,4]||0.5139016||0.5301611||0.5871276||1.0000000&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # We can also examine for multicollinearity problem, using the correlation matrix for X&lt;br /&gt;
 cor(model.matrix(model.glm)[,-1])&lt;br /&gt;
&lt;br /&gt;
 # GEE modeling: R function arguments/options&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;corstr&amp;lt;/b&amp;gt;= for defining the correlation structure within groups in a GEE model&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;= is used to identify the grouping variable in a GEE model&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;scale.fix&amp;lt;/b&amp;gt;= when TRUE causes the scale parameter to be fixed (by default at 1) rather than estimated&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;waves&amp;lt;/b&amp;gt;= names a positive integer-valued variable that is used to identify the order and spacing of observations within groups in a GEE model. This argument is crucial when there are missing values and gaps in the data&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, corstr = &amp;quot;exchangeable&amp;quot;, scale.fix = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # The column labeled &amp;lt;b&amp;gt;Wald&amp;lt;/b&amp;gt; in the summary table is the square of the z-statistic. The reported p-values are the &lt;br /&gt;
 # upper tailed probabilities from a chisq1 distribution and test whether the true parameter value ≠0.&lt;br /&gt;
 summary(gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # To test the effect of ''treatment'' using anova()&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;treat&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id = id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 gee.model2 &amp;lt;- geeglm(outcome ~ center + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id=id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 anova(gee.model1, gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # To test whether a categorical predictor with more than two levels should be retained in a GEE model we need &lt;br /&gt;
 # to test the entire set of dummy variables simultaneously as a single construct. &lt;br /&gt;
 # The geepack package provides a method for the anova function for a multivariate Wald test&lt;br /&gt;
 # When the anova function is applied to a single geeglm object it returns sequential Wald tests for &lt;br /&gt;
 # individual predictors with the tests carried out in the order the predictors are listed in the model formula.&lt;br /&gt;
 anova(gee.model1)&lt;br /&gt;
&lt;br /&gt;
===PD GEE example===&lt;br /&gt;
&lt;br /&gt;
This example used the PPMI/PD data to show GEE analysis.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;# 05_PPMI_top_UPDRS_Integrated_LongFormat1.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 longData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330397/download?download_frd=1&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Data Elements: FID_IID	L_insular_cortex_ComputeArea	L_insular_cortex_Volume	R_insular_cortex_ComputeArea	R_insular_cortex_Volume	L_cingulate_gyrus_ComputeArea	L_cingulate_gyrus_Volume	 R_cingulate_gyrus_ComputeArea	R_cingulate_gyrus_Volume	L_caudate_ComputeArea	L_caudate_Volume	R_caudate_ComputeArea	R_caudate_Volume	L_putamen_ComputeArea	L_putamen_Volume	R_putamen_ComputeArea	 R_putamen_Volume	Sex	Weight	ResearchGroup	Age	chr12_rs34637584_GT	chr17_rs11868035_GT	chr17_rs11012_GT	chr17_rs393152_GT	chr17_rs12185268_GT	chr17_rs199533_GT	UPDRS_part_I	 UPDRS_part_II	UPDRS_part_III	time_visit&lt;br /&gt;
&lt;br /&gt;
 dim(longData) &lt;br /&gt;
&lt;br /&gt;
 data1 = na.omit(longData)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 ControlGroup &amp;lt;- ifelse(ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # these calculations take a long time!!!&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca,  : &lt;br /&gt;
 # nrow(zsca) and length(y)&amp;lt;/i&amp;gt; not match” – this indicates some of the variables are of different lengths&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“glm.fit: algorithm did not converge”&amp;lt;/i&amp;gt; – see this discussion: http://goo.gl/lrjBjB &lt;br /&gt;
&lt;br /&gt;
 gee.model0 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1,  family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II +   time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # compare 2 gee models&lt;br /&gt;
 # anova(gee.model0,gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # you can try the “family = poisson(link = &amp;quot;log&amp;quot;)” model for the ResearchGroup response, as well&lt;br /&gt;
&lt;br /&gt;
 gee.model2 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(ControlGroup &lt;br /&gt;
 ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+R_insular_cortex_ComputeArea+ R_insular_cortex_Volume +L_cingulate_gyrus_ComputeArea + L_cingulate_gyrus_Volume + R_cingulate_gyrus_ComputeArea  + R_cingulate_gyrus_Volume +  L_caudate_ComputeArea + L_caudate_Volume + R_caudate_ComputeArea + R_caudate_Volume + L_putamen_ComputeArea + L_putamen_Volume + R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age +  chr12_rs34637584_GT +   chr17_rs11868035_GT + chr17_rs11012_GT + chr17_rs393152_GT + chr17_rs12185268_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr  = &amp;quot;unstructured&amp;quot;,  std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Remember that we do not interpret GEE coefficients as relating to individuals – GEE models are marginal models and the conclusions drawn are interpreted as population-based. Also, the time element in the model (time_visit) is just another controlling factor. &amp;lt;b&amp;gt;The effect-sizes (betas) associated with each variable/predictor represent the slopes associated with the corresponding covariate, while holding time constant&amp;lt;/b&amp;gt;. If we need to examine interactions (e.g., Weight change over Time), we need to include an interaction term in model: (i.e. + Weight*time_visit).&lt;br /&gt;
&lt;br /&gt;
 summary (gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # Individual Wald test and &amp;lt;b&amp;gt;confidence intervals&amp;lt;/b&amp;gt; for each covariate&lt;br /&gt;
 predictors2 &amp;lt;- coef(summary(gee.model2))&lt;br /&gt;
 CI2 &amp;lt;- with(as.data.frame(predictors2), cbind(lwr=Estimate-1.96*Std.err, est=Estimate, upr=Estimate+1.96*Std.err))&lt;br /&gt;
 rownames(CI2) &amp;lt;- rownames(predictors2)&lt;br /&gt;
 CI2&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
SEM References&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://socserv.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GEE References&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;https://cran.r-project.org/web/packages/geepack/geepack.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.jstatsoft.org/v15/i02/paper&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; http://www.jstatsoft.org/v15/i02/ &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; https://books.google.com/books?id=mdEqBgAAQBAJ&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci| Back to Model-based Analytics]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_GEE| Next Section: Generalized Estimating Equation (GEE) Modeling]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16172</id>
		<title>SMHS BigDataBigSci GCM</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16172"/>
		<updated>2016-05-23T13:42:45Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Root Mean Square Error of Approximation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci| Model-based Analytics]] - Growth Curve Models==&lt;br /&gt;
&lt;br /&gt;
Latent growth curve models may be used to analyze longitudinal or temporal data where the outcome measure is assessed on multiple occasions, and we examine its change over time, e.g., the trajectory over time can be&lt;br /&gt;
modeled as a linear or quadratic function.  Random effects are used to capture individual differences by conveniently representing (continuous) latent variables, aka growth factors.  To fit a linear growth model we may specify a model with two latent variables:  a random intercept, and a random slope:&lt;br /&gt;
&lt;br /&gt;
 #load data   &amp;lt;b&amp;gt;05_PPMI_top_UPDRS_Integrated_LongFormat.csv ( dim(myData) 661  71), wide&amp;lt;/b&amp;gt; &lt;br /&gt;
 # setwd(&amp;quot;/dir/&amp;quot;)&lt;br /&gt;
 myData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330395/download?download_frd=1&amp;amp;verifier=v6jBvV4x94ka3EYcGKuXXg5BZNaOLBVp0xkJih0H&amp;quot;,header=TRUE)&lt;br /&gt;
 attach(myData)&lt;br /&gt;
&lt;br /&gt;
 # dichotomize the &amp;quot;ResearchGroup&amp;quot; variable&lt;br /&gt;
 table(myData$\$$ResearchGroup)&lt;br /&gt;
 myData$\$$ResearchGroup &amp;lt;- ifelse(myData$\$$ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # linear growth model with 4 timepoints&lt;br /&gt;
 # intercept (i) and slope (s) with fixed coefficients&lt;br /&gt;
 # i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4 (intercept/constant)&lt;br /&gt;
 # s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (slope/linear term)&lt;br /&gt;
 # ??? =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (quadratic term)&lt;br /&gt;
&lt;br /&gt;
In this model, we have fixed all the coefficients of the linear growth functions:&lt;br /&gt;
&lt;br /&gt;
 model4 &amp;lt;-&lt;br /&gt;
 ' &lt;br /&gt;
 i =~ 1*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_06 + 1*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_12 + 1*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +&lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_06 + 1*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_12 + 1*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 +&lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24 &lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_I_Summary_Score_Month_06 + 3*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_I_Summary_Score_Month_12 + 5*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_I_Summary_Score_Month_24 +&lt;br /&gt;
 0*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 3*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 5*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +         &lt;br /&gt;
 6*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 0*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_III_Summary_Score_Month_06 + 3*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_III_Summary_Score_Month_12 + 5*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 0*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 +&lt;br /&gt;
 6*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 +&lt;br /&gt;
 0*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 6*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit4 &amp;lt;- growth(model4, data=myData)&lt;br /&gt;
 summary(fit4)&lt;br /&gt;
 parameterEstimates(fit4)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame	&lt;br /&gt;
 fitted(fit4)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit4)&lt;br /&gt;
&lt;br /&gt;
==Measures of model quality (Comparative Fit Index (CFI), Root Mean Square Error of Approximation (RMSEA))==&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector: Comparative Fit Index (CFI), Root Mean Square Error of &lt;br /&gt;
 # Approximation (RMSEA)&lt;br /&gt;
 fitMeasures(fit4, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
====Comparative Fit Index====&lt;br /&gt;
&lt;br /&gt;
(CFI) is an incremental measure directly based on the non-centrality measure.  If d = χ2(df) where df are the degrees of freedom of the model, the Comparative Fit Index is:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{(Null Model)-d(Proposed Model)}{d(Null Model)}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
$0≤CFI≤1$ (by definition). It is interpreted as:&lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;lt;0.9$  - model fitting is poor.&lt;br /&gt;
&lt;br /&gt;
*$0.9≤CFI≤0.95$  is considered marginal, &lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;gt;0.95$   is good. &lt;br /&gt;
&lt;br /&gt;
CFI is a relative index of model fit – it compare the fit of your model to the fit of (the worst) fitting null model.&lt;br /&gt;
&lt;br /&gt;
====Root Mean Square Error of Approximation====&lt;br /&gt;
(RMSEA) - “Ramsey”&lt;br /&gt;
&lt;br /&gt;
An absolute measure of fit based on the non-centrality parameter: &lt;br /&gt;
&lt;br /&gt;
$\sqrt{\frac{X^2-df}{df×(N - 1)}}$,&lt;br /&gt;
&lt;br /&gt;
where N the sample size and df the degrees of freedom of the model.  If χ&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  &amp;lt; df, then the RMSEA∶=0.  It has a penalty for complexity via the chi square to df ratio.  The RMSEA is a popular measure of model fit. &lt;br /&gt;
&lt;br /&gt;
*RMSEA &amp;lt; 0.01, excellent, &lt;br /&gt;
&lt;br /&gt;
*RMSEA  &amp;lt; 0.05, good &lt;br /&gt;
&lt;br /&gt;
*RMSEA &amp;gt; 0.10 cutoff for poor fitting models&lt;br /&gt;
&lt;br /&gt;
====Standardized Root Mean Square Residual==== &lt;br /&gt;
(SRMR) is an absolute measure of fit defined as the standardized difference between the observed correlation and the predicted correlation.  A value of zero indicates perfect fit.  The SRMR has no penalty for model complexity.  SRMR &amp;lt;0.08 is considered a good fit.&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit4)&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
 # library(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;A Simpler Model (fit5)&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 model5 &amp;lt;- '&lt;br /&gt;
  # intercept and slope with fixed coefficients&lt;br /&gt;
 i =~ UPDRS_Part_I_Summary_Score_Baseline + UPDRS_Part_I_Summary_Score_Month_03 + UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + 6*UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
  # regressions&lt;br /&gt;
 i ~  R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT                                                              &lt;br /&gt;
 s ~ R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT&lt;br /&gt;
  # time-varying covariates&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Baseline ~ Weight&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Month_03  ~ ResearchGroup &lt;br /&gt;
     UPDRS_Part_I_Summary_Score_Month_24 ~ Age&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit5 &amp;lt;- growth(model5, data=myData)&lt;br /&gt;
 summary(fit5); fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
 parameterEstimates(fit5)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame&lt;br /&gt;
&lt;br /&gt;
 lavaan (0.5-18) converged normally after  99 iterations&lt;br /&gt;
  Number of observations                           661&lt;br /&gt;
  Estimator                                         ML&lt;br /&gt;
  Minimum Function Test Statistic                3.703&lt;br /&gt;
  Degrees of freedom                                 1&lt;br /&gt;
  P-value (Chi-square)                           0.054&lt;br /&gt;
 Parameter estimates:&lt;br /&gt;
  Information                                 Expected&lt;br /&gt;
  Standard Errors                             Standard&lt;br /&gt;
                    Estimate  Std.err  Z-value  P(&amp;gt;|z|)&lt;br /&gt;
 Latent variables:&lt;br /&gt;
  i =~&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.074&lt;br /&gt;
    UPDRS_P_I_S_S     1.172&lt;br /&gt;
  s =~&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     6.000&lt;br /&gt;
 &lt;br /&gt;
 Regressions:&lt;br /&gt;
  i ~&lt;br /&gt;
    R_fsfrm_gyr_V     0.000&lt;br /&gt;
    Weight            0.003&lt;br /&gt;
    ResearchGroup    -0.880&lt;br /&gt;
    Age              -0.009&lt;br /&gt;
    c12_34637584_    -0.907&lt;br /&gt;
  s ~&lt;br /&gt;
    R_fsfrm_gyr_V    -0.000&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
    ResearchGroup    -0.084&lt;br /&gt;
    Age               0.002&lt;br /&gt;
    c12_34637584_    -0.047&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Baseline ~&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_03 ~&lt;br /&gt;
    ResearchGroup     0.693&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_24 ~&lt;br /&gt;
    Age              -0.002&lt;br /&gt;
 &lt;br /&gt;
 Covariances:&lt;br /&gt;
  i ~~&lt;br /&gt;
    s                 0.074&lt;br /&gt;
 &lt;br /&gt;
 Intercepts:&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    i                 1.633&lt;br /&gt;
    s                -0.023&lt;br /&gt;
 &lt;br /&gt;
 Variances:&lt;br /&gt;
    UPDRS_P_I_S_S     1.017&lt;br /&gt;
    UPDRS_P_I_S_S     1.093&lt;br /&gt;
    UPDRS_P_I_S_S     2.993&lt;br /&gt;
    i                 1.019&lt;br /&gt;
    s                -0.025&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;b&amp;gt;cfi rmsea  srmr&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;0.996 0.064 0.008&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 fitted(fit5)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
 # write.table(fitted(fit5), file=&amp;quot;C:\\Users\\Dinov\\Desktop\\test1.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit5)&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector&lt;br /&gt;
 fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))   # comparative fit index (CFI)&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; See discussion of SEM modeling pros/cons &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Generalized Estimating Equation (GEE) Modeling==&lt;br /&gt;
&lt;br /&gt;
Generalized Estimating Equations (GEE) modeling&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; is used for analyzing data with the following characteristics:&lt;br /&gt;
(1) the observations within a group may be correlated, (2) observations in separate clusters are independent, (3) a monotone transformation of the expectation is linearly related to the explanatory variables, and (4) the variance is a function of the expectation. The expectation (#3) and the variance (# 4) are conditional given group-level or individual-level covariates.&lt;br /&gt;
&lt;br /&gt;
GEE is applied to handle correlated discrete and continuous outcome variables. For the outcome variables, it only requires specification   of the first 2 moments and   correlation   among   them.    The   goal   is   to estimate fixed parameters    without    specifying    their    joint    distribution.  The correlation is specified by one of these 4 alternatives (which is specified in the R call: geeglm(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, &amp;lt;b&amp;gt;corstr = &amp;quot; exchangeable&amp;quot;&amp;lt;/b&amp;gt;, scale.fix = TRUE):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci8.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Respiratory Illness GEE R example===&lt;br /&gt;
&lt;br /&gt;
This example is based on a data set on respiratory illness &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; and the &amp;lt;b&amp;gt;geepack&amp;lt;/b&amp;gt; package. The data is from a clinical study of the treatment effects on patients with respiratory illness. N=111 patients from 2 clinical centers randomized to receive either placebo or active treatments. 4 temporal examinations assessed the &amp;lt;b&amp;gt;respiratory state&amp;lt;/b&amp;gt; of patients as good (=1) or poor (=0). Explanatory variables characterizing a patient were: &amp;lt;b&amp;gt;center&amp;lt;/b&amp;gt; (1,2), treatment (A=active, P=placebo), &amp;lt;b&amp;gt;sex&amp;lt;/b&amp;gt; (M=male, F=female), &amp;lt;b&amp;gt;age&amp;lt;/b&amp;gt; (in years) at baseline. The values of the covariates were constant for the repeated elementary observations on each patient.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt; shows the number of patients for the response patterns across the 4 visits split by baseline-status and treatment. Baseline respiratory status = 0 appear to have either low or high number of positive responses. Baseline respiratory status = 1 tend to respond positively. &amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt; describes the distribution of the number of positive responses per patient for sex and center.&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt;: Distribution of patients for &amp;lt;b&amp;gt;different response patterns&amp;lt;/b&amp;gt; classified by &amp;lt;b&amp;gt;baseline-respiratory&amp;lt;/b&amp;gt; response and &amp;lt;b&amp;gt;treatment&amp;lt;/b&amp;gt;. The patterns are ordered according to increasing numbers of positive responses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ||Visit|| colspan=&amp;quot;15&amp;quot;| All Possible Response Patterns (2*2*2*2=16 permutation patterns)||&lt;br /&gt;
|-&lt;br /&gt;
|||1||0||1||0||0||0||1||1||1||0||0||1||1||1||0||1||&lt;br /&gt;
|-&lt;br /&gt;
|||2||0||0||1||0||0||1||0||0||1||0||1||1||0||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||3||0||0||0||1||0||0||1||0||1||1||1||0||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||4||0||0||0||0||1||0||0||1||0||1||0||1||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
!Baseline||Treatment||||||||||||||||||||||||||||||||Sum&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;|0||A||7||2||2||2||1||0||1||0||1||0||1||2||0||4||7||30&lt;br /&gt;
|-&lt;br /&gt;
|P||18||1||0||2||1||2||0||0||1||0||0||1||2||0||3||31&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|1||A||0||0||0||0||0||0||1||1||0||0||4||0||1||0||17||24&lt;br /&gt;
|-&lt;br /&gt;
|P||1||4||1||0||0||0||0||1||1||3||1||1||2||1||10||26&lt;br /&gt;
|-&lt;br /&gt;
|Sum||||26||7||3||4||2||2||2||2||3||3||6||4||5||5||37||111&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt;: Distribution of patients for the number of positive responses across the 4 visits for &amp;lt;b&amp;gt;Sex&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;Center&amp;lt;/b&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; rowspan=&amp;quot;2&amp;quot;| ||colspan=&amp;quot;5&amp;quot;|Number of positive responses&lt;br /&gt;
|-&lt;br /&gt;
| 0||1||2||3||4&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Sex || F||7||3||3||3||7&lt;br /&gt;
|-&lt;br /&gt;
|M||19||13||9||17||30&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Center|| 1||18||9||6||11||12&lt;br /&gt;
|-&lt;br /&gt;
|2||8||7||6||9||25&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Figure 1&amp;lt;/b&amp;gt; shows a plot of age against the proportion of positive responses for each patient. It indicates a quadratic relationship between the proportions and the age. Fitting a logistic model to the data (which would be appropriate if there were &amp;lt;i&amp;gt;no time effects&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;no spread in the response probabilities&amp;lt;/i&amp;gt; for patients with the same covariate values).&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
 library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # data include a clinical trial of 111 patients with respiratory illness from two different clinics were randomized to receive either &lt;br /&gt;
 # placebo (P) or an active (A) treatment. Patients were examined at baseline and at four visits during treatment. &lt;br /&gt;
 # At each examination, respiratory status (categorized as 1 = good, 0 = poor)&lt;br /&gt;
 data(&amp;quot;respiratory&amp;quot;)&lt;br /&gt;
 head(respiratory)&lt;br /&gt;
 myData &amp;lt;- respiratory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(myData)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Center||ID||Treat||Sex||Age||Baseline||Visit||Outcome&lt;br /&gt;
|-&lt;br /&gt;
|1 ||1||1||P||M||46||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|2 ||1||1||P||M||46||0||2||0&lt;br /&gt;
|-&lt;br /&gt;
|3 ||1||1||P||M||46||0||3||0&lt;br /&gt;
|-&lt;br /&gt;
|4 ||1||1||P||M||46||0||4||0&lt;br /&gt;
|-&lt;br /&gt;
|5||1||2||P||M||28||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|6||1||2||P||M||28||0||2||0&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Get proportions of positive responses&lt;br /&gt;
 responses &amp;lt;- factor(myData$\$$outcome, labels = c(&amp;quot;OutcomePositive&amp;quot;, &amp;quot;OutcomeNegative&amp;quot;))&lt;br /&gt;
 data.frame &amp;lt;- data.frame(responses, myData$\$$age)&lt;br /&gt;
 head(data.frame)&lt;br /&gt;
 tab &amp;lt;- prop.table(table(data.frame), 1); tab	# compute proportions&lt;br /&gt;
 sum(tab[1,])				# check proportions (sums to 1.0)?&lt;br /&gt;
 prop &amp;lt;- tab[1,]				# save the proportions of positive responses for each patient&lt;br /&gt;
 plot(as.numeric(dimnames(tab)$\$$myData.age), tab[1,], xlab = &amp;quot;Age&amp;quot;, ylab = &amp;quot;Proportion of Positive Outcomes&amp;quot;)&lt;br /&gt;
 # dimnames(tab)				# to see/inspect positive/negative outcomes&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci9.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- as.numeric(dimnames(tab)$\$$myData.age)&lt;br /&gt;
 poly &amp;lt;- loess( prop ~ x)	# fit a Local Polynomial Regression Fitting&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(predict(poly), col='red', lwd=2)&lt;br /&gt;
&lt;br /&gt;
 smoothingSpline &amp;lt;- smooth.spline(x, prop, spar=0.6)&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(smoothingSpline, col='red', lwd=1.5)&lt;br /&gt;
 smoothPolySpline &amp;lt;- smooth.spline(x, predict(poly), spar=0.6)&lt;br /&gt;
 lines(smoothPolySpline, col='blue', lwd=2)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, inset=.05, title=&amp;quot;Polynomial regression models&amp;quot;,  c(&amp;quot;Raw Poly&amp;quot;,&amp;quot;Smooth Poly&amp;quot;), fill=c('red', 'blue'), horiz=TRUE)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci10.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 model.glm &amp;lt;- &amp;lt;b&amp;gt;glm&amp;lt;/b&amp;gt;(outcome ~ baseline + center + sex + treat + age + I(age^2), data = respiratory, family = binomial)&lt;br /&gt;
&lt;br /&gt;
 summary(model.glm)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Deviance Residuals: &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
| -2.5951||-0.9108||0.4034||0.8336||2.0951&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Estimate||Std. Error||z value||$Pr( \gt |z|)$  &lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||3.3579727||1.0285292||3.265||0.0011 **&lt;br /&gt;
|-&lt;br /&gt;
|baseline||1.8850421||0.2482959||7.592||3.15e-14 ***&lt;br /&gt;
|-&lt;br /&gt;
|center||0.5099244||0.2453982||2.078||0.0377 *&lt;br /&gt;
|-&lt;br /&gt;
|sexM||-0.4510595||0.3166570||-1.424||0.1543&lt;br /&gt;
|-&lt;br /&gt;
|Treatp||-1.3231587||0.2431603||-5.442||5.28e-08 ***&lt;br /&gt;
|-&lt;br /&gt;
|age||-0.2072815||0.0472538||-4.387||1.15e-05 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||0.0025650||0.0006324||4.056||4.99e-05 ***&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
(Dispersion parameter for binomial family taken to be 1)&lt;br /&gt;
&lt;br /&gt;
Null deviance: 609.41  on 443  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
Residual deviance: 468.62  on 437  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
AIC: 482.62&lt;br /&gt;
&lt;br /&gt;
The correlation matrix of the of the outcome measures across visits is shown in &amp;lt;b&amp;gt;Table 3.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 attach(myData)&lt;br /&gt;
 mat1 &amp;lt;- matrix(c(outcome[visit==1], outcome [visit==2], outcome [visit==3], &lt;br /&gt;
	outcome[visit==4]), ncol = 4)&lt;br /&gt;
 cor(mat1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 3&amp;lt;/b&amp;gt;: Correlation matrix for the outcome measurements at different visits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||[,1]||[,2]||[,3]||[,4]&lt;br /&gt;
|-&lt;br /&gt;
|[,1]||1.0000000||0.5087944||0.4431438||0.5139016&lt;br /&gt;
|-&lt;br /&gt;
|[,2]||0.5087944||1.0000000||0.5821877||0.5301611&lt;br /&gt;
|-&lt;br /&gt;
|[,3]||0.4431438||0.5821877||1.0000000||0.5871276&lt;br /&gt;
|-&lt;br /&gt;
|[,4]||0.5139016||0.5301611||0.5871276||1.0000000&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # We can also examine for multicollinearity problem, using the correlation matrix for X&lt;br /&gt;
 cor(model.matrix(model.glm)[,-1])&lt;br /&gt;
&lt;br /&gt;
 # GEE modeling: R function arguments/options&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;corstr&amp;lt;/b&amp;gt;= for defining the correlation structure within groups in a GEE model&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;= is used to identify the grouping variable in a GEE model&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;scale.fix&amp;lt;/b&amp;gt;= when TRUE causes the scale parameter to be fixed (by default at 1) rather than estimated&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;waves&amp;lt;/b&amp;gt;= names a positive integer-valued variable that is used to identify the order and spacing of observations within groups in a GEE model. This argument is crucial when there are missing values and gaps in the data&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, corstr = &amp;quot;exchangeable&amp;quot;, scale.fix = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # The column labeled &amp;lt;b&amp;gt;Wald&amp;lt;/b&amp;gt; in the summary table is the square of the z-statistic. The reported p-values are the &lt;br /&gt;
 # upper tailed probabilities from a chisq1 distribution and test whether the true parameter value ≠0.&lt;br /&gt;
 summary(gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # To test the effect of ''treatment'' using anova()&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;treat&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id = id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 gee.model2 &amp;lt;- geeglm(outcome ~ center + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id=id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 anova(gee.model1, gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # To test whether a categorical predictor with more than two levels should be retained in a GEE model we need &lt;br /&gt;
 # to test the entire set of dummy variables simultaneously as a single construct. &lt;br /&gt;
 # The geepack package provides a method for the anova function for a multivariate Wald test&lt;br /&gt;
 # When the anova function is applied to a single geeglm object it returns sequential Wald tests for &lt;br /&gt;
 # individual predictors with the tests carried out in the order the predictors are listed in the model formula.&lt;br /&gt;
 anova(gee.model1)&lt;br /&gt;
&lt;br /&gt;
===PD GEE example===&lt;br /&gt;
&lt;br /&gt;
This example used the PPMI/PD data to show GEE analysis.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;# 05_PPMI_top_UPDRS_Integrated_LongFormat1.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 longData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330397/download?download_frd=1&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Data Elements: FID_IID	L_insular_cortex_ComputeArea	L_insular_cortex_Volume	R_insular_cortex_ComputeArea	R_insular_cortex_Volume	L_cingulate_gyrus_ComputeArea	L_cingulate_gyrus_Volume	 R_cingulate_gyrus_ComputeArea	R_cingulate_gyrus_Volume	L_caudate_ComputeArea	L_caudate_Volume	R_caudate_ComputeArea	R_caudate_Volume	L_putamen_ComputeArea	L_putamen_Volume	R_putamen_ComputeArea	 R_putamen_Volume	Sex	Weight	ResearchGroup	Age	chr12_rs34637584_GT	chr17_rs11868035_GT	chr17_rs11012_GT	chr17_rs393152_GT	chr17_rs12185268_GT	chr17_rs199533_GT	UPDRS_part_I	 UPDRS_part_II	UPDRS_part_III	time_visit&lt;br /&gt;
&lt;br /&gt;
 dim(longData) &lt;br /&gt;
&lt;br /&gt;
 data1 = na.omit(longData)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 ControlGroup &amp;lt;- ifelse(ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # these calculations take a long time!!!&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca,  : &lt;br /&gt;
 # nrow(zsca) and length(y)&amp;lt;/i&amp;gt; not match” – this indicates some of the variables are of different lengths&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“glm.fit: algorithm did not converge”&amp;lt;/i&amp;gt; – see this discussion: http://goo.gl/lrjBjB &lt;br /&gt;
&lt;br /&gt;
 gee.model0 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1,  family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II +   time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # compare 2 gee models&lt;br /&gt;
 # anova(gee.model0,gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # you can try the “family = poisson(link = &amp;quot;log&amp;quot;)” model for the ResearchGroup response, as well&lt;br /&gt;
&lt;br /&gt;
 gee.model2 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(ControlGroup &lt;br /&gt;
 ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+R_insular_cortex_ComputeArea+ R_insular_cortex_Volume +L_cingulate_gyrus_ComputeArea + L_cingulate_gyrus_Volume + R_cingulate_gyrus_ComputeArea  + R_cingulate_gyrus_Volume +  L_caudate_ComputeArea + L_caudate_Volume + R_caudate_ComputeArea + R_caudate_Volume + L_putamen_ComputeArea + L_putamen_Volume + R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age +  chr12_rs34637584_GT +   chr17_rs11868035_GT + chr17_rs11012_GT + chr17_rs393152_GT + chr17_rs12185268_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr  = &amp;quot;unstructured&amp;quot;,  std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Remember that we do not interpret GEE coefficients as relating to individuals – GEE models are marginal models and the conclusions drawn are interpreted as population-based. Also, the time element in the model (time_visit) is just another controlling factor. &amp;lt;b&amp;gt;The effect-sizes (betas) associated with each variable/predictor represent the slopes associated with the corresponding covariate, while holding time constant&amp;lt;/b&amp;gt;. If we need to examine interactions (e.g., Weight change over Time), we need to include an interaction term in model: (i.e. + Weight*time_visit).&lt;br /&gt;
&lt;br /&gt;
 summary (gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # Individual Wald test and &amp;lt;b&amp;gt;confidence intervals&amp;lt;/b&amp;gt; for each covariate&lt;br /&gt;
 predictors2 &amp;lt;- coef(summary(gee.model2))&lt;br /&gt;
 CI2 &amp;lt;- with(as.data.frame(predictors2), cbind(lwr=Estimate-1.96*Std.err, est=Estimate, upr=Estimate+1.96*Std.err))&lt;br /&gt;
 rownames(CI2) &amp;lt;- rownames(predictors2)&lt;br /&gt;
 CI2&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
SEM References&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://socserv.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GEE References&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;https://cran.r-project.org/web/packages/geepack/geepack.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.jstatsoft.org/v15/i02/paper&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; http://www.jstatsoft.org/v15/i02/ &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; https://books.google.com/books?id=mdEqBgAAQBAJ&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci| Back to Model-based Analytics]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_GEE| Next Section: Generalized Estimating Equation (GEE) Modeling]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16171</id>
		<title>SMHS BigDataBigSci GCM</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM&amp;diff=16171"/>
		<updated>2016-05-23T13:42:13Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Comparative Fit Index */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci| Model-based Analytics]] - Growth Curve Models==&lt;br /&gt;
&lt;br /&gt;
Latent growth curve models may be used to analyze longitudinal or temporal data where the outcome measure is assessed on multiple occasions, and we examine its change over time, e.g., the trajectory over time can be&lt;br /&gt;
modeled as a linear or quadratic function.  Random effects are used to capture individual differences by conveniently representing (continuous) latent variables, aka growth factors.  To fit a linear growth model we may specify a model with two latent variables:  a random intercept, and a random slope:&lt;br /&gt;
&lt;br /&gt;
 #load data   &amp;lt;b&amp;gt;05_PPMI_top_UPDRS_Integrated_LongFormat.csv ( dim(myData) 661  71), wide&amp;lt;/b&amp;gt; &lt;br /&gt;
 # setwd(&amp;quot;/dir/&amp;quot;)&lt;br /&gt;
 myData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330395/download?download_frd=1&amp;amp;verifier=v6jBvV4x94ka3EYcGKuXXg5BZNaOLBVp0xkJih0H&amp;quot;,header=TRUE)&lt;br /&gt;
 attach(myData)&lt;br /&gt;
&lt;br /&gt;
 # dichotomize the &amp;quot;ResearchGroup&amp;quot; variable&lt;br /&gt;
 table(myData$\$$ResearchGroup)&lt;br /&gt;
 myData$\$$ResearchGroup &amp;lt;- ifelse(myData$\$$ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # linear growth model with 4 timepoints&lt;br /&gt;
 # intercept (i) and slope (s) with fixed coefficients&lt;br /&gt;
 # i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4 (intercept/constant)&lt;br /&gt;
 # s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (slope/linear term)&lt;br /&gt;
 # ??? =~ 0*t1 + 1*t2 + 2*t3 + 3*t4  (quadratic term)&lt;br /&gt;
&lt;br /&gt;
In this model, we have fixed all the coefficients of the linear growth functions:&lt;br /&gt;
&lt;br /&gt;
 model4 &amp;lt;-&lt;br /&gt;
 ' &lt;br /&gt;
 i =~ 1*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_06 + 1*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_12 + 1*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_I_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +&lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_06 + 1*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_12 + 1*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 1*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 +&lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 1*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24 &lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_I_Summary_Score_Month_06 + 3*UPDRS_Part_I_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_I_Summary_Score_Month_12 + 5*UPDRS_Part_I_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_I_Summary_Score_Month_24 +&lt;br /&gt;
 0*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + &lt;br /&gt;
 1*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06 + &lt;br /&gt;
 3*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12 + &lt;br /&gt;
 5*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18 +         &lt;br /&gt;
 6*UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24 + &lt;br /&gt;
 0*UPDRS_Part_III_Summary_Score_Baseline + 1*UPDRS_Part_III_Summary_Score_Month_03 + &lt;br /&gt;
 2*UPDRS_Part_III_Summary_Score_Month_06 + 3*UPDRS_Part_III_Summary_Score_Month_09 + &lt;br /&gt;
 4*UPDRS_Part_III_Summary_Score_Month_12 + 5*UPDRS_Part_III_Summary_Score_Month_18 + &lt;br /&gt;
 6*UPDRS_Part_III_Summary_Score_Month_24 + &lt;br /&gt;
 0*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12 +&lt;br /&gt;
 6*X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24 +&lt;br /&gt;
 0*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline + &lt;br /&gt;
 2*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06 + &lt;br /&gt;
 4*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12 + &lt;br /&gt;
 6*X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit4 &amp;lt;- growth(model4, data=myData)&lt;br /&gt;
 summary(fit4)&lt;br /&gt;
 parameterEstimates(fit4)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame	&lt;br /&gt;
 fitted(fit4)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit4)&lt;br /&gt;
&lt;br /&gt;
==Measures of model quality (Comparative Fit Index (CFI), Root Mean Square Error of Approximation (RMSEA))==&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector: Comparative Fit Index (CFI), Root Mean Square Error of &lt;br /&gt;
 # Approximation (RMSEA)&lt;br /&gt;
 fitMeasures(fit4, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
====Comparative Fit Index====&lt;br /&gt;
&lt;br /&gt;
(CFI) is an incremental measure directly based on the non-centrality measure.  If d = χ2(df) where df are the degrees of freedom of the model, the Comparative Fit Index is:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{(Null Model)-d(Proposed Model)}{d(Null Model)}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
$0≤CFI≤1$ (by definition). It is interpreted as:&lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;lt;0.9$  - model fitting is poor.&lt;br /&gt;
&lt;br /&gt;
*$0.9≤CFI≤0.95$  is considered marginal, &lt;br /&gt;
&lt;br /&gt;
*$CFI&amp;gt;0.95$   is good. &lt;br /&gt;
&lt;br /&gt;
CFI is a relative index of model fit – it compare the fit of your model to the fit of (the worst) fitting null model.&lt;br /&gt;
&lt;br /&gt;
====Root Mean Square Error of Approximation====&lt;br /&gt;
(RMSEA) - “Ramsey”&lt;br /&gt;
&lt;br /&gt;
An absolute measure of fit based on the non-centrality parameter: &lt;br /&gt;
&lt;br /&gt;
$\sqrt{\frac{X^2-df}{df×(N - 1)}}$,&lt;br /&gt;
&lt;br /&gt;
where N the sample size and df the degrees of freedom of the model.  If χ&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  &amp;lt; df, then the RMSEA∶=0.  It has a penalty for complexity via the chi square to df ratio.  The RMSEA is a popular measure of model fit. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;RMSEA &amp;lt; 0.01, excellent, &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;RMSEA  &amp;lt; 0.05, good &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;RMSEA &amp;gt; 0.10 cutoff for poor fitting models&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Standardized Root Mean Square Residual==== &lt;br /&gt;
(SRMR) is an absolute measure of fit defined as the standardized difference between the observed correlation and the predicted correlation.  A value of zero indicates perfect fit.  The SRMR has no penalty for model complexity.  SRMR &amp;lt;0.08 is considered a good fit.&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit4)&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
 # library(&amp;quot;semTools&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;A Simpler Model (fit5)&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 model5 &amp;lt;- '&lt;br /&gt;
  # intercept and slope with fixed coefficients&lt;br /&gt;
 i =~ UPDRS_Part_I_Summary_Score_Baseline + UPDRS_Part_I_Summary_Score_Month_03 + UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
 s =~ 0*UPDRS_Part_I_Summary_Score_Baseline + 1*UPDRS_Part_I_Summary_Score_Month_03 + 6*UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
  # regressions&lt;br /&gt;
 i ~  R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT                                                              &lt;br /&gt;
 s ~ R_fusiform_gyrus_Volume + Weight + ResearchGroup + Age + chr12_rs34637584_GT&lt;br /&gt;
  # time-varying covariates&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Baseline ~ Weight&lt;br /&gt;
    UPDRS_Part_I_Summary_Score_Month_03  ~ ResearchGroup &lt;br /&gt;
     UPDRS_Part_I_Summary_Score_Month_24 ~ Age&lt;br /&gt;
 '&lt;br /&gt;
&lt;br /&gt;
 fit5 &amp;lt;- growth(model5, data=myData)&lt;br /&gt;
 summary(fit5); fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))&lt;br /&gt;
 parameterEstimates(fit5)	# extracts the values of the estimated parameters, the standard errors, &lt;br /&gt;
 # the z-values, the standardized parameter values, and returns a data frame&lt;br /&gt;
&lt;br /&gt;
 lavaan (0.5-18) converged normally after  99 iterations&lt;br /&gt;
  Number of observations                           661&lt;br /&gt;
  Estimator                                         ML&lt;br /&gt;
  Minimum Function Test Statistic                3.703&lt;br /&gt;
  Degrees of freedom                                 1&lt;br /&gt;
  P-value (Chi-square)                           0.054&lt;br /&gt;
 Parameter estimates:&lt;br /&gt;
  Information                                 Expected&lt;br /&gt;
  Standard Errors                             Standard&lt;br /&gt;
                    Estimate  Std.err  Z-value  P(&amp;gt;|z|)&lt;br /&gt;
 Latent variables:&lt;br /&gt;
  i =~&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.074&lt;br /&gt;
    UPDRS_P_I_S_S     1.172&lt;br /&gt;
  s =~&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     1.000&lt;br /&gt;
    UPDRS_P_I_S_S     6.000&lt;br /&gt;
 &lt;br /&gt;
 Regressions:&lt;br /&gt;
  i ~&lt;br /&gt;
    R_fsfrm_gyr_V     0.000&lt;br /&gt;
    Weight            0.003&lt;br /&gt;
    ResearchGroup    -0.880&lt;br /&gt;
    Age              -0.009&lt;br /&gt;
    c12_34637584_    -0.907&lt;br /&gt;
  s ~&lt;br /&gt;
    R_fsfrm_gyr_V    -0.000&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
    ResearchGroup    -0.084&lt;br /&gt;
    Age               0.002&lt;br /&gt;
    c12_34637584_    -0.047&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Baseline ~&lt;br /&gt;
    Weight           -0.000&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_03 ~&lt;br /&gt;
    ResearchGroup     0.693&lt;br /&gt;
  UPDRS_Part_I_Summary_Score_Month_24 ~&lt;br /&gt;
    Age              -0.002&lt;br /&gt;
 &lt;br /&gt;
 Covariances:&lt;br /&gt;
  i ~~&lt;br /&gt;
    s                 0.074&lt;br /&gt;
 &lt;br /&gt;
 Intercepts:&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    UPDRS_P_I_S_S     0.000&lt;br /&gt;
    i                 1.633&lt;br /&gt;
    s                -0.023&lt;br /&gt;
 &lt;br /&gt;
 Variances:&lt;br /&gt;
    UPDRS_P_I_S_S     1.017&lt;br /&gt;
    UPDRS_P_I_S_S     1.093&lt;br /&gt;
    UPDRS_P_I_S_S     2.993&lt;br /&gt;
    i                 1.019&lt;br /&gt;
    s                -0.025&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;b&amp;gt;cfi rmsea  srmr&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;0.996 0.064 0.008&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 fitted(fit5)	# return the model-implied (fitted) covariance matrix (and mean vector) of a fitted model&lt;br /&gt;
 # write.table(fitted(fit5), file=&amp;quot;C:\\Users\\Dinov\\Desktop\\test1.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # resid() function return (unstandardized) residuals of a fitted model including the difference between &lt;br /&gt;
 # the observed and implied covariance matrix and mean vector&lt;br /&gt;
 resid(fit5)&lt;br /&gt;
&lt;br /&gt;
 # report the fit measures as a signature vector&lt;br /&gt;
 fitMeasures(fit5, c(&amp;quot;cfi&amp;quot;, &amp;quot;rmsea&amp;quot;, &amp;quot;srmr&amp;quot;))   # comparative fit index (CFI)&lt;br /&gt;
&lt;br /&gt;
 # inspect the model results (report parameter table)&lt;br /&gt;
 inspect(fit5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; See discussion of SEM modeling pros/cons &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Generalized Estimating Equation (GEE) Modeling==&lt;br /&gt;
&lt;br /&gt;
Generalized Estimating Equations (GEE) modeling&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; is used for analyzing data with the following characteristics:&lt;br /&gt;
(1) the observations within a group may be correlated, (2) observations in separate clusters are independent, (3) a monotone transformation of the expectation is linearly related to the explanatory variables, and (4) the variance is a function of the expectation. The expectation (#3) and the variance (# 4) are conditional given group-level or individual-level covariates.&lt;br /&gt;
&lt;br /&gt;
GEE is applied to handle correlated discrete and continuous outcome variables. For the outcome variables, it only requires specification   of the first 2 moments and   correlation   among   them.    The   goal   is   to estimate fixed parameters    without    specifying    their    joint    distribution.  The correlation is specified by one of these 4 alternatives (which is specified in the R call: geeglm(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, &amp;lt;b&amp;gt;corstr = &amp;quot; exchangeable&amp;quot;&amp;lt;/b&amp;gt;, scale.fix = TRUE):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci8.png|300px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Respiratory Illness GEE R example===&lt;br /&gt;
&lt;br /&gt;
This example is based on a data set on respiratory illness &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; and the &amp;lt;b&amp;gt;geepack&amp;lt;/b&amp;gt; package. The data is from a clinical study of the treatment effects on patients with respiratory illness. N=111 patients from 2 clinical centers randomized to receive either placebo or active treatments. 4 temporal examinations assessed the &amp;lt;b&amp;gt;respiratory state&amp;lt;/b&amp;gt; of patients as good (=1) or poor (=0). Explanatory variables characterizing a patient were: &amp;lt;b&amp;gt;center&amp;lt;/b&amp;gt; (1,2), treatment (A=active, P=placebo), &amp;lt;b&amp;gt;sex&amp;lt;/b&amp;gt; (M=male, F=female), &amp;lt;b&amp;gt;age&amp;lt;/b&amp;gt; (in years) at baseline. The values of the covariates were constant for the repeated elementary observations on each patient.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt; shows the number of patients for the response patterns across the 4 visits split by baseline-status and treatment. Baseline respiratory status = 0 appear to have either low or high number of positive responses. Baseline respiratory status = 1 tend to respond positively. &amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt; describes the distribution of the number of positive responses per patient for sex and center.&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 1&amp;lt;/b&amp;gt;: Distribution of patients for &amp;lt;b&amp;gt;different response patterns&amp;lt;/b&amp;gt; classified by &amp;lt;b&amp;gt;baseline-respiratory&amp;lt;/b&amp;gt; response and &amp;lt;b&amp;gt;treatment&amp;lt;/b&amp;gt;. The patterns are ordered according to increasing numbers of positive responses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ||Visit|| colspan=&amp;quot;15&amp;quot;| All Possible Response Patterns (2*2*2*2=16 permutation patterns)||&lt;br /&gt;
|-&lt;br /&gt;
|||1||0||1||0||0||0||1||1||1||0||0||1||1||1||0||1||&lt;br /&gt;
|-&lt;br /&gt;
|||2||0||0||1||0||0||1||0||0||1||0||1||1||0||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||3||0||0||0||1||0||0||1||0||1||1||1||0||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
|||4||0||0||0||0||1||0||0||1||0||1||0||1||1||1||1||&lt;br /&gt;
|-&lt;br /&gt;
!Baseline||Treatment||||||||||||||||||||||||||||||||Sum&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;|0||A||7||2||2||2||1||0||1||0||1||0||1||2||0||4||7||30&lt;br /&gt;
|-&lt;br /&gt;
|P||18||1||0||2||1||2||0||0||1||0||0||1||2||0||3||31&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|1||A||0||0||0||0||0||0||1||1||0||0||4||0||1||0||17||24&lt;br /&gt;
|-&lt;br /&gt;
|P||1||4||1||0||0||0||0||1||1||3||1||1||2||1||10||26&lt;br /&gt;
|-&lt;br /&gt;
|Sum||||26||7||3||4||2||2||2||2||3||3||6||4||5||5||37||111&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 2&amp;lt;/b&amp;gt;: Distribution of patients for the number of positive responses across the 4 visits for &amp;lt;b&amp;gt;Sex&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;Center&amp;lt;/b&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; rowspan=&amp;quot;2&amp;quot;| ||colspan=&amp;quot;5&amp;quot;|Number of positive responses&lt;br /&gt;
|-&lt;br /&gt;
| 0||1||2||3||4&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Sex || F||7||3||3||3||7&lt;br /&gt;
|-&lt;br /&gt;
|M||19||13||9||17||30&lt;br /&gt;
|-&lt;br /&gt;
|rowspan=&amp;quot;2&amp;quot;|Center|| 1||18||9||6||11||12&lt;br /&gt;
|-&lt;br /&gt;
|2||8||7||6||9||25&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Figure 1&amp;lt;/b&amp;gt; shows a plot of age against the proportion of positive responses for each patient. It indicates a quadratic relationship between the proportions and the age. Fitting a logistic model to the data (which would be appropriate if there were &amp;lt;i&amp;gt;no time effects&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;no spread in the response probabilities&amp;lt;/i&amp;gt; for patients with the same covariate values).&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
 library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # data include a clinical trial of 111 patients with respiratory illness from two different clinics were randomized to receive either &lt;br /&gt;
 # placebo (P) or an active (A) treatment. Patients were examined at baseline and at four visits during treatment. &lt;br /&gt;
 # At each examination, respiratory status (categorized as 1 = good, 0 = poor)&lt;br /&gt;
 data(&amp;quot;respiratory&amp;quot;)&lt;br /&gt;
 head(respiratory)&lt;br /&gt;
 myData &amp;lt;- respiratory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(myData)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Center||ID||Treat||Sex||Age||Baseline||Visit||Outcome&lt;br /&gt;
|-&lt;br /&gt;
|1 ||1||1||P||M||46||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|2 ||1||1||P||M||46||0||2||0&lt;br /&gt;
|-&lt;br /&gt;
|3 ||1||1||P||M||46||0||3||0&lt;br /&gt;
|-&lt;br /&gt;
|4 ||1||1||P||M||46||0||4||0&lt;br /&gt;
|-&lt;br /&gt;
|5||1||2||P||M||28||0||1||0&lt;br /&gt;
|-&lt;br /&gt;
|6||1||2||P||M||28||0||2||0&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Get proportions of positive responses&lt;br /&gt;
 responses &amp;lt;- factor(myData$\$$outcome, labels = c(&amp;quot;OutcomePositive&amp;quot;, &amp;quot;OutcomeNegative&amp;quot;))&lt;br /&gt;
 data.frame &amp;lt;- data.frame(responses, myData$\$$age)&lt;br /&gt;
 head(data.frame)&lt;br /&gt;
 tab &amp;lt;- prop.table(table(data.frame), 1); tab	# compute proportions&lt;br /&gt;
 sum(tab[1,])				# check proportions (sums to 1.0)?&lt;br /&gt;
 prop &amp;lt;- tab[1,]				# save the proportions of positive responses for each patient&lt;br /&gt;
 plot(as.numeric(dimnames(tab)$\$$myData.age), tab[1,], xlab = &amp;quot;Age&amp;quot;, ylab = &amp;quot;Proportion of Positive Outcomes&amp;quot;)&lt;br /&gt;
 # dimnames(tab)				# to see/inspect positive/negative outcomes&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci9.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- as.numeric(dimnames(tab)$\$$myData.age)&lt;br /&gt;
 poly &amp;lt;- loess( prop ~ x)	# fit a Local Polynomial Regression Fitting&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(predict(poly), col='red', lwd=2)&lt;br /&gt;
&lt;br /&gt;
 smoothingSpline &amp;lt;- smooth.spline(x, prop, spar=0.6)&lt;br /&gt;
 plot(x, prop)&lt;br /&gt;
 lines(smoothingSpline, col='red', lwd=1.5)&lt;br /&gt;
 smoothPolySpline &amp;lt;- smooth.spline(x, predict(poly), spar=0.6)&lt;br /&gt;
 lines(smoothPolySpline, col='blue', lwd=2)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, inset=.05, title=&amp;quot;Polynomial regression models&amp;quot;,  c(&amp;quot;Raw Poly&amp;quot;,&amp;quot;Smooth Poly&amp;quot;), fill=c('red', 'blue'), horiz=TRUE)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci10.png|500px]]&lt;br /&gt;
&lt;br /&gt;
 model.glm &amp;lt;- &amp;lt;b&amp;gt;glm&amp;lt;/b&amp;gt;(outcome ~ baseline + center + sex + treat + age + I(age^2), data = respiratory, family = binomial)&lt;br /&gt;
&lt;br /&gt;
 summary(model.glm)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Deviance Residuals: &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
| -2.5951||-0.9108||0.4034||0.8336||2.0951&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Estimate||Std. Error||z value||$Pr( \gt |z|)$  &lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||3.3579727||1.0285292||3.265||0.0011 **&lt;br /&gt;
|-&lt;br /&gt;
|baseline||1.8850421||0.2482959||7.592||3.15e-14 ***&lt;br /&gt;
|-&lt;br /&gt;
|center||0.5099244||0.2453982||2.078||0.0377 *&lt;br /&gt;
|-&lt;br /&gt;
|sexM||-0.4510595||0.3166570||-1.424||0.1543&lt;br /&gt;
|-&lt;br /&gt;
|Treatp||-1.3231587||0.2431603||-5.442||5.28e-08 ***&lt;br /&gt;
|-&lt;br /&gt;
|age||-0.2072815||0.0472538||-4.387||1.15e-05 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||0.0025650||0.0006324||4.056||4.99e-05 ***&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
(Dispersion parameter for binomial family taken to be 1)&lt;br /&gt;
&lt;br /&gt;
Null deviance: 609.41  on 443  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
Residual deviance: 468.62  on 437  degrees of freedom&lt;br /&gt;
&lt;br /&gt;
AIC: 482.62&lt;br /&gt;
&lt;br /&gt;
The correlation matrix of the of the outcome measures across visits is shown in &amp;lt;b&amp;gt;Table 3.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 attach(myData)&lt;br /&gt;
 mat1 &amp;lt;- matrix(c(outcome[visit==1], outcome [visit==2], outcome [visit==3], &lt;br /&gt;
	outcome[visit==4]), ncol = 4)&lt;br /&gt;
 cor(mat1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Table 3&amp;lt;/b&amp;gt;: Correlation matrix for the outcome measurements at different visits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||[,1]||[,2]||[,3]||[,4]&lt;br /&gt;
|-&lt;br /&gt;
|[,1]||1.0000000||0.5087944||0.4431438||0.5139016&lt;br /&gt;
|-&lt;br /&gt;
|[,2]||0.5087944||1.0000000||0.5821877||0.5301611&lt;br /&gt;
|-&lt;br /&gt;
|[,3]||0.4431438||0.5821877||1.0000000||0.5871276&lt;br /&gt;
|-&lt;br /&gt;
|[,4]||0.5139016||0.5301611||0.5871276||1.0000000&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # We can also examine for multicollinearity problem, using the correlation matrix for X&lt;br /&gt;
 cor(model.matrix(model.glm)[,-1])&lt;br /&gt;
&lt;br /&gt;
 # GEE modeling: R function arguments/options&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;corstr&amp;lt;/b&amp;gt;= for defining the correlation structure within groups in a GEE model&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;= is used to identify the grouping variable in a GEE model&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;scale.fix&amp;lt;/b&amp;gt;= when TRUE causes the scale parameter to be fixed (by default at 1) rather than estimated&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;waves&amp;lt;/b&amp;gt;= names a positive integer-valued variable that is used to identify the order and spacing of observations within groups in a GEE model. This argument is crucial when there are missing values and gaps in the data&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + treat + sex + baseline + age, data = respiratory, family = &amp;quot;binomial&amp;quot;, id = id, corstr = &amp;quot;exchangeable&amp;quot;, scale.fix = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # The column labeled &amp;lt;b&amp;gt;Wald&amp;lt;/b&amp;gt; in the summary table is the square of the z-statistic. The reported p-values are the &lt;br /&gt;
 # upper tailed probabilities from a chisq1 distribution and test whether the true parameter value ≠0.&lt;br /&gt;
 summary(gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # To test the effect of ''treatment'' using anova()&lt;br /&gt;
 gee.model1 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(outcome ~ center + &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;treat&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id = id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 gee.model2 &amp;lt;- geeglm(outcome ~ center + sex + baseline + age, data = respiratory, family=binomial(link=&amp;quot;logit&amp;quot;), id=id, corstr = &amp;quot;exchangeable&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
 anova(gee.model1, gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # To test whether a categorical predictor with more than two levels should be retained in a GEE model we need &lt;br /&gt;
 # to test the entire set of dummy variables simultaneously as a single construct. &lt;br /&gt;
 # The geepack package provides a method for the anova function for a multivariate Wald test&lt;br /&gt;
 # When the anova function is applied to a single geeglm object it returns sequential Wald tests for &lt;br /&gt;
 # individual predictors with the tests carried out in the order the predictors are listed in the model formula.&lt;br /&gt;
 anova(gee.model1)&lt;br /&gt;
&lt;br /&gt;
===PD GEE example===&lt;br /&gt;
&lt;br /&gt;
This example used the PPMI/PD data to show GEE analysis.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;# 05_PPMI_top_UPDRS_Integrated_LongFormat1.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 longData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330397/download?download_frd=1&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;geepack&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Data Elements: FID_IID	L_insular_cortex_ComputeArea	L_insular_cortex_Volume	R_insular_cortex_ComputeArea	R_insular_cortex_Volume	L_cingulate_gyrus_ComputeArea	L_cingulate_gyrus_Volume	 R_cingulate_gyrus_ComputeArea	R_cingulate_gyrus_Volume	L_caudate_ComputeArea	L_caudate_Volume	R_caudate_ComputeArea	R_caudate_Volume	L_putamen_ComputeArea	L_putamen_Volume	R_putamen_ComputeArea	 R_putamen_Volume	Sex	Weight	ResearchGroup	Age	chr12_rs34637584_GT	chr17_rs11868035_GT	chr17_rs11012_GT	chr17_rs393152_GT	chr17_rs12185268_GT	chr17_rs199533_GT	UPDRS_part_I	 UPDRS_part_II	UPDRS_part_III	time_visit&lt;br /&gt;
&lt;br /&gt;
 dim(longData) &lt;br /&gt;
&lt;br /&gt;
 data1 = na.omit(longData)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 ControlGroup &amp;lt;- ifelse(ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # these calculations take a long time!!!&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca,  : &lt;br /&gt;
 # nrow(zsca) and length(y)&amp;lt;/i&amp;gt; not match” – this indicates some of the variables are of different lengths&lt;br /&gt;
 # if you get &amp;lt;i&amp;gt;“glm.fit: algorithm did not converge”&amp;lt;/i&amp;gt; – see this discussion: http://goo.gl/lrjBjB &lt;br /&gt;
&lt;br /&gt;
 gee.model0 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1,  family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 gee.model1 &amp;lt;- geeglm(ControlGroup ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+ R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age + chr17_rs11012_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II +   time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr = &amp;quot;unstructured&amp;quot;, std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # compare 2 gee models&lt;br /&gt;
 # anova(gee.model0,gee.model1)&lt;br /&gt;
&lt;br /&gt;
 # you can try the “family = poisson(link = &amp;quot;log&amp;quot;)” model for the ResearchGroup response, as well&lt;br /&gt;
&lt;br /&gt;
 gee.model2 &amp;lt;- &amp;lt;b&amp;gt;geeglm&amp;lt;/b&amp;gt;(ControlGroup &lt;br /&gt;
 ~ L_insular_cortex_ComputeArea+L_insular_cortex_Volume+R_insular_cortex_ComputeArea+ R_insular_cortex_Volume +L_cingulate_gyrus_ComputeArea + L_cingulate_gyrus_Volume + R_cingulate_gyrus_ComputeArea  + R_cingulate_gyrus_Volume +  L_caudate_ComputeArea + L_caudate_Volume + R_caudate_ComputeArea + R_caudate_Volume + L_putamen_ComputeArea + L_putamen_Volume + R_putamen_ComputeArea + R_putamen_Volume + Sex + Weight + Age +  chr12_rs34637584_GT +   chr17_rs11868035_GT + chr17_rs11012_GT + chr17_rs393152_GT + chr17_rs12185268_GT + chr17_rs199533_GT + UPDRS_part_I + UPDRS_part_II + time_visit, data = data1, family=binomial(link=&amp;quot;logit&amp;quot;), id = FID_IID, corstr  = &amp;quot;unstructured&amp;quot;,  std.err=&amp;quot;san.se&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Remember that we do not interpret GEE coefficients as relating to individuals – GEE models are marginal models and the conclusions drawn are interpreted as population-based. Also, the time element in the model (time_visit) is just another controlling factor. &amp;lt;b&amp;gt;The effect-sizes (betas) associated with each variable/predictor represent the slopes associated with the corresponding covariate, while holding time constant&amp;lt;/b&amp;gt;. If we need to examine interactions (e.g., Weight change over Time), we need to include an interaction term in model: (i.e. + Weight*time_visit).&lt;br /&gt;
&lt;br /&gt;
 summary (gee.model2)&lt;br /&gt;
&lt;br /&gt;
 # Individual Wald test and &amp;lt;b&amp;gt;confidence intervals&amp;lt;/b&amp;gt; for each covariate&lt;br /&gt;
 predictors2 &amp;lt;- coef(summary(gee.model2))&lt;br /&gt;
 CI2 &amp;lt;- with(as.data.frame(predictors2), cbind(lwr=Estimate-1.96*Std.err, est=Estimate, upr=Estimate+1.96*Std.err))&lt;br /&gt;
 rownames(CI2) &amp;lt;- rownames(predictors2)&lt;br /&gt;
 CI2&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
SEM References&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://socserv.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GEE References&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;https://cran.r-project.org/web/packages/geepack/geepack.pdf&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;http://www.jstatsoft.org/v15/i02/paper&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Footnotes===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; http://www.jstatsoft.org/v15/i02/ &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; https://books.google.com/books?id=mdEqBgAAQBAJ&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci| Back to Model-based Analytics]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] &lt;br /&gt;
* [[SMHS_BigDataBigSci_GEE| Next Section: Generalized Estimating Equation (GEE) Modeling]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_GCM}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex2&amp;diff=16170</id>
		<title>SMHS BigDataBigSci SEM Ex2</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex2&amp;diff=16170"/>
		<updated>2016-05-23T13:41:07Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] - Hands-on Example 2 (Parkinson’s Disease data) ==&lt;br /&gt;
&lt;br /&gt;
 # Data: PPMI Integrated imaging, demographics, genetics, clinical and cognitive (UPDRS) data. &lt;br /&gt;
 # Dinov et al., 2016&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:75%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Index||FID_IID||L_cingulate_gyrus_ComputeArea||L_cingulate_gyrus_Volume||R_cingulate_gyrus_ComputeArea||R_cingulate_gyrus_Volume||L_caudate_ComputeArea||L_caudate_Volume||R_caudate_ComputeArea||R_caudate_Volume||L_putamen_ComputeArea||L_putamen_Volume||R_putamen_ComputeArea||R_putamen_Volume||L_hippocampus_ComputeArea||L_hippocampus_Volume||R_hippocampus_ComputeArea||R_hippocampus_Volume||cerebellum_ComputeArea||cerebellum_Volume||L_fusiform_gyrus_ComputeArea||L_fusiform_gyrus_Volume||R_fusiform_gyrus_ComputeArea||R_fusiform_gyrus_Volume||Sex||Weight||ResearchGroup||Age||chr12_rs34637584_GT||chr17_rs11868035_GT||chr17_rs11012_GT||chr17_rs393152_GT||chr17_rs12185268_GT||UPDRS_part_I||UPDRS_part_II||UPDRS_part_III||UPDRS_part_IV||time_visit&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||0||2||12||NA||0&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||0||2||18||NA||42&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||0||3||23||NA||24&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||1||3||19||NA||9&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||4||3||20||NA||0&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||1||4||29||NA||42&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||0||2||39||NA||24&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||0||5||25||NA||9&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||1||6||34||NA||0&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||1||11||42||0||42&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||1||5||39||0||24&lt;br /&gt;
|-&lt;br /&gt;
|2||3001||4381.93||11205.13||4610.447||12246.55||621.5344||821.8991||1302.146||2526.248||1029.175||1543.017||1680.197||3792.201||1769.672||4737.038||1578.946||3817.621||20909.58||185742.6||4534.707||15830.32||3945.037||14471.84||1||74.2||PD||65.1808||0||1||1||1||1||NA||NA||NA||NA||9&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||3||15||17||NA||3&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||2||10||22||NA||48&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||NA||NA||NA||NA||30&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||1||16||20||NA||12&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||3||15||27||0||3&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||4||16||22||0||48&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||8||14||22||0||30&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||4||13||24||1||12&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||4||16||31||4||3&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||6||14||19||4||48&lt;br /&gt;
|-&lt;br /&gt;
|3||3002||3221.54||7439.645||3194.348||7264.683||876.9414||1364.86||1056.22||1965.206||1275.905||2696.695||1375.725||2966.682||1529.759||3736.04||1799.439||4665.168||17627.01||155632.3||4013.385||12677.99||3551.876||11263.23||2||70.6||PD||67.6247||0||1||0||0||0||5||18||29||3||30&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;lavaan&amp;quot;) &lt;br /&gt;
 library(lavaan)&lt;br /&gt;
 #load data   05_PPMI_top_UPDRS_Integrated_LongFormat1.csv ( dim(myData) 1764   31 )&lt;br /&gt;
 # setwd(&amp;quot;/dir/&amp;quot;)&lt;br /&gt;
 myData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330397/download?download_frd=1&amp;amp;verifier=3bYRT9FXgBGMCQv8MNxsclWnMgodiJRYo3ODFtDq&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 # dichotomize the &amp;quot;ResearchGroup&amp;quot; variable&lt;br /&gt;
 myData$\$$ResearchGroup &amp;lt;- ifelse(myData$\$$ResearchGroup == &amp;quot;Control&amp;quot;, 1, 0)&lt;br /&gt;
&lt;br /&gt;
 # Data elements: Index	FID_IID	L_cingulate_gyrus_ComputeArea	L_cingulate_gyrus_Volume	&lt;br /&gt;
 R_cingulate_gyrus_ComputeArea	R_cingulate_gyrus_Volume	L_caudate_ComputeArea	&lt;br /&gt;
 L_caudate_Volume	R_caudate_ComputeArea	R_caudate_Volume	&lt;br /&gt;
 L_putamen_ComputeArea	L_putamen_Volume	R_putamen_ComputeArea	&lt;br /&gt;
 R_putamen_Volume	L_hippocampus_ComputeArea	L_hippocampus_Volume	R_hippocampus_ComputeArea	&lt;br /&gt;
 R_hippocampus_Volume	cerebellum_ComputeArea	&lt;br /&gt;
 cerebellum_Volume	L_fusiform_gyrus_ComputeArea	L_fusiform_gyrus_Volume	R_fusiform_gyrus_ComputeArea	&lt;br /&gt;
 R_fusiform_gyrus_Volume	Sex	Weight	ResearchGroup	Age	chr12_rs34637584_GT	chr17_rs11868035_GT	chr17_rs11012_GT	chr17_rs393152_GT	&lt;br /&gt;
 chr17_rs12185268_GT	UPDRS_Part_I_Summary_Score_Baseline&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_03	UPDRS_Part_I_Summary_Score_Month_06	UPDRS_Part_I_Summary_Score_Month_09	UPDRS_Part_I_Summary_Score_Month_12	UPDRS_Part_I_Summary_Score_Month_18	 UPDRS_Part_I_Summary_Score_Month_24	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06	 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18	  UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24	UPDRS_Part_III_Summary_Score_Baseline	UPDRS_Part_III_Summary_Score_Month_03	UPDRS_Part_III_Summary_Score_Month_06	UPDRS_Part_III_Summary_Score_Month_09	 UPDRS_Part_III_Summary_Score_Month_12	UPDRS_Part_III_Summary_Score_Month_18	UPDRS_Part_III_Summary_Score_Month_24	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline	 X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24	 X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline	X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06	 X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12	X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
&lt;br /&gt;
====Validation of the measurement model====&lt;br /&gt;
&lt;br /&gt;
 myData&amp;lt;-within(myData, {&lt;br /&gt;
 L_cingulate_gyrus_ComputeArea &amp;lt;- lm(L_cingulate_gyrus_ComputeArea ~  L_cingulate_gyrus_Volume+R_cingulate_gyrus_ComputeArea+R_cingulate_gyrus_Volume+L_caudate_ComputeArea+L_caudate_Volume+R_caudate_ComputeArea+R_caudate_Volume+L_putamen_ComputeArea+L_putamen_Volume+R_putamen_ComputeArea+R_putamen_Volum e+L_hippocampus_ComputeArea+L_hippocampus_Volume+R_hippocampus_ComputeArea+R_hippocampus_Volume+cerebellum_ComputeArea+cerebellum_Volume+L_fusiform_gyrus_ComputeArea+L_fusiform_gyrus_Volume+R_fusiform_gyrus_ComputeArea+R_fusiform_gyru s_Volume, data=myData)$\$$residuals&lt;br /&gt;
 Weight &amp;lt;- lm(Weight ~ Sex+ResearchGroup+Age+chr12_rs34637584_GT+chr17_rs11868035_GT+chr17_rs11012_GT+chr17_rs393152_GT+chr17_rs12185268_GT, data=myData)$\$$residuals&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Baseline  &amp;lt;- lm(UPDRS_Part_I_Summary_Score_Baseline  ~  UPDRS_Part_I_Summary_Score_Month_03+UPDRS_Part_I_Summary_Score_Month_06+UPDRS_Part_I_Summary_Score_Month_09+UPDRS_Part_I_Summary_Score_Month_12+UPDRS_Part_I_Summary_Score_Month_18+UPDRS_Part_I_Summary_Score_Month_24+UPDRS_Part_II_Pati ent_Questionnaire_Summary_Score_Baseline+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09+UPDRS_Part_II_Pa tient_Questionnaire_Summary_Score_Month_12+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24+UPDRS_Part_III_Summary_Score_Baseline+UPDRS_Part_III_Summary_Score_Month_ 03+UPDRS_Part_III_Summary_Score_Month_06+UPDRS_Part_III_Summary_Score_Month_09+UPDRS_Part_III_Summary_Score_Month_12+UPDRS_Part_III_Summary_Score_Month_18+UPDRS_Part_III_Summary_Score_Month_24+X_Assessment_Non.Motor_Epworth_Sleepiness _Scale_Summary_Score_Baseline+X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06+X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12+X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_ Month_24+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short _Summary_Score_Month_12+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24, data=myData)$\$$residuals })&lt;br /&gt;
&lt;br /&gt;
====Structural Model====&lt;br /&gt;
&lt;br /&gt;
 # Next, proceed with the structural model including the residuals from data to account for effects of site.&lt;br /&gt;
&lt;br /&gt;
Lavaan model specification:&lt;br /&gt;
&lt;br /&gt;
formula type                       operator    	           mnemonic&lt;br /&gt;
latent variable definition	=~	                  is measured by&lt;br /&gt;
regression		        ~	                  is regressed on&lt;br /&gt;
(residual) (co)variance	        ~~	                  is correlated with&lt;br /&gt;
Intercept		        ~ 1	                  Intercept&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
 myModel &amp;lt;-&lt;br /&gt;
 &amp;lt;b&amp;gt;# regressions&amp;lt;/b&amp;gt;&lt;br /&gt;
 y1 + y2 &amp;lt;mark&amp;gt;~&amp;lt;/mark&amp;gt; f1 + f2 + x1 + x2&lt;br /&gt;
 f1 ~ f2 + f3&lt;br /&gt;
 f2 ~ f3 + x1 + x2&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;# latent variable definitions&amp;lt;/b&amp;gt;&lt;br /&gt;
 f1 &amp;lt;mark&amp;gt;=~&amp;lt;/mark&amp;gt; y1 + y2 + y3&lt;br /&gt;
 f2 =~ y4 + y5 + y6&lt;br /&gt;
 f3 =~ y7 + y8 + y9 + y10&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;# variances and covariances&amp;lt;/b&amp;gt;&lt;br /&gt;
 y1 &amp;lt;mark&amp;gt;~~&amp;lt;/mark&amp;gt; y1&lt;br /&gt;
 y1 ~~ y2&lt;br /&gt;
 f1 ~~ f2&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;b&amp;gt;# intercepts&amp;lt;/b&amp;gt;&lt;br /&gt;
 y1 &amp;lt;mark&amp;gt;~&amp;lt;/mark&amp;gt; 1&lt;br /&gt;
 f1 ~ 1&lt;br /&gt;
  model1 &amp;lt;-&lt;br /&gt;
    '&lt;br /&gt;
 # latent variable definitions - defining how the latent variables are “manifested by” a set of observed &lt;br /&gt;
 # (or manifest) variables, aka “indicators”&lt;br /&gt;
 # (1) Measurement Model &lt;br /&gt;
 Imaging =~ L_cingulate_gyrus_ComputeArea+L_cingulate_gyrus_Volume&lt;br /&gt;
 DemoGeno =~ Weight+Sex+Age&lt;br /&gt;
 UPDRS =~ UPDRS_Part_I_Summary_Score_Baseline+UPDRS_Part_I_Summary_Score_Month_03&lt;br /&gt;
&lt;br /&gt;
 # (2) Regressions &lt;br /&gt;
 ResearchGroup ~ Imaging + DemoGeno + UPDRS &lt;br /&gt;
 '&lt;br /&gt;
 model2 &amp;lt;-&lt;br /&gt;
 '&lt;br /&gt;
 # latent variable definitions - defining how the latent variables are “manifested by” a set of observed &lt;br /&gt;
 # (or manifest) variables, aka “indicators”&lt;br /&gt;
 # (1) Measurement Model &lt;br /&gt;
 Imaging =~  L_cingulate_gyrus_ComputeArea+L_cingulate_gyrus_Volume+R_cingulate_gyrus_ComputeArea+R_cingulate_gyrus_Volume+L_caudate_ComputeArea+L_caudate_Volume+R_caudate_ComputeArea+R_caudate_Volume+L_putamen_ComputeArea+L_putamen_Volume+R_putam en_ComputeArea+R_putamen_Volume+L_hippocampus_ComputeArea+L_hippocampus_Volume+R_hippocampus_ComputeArea+R_hippocampus_Volume+cerebellum_ComputeArea+cerebellum_Volume+L_fusiform_gyrus_ComputeArea+L_fusiform_gyrus_Volume+R_fusiform_gyr us_ComputeArea+R_fusiform_gyrus_Volume&lt;br /&gt;
 DemoGeno =~ Weight+Sex+Age+chr12_rs34637584_GT+chr17_rs11868035_GT+chr17_rs11012_GT+chr17_rs393152_GT+chr17_rs12185268_GT&lt;br /&gt;
 UPDRS =~  UPDRS_Part_I_Summary_Score_Baseline+UPDRS_Part_I_Summary_Score_Month_03+UPDRS_Part_I_Summary_Score_Month_06+UPDRS_Part_I_Summary_Score_Month_09+UPDRS_Part_I_Summary_Score_Month_12+UPDRS_Part_I_Summary_Score_Month_18+UPDRS_Part_I_Summa ry_Score_Month_24+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06+UPDRS_Part_II_Patient_Questionnaire_Sum mary_Score_Month_09+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18+UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24+UPDRS_Part_III_Summary_Score_Baseline +UPDRS_Part_III_Summary_Score_Month_03+UPDRS_Part_III_Summary_Score_Month_06+UPDRS_Part_III_Summary_Score_Month_09+UPDRS_Part_III_Summary_Score_Month_12+UPDRS_Part_III_Summary_Score_Month_18+UPDRS_Part_III_Summary_Score_Month_24+X_Ass essment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline+X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06+X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12+X_Assessment_Non.Motor_Epw orth_Sleepiness_Scale_Summary_Score_Month_24+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06+X_Assessment_Non.Motor_ Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
&lt;br /&gt;
 # (2) Regressions &lt;br /&gt;
 # ResearchGroup ~ Imaging + DemoGeno + UPDRS &lt;br /&gt;
 # transform cat variable to numeric:&lt;br /&gt;
 # myData$\$$ResearchGroup &amp;lt;- ifelse(myData$\$$ResearchGroup == &amp;quot;Control&amp;quot;, 0, &lt;br /&gt;
 # 	ifelse(myData$\$$ResearchGroup == &amp;quot;PD&amp;quot;, 2, 1))&lt;br /&gt;
 RG_ranked ~ Imaging + DemoGeno + UPDRS&lt;br /&gt;
&lt;br /&gt;
 # (3) Residual Variances&lt;br /&gt;
 L_insular_cortex_ComputeArea	~~	L_insular_cortex_ComputeArea&lt;br /&gt;
 L_insular_cortex_Volume	~~	L_insular_cortex_Volume&lt;br /&gt;
 R_insular_cortex_ComputeArea	~~	R_insular_cortex_ComputeArea&lt;br /&gt;
 R_insular_cortex_Volume	~~	R_insular_cortex_Volume&lt;br /&gt;
 L_cingulate_gyrus_ComputeArea	~~	L_cingulate_gyrus_ComputeArea&lt;br /&gt;
 L_cingulate_gyrus_Volume	~~	L_cingulate_gyrus_Volume&lt;br /&gt;
 R_cingulate_gyrus_ComputeArea	~~	R_cingulate_gyrus_ComputeArea&lt;br /&gt;
 R_cingulate_gyrus_Volume	~~	R_cingulate_gyrus_Volume&lt;br /&gt;
 L_caudate_ComputeArea	~~	L_caudate_ComputeArea&lt;br /&gt;
 L_caudate_Volume	~~	L_caudate_Volume&lt;br /&gt;
 R_caudate_ComputeArea	~~	R_caudate_ComputeArea&lt;br /&gt;
 R_caudate_Volume	~~	R_caudate_Volume&lt;br /&gt;
 L_putamen_ComputeArea	~~	L_putamen_ComputeArea&lt;br /&gt;
 L_putamen_Volume	~~	L_putamen_Volume&lt;br /&gt;
 R_putamen_ComputeArea	~~	R_putamen_ComputeArea&lt;br /&gt;
 R_putamen_Volume	~~	R_putamen_Volume&lt;br /&gt;
 L_hippocampus_ComputeArea	~~	L_hippocampus_ComputeArea&lt;br /&gt;
 L_hippocampus_Volume	~~	L_hippocampus_Volume&lt;br /&gt;
 R_hippocampus_ComputeArea	~~	R_hippocampus_ComputeArea&lt;br /&gt;
 R_hippocampus_Volume	~~	R_hippocampus_Volume&lt;br /&gt;
 cerebellum_ComputeArea	~~	cerebellum_ComputeArea&lt;br /&gt;
 cerebellum_Volume	~~	cerebellum_Volume&lt;br /&gt;
 L_fusiform_gyrus_ComputeArea	~~	L_fusiform_gyrus_ComputeArea&lt;br /&gt;
 L_fusiform_gyrus_Volume	~~	L_fusiform_gyrus_Volume&lt;br /&gt;
 R_fusiform_gyrus_ComputeArea	~~	R_fusiform_gyrus_ComputeArea&lt;br /&gt;
 R_fusiform_gyrus_Volume	~~	R_fusiform_gyrus_Volume&lt;br /&gt;
 R_fusiform_gyrus_ShapeIndex	~~	R_fusiform_gyrus_ShapeIndex&lt;br /&gt;
 R_fusiform_gyrus_Curvedness	~~	R_fusiform_gyrus_Curvedness&lt;br /&gt;
 Sex	~~	Sex&lt;br /&gt;
 Weight	~~	Weight&lt;br /&gt;
 ResearchGroup	~~	ResearchGroup&lt;br /&gt;
 VisitID	~~	VisitID&lt;br /&gt;
 Age	~~	Age&lt;br /&gt;
 chr12_rs34637584_GT	~~	chr12_rs34637584_GT&lt;br /&gt;
 chr17_rs11868035_GT	~~	chr17_rs11868035_GT&lt;br /&gt;
 chr17_rs11012_GT	~~	chr17_rs11012_GT&lt;br /&gt;
 chr17_rs393152_GT	~~	chr17_rs393152_GT&lt;br /&gt;
 chr17_rs12185268_GT	~~	chr17_rs12185268_GT&lt;br /&gt;
 chr17_rs199533_GT	~~	chr17_rs199533_GT&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Baseline	~~	UPDRS_Part_I_Summary_Score_Baseline&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_03	~~	UPDRS_Part_I_Summary_Score_Month_03&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_06	~~	UPDRS_Part_I_Summary_Score_Month_06&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_09	~~	UPDRS_Part_I_Summary_Score_Month_09&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_12	~~	UPDRS_Part_I_Summary_Score_Month_12&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_18	~~	UPDRS_Part_I_Summary_Score_Month_18&lt;br /&gt;
 UPDRS_Part_I_Summary_Score_Month_24	~~	UPDRS_Part_I_Summary_Score_Month_24&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_03&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_06&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_09&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_12&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_18&lt;br /&gt;
 UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24	~~	UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Month_24&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Baseline	~~	UPDRS_Part_III_Summary_Score_Baseline&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Month_03	~~	UPDRS_Part_III_Summary_Score_Month_03&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Month_06	~~	UPDRS_Part_III_Summary_Score_Month_06&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Month_09	~~	UPDRS_Part_III_Summary_Score_Month_09&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Month_12	~~	UPDRS_Part_III_Summary_Score_Month_12&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Month_18	~~	UPDRS_Part_III_Summary_Score_Month_18&lt;br /&gt;
 UPDRS_Part_III_Summary_Score_Month_24	~~	UPDRS_Part_III_Summary_Score_Month_24&lt;br /&gt;
 X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline	~~	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Baseline&lt;br /&gt;
 X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06	~~	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_06&lt;br /&gt;
 X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12	~~	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_12&lt;br /&gt;
 X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24	~~	X_Assessment_Non.Motor_Epworth_Sleepiness_Scale_Summary_Score_Month_24&lt;br /&gt;
 X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline	~~	X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline&lt;br /&gt;
 X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06	~~	X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_06&lt;br /&gt;
 X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12	~~	X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_12&lt;br /&gt;
 X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24	~~	X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Month_24&lt;br /&gt;
 &lt;br /&gt;
 # (4) Residual Covariances &lt;br /&gt;
 Sex ~~ Weight&lt;br /&gt;
 '&lt;br /&gt;
 # confirmatory factor analysis (CFA)&lt;br /&gt;
 # The baseline is a null model constraining the observed variables to covary with no other variables.&lt;br /&gt;
 # That is, the covariances are fixed to 0 and only individual variances are estimated. This is represents&lt;br /&gt;
 # a “reasonable worst-possible fitting model”, against which the new fitted model is compared &lt;br /&gt;
 # to calculate appropriate model-quality indices (e.g., CFA).&lt;br /&gt;
&lt;br /&gt;
 # standardize all variable to avoid huge variations between variable distributions&lt;br /&gt;
 library(&amp;quot;MASS&amp;quot;)&lt;br /&gt;
 # myData &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330397/download?download_frd=1&amp;amp;verifier=3bYRT9FXgBGMCQv8MNxsclWnMgodiJRYo3ODFtDq&amp;quot;,header=TRUE)&lt;br /&gt;
&lt;br /&gt;
 summary(myData)&lt;br /&gt;
 myData2&amp;lt;-scale(myData); summary(myData2)&lt;br /&gt;
&lt;br /&gt;
 myDF &amp;lt;- data.frame(myData2)&lt;br /&gt;
 # myDF3 &amp;lt;- subset(myDF, select=c(&amp;quot;L_cingulate_gyrus_ComputeArea&amp;quot;, &amp;quot;cerebellum_Volume&amp;quot;, &amp;quot;Weight&amp;quot;, &amp;quot;Sex&amp;quot;, &amp;quot;Age&amp;quot;, &amp;quot; UPDRS_part_I&amp;quot;, &amp;quot;UPDRS_part_II&amp;quot;, &amp;quot;UPDRS_part_III&amp;quot;, &amp;quot;ResearchGroup&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
 myDF3 &amp;lt;- subset(myDF, select=c(&amp;quot;R_insular_cortex_ComputeArea&amp;quot;,  &amp;quot;R_insular_cortex_Volume&amp;quot;, &amp;quot;Sex&amp;quot;, &amp;quot;Weight&amp;quot;,     &amp;quot;ResearchGroup&amp;quot;, &amp;quot;Age&amp;quot;, &amp;quot;chr12_rs34637584_GT&amp;quot;, &amp;quot;chr17_rs11868035_GT&amp;quot;, &amp;quot;chr17_rs11012_GT&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
 model3 &amp;lt;-&lt;br /&gt;
 '&lt;br /&gt;
 # latent variable definitions - defining how the latent variables are “manifested by” a set of observed &lt;br /&gt;
 # (or manifest) variables, aka “indicators”&lt;br /&gt;
 # (1) Measurement Model &lt;br /&gt;
 # Imaging =~ L_cingulate_gyrus_ComputeArea + cerebellum_Volume&lt;br /&gt;
 Imaging =~  R_insular_cortex_ComputeArea + R_insular_cortex_Volume&lt;br /&gt;
 DemoGeno =~ Weight+Sex+Age&lt;br /&gt;
 # UPDRS =~ UPDRS_Part_I_Summary_Score_Baseline+X_Assessment_Non.Motor_Geriatric_Depression_Scale_GDS_Short_Summary_Score_Baseline&lt;br /&gt;
 UPDRS =~  UPDRS_part_I  +UPDRS_part_II + UPDRS_part_III&lt;br /&gt;
 # (2) Regressions &lt;br /&gt;
 ResearchGroup ~ Imaging + DemoGeno + UPDRS&lt;br /&gt;
&lt;br /&gt;
 fit3 &amp;lt;- cfa(model3, data= myData2, missing='FIML') 		# deal with missing values (missing='FIML')&lt;br /&gt;
 summary(fit3, fit.measures=TRUE)&lt;br /&gt;
 lavaan (0.5-18) converged normally after 2044 iterations&lt;br /&gt;
 Number of observations       &amp;amp;nbsp;&amp;amp;nbsp;             1764&lt;br /&gt;
 Number of missing patterns   &amp;amp;nbsp;&amp;amp;nbsp;             3&lt;br /&gt;
 Estimator                    &amp;amp;nbsp;&amp;amp;nbsp;             ML&lt;br /&gt;
 Minimum Function Test Statistic  &amp;amp;nbsp;&amp;amp;nbsp;         455.923&lt;br /&gt;
 Degrees of freedom           &amp;amp;nbsp;&amp;amp;nbsp;             15&lt;br /&gt;
 P-value (Chi-square)         &amp;amp;nbsp;&amp;amp;nbsp;             0.000&lt;br /&gt;
 Model test baseline model:&lt;br /&gt;
 Minimum Function Test Statistic  &amp;amp;nbsp;&amp;amp;nbsp;         2625.020&lt;br /&gt;
 Degrees of freedom               &amp;amp;nbsp;&amp;amp;nbsp;         28&lt;br /&gt;
 P-value                          &amp;amp;nbsp;&amp;amp;nbsp;         0.000&lt;br /&gt;
 User model versus baseline model:&lt;br /&gt;
 Comparative Fit Index (CFI)      &amp;amp;nbsp;&amp;amp;nbsp;         0.830&lt;br /&gt;
 Tucker-Lewis Index (TLI)          &amp;amp;nbsp;&amp;amp;nbsp;        0.683&lt;br /&gt;
 Loglikelihood and Information Criteria:&lt;br /&gt;
 Loglikelihood user model (H0)      &amp;amp;nbsp;&amp;amp;nbsp;       -51499.484&lt;br /&gt;
 Loglikelihood unrestricted model (H1) &amp;amp;nbsp;&amp;amp;nbsp;    -51271.522&lt;br /&gt;
 Number of free parameters          &amp;amp;nbsp;&amp;amp;nbsp;        29&lt;br /&gt;
 Akaike (AIC)                       &amp;amp;nbsp;&amp;amp;nbsp;        103056.967&lt;br /&gt;
 Bayesian (BIC)                     &amp;amp;nbsp;&amp;amp;nbsp;        103215.752&lt;br /&gt;
 Sample-size adjusted Bayesian (BIC)  &amp;amp;nbsp;&amp;amp;nbsp;      103123.621&lt;br /&gt;
 Root Mean Square Error of Approximation:&lt;br /&gt;
 RMSEA                              &amp;amp;nbsp;&amp;amp;nbsp;        0.129&lt;br /&gt;
 90 Percent Confidence Interval     &amp;amp;nbsp;&amp;amp;nbsp;       0.119  0.139&lt;br /&gt;
 P-value RMSEA &amp;lt;= 0.05              &amp;amp;nbsp;&amp;amp;nbsp;       0.000&lt;br /&gt;
 Standardized Root Mean Square Residual:&lt;br /&gt;
 SRMR                               &amp;amp;nbsp;&amp;amp;nbsp;       0.062&lt;br /&gt;
 Parameter estimates:&lt;br /&gt;
 Information                        &amp;amp;nbsp;&amp;amp;nbsp;      Observed&lt;br /&gt;
 Standard Errors                    &amp;amp;nbsp;&amp;amp;nbsp;      Standard&lt;br /&gt;
&lt;br /&gt;
Estimate  Std.err  Z-value  P(&amp;gt;|z|)&lt;br /&gt;
&lt;br /&gt;
 Latent variables:&lt;br /&gt;
 Imaging =~&lt;br /&gt;
 R_cnglt_gyr_V    &amp;amp;nbsp;&amp;amp;nbsp;   1.000&lt;br /&gt;
 L_cadt_CmptAr  &amp;amp;nbsp;&amp;amp;nbsp;   493.058&lt;br /&gt;
 DemoGeno =~&lt;br /&gt;
 Weight      &amp;amp;nbsp;&amp;amp;nbsp;        1.000&lt;br /&gt;
 Sex         &amp;amp;nbsp;&amp;amp;nbsp;       24.158&lt;br /&gt;
 Age          &amp;amp;nbsp;&amp;amp;nbsp;       0.094&lt;br /&gt;
 UPDRS =~&lt;br /&gt;
 UPDRS_part_I   &amp;amp;nbsp;&amp;amp;nbsp;     1.000&lt;br /&gt;
 UPDRS_part_II   &amp;amp;nbsp;&amp;amp;nbsp;    7.389&lt;br /&gt;
 Regressions:&lt;br /&gt;
 ResearchGroup ~&lt;br /&gt;
 Imaging     &amp;amp;nbsp;&amp;amp;nbsp;       -0.000&lt;br /&gt;
 DemoGeno    &amp;amp;nbsp;&amp;amp;nbsp;      0.002&lt;br /&gt;
 UPDRS       &amp;amp;nbsp;&amp;amp;nbsp;     -0.323&lt;br /&gt;
 Covariances:&lt;br /&gt;
 Imaging ~~&lt;br /&gt;
 DemoGeno      &amp;amp;nbsp;&amp;amp;nbsp;      0.001&lt;br /&gt;
 UPDRS         &amp;amp;nbsp;&amp;amp;nbsp;       0.002&lt;br /&gt;
 DemoGeno ~~&lt;br /&gt;
 UPDRS        &amp;amp;nbsp;&amp;amp;nbsp;       0.000&lt;br /&gt;
 Intercepts:&lt;br /&gt;
 R_cnglt_gyr_V  &amp;amp;nbsp;&amp;amp;nbsp;  7895.658&lt;br /&gt;
 L_cadt_CmptAr  &amp;amp;nbsp;&amp;amp;nbsp;   635.570&lt;br /&gt;
 Weight       &amp;amp;nbsp;&amp;amp;nbsp;      82.048&lt;br /&gt;
 Sex         &amp;amp;nbsp;&amp;amp;nbsp;        1.340&lt;br /&gt;
 Age         &amp;amp;nbsp;&amp;amp;nbsp;       61.073&lt;br /&gt;
 UPDRS_part_I   &amp;amp;nbsp;&amp;amp;nbsp;     1.126&lt;br /&gt;
 UPDRS_part_II  &amp;amp;nbsp;&amp;amp;nbsp;     4.905&lt;br /&gt;
 ResearchGroup   &amp;amp;nbsp;&amp;amp;nbsp;    0.290&lt;br /&gt;
 Imaging       &amp;amp;nbsp;&amp;amp;nbsp;      0.000&lt;br /&gt;
 DemoGeno      &amp;amp;nbsp;&amp;amp;nbsp;      0.000&lt;br /&gt;
 UPDRS         &amp;amp;nbsp;&amp;amp;nbsp;      0.000&lt;br /&gt;
 Variances:&lt;br /&gt;
 R_cnglt_gyr_V  &amp;amp;nbsp;&amp;amp;nbsp; 17070159.189&lt;br /&gt;
 L_cadt_CmptAr  &amp;amp;nbsp;&amp;amp;nbsp; -536243845.090&lt;br /&gt;
 Weight           &amp;amp;nbsp;&amp;amp;nbsp; 274.912&lt;br /&gt;
 Sex               &amp;amp;nbsp;&amp;amp;nbsp; 96.664&lt;br /&gt;
 Age              &amp;amp;nbsp;&amp;amp;nbsp; 105.347&lt;br /&gt;
 UPDRS_part_I       &amp;amp;nbsp;&amp;amp;nbsp; 2.442&lt;br /&gt;
 UPDRS_part_II     &amp;amp;nbsp;&amp;amp;nbsp; -0.256&lt;br /&gt;
 ResearchGroup      &amp;amp;nbsp;&amp;amp;nbsp; 0.149&lt;br /&gt;
 Imaging         &amp;amp;nbsp;&amp;amp;nbsp; 2206.397&lt;br /&gt;
 DemoGeno          &amp;amp;nbsp;&amp;amp;nbsp; -0.165&lt;br /&gt;
 UPDRS              &amp;amp;nbsp;&amp;amp;nbsp; 0.550&lt;br /&gt;
  '&lt;br /&gt;
&lt;br /&gt;
====Output====&lt;br /&gt;
3 parts of the Lavaan SEM output&lt;br /&gt;
*First six lines are called the header contains the following information:&lt;br /&gt;
*lavaan version number&lt;br /&gt;
*lavaan converge info (normal or not), and # iterations needed&lt;br /&gt;
*the number of observations that were effectively used in the analysis&lt;br /&gt;
*the estimator that was used to obtain the parameter values (here: ML)&lt;br /&gt;
*the model test statistic, the degrees of freedom, and a corresponding p-value&lt;br /&gt;
&lt;br /&gt;
# Next, is the Model test baseline model and the value for the SRMR&lt;br /&gt;
# The last section contains the parameter estimates, standard errors (if the information matrix is expected or observed, and if the standard errors are standard, robust, or based on the bootstrap).  Then, it tabulates all free (and fixed) parameters that were included in the model.  Typically, first the latent variables are shown, followed by covariances and (residual) variances.  The first column (Estimate) contains the (estimated or fixed) parameter value for each model parameter;  the second column (Std.err) contains  the  standard  error  for  each  estimated  parameter;  the  third  column  (Z-value)  contains  the  Wald statistic (which is simply obtained by dividing the parameter value by its standard error), and the last column contains the p-value for testing the null hypothesis that the parameter equals zero in the population.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; You can get this type of error &amp;lt;b&amp;gt;“…system is computationally singular: reciprocal condition…”,&amp;lt;/b&amp;gt; which indicates that the design matrix is not invertible. Thus, it can't be used to develop a regression model. This is due to linearly dependent columns, i.e. strongly correlated variables. Resolve pairwise covariances (or correlations) of your variables to investigate if there are any variables that can potentially be removed. You're looking for covariances (or correlations) &amp;gt;&amp;gt; 0. We can also automate this variable selection by using a forward stepwise regression.&lt;br /&gt;
&lt;br /&gt;
 # Graphical fit model visualization&lt;br /&gt;
 library(semPlot)&lt;br /&gt;
 semPaths(fit3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci4.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 semPaths(fit3, &amp;quot;std&amp;quot;, ask = FALSE, as.expression = &amp;quot;edges&amp;quot;, mar = c(3, 1, 5, 1))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci5.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM_sem_vs_cfa| Next See: Differences and Similarities between '''sem'''() and '''cfa'''() ]]&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Back to Structural Equation Modeling (SEM)]]&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM_Ex1| Back to SEM Example 1: School Kids Mental Abilities]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex2}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1&amp;diff=16168</id>
		<title>SMHS BigDataBigSci SEM Ex1</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1&amp;diff=16168"/>
		<updated>2016-05-23T13:40:14Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /*  Structural Equation Modeling (SEM) - Hands-on Example 1 (School Kids Mental Abilities) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] - Hands-on Example 1 (School Kids Mental Abilities) ==&lt;br /&gt;
&lt;br /&gt;
These data (Holzinger &amp;amp; Swineford 1939) include mental ability test scores of 7 &amp;amp; 8 grade children from two schools (Pasteur and Grant-White). This version of the dataset includes only 9 (out of the 26) tests. We can build and test a confirmatory factor analysis (CFA) SEM model for 3 correlated latent variables (or factors), each with three indicators:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;u&amp;gt;'''visual'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x1, x2 and x3,&lt;br /&gt;
*&amp;lt;u&amp;gt;'''textual'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x4, x5 and x6,&lt;br /&gt;
*&amp;lt;u&amp;gt;'''speed'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x7, x8 and x9.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;lhs&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;op&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;rhs&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;user&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;free&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;ustart&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1 ||Visual||=~||x1||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|2 ||Visual||=~||x2||1||1||NA&lt;br /&gt;
|-&lt;br /&gt;
|3 ||Visual||=~||x3||1||2||NA&lt;br /&gt;
|-&lt;br /&gt;
|4 ||Textual||=~||x4||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|5||Textual||=~||x5||1||3||NA&lt;br /&gt;
|-&lt;br /&gt;
|6||Textual||=~||x6||1||4||NA&lt;br /&gt;
|-&lt;br /&gt;
|7 ||Speed||=~||x7||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|8 ||Speed||=~||x8||1||5||NA&lt;br /&gt;
|-&lt;br /&gt;
|9 ||Speed||=~||x9||1||6||NA&lt;br /&gt;
|-&lt;br /&gt;
|10 ||x1||~~||x1||0||7||NA&lt;br /&gt;
|-&lt;br /&gt;
|11||x2||~~||x2||0||8||NA&lt;br /&gt;
|-&lt;br /&gt;
|12||x3||~~||x3||0||9||NA&lt;br /&gt;
|-&lt;br /&gt;
|13||x4||~~||x4||0||10||NA&lt;br /&gt;
|-&lt;br /&gt;
|14||x5||~~||x5||0||11||NA&lt;br /&gt;
|-&lt;br /&gt;
|15||x6||~~||x6||0||12||NA&lt;br /&gt;
|-&lt;br /&gt;
|16||x7||~~||x7||0||13||NA&lt;br /&gt;
|-&lt;br /&gt;
|17||x8||~~||x8||0||14||NA&lt;br /&gt;
|-&lt;br /&gt;
|18||x9||~~||x9||0||15||47.8&lt;br /&gt;
|-&lt;br /&gt;
|19||Visual||~~||Visual||0||16||NA&lt;br /&gt;
|-&lt;br /&gt;
|20||Textual||~~||Textual||0||17||NA&lt;br /&gt;
|-&lt;br /&gt;
|21||Speed||~~||Speed||boy||18||NA&lt;br /&gt;
|-&lt;br /&gt;
|22||Visual||~~||Textual||girl||19||NA&lt;br /&gt;
|-&lt;br /&gt;
|23||Visual||~~||Speed||girl||20||NA&lt;br /&gt;
|-&lt;br /&gt;
|24||Textual||~~||Speed||boy||21||NA&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are 3 latent variables (factors) in this model, each with 3 indicators, resulting in 9 factor loadings that need to be estimated. There are also 3 covariances among the latent variables {another three parameters}. &lt;br /&gt;
&lt;br /&gt;
These &amp;lt;b&amp;gt;12 parameters&amp;lt;/b&amp;gt; are represented in the path diagram as single-headed and double-headed arrows, respectively. We also need to estimate the residual variances of the 9 observed variables and the variances of the 3 latent variables, resulting in &amp;lt;b&amp;gt;12 additional free parameters&amp;lt;/b&amp;gt;. In total, we have &amp;lt;b&amp;gt;24 parameters.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci2.png|200px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To fully identify the model we need to set the metric of the latent variables. There are 2 ways to do this: &lt;br /&gt;
*for each latent variable, fix the factor loading of one of the indicators (typically the first) to a constant (e.g., 1.0), or&lt;br /&gt;
*standardize the variances of the 3 latent variables. &lt;br /&gt;
&lt;br /&gt;
Either way, we fix 3 of these 24 parameters, and 21 parameters remain free. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;parTable(fit)&amp;lt;/b&amp;gt; method, generates this table output.&lt;br /&gt;
&lt;br /&gt;
The `rhs', `op' and `lhs' columns define the parameters of the model. &lt;br /&gt;
All parameters with the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;`=~'&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; operator are factor loadings, whereas all parameters with the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;`~~'&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; operator are variances or covariances. Nonzero elements in the `free' column are the free parameters of the model. Zero elements in the `free' column correspond to fixed parameters, whose value is found in the `start' column.&lt;br /&gt;
&lt;br /&gt;
Lavaan’s user-friendly model-specification approach is implemented in the fitting functions: cfa() and sem(). &lt;br /&gt;
&lt;br /&gt;
Since these data contain 3 latent variables, and no regressions, the minimalist syntax is:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;data.model &amp;lt;- 'visual 	        =~ x1 + x2 + x3&lt;br /&gt;
 textual 	                =~ x4 + x5 + x6&lt;br /&gt;
 speed 	                        =~ x7 + x8 + x9'&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fit the CFA model:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.1 &amp;lt;- cfa(data.model, data = HolzingerSwineford1939)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The `user' column (parTabale) shows which parameters were explicitly contained in the user-specified model syntax (= 1), and which parameters were added by the cfa() function (= 0). &lt;br /&gt;
 &amp;lt;b&amp;gt;parTable(fit.1)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we prefer &amp;lt;b&amp;gt;not to fix the factor loadings&amp;lt;/b&amp;gt; of the first indicator, but instead want to fix the variances of the latent variances, the model syntax would be changed to:&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.2 &amp;lt;- 'visual =~ NA*x1 + x2 + x3&lt;br /&gt;
 textual =~ NA*x4 + x5 + x6&lt;br /&gt;
 speed =~ NA*x7 + x8 + x9&lt;br /&gt;
 visual ~~ 1*visual&lt;br /&gt;
 textual ~~ 1*textual&lt;br /&gt;
 speed ~~ 1*speed'&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complex model specifications can be made using the full '''lavaan''' model syntax:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.full &amp;lt;- '			# latent variables&lt;br /&gt;
 visual 	=~ 1*x1 + x2 + x3&lt;br /&gt;
 textual =~ 1*x4 + x5 + x6&lt;br /&gt;
 speed 	=~ 1*x7 + x8 + x9&lt;br /&gt;
 # residual variances observed variables&lt;br /&gt;
 x1 	~~ x1&lt;br /&gt;
 x2 	~~ x2&lt;br /&gt;
 x3 	~~ x3&lt;br /&gt;
 x4 	~~ x4&lt;br /&gt;
 x5 	~~ x5&lt;br /&gt;
 x6 	~~ x6&lt;br /&gt;
 x7 	~~ x7&lt;br /&gt;
 x8 	~~ x8&lt;br /&gt;
 x9 	~~ x9&lt;br /&gt;
 # factor variances&lt;br /&gt;
 visual 	~~ visual&lt;br /&gt;
 textual ~~ textual&lt;br /&gt;
 speed 	~~ speed&lt;br /&gt;
 # factor covariances&lt;br /&gt;
 visual 	~~ textual + speed&lt;br /&gt;
 textual ~~ speed'&lt;br /&gt;
 fit.3 &amp;lt;- lavaan(fit.full, data = HolzingerSwineford1939)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can specify the model where the first factor loadings are explicitly fixed to one, and the covariances among the factors are added manually.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.mixed &amp;lt;- '		# latent variables&lt;br /&gt;
 visual =~ 1*x1 + x2 + x3&lt;br /&gt;
 textual =~ 1*x4 + x5 + x6&lt;br /&gt;
 speed =~ 1*x7 + x8 + x9&lt;br /&gt;
 # factor covariances&lt;br /&gt;
 visual ~~ textual + speed&lt;br /&gt;
 textual ~~ speed'&lt;br /&gt;
 fit &amp;lt;- lavaan(fit.mixed, data = HolzingerSwineford1939, auto.var = TRUE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The best method to view results from a SEM fitted with lavaan is &amp;lt;b&amp;gt;summary()&amp;lt;/b&amp;gt;, which can be called with optional arguments like fit.measures, standardized, and rsquare.&lt;br /&gt;
&lt;br /&gt;
===Core Lavaan Methods===&lt;br /&gt;
*&amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() print a long summary of the model results&lt;br /&gt;
*&amp;lt;b&amp;gt;show&amp;lt;/b&amp;gt;() print a short summary of the model results&lt;br /&gt;
*&amp;lt;b&amp;gt;coef&amp;lt;/b&amp;gt;() returns the estimates of the free parameters in the model as a named numeric vector&lt;br /&gt;
*&amp;lt;b&amp;gt;fitted&amp;lt;/b&amp;gt;() returns the implied moments (covariance matrix and mean vector) of the model&lt;br /&gt;
*&amp;lt;b&amp;gt;resid&amp;lt;/b&amp;gt;() returns the raw, normalized or standardized residuals (difference between implied and observed moments)&lt;br /&gt;
*&amp;lt;b&amp;gt;vcov&amp;lt;/b&amp;gt;() returns the covariance matrix of the estimated parameters&lt;br /&gt;
*&amp;lt;b&amp;gt;predict&amp;lt;/b&amp;gt;() compute factor scores&lt;br /&gt;
*&amp;lt;b&amp;gt;logLik&amp;lt;/b&amp;gt;() returns the log-likelihood of the fitted model (if maximum likelihood estimation was used)&lt;br /&gt;
*&amp;lt;b&amp;gt;AIC&amp;lt;/b&amp;gt;(), BIC() compute information criteria (if maximum likelihood estimation is used)&lt;br /&gt;
*&amp;lt;b&amp;gt;update&amp;lt;/b&amp;gt;() update a fitted lavaan object&lt;br /&gt;
*&amp;lt;b&amp;gt;inspect&amp;lt;/b&amp;gt;() peek into the internal representation of the model; by default, it returns a list of model matrices counting the free parameters in the model; can also be used to extract starting values, gradient values, and much more&lt;br /&gt;
&lt;br /&gt;
If these args are set to TRUE, the output includes additional fit measures, standardized estimates, and R2 values for the dependent variables, respectively&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.model &amp;lt;- 'visual =~ x1 + x2 + x3&lt;br /&gt;
 textual =~ x4 + x5 + x6&lt;br /&gt;
  speed =~ x7 + x8 + x9'&lt;br /&gt;
 fit &amp;lt;- cfa(fit.model, data = HolzingerSwineford1939)&lt;br /&gt;
 summary(fit, fit.measures = TRUE)&lt;br /&gt;
&lt;br /&gt;
 fit &amp;lt;- cfa(fit.model, data=HolzingerSwineford1939, estimator=&amp;quot;GLS&amp;quot;, group=&amp;quot;sex&amp;quot;)&lt;br /&gt;
 fit.4 &amp;lt;- cfa(fit.model, data=HolzingerSwineford1939, estimator=&amp;quot;GLD&amp;quot;, group=&amp;quot;sex&amp;quot;, group.equal=&amp;quot;regressions&amp;quot;) &lt;br /&gt;
 anova(fit, fit.4)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Output===&lt;br /&gt;
The output consists of three sections. &lt;br /&gt;
&lt;br /&gt;
*The &amp;lt;b&amp;gt;first section&amp;lt;/b&amp;gt; (first 6 lines) contains the package version number, an indication whether the model has converged (and in how many iterations), and the effective number of observations used in the analysis.&lt;br /&gt;
	&lt;br /&gt;
*The &amp;lt;b&amp;gt;second section&amp;lt;/b&amp;gt; contains the model χ^2 test statistic, degrees of freedom, and a p value are printed. If fit.measures = TRUE, it also prints the test statistic of the baseline model (where all observed variables are assumed to be uncorrelated) and several popular fit indices. If maximum likelihood estimation is used, this section will also contain information about the log-likelihood, the AIC, and the BIC.&lt;br /&gt;
	&lt;br /&gt;
*The &amp;lt;b&amp;gt;third section&amp;lt;/b&amp;gt; provides an overview of the parameter estimates, including the type of standard errors used and whether the observed or expected information matrix was used to compute standard errors. Then, for each model parameter, the estimate and the standard error are displayed, and if appropriate, a z value based on the Wald test and a corresponding two-sided p value are also shown. To ease the reading of the parameter estimates, they are grouped into three blocks:&lt;br /&gt;
*factor loadings, &lt;br /&gt;
*factor covariances, and &lt;br /&gt;
*residual variances of both observed variables and factors.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() method provides a nice summary of the model results for visualization purposes. The &amp;lt;b&amp;gt;parameterEstimates&amp;lt;/b&amp;gt;() method returns the actual parameter estimates as a &amp;lt;b&amp;gt;data.frame&amp;lt;/b&amp;gt;, which can be processed further.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;parameterEstimates(fit)&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||lhs||op||rhs||est||se||z||pvalue||ci.lower||ci.upper&lt;br /&gt;
|-&lt;br /&gt;
|1||visual||=~||x1||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|2||visual||=~||x2||0.553||0.1||5.554||0||0.358||0.749&lt;br /&gt;
|-&lt;br /&gt;
|3||visual||=~||x3||0.729||0.109||6.685||0||0.516||0.943&lt;br /&gt;
|-&lt;br /&gt;
|4||textual||=~||x4||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|5||textual||=~||x5||1.113||0.065||17.014||0||0.985||1.241&lt;br /&gt;
|-&lt;br /&gt;
|6||textual||=~||x6||0.926||0.055||16.703||0||0.817||1.035&lt;br /&gt;
|-&lt;br /&gt;
|7||speed||=~||x7||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|8||speed||=~||x8||1.18||0.165||7.152||0||0.857||1.503&lt;br /&gt;
|-&lt;br /&gt;
|9||speed||=~||x9||1.082||0.151||7.155||0||0.785||1.378&lt;br /&gt;
|-&lt;br /&gt;
|10||x1||~~||x1||0.549||0.114||4.833||0||0.326||0.772&lt;br /&gt;
|-&lt;br /&gt;
|11||x2||~~||x2||1.134||0.102||11.146||0||0.934||1.333&lt;br /&gt;
|-&lt;br /&gt;
|12||x3||~~||x3||0.844||0.091||9.317||0||0.667||1.022&lt;br /&gt;
|-&lt;br /&gt;
|13||x4||~~||x4||0.371||0.048||7.779||0||0.278||0.465&lt;br /&gt;
|-&lt;br /&gt;
|14||x5||~~||x5||0.446||0.058||7.642||0||0.332||0.561&lt;br /&gt;
|-&lt;br /&gt;
|15||x6||~~||x6||0.356||0.043||8.277||0||0.272||0.441&lt;br /&gt;
|-&lt;br /&gt;
|16||x7||~~||x7||0.799||0.081||9.823||0||0.64||0.959&lt;br /&gt;
|-&lt;br /&gt;
|17||x8||~~||x8||0.488||0.074||6.573||0||0.342||0.633&lt;br /&gt;
|-&lt;br /&gt;
|18||x9||~~||x9||0.566||0.071||8.003||0||0.427||0.705&lt;br /&gt;
|-&lt;br /&gt;
|19||visual||~~||visual||0.809||0.145||5.564||0||0.524||1.094&lt;br /&gt;
|-&lt;br /&gt;
|20||textual||~~||textual||0.979||0.112||8.737||0||0.76||1.199&lt;br /&gt;
|-&lt;br /&gt;
|21||speed||~~||speed||0.384||0.086||4.451||0||0.215||0.553&lt;br /&gt;
|-&lt;br /&gt;
|22||visual||~~||textual||0.408||0.074||5.552||0||0.264||0.552&lt;br /&gt;
|-&lt;br /&gt;
|23||visual||~~||speed||0.262||0.056||4.66||0||0.152||0.373&lt;br /&gt;
|-&lt;br /&gt;
|24||textual||~~||speed||0.173||0.049||3.518||0||0.077||0.27&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The confidence level can be changed by setting the level argument. To obtain several standardized versions of the estimates, we can use standardized = TRUE:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;est &amp;lt;- parameterEstimates(fit, ci = FALSE, standardized = TRUE)&lt;br /&gt;
subset(est, op == &amp;quot;=~&amp;quot;) &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||lhs||op||rhs||est||se||z||pvalue||std.lv||std.all||std.nox&lt;br /&gt;
|-&lt;br /&gt;
|1||visual||=~||x1||1||0||NA||NA||0.9||0.772||0.772&lt;br /&gt;
|-&lt;br /&gt;
|2||visual||=~||x2||0.553||0.1||5.554||0||0.498||0.424||0.424&lt;br /&gt;
|-&lt;br /&gt;
|3||visual||=~||x3||0.729||0.109||6.685||0||0.656||0.581||0.581&lt;br /&gt;
|-&lt;br /&gt;
|4||textual||=~||x4||1||0||NA||NA||0.99||0.852||0.852&lt;br /&gt;
|-&lt;br /&gt;
|5||textual||=~||x5||1.113||0.065||17.014||0||1.102||0.855||0.855&lt;br /&gt;
|-&lt;br /&gt;
|6||textual||=~||x6||0.926||0.055||16.703||0||0.917||0.838||0.838&lt;br /&gt;
|-&lt;br /&gt;
|7||speed||=~||x7||1||0||NA||NA||0.619||0.57||0.57&lt;br /&gt;
|-&lt;br /&gt;
|8||speed||=~||x8||1.18||0.165||7.152||0||0.731||0.723||0.723&lt;br /&gt;
|-&lt;br /&gt;
|9||speed||=~||x9||1.082||0.151||7.155||0||0.67||0.665||0.665&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This only shows the factor loadings are shown but 3 additional columns with standardized values are added. &lt;br /&gt;
&amp;lt;li&amp;gt;In the first column &amp;lt;b&amp;gt;(std.lv)&amp;lt;/b&amp;gt;, only the latent variables have been standardized; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the second column &amp;lt;b&amp;gt;(std.all)&amp;lt;/b&amp;gt;, both the latent and the observed variables have been standardized; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In the third column &amp;lt;b&amp;gt;(std.nox)&amp;lt;/b&amp;gt;, both the latent and the observed variables have been standardized, except for the exogenous observed variables. This option may be useful if the standardization of exogenous observed variables has little meaning (for example, binary covariates). Since there are no exogenous covariates in this model, the last two columns are identical in this output.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;semPlot&amp;quot;)&lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, &amp;quot;show&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0) &lt;br /&gt;
 # get the margines right:&lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0, mar = c(10, 3, 10, 3)) &lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0, mar = c(10, 3, 10, 3), as.expression = c(&amp;quot;nodes&amp;quot;, &lt;br /&gt;
 # 	&amp;quot;edges&amp;quot;), sizeMan = 3, sizeInt = 1, sizeLat = 4)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci3.png|500px]]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Back to Structural Equation Modeling (SEM)]]&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM_Ex2| Next Section: SEM Example 2: Parkinson’s Disease data]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1&amp;diff=16167</id>
		<title>SMHS BigDataBigSci SEM Ex1</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1&amp;diff=16167"/>
		<updated>2016-05-23T13:39:33Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]] - Hands-on Example 1 (School Kids Mental Abilities) ==&lt;br /&gt;
&lt;br /&gt;
These data (Holzinger &amp;amp; Swineford 1939) include mental ability test scores of 7 &amp;amp; 8 grade children from two schools (Pasteur and Grant-White). This version of the dataset includes only 9 (out of the 26) tests. We can build and test a confirmatory factor analysis (CFA) SEM model for 3 correlated latent variables (or factors), each with three indicators:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;u&amp;gt;'''visual'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x1, x2 and x3,&lt;br /&gt;
*&amp;lt;u&amp;gt;'''textual'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x4, x5 and x6,&lt;br /&gt;
*&amp;lt;u&amp;gt;'''speed'''&amp;lt;/u&amp;gt; factor measured by 3 variables: x7, x8 and x9.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;id&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;lhs&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;op&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;rhs&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;user&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;free&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;ustart&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1 ||Visual||=~||x1||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|2 ||Visual||=~||x2||1||1||NA&lt;br /&gt;
|-&lt;br /&gt;
|3 ||Visual||=~||x3||1||2||NA&lt;br /&gt;
|-&lt;br /&gt;
|4 ||Textual||=~||x4||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|5||Textual||=~||x5||1||3||NA&lt;br /&gt;
|-&lt;br /&gt;
|6||Textual||=~||x6||1||4||NA&lt;br /&gt;
|-&lt;br /&gt;
|7 ||Speed||=~||x7||1||0||1&lt;br /&gt;
|-&lt;br /&gt;
|8 ||Speed||=~||x8||1||5||NA&lt;br /&gt;
|-&lt;br /&gt;
|9 ||Speed||=~||x9||1||6||NA&lt;br /&gt;
|-&lt;br /&gt;
|10 ||x1||~~||x1||0||7||NA&lt;br /&gt;
|-&lt;br /&gt;
|11||x2||~~||x2||0||8||NA&lt;br /&gt;
|-&lt;br /&gt;
|12||x3||~~||x3||0||9||NA&lt;br /&gt;
|-&lt;br /&gt;
|13||x4||~~||x4||0||10||NA&lt;br /&gt;
|-&lt;br /&gt;
|14||x5||~~||x5||0||11||NA&lt;br /&gt;
|-&lt;br /&gt;
|15||x6||~~||x6||0||12||NA&lt;br /&gt;
|-&lt;br /&gt;
|16||x7||~~||x7||0||13||NA&lt;br /&gt;
|-&lt;br /&gt;
|17||x8||~~||x8||0||14||NA&lt;br /&gt;
|-&lt;br /&gt;
|18||x9||~~||x9||0||15||47.8&lt;br /&gt;
|-&lt;br /&gt;
|19||Visual||~~||Visual||0||16||NA&lt;br /&gt;
|-&lt;br /&gt;
|20||Textual||~~||Textual||0||17||NA&lt;br /&gt;
|-&lt;br /&gt;
|21||Speed||~~||Speed||boy||18||NA&lt;br /&gt;
|-&lt;br /&gt;
|22||Visual||~~||Textual||girl||19||NA&lt;br /&gt;
|-&lt;br /&gt;
|23||Visual||~~||Speed||girl||20||NA&lt;br /&gt;
|-&lt;br /&gt;
|24||Textual||~~||Speed||boy||21||NA&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are 3 latent variables (factors) in this model, each with 3 indicators, resulting in 9 factor loadings that need to be estimated. There are also 3 covariances among the latent variables {another three parameters}. &lt;br /&gt;
&lt;br /&gt;
These &amp;lt;b&amp;gt;12 parameters&amp;lt;/b&amp;gt; are represented in the path diagram as single-headed and double-headed arrows, respectively. We also need to estimate the residual variances of the 9 observed variables and the variances of the 3 latent variables, resulting in &amp;lt;b&amp;gt;12 additional free parameters&amp;lt;/b&amp;gt;. In total, we have &amp;lt;b&amp;gt;24 parameters.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_BigDataBigSci2.png|200px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To fully identify the model we need to set the metric of the latent variables. There are 2 ways to do this: &lt;br /&gt;
&amp;lt;li&amp;gt;for each latent variable, fix the factor loading of one of the indicators (typically the first) to a constant (e.g., 1.0), or &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; standardize the variances of the 3 latent variables. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Either way, we fix 3 of these 24 parameters, and 21 parameters remain free. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;parTable(fit)&amp;lt;/b&amp;gt; method, generates this table output.&lt;br /&gt;
&lt;br /&gt;
The `rhs', `op' and `lhs' columns define the parameters of the model. &lt;br /&gt;
All parameters with the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;`=~'&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; operator are factor loadings, whereas all parameters with the &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;`~~'&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; operator are variances or covariances. Nonzero elements in the `free' column are the free parameters of the model. Zero elements in the `free' column correspond to fixed parameters, whose value is found in the `start' column.&lt;br /&gt;
&lt;br /&gt;
Lavaan’s user-friendly model-specification approach is implemented in the fitting functions: cfa() and sem(). &lt;br /&gt;
&lt;br /&gt;
Since these data contain 3 latent variables, and no regressions, the minimalist syntax is:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;data.model &amp;lt;- 'visual 	        =~ x1 + x2 + x3&lt;br /&gt;
 textual 	                =~ x4 + x5 + x6&lt;br /&gt;
 speed 	                        =~ x7 + x8 + x9'&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fit the CFA model:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.1 &amp;lt;- cfa(data.model, data = HolzingerSwineford1939)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The `user' column (parTabale) shows which parameters were explicitly contained in the user-specified model syntax (= 1), and which parameters were added by the cfa() function (= 0). &lt;br /&gt;
 &amp;lt;b&amp;gt;parTable(fit.1)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we prefer &amp;lt;b&amp;gt;not to fix the factor loadings&amp;lt;/b&amp;gt; of the first indicator, but instead want to fix the variances of the latent variances, the model syntax would be changed to:&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.2 &amp;lt;- 'visual =~ NA*x1 + x2 + x3&lt;br /&gt;
 textual =~ NA*x4 + x5 + x6&lt;br /&gt;
 speed =~ NA*x7 + x8 + x9&lt;br /&gt;
 visual ~~ 1*visual&lt;br /&gt;
 textual ~~ 1*textual&lt;br /&gt;
 speed ~~ 1*speed'&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complex model specifications can be made using the full '''lavaan''' model syntax:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.full &amp;lt;- '			# latent variables&lt;br /&gt;
 visual 	=~ 1*x1 + x2 + x3&lt;br /&gt;
 textual =~ 1*x4 + x5 + x6&lt;br /&gt;
 speed 	=~ 1*x7 + x8 + x9&lt;br /&gt;
 # residual variances observed variables&lt;br /&gt;
 x1 	~~ x1&lt;br /&gt;
 x2 	~~ x2&lt;br /&gt;
 x3 	~~ x3&lt;br /&gt;
 x4 	~~ x4&lt;br /&gt;
 x5 	~~ x5&lt;br /&gt;
 x6 	~~ x6&lt;br /&gt;
 x7 	~~ x7&lt;br /&gt;
 x8 	~~ x8&lt;br /&gt;
 x9 	~~ x9&lt;br /&gt;
 # factor variances&lt;br /&gt;
 visual 	~~ visual&lt;br /&gt;
 textual ~~ textual&lt;br /&gt;
 speed 	~~ speed&lt;br /&gt;
 # factor covariances&lt;br /&gt;
 visual 	~~ textual + speed&lt;br /&gt;
 textual ~~ speed'&lt;br /&gt;
 fit.3 &amp;lt;- lavaan(fit.full, data = HolzingerSwineford1939)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can specify the model where the first factor loadings are explicitly fixed to one, and the covariances among the factors are added manually.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.mixed &amp;lt;- '		# latent variables&lt;br /&gt;
 visual =~ 1*x1 + x2 + x3&lt;br /&gt;
 textual =~ 1*x4 + x5 + x6&lt;br /&gt;
 speed =~ 1*x7 + x8 + x9&lt;br /&gt;
 # factor covariances&lt;br /&gt;
 visual ~~ textual + speed&lt;br /&gt;
 textual ~~ speed'&lt;br /&gt;
 fit &amp;lt;- lavaan(fit.mixed, data = HolzingerSwineford1939, auto.var = TRUE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The best method to view results from a SEM fitted with lavaan is &amp;lt;b&amp;gt;summary()&amp;lt;/b&amp;gt;, which can be called with optional arguments like fit.measures, standardized, and rsquare.&lt;br /&gt;
&lt;br /&gt;
===Core Lavaan Methods===&lt;br /&gt;
*&amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() print a long summary of the model results&lt;br /&gt;
*&amp;lt;b&amp;gt;show&amp;lt;/b&amp;gt;() print a short summary of the model results&lt;br /&gt;
*&amp;lt;b&amp;gt;coef&amp;lt;/b&amp;gt;() returns the estimates of the free parameters in the model as a named numeric vector&lt;br /&gt;
*&amp;lt;b&amp;gt;fitted&amp;lt;/b&amp;gt;() returns the implied moments (covariance matrix and mean vector) of the model&lt;br /&gt;
*&amp;lt;b&amp;gt;resid&amp;lt;/b&amp;gt;() returns the raw, normalized or standardized residuals (difference between implied and observed moments)&lt;br /&gt;
*&amp;lt;b&amp;gt;vcov&amp;lt;/b&amp;gt;() returns the covariance matrix of the estimated parameters&lt;br /&gt;
*&amp;lt;b&amp;gt;predict&amp;lt;/b&amp;gt;() compute factor scores&lt;br /&gt;
*&amp;lt;b&amp;gt;logLik&amp;lt;/b&amp;gt;() returns the log-likelihood of the fitted model (if maximum likelihood estimation was used)&lt;br /&gt;
*&amp;lt;b&amp;gt;AIC&amp;lt;/b&amp;gt;(), BIC() compute information criteria (if maximum likelihood estimation is used)&lt;br /&gt;
*&amp;lt;b&amp;gt;update&amp;lt;/b&amp;gt;() update a fitted lavaan object&lt;br /&gt;
*&amp;lt;b&amp;gt;inspect&amp;lt;/b&amp;gt;() peek into the internal representation of the model; by default, it returns a list of model matrices counting the free parameters in the model; can also be used to extract starting values, gradient values, and much more&lt;br /&gt;
&lt;br /&gt;
If these args are set to TRUE, the output includes additional fit measures, standardized estimates, and R2 values for the dependent variables, respectively&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;fit.model &amp;lt;- 'visual =~ x1 + x2 + x3&lt;br /&gt;
 textual =~ x4 + x5 + x6&lt;br /&gt;
  speed =~ x7 + x8 + x9'&lt;br /&gt;
 fit &amp;lt;- cfa(fit.model, data = HolzingerSwineford1939)&lt;br /&gt;
 summary(fit, fit.measures = TRUE)&lt;br /&gt;
&lt;br /&gt;
 fit &amp;lt;- cfa(fit.model, data=HolzingerSwineford1939, estimator=&amp;quot;GLS&amp;quot;, group=&amp;quot;sex&amp;quot;)&lt;br /&gt;
 fit.4 &amp;lt;- cfa(fit.model, data=HolzingerSwineford1939, estimator=&amp;quot;GLD&amp;quot;, group=&amp;quot;sex&amp;quot;, group.equal=&amp;quot;regressions&amp;quot;) &lt;br /&gt;
 anova(fit, fit.4)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Output===&lt;br /&gt;
The output consists of three sections. &lt;br /&gt;
&lt;br /&gt;
*The &amp;lt;b&amp;gt;first section&amp;lt;/b&amp;gt; (first 6 lines) contains the package version number, an indication whether the model has converged (and in how many iterations), and the effective number of observations used in the analysis.&lt;br /&gt;
	&lt;br /&gt;
*The &amp;lt;b&amp;gt;second section&amp;lt;/b&amp;gt; contains the model χ^2 test statistic, degrees of freedom, and a p value are printed. If fit.measures = TRUE, it also prints the test statistic of the baseline model (where all observed variables are assumed to be uncorrelated) and several popular fit indices. If maximum likelihood estimation is used, this section will also contain information about the log-likelihood, the AIC, and the BIC.&lt;br /&gt;
	&lt;br /&gt;
*The &amp;lt;b&amp;gt;third section&amp;lt;/b&amp;gt; provides an overview of the parameter estimates, including the type of standard errors used and whether the observed or expected information matrix was used to compute standard errors. Then, for each model parameter, the estimate and the standard error are displayed, and if appropriate, a z value based on the Wald test and a corresponding two-sided p value are also shown. To ease the reading of the parameter estimates, they are grouped into three blocks:&lt;br /&gt;
*factor loadings, &lt;br /&gt;
*factor covariances, and &lt;br /&gt;
*residual variances of both observed variables and factors.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() method provides a nice summary of the model results for visualization purposes. The &amp;lt;b&amp;gt;parameterEstimates&amp;lt;/b&amp;gt;() method returns the actual parameter estimates as a &amp;lt;b&amp;gt;data.frame&amp;lt;/b&amp;gt;, which can be processed further.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;parameterEstimates(fit)&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||lhs||op||rhs||est||se||z||pvalue||ci.lower||ci.upper&lt;br /&gt;
|-&lt;br /&gt;
|1||visual||=~||x1||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|2||visual||=~||x2||0.553||0.1||5.554||0||0.358||0.749&lt;br /&gt;
|-&lt;br /&gt;
|3||visual||=~||x3||0.729||0.109||6.685||0||0.516||0.943&lt;br /&gt;
|-&lt;br /&gt;
|4||textual||=~||x4||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|5||textual||=~||x5||1.113||0.065||17.014||0||0.985||1.241&lt;br /&gt;
|-&lt;br /&gt;
|6||textual||=~||x6||0.926||0.055||16.703||0||0.817||1.035&lt;br /&gt;
|-&lt;br /&gt;
|7||speed||=~||x7||1||0||NA||NA||1||1&lt;br /&gt;
|-&lt;br /&gt;
|8||speed||=~||x8||1.18||0.165||7.152||0||0.857||1.503&lt;br /&gt;
|-&lt;br /&gt;
|9||speed||=~||x9||1.082||0.151||7.155||0||0.785||1.378&lt;br /&gt;
|-&lt;br /&gt;
|10||x1||~~||x1||0.549||0.114||4.833||0||0.326||0.772&lt;br /&gt;
|-&lt;br /&gt;
|11||x2||~~||x2||1.134||0.102||11.146||0||0.934||1.333&lt;br /&gt;
|-&lt;br /&gt;
|12||x3||~~||x3||0.844||0.091||9.317||0||0.667||1.022&lt;br /&gt;
|-&lt;br /&gt;
|13||x4||~~||x4||0.371||0.048||7.779||0||0.278||0.465&lt;br /&gt;
|-&lt;br /&gt;
|14||x5||~~||x5||0.446||0.058||7.642||0||0.332||0.561&lt;br /&gt;
|-&lt;br /&gt;
|15||x6||~~||x6||0.356||0.043||8.277||0||0.272||0.441&lt;br /&gt;
|-&lt;br /&gt;
|16||x7||~~||x7||0.799||0.081||9.823||0||0.64||0.959&lt;br /&gt;
|-&lt;br /&gt;
|17||x8||~~||x8||0.488||0.074||6.573||0||0.342||0.633&lt;br /&gt;
|-&lt;br /&gt;
|18||x9||~~||x9||0.566||0.071||8.003||0||0.427||0.705&lt;br /&gt;
|-&lt;br /&gt;
|19||visual||~~||visual||0.809||0.145||5.564||0||0.524||1.094&lt;br /&gt;
|-&lt;br /&gt;
|20||textual||~~||textual||0.979||0.112||8.737||0||0.76||1.199&lt;br /&gt;
|-&lt;br /&gt;
|21||speed||~~||speed||0.384||0.086||4.451||0||0.215||0.553&lt;br /&gt;
|-&lt;br /&gt;
|22||visual||~~||textual||0.408||0.074||5.552||0||0.264||0.552&lt;br /&gt;
|-&lt;br /&gt;
|23||visual||~~||speed||0.262||0.056||4.66||0||0.152||0.373&lt;br /&gt;
|-&lt;br /&gt;
|24||textual||~~||speed||0.173||0.049||3.518||0||0.077||0.27&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The confidence level can be changed by setting the level argument. To obtain several standardized versions of the estimates, we can use standardized = TRUE:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;est &amp;lt;- parameterEstimates(fit, ci = FALSE, standardized = TRUE)&lt;br /&gt;
subset(est, op == &amp;quot;=~&amp;quot;) &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||lhs||op||rhs||est||se||z||pvalue||std.lv||std.all||std.nox&lt;br /&gt;
|-&lt;br /&gt;
|1||visual||=~||x1||1||0||NA||NA||0.9||0.772||0.772&lt;br /&gt;
|-&lt;br /&gt;
|2||visual||=~||x2||0.553||0.1||5.554||0||0.498||0.424||0.424&lt;br /&gt;
|-&lt;br /&gt;
|3||visual||=~||x3||0.729||0.109||6.685||0||0.656||0.581||0.581&lt;br /&gt;
|-&lt;br /&gt;
|4||textual||=~||x4||1||0||NA||NA||0.99||0.852||0.852&lt;br /&gt;
|-&lt;br /&gt;
|5||textual||=~||x5||1.113||0.065||17.014||0||1.102||0.855||0.855&lt;br /&gt;
|-&lt;br /&gt;
|6||textual||=~||x6||0.926||0.055||16.703||0||0.917||0.838||0.838&lt;br /&gt;
|-&lt;br /&gt;
|7||speed||=~||x7||1||0||NA||NA||0.619||0.57||0.57&lt;br /&gt;
|-&lt;br /&gt;
|8||speed||=~||x8||1.18||0.165||7.152||0||0.731||0.723||0.723&lt;br /&gt;
|-&lt;br /&gt;
|9||speed||=~||x9||1.082||0.151||7.155||0||0.67||0.665||0.665&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This only shows the factor loadings are shown but 3 additional columns with standardized values are added. &lt;br /&gt;
&amp;lt;li&amp;gt;In the first column &amp;lt;b&amp;gt;(std.lv)&amp;lt;/b&amp;gt;, only the latent variables have been standardized; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the second column &amp;lt;b&amp;gt;(std.all)&amp;lt;/b&amp;gt;, both the latent and the observed variables have been standardized; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In the third column &amp;lt;b&amp;gt;(std.nox)&amp;lt;/b&amp;gt;, both the latent and the observed variables have been standardized, except for the exogenous observed variables. This option may be useful if the standardization of exogenous observed variables has little meaning (for example, binary covariates). Since there are no exogenous covariates in this model, the last two columns are identical in this output.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;semPlot&amp;quot;)&lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, &amp;quot;show&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0) &lt;br /&gt;
 # get the margines right:&lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0, mar = c(10, 3, 10, 3)) &lt;br /&gt;
 # semPaths(fit, &amp;quot;std&amp;quot;, curvePivot = TRUE, edge.label.cex = 1.0, mar = c(10, 3, 10, 3), as.expression = c(&amp;quot;nodes&amp;quot;, &lt;br /&gt;
 # 	&amp;quot;edges&amp;quot;), sizeMan = 3, sizeInt = 1, sizeLat = 4)&lt;br /&gt;
&lt;br /&gt;
[[Image:SMHS_BigDataBigSci3.png|500px]]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM| Back to Structural Equation Modeling (SEM)]]&lt;br /&gt;
* [[SMHS_BigDataBigSci_SEM_Ex2| Next Section: SEM Example 2: Parkinson’s Disease data]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci_SEM_Ex1}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci&amp;diff=16165</id>
		<title>SMHS BigDataBigSci</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci&amp;diff=16165"/>
		<updated>2016-05-23T13:36:25Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Model-based Analyses ==&lt;br /&gt;
&lt;br /&gt;
Structural Equation Modeling (SEM), Growth Curve Models (GCM), and Generalized Estimating Equation (GEE) Modeling&lt;br /&gt;
&lt;br /&gt;
==Questions ==&lt;br /&gt;
&lt;br /&gt;
*How to represent dependencies in linear models and examine causal effects?&lt;br /&gt;
*Is there a way to study population average effects of a covariate against specific individual effects?&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
SEM allow re-parameterization of random-effects to specify latent variables that may affect measures at different time points using structural equations. SEM show variables having predictive (possibly causal) effects on other variables (denoted by arrows) where coefficients index the strength and direction of predictive relations. SEM does not offer much more than what classical regression methods do, but it does allow simultaneous estimation of multiple equations modeling complementary relations. &lt;br /&gt;
&lt;br /&gt;
Growth Curve (or latent growth) modeling is a statistical technique employed in SEM for estimating growth trajectories for longitudinal data (over time). It represent repeated measures of dependent variables as functions of time and other covariates. When subjects or units are observed repeatedly over known time points latent growth curve models reveal the trend of an individual as a function of an underlying growth process where the growth curve parameters can be estimated for each subject/unit.&lt;br /&gt;
&lt;br /&gt;
GEE is a marginal longitudinal method that directly assesses the mean relations of interest (i.e., how the mean dependent variable changes over time), accounting for covariances among the observations within subjects, and getting a better estimate and valid significance tests of the relations. Thus, GEE estimates two different equations, (1) for the mean relations, and (2) for the covariance structure. An advantage of GEE over random-effect models is that it does not require the dependent variable to be normally distributed. However, a disadvantage of GEE is that it is less flexible and versatile – commonly employed algorithms for it require a small-to-moderate number of time points evenly (or approximately evenly) spaced, and similarly spaced across subjects. Nevertheless, it is a little more flexible than repeated-measure ANOVA because it permits some missing values and has an easy way to test for and model away the specific form of autocorrelation within subjects.&lt;br /&gt;
&lt;br /&gt;
GEE is mostly used when the study is focused on uncovering the population average effect of a covariate vs. the individual specific effect. These two things are only equivalent for linear models, but not in non-linear models.&lt;br /&gt;
&lt;br /&gt;
For instance, suppose $Y_{i,j}$ is the random effects &amp;lt;b&amp;gt;logistic model&amp;lt;/b&amp;gt; of the $j^{th}$,  observation of the $i^{th}$ subject, then &lt;br /&gt;
$&lt;br /&gt;
log\Bigg(\frac{p_{i,j}}{1-p_{i,j}} \Bigg)=μ+ν_i,&lt;br /&gt;
$&lt;br /&gt;
where  $ν_i \sim N(0,σ^2)$ is a random effect for &amp;lt;u&amp;gt;subject i&amp;lt;/u&amp;gt; and $p_{i,j}=P(Y_{i,j}=1|ν_i).$&lt;br /&gt;
&lt;br /&gt;
(1) When using a random effects model on such data, the estimate of μ accounts for the fact that a mean zero normally distributed perturbation was applied to each individual, making it ''individual-specific''.&lt;br /&gt;
&lt;br /&gt;
(2) When using a GEE model on the same data, we estimate the &amp;lt;i&amp;gt;population average log odds&amp;lt;/i&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
\begin{equation}&lt;br /&gt;
δ=log\Bigg(\frac{E_v(\frac{1}{1+e^{-μ+v}i})}{1-E_v(\frac{1}{1+e^{-μ+v}i})}&lt;br /&gt;
\Bigg),&lt;br /&gt;
\end{equation} &lt;br /&gt;
&lt;br /&gt;
in general $μ≠δ$.&lt;br /&gt;
&lt;br /&gt;
If $μ=1$ and $σ^2=1$, then $δ≈.83$. &lt;br /&gt;
&lt;br /&gt;
empirically:&lt;br /&gt;
&lt;br /&gt;
m &amp;lt;- 1; s &amp;lt;- 1; v&amp;lt;-rnorm(1000, 0,s); v2 &amp;lt;- 1/(1+exp(-m+v)); v_mean &amp;lt;- mean(v2)&lt;br /&gt;
&lt;br /&gt;
d &amp;lt;- log(v_mean/(1-v_mean)); d&lt;br /&gt;
&lt;br /&gt;
Note that the random effects have mean zero on the transformed, linked, scale, but their effect is not mean zero on the original scale of the data. We can also simulate data from a mixed effects logistic regression model and compare the population level average with the inverse-logit of the intercept to see that they are not equal. This leads to a difference of the interpretation of the coefficients between GEE and random effects models, or SEM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;That is, there will be a difference between the GEE population average coefficients and the individual specific coefficients (random effects models).&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;# theoretically&amp;lt;/b&amp;gt;, if it can be computed:&lt;br /&gt;
&lt;br /&gt;
$E(Y)=μ=1$ (in this specific case), but the expectation of the population average log odds &lt;br /&gt;
$δ=log\Bigg[\frac{P(Y_{i,j}=1|v_i)}{1-P(Y_{i,j}=1|v_i)}\Bigg]$  would be $&amp;lt; 1$ &amp;lt;SUP&amp;gt;1&amp;lt;/SUP&amp;gt;. &lt;br /&gt;
Note that this is kind of related to the fact that a grand-total average  need not be equal to an average of partial averages. &lt;br /&gt;
&lt;br /&gt;
The mean of the $i^{th}$ person in the $j^{th}$ observation (e.g., location, time, etc.) can be expressed by:&lt;br /&gt;
&lt;br /&gt;
$E(Yij | Xij,α_j)= g[μ(Xij|β)+Uij(α_j,Xij)]$,&lt;br /&gt;
&lt;br /&gt;
Where $μ(X_{ij}|β)$ is the average “response” of a person with the same covariates $X_{ij}$, $β$ a set of fixed effect coefficients, and $Uij(α_j,Xij)$ is an error term that is a function of the (time, space) random effects, $α_j$, and also a  function of the covariates $X_{ij}$, and $g$ is the '''link function''' which specifies the regression type -- e.g., &lt;br /&gt;
 &lt;br /&gt;
*&amp;lt;u&amp;gt;linear&amp;lt;/u&amp;gt;:''' 		$g^{-1} (u)=u,$&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;u&amp;gt;log&amp;lt;/u&amp;gt;:'''		        $g^{-1} (u)= log(u),$ &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;u&amp;gt;logistic&amp;lt;/u&amp;gt;:''' 		$g^{-1} (u)=log(\frac{u}{1-u})$&lt;br /&gt;
 &lt;br /&gt;
*$E(Uij(α_j,Xij)|Xij)=0.$&lt;br /&gt;
&lt;br /&gt;
The link function, $g(u)$, provides the relationship between the linear predictor and the mean of the distribution function. For practical applications there are many commonly used link functions. It makes sense to try to match the domain of the link function to the range of the distribution function's mean.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Common distributions with typical uses and canonical link functions&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Distribution&amp;lt;/b&amp;gt; ||&amp;lt;b&amp;gt;Support of distribution&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Typical uses&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Link name&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Link function&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Mean function&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Normal||real: $(-&amp;amp;#8734;, +&amp;amp;#8734;)$||Linear-response data||Identity||$X\beta=\mu$||$\mu=X\beta$&lt;br /&gt;
|-&lt;br /&gt;
|Exponential, Gamma||real:$(0, +&amp;amp;#8734;)$||Exponential-response data, scale parameters||Inverse||$X\beta=-\mu^{-1}$||$\mu=-(X\beta)^{-1}$&lt;br /&gt;
|-&lt;br /&gt;
|Inverse Gaussian||real:$(0, +&amp;amp;#8734;)$|| ||Inverse squared||$X\beta=-\mu^{-2}$||$\mu=(-X\beta)^{-1/2}$ &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model-based Analytics==&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_BigDataBigSci_SEM| Structural Equation Modeling (SEM)]]===&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_BigDataBigSci_GCM| Growth Curve Modeling (GCM)]]===&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_BigDataBigSci_GEE| Generalized Estimating Equation (GEE) Modeling]]===&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_BigDataBigSci_CrossVal|Internal Validation - Statistical n-fold cross-validaiton]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_BigDataBigSci}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_NetworkViz&amp;diff=16164</id>
		<title>SMHS SciVisualization NetworkViz</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_NetworkViz&amp;diff=16164"/>
		<updated>2016-05-23T13:35:15Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Circos Connectogram/Table visualization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - Complex Network Visualization ==&lt;br /&gt;
&lt;br /&gt;
===Background===&lt;br /&gt;
[[SMHS_SciVisualization_SOCR_Excel_R_Charts|First see the SOCR, Excel and R charts section]].&lt;br /&gt;
&lt;br /&gt;
 # Install package&lt;br /&gt;
 # install.packages(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
 library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # build a simple graph&lt;br /&gt;
 g &amp;lt;- graph( c(1,2, 1,3, 2,3, 3,4), n=10)&lt;br /&gt;
 plot(g)&lt;br /&gt;
&lt;br /&gt;
 summary(g); g; is.igraph(g); is.directed(g); vcount(g); ecount(g)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization38.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization39.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(g, layout=layout.circle)&lt;br /&gt;
&lt;br /&gt;
 plot(g, layout=layout.fruchterman.reingold)&lt;br /&gt;
 plot(g, layout=layout.graphopt)&lt;br /&gt;
 plot(g, layout=layout.kamada.kawai, vertex.color=&amp;quot;cyan&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Interactive&lt;br /&gt;
 tkplot(g, layout=layout.kamada.kawai)&lt;br /&gt;
 # 3D plot&lt;br /&gt;
 rglplot(g, layout=layout.kamada.kawai(g))&lt;br /&gt;
&lt;br /&gt;
Dataset 1: Coappearance network in the novel “les miserablese”. &lt;br /&gt;
&lt;br /&gt;
D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).&lt;br /&gt;
&lt;br /&gt;
The data contains the weighted network of coappearances of characters in Victor Hugo's novel &amp;quot;Les Miserables&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
Nodes represent characters as indicated by the labels and edges connect any pair of characters that appear in the same chapter of the book.  The values on the edges are the number of such coappearances.&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use a directed, weighted network representing the neural network of the nematode &lt;br /&gt;
&lt;br /&gt;
C. Elegans. D. Watts and S. Strogatz, Nature 393, 440-442 (1998). &lt;br /&gt;
&lt;br /&gt;
The file celegansneural.gml describes a weighted, directed network where the nodes have been renumbered to be consecutive.&lt;br /&gt;
&lt;br /&gt;
Edge weights are the weights given by Watts.&lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;rgl&amp;quot;)&lt;br /&gt;
 library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 g&amp;lt;-read.graph(&amp;quot;C:\\Users\\Dinov\\Desktop\\celegansneural.gml&amp;quot;,format=c(&amp;quot;gml&amp;quot;))&lt;br /&gt;
 g&lt;br /&gt;
 plot(g, layout=layout.graphopt)&lt;br /&gt;
&lt;br /&gt;
 data_g &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330389/download?download_frd=1&amp;amp;verifier=u1jqCGS8AAU0MsO5ffLCyvVFYXXAflpdLtg8RXhk&amp;quot;, sep=&amp;quot; &amp;quot;, header = FALSE)&lt;br /&gt;
&lt;br /&gt;
 data_g_mat &amp;lt;- as.matrix(data_g, byrow=TRUE, nc=2)&lt;br /&gt;
 g_miserab &amp;lt;- graph.edgelist(data_g_mat, dir=FALSE)&lt;br /&gt;
 summary(g_miserab)&lt;br /&gt;
 plot(g_miserab, layout=layout.graphopt)&lt;br /&gt;
 # rglplot(g_miserab, layout=layout.kamada.kawai(g_miserab))&lt;br /&gt;
&lt;br /&gt;
 # to name the vertices and and plot the graph  of the first 10 vertices&lt;br /&gt;
 V(g_miserab)$\$$name&lt;br /&gt;
 g_miserab.1 &amp;lt;- graph.ring(10)&lt;br /&gt;
 V(g_miserab.1)$\$$name &amp;lt;- sample(letters, vcount(g_miserab.1))&lt;br /&gt;
 plot(g_miserab.1, layout=layout.graphopt)&lt;br /&gt;
&lt;br /&gt;
 # compute the node adjacency matrix&lt;br /&gt;
 g &amp;lt;- g_miserab; as_adjacency_matrix(g)&lt;br /&gt;
 E(g)$\$$weight &amp;lt;- runif(ecount(g))&lt;br /&gt;
 W &amp;lt;- get.adjacency(g, attr=&amp;quot;weight&amp;quot;)&lt;br /&gt;
 W&lt;br /&gt;
&lt;br /&gt;
===Social Network Analysis Example===&lt;br /&gt;
&lt;br /&gt;
 # free memory&lt;br /&gt;
 # rm(list = ls())&lt;br /&gt;
 # gc()&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 # load termDocMatrix dataset&lt;br /&gt;
 # These data include Twitter text data of @RDataMining representing a general social network analysis&lt;br /&gt;
 # example. The terms represent people and the tweets represent LinkedIn groups.&lt;br /&gt;
 # The term-document matrix can be viewed as the group membership of people. &lt;br /&gt;
 # We may want to build a network of terms based on their co-occurrence in the same tweets,&lt;br /&gt;
 # similarly to a network of people based on their group membership.&lt;br /&gt;
 # https://umich.instructure.com/files/541336/download?download_frd=1 &lt;br /&gt;
&lt;br /&gt;
load(&amp;quot;E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\03_GraphNetwork_TermDocMatrix.rdata&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Labeled graph [[Image:SMHS_SciVisualization40.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Adjacency matrix [[Image:SMHS_SciVisualization41.png|300px]] Coordinates are 1-6.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # inspect part of the matrix&lt;br /&gt;
 termDocMatrix [5:10,1:20]&lt;br /&gt;
 # change it to a Boolean matrix == incidence matrix&lt;br /&gt;
 termDocMatrix [termDocMatrix &amp;gt;=1] &amp;lt;- 1&lt;br /&gt;
&lt;br /&gt;
 # transform into a term-term adjacency matrix (n×n), where (i,j)th entries correspond to the number of edges &lt;br /&gt;
 # node from xi to node xj.&lt;br /&gt;
 # Matrix Multiplication in R: http://www.statmethods.net/advstats/matrix.html, dim(t(termDocMatrix))&lt;br /&gt;
 termMatrix &amp;lt;- termDocMatrix %*% t(termDocMatrix)&lt;br /&gt;
&lt;br /&gt;
 # A graph has no loops, when all entries of the adjacency matrix on the main diagonal of are zeroes&lt;br /&gt;
 # http://mathonline.wikidot.com/adjacency-matrices &lt;br /&gt;
 diag(termMatrix)&lt;br /&gt;
&lt;br /&gt;
 # The matrix product of incidence matrix (B) and it’s transpose B×B^T represents the degrees of all nodes!&lt;br /&gt;
 # inspect terms numbered 5 to 10&lt;br /&gt;
 termMatrix[5:10,5:10]&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
 # build a graph from the adjacency matrix&lt;br /&gt;
 g &amp;lt;- graph.adjacency(termMatrix, weighted=T, mode=&amp;quot;undirected&amp;quot;)&lt;br /&gt;
 plot(g)&lt;br /&gt;
&lt;br /&gt;
 # remove loops &lt;br /&gt;
 g &amp;lt;- simplify(g); plot(g)&lt;br /&gt;
&lt;br /&gt;
 # set labels and degrees of  V(g)&lt;br /&gt;
 V(g)$\$$label &amp;lt;- V(g)$\$$name&lt;br /&gt;
 V(g)$\$$degree &amp;lt;- degree(g)&lt;br /&gt;
&lt;br /&gt;
 # set seed to make the layout reproducible&lt;br /&gt;
 set.seed(1953)&lt;br /&gt;
 layout1 &amp;lt;- layout.fruchterman.reingold(g)   # Fruchterman-Reingold layout&lt;br /&gt;
 plot(g, layout=layout1)&lt;br /&gt;
&lt;br /&gt;
 # plot(g, layout=layout.kamada.kawai)&lt;br /&gt;
 # tkplot(g, layout=layout.kamada.kawai)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization42.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Finesse the graph appearance – vertices and edges&lt;br /&gt;
 V(g)$\$$label.cex &amp;lt;- 2.2 * V(g)$\$$degree / max(V(g)$\$$degree)+ .2&lt;br /&gt;
 V(g)$\$$label.color &amp;lt;- rgb(0, 0, .2, .8)&lt;br /&gt;
 V(g)$\$$frame.color &amp;lt;- rgb(0,0,1)&lt;br /&gt;
 egam &amp;lt;- (log(E(g)$\$$weight)+.4) / max(log(E(g)$\$$weight)+.4)&lt;br /&gt;
 E(g)$\$$color &amp;lt;- rgb(.5, .5, 0, egam)		# Graph Edges, E(g)&lt;br /&gt;
 E(g)$\$$width &amp;lt;- egam&lt;br /&gt;
 # plot the graph in layout1&lt;br /&gt;
 plot(g, layout=layout1)&lt;br /&gt;
&lt;br /&gt;
 V(g)$\$$label &amp;lt;- V(g)$\$$name&lt;br /&gt;
 V(g)$\$$label.color &amp;lt;- rgb(0, 0, 0, 0.5)&lt;br /&gt;
 V(g)$\$$label.dist &amp;lt;- 1.0	# relative distance of labels from node center&lt;br /&gt;
 V(g)$\$$label.angle&amp;lt;- 3/8   #in radians&lt;br /&gt;
 V(g)$\$$label.cex &amp;lt;- 1.4*V(g)$\$$degree/max(V(g)$\$$degree) + 1&lt;br /&gt;
 V(g)$\$$color &amp;lt;- rgb(1, 0, 0, .4)&lt;br /&gt;
 V(g)$\$$size &amp;lt;- 22 * V(g)$\$$degree / max(V(g)$\$$degree)+ 2&lt;br /&gt;
 V(g)$\$$shape &amp;lt;- &amp;quot;rectangle&amp;quot;&lt;br /&gt;
 # V(g)$\$$.size=10*(strwidth(V(g)$\$$label) + strwidth(&amp;quot;oo&amp;quot;)) * 10&lt;br /&gt;
 # V(g)$\$$.size2=strheight(&amp;quot;I&amp;quot;) * 10&lt;br /&gt;
 V(g)$\$$frame.color &amp;lt;- NA&lt;br /&gt;
 # set vertex labels and their colors and sizes&lt;br /&gt;
 # set edge width and color&lt;br /&gt;
 E(g)$\$$width &amp;lt;- .3	&lt;br /&gt;
 E(g)$\$$color &amp;lt;- rgb(.5, .5, 0, .3) &lt;br /&gt;
&lt;br /&gt;
 set.seed(1234)&lt;br /&gt;
 plot(g, layout=layout.fruchterman.reingold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization43.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on activity (oncological primary doctor and a second-opinion)===&lt;br /&gt;
&lt;br /&gt;
We use some of the Stanford Real Graph Data (http://snap.stanford.edu/data/) or this graph data on cancer patients seen by a primary doctor and a second-opinion doctor, stage of the disease, and diagnostic agreement between primary and secondary oncologist: &amp;lt;b&amp;gt;Primary&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;Secondary&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;Stage&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;DxAgreement&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # 03_GraphData_Health.txt&lt;br /&gt;
 healthGraphTable &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/554234/download?download_frd=1&amp;quot;, sep='\t', dec=',', header=T)&lt;br /&gt;
 #specify the path, separator(tab, comma, ...), decimal point symbol, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(healthGraphTable)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Primary||Secondary||Stage||DxAgreement&lt;br /&gt;
|-&lt;br /&gt;
|1||AA||DD||3||Y&lt;br /&gt;
|-&lt;br /&gt;
|2||AB||DD||3||R&lt;br /&gt;
|-&lt;br /&gt;
|3||AF||BA||3||Q&lt;br /&gt;
|-&lt;br /&gt;
|4||DD||DA||3||Q&lt;br /&gt;
|-&lt;br /&gt;
|5||CD||EC||3||X&lt;br /&gt;
|-&lt;br /&gt;
|6||DD||CE||3||Y&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Transform the table into the required graph format:&lt;br /&gt;
 healthGraph.network&amp;lt;-graph.data.frame(healthGraphTable, directed=F) &lt;br /&gt;
 # the 'directed' attribute specifies whether the edges are directed&lt;br /&gt;
 # or equivalent irrespective of the position (1st vs 2nd column). For directed graphs use 'directed=T'&lt;br /&gt;
&lt;br /&gt;
 # Inspect the data:&lt;br /&gt;
 V(healthGraph.network) &amp;lt;blockquote&amp;gt;# prints the list of vertices (physicians/oncologists)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 E(healthGraph.network) &amp;lt;blockquote&amp;gt;# prints the list of edges (primary-secondary relationships)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 degree(healthGraph.network) &amp;lt;blockquote&amp;gt;# print the number of edges (relationships) per node (physician)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # first plot of graph&lt;br /&gt;
 plot(healthGraph.network)&lt;br /&gt;
&lt;br /&gt;
 #Subset the data. If we want to exclude only physicians who are mostly outside of the network &lt;br /&gt;
 # i.e., participate only tangentially (with 1 or 2 relationships only)&lt;br /&gt;
 # we can exclude nodes by subsetting the graph on the basis of the node/physician’s 'degree':&lt;br /&gt;
 healthGraph.out.network &amp;lt;- V(healthGraph.network)[degree(healthGraph.network)&amp;lt;=2] &lt;br /&gt;
 #identify those vertices part of less than or equal to 2 connections (edges)&lt;br /&gt;
 healthGraph.in.network &amp;lt;- delete.vertices(healthGraph.network, healthGraph.out.network) &lt;br /&gt;
 #exclude them from the graph&lt;br /&gt;
&lt;br /&gt;
 # Plot the data by specifying certain details about the graph, e.g., separate some nodes (people) by color:&lt;br /&gt;
 V(healthGraph.in.network)$\$$color &amp;lt;- ifelse(V(healthGraph.in.network)$\$$name=='CA', 'blue', 'red') &lt;br /&gt;
 #useful for highlighting certain people. Works by matching the name attribute of the vertex to the one specified in the 'ifelse' expression&lt;br /&gt;
 # We can also color the connecting edges differently depending on the 'Stage': &lt;br /&gt;
 E(healthGraph.in.network)$\$$color&amp;lt;-ifelse(E(healthGraph.in.network)$\$$Stage&amp;gt;3, &amp;quot;red&amp;quot;, &amp;quot;grey&amp;quot;)&lt;br /&gt;
 # or depending on the different diagnostic agreement labels ('DxAgreement'):&lt;br /&gt;
 E(healthGraph.in.network)$\$$color&amp;lt;-ifelse(E(healthGraph.in.network)$\$$DxAgreement =='X', &amp;quot;red&amp;quot;, ifelse(E(healthGraph.in.network)$\$$DxAgreement=='Y', &amp;quot;blue&amp;quot;, &amp;quot;grey&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Note: the example uses nested ifelse expressions which can be improved&lt;br /&gt;
 # Additional attributes like size can be further specified in an analogous manner:&lt;br /&gt;
 V(healthGraph.in.network)$\$$size&amp;lt;-degree(healthGraph.in.network)/10	&lt;br /&gt;
 #here the size of the vertices is specified by the degree of the vertex, so that people supervising more have get proportionally bigger dots. Getting the right scale gets some playing around with the parameters of the scale function    (from the 'base' package)&lt;br /&gt;
&lt;br /&gt;
 # Note that if the same attribute is specified beforehand and inside the function, the former will be overridden.&lt;br /&gt;
 # And finally the plot itself:&lt;br /&gt;
 par(mai=c(0,0,1,0)) 		&lt;br /&gt;
 #this specifies the size of the margins, default settings leave too much free space on all sides&lt;br /&gt;
 plot(healthGraph.in.network,		#the graph to be plotted&lt;br /&gt;
 layout=layout.fruchterman.reingold,	# the layout method. see the igraph documentation for details&lt;br /&gt;
 main='Onco Physician Network Example',	#specifies the title&lt;br /&gt;
 vertex.label.dist=0.5,			#puts the name labels slightly off the dots&lt;br /&gt;
 vertex.frame.color='blue', 		#the color of the border of the dots &lt;br /&gt;
 vertex.label.color='black',		#the color of the name labels&lt;br /&gt;
 vertex.label.font=2,			#the font of the name labels&lt;br /&gt;
 vertex.label=V(healthGraph.in.network)$\$$name,   #specifies the labels of the vertices&lt;br /&gt;
 vertex.label.cex=1			#specifies the size of the font of the labels&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # Save or export the plot as a metafile to the clipboard, a pdf or png (and other formats).&lt;br /&gt;
 png(filename=&amp;quot;org_network.png&amp;quot;, height=1900, width=1200) #call the png writer&lt;br /&gt;
 # alternatively print to high-res PDF file # pdf(file=&amp;quot;org_network.pdf&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 #run the plot&lt;br /&gt;
&lt;br /&gt;
 dev.off() #don’t forget to close the device&lt;br /&gt;
&lt;br /&gt;
==Pathway analysis==&lt;br /&gt;
&lt;br /&gt;
Pathway analysis   is a technique that reduces complexity and increased explanatory power in studies examining underlying biological structure of differentially expressed genes and proteins.&lt;br /&gt;
&lt;br /&gt;
 # install package &lt;br /&gt;
 # install.packages(&amp;quot;dendsort&amp;quot;) – contains the “” dataset&lt;br /&gt;
 # Data: Sample data matrix from the integrated pathway analysis of gastric cancer from the &lt;br /&gt;
 # Cancer Genome Atlas (TCGA) study. A multivariate table obtained from the integrated pathway analysis &lt;br /&gt;
 # of gastric cancer from the Cancer Genome Atlas (TCGA) study. Each column represents a pathway&lt;br /&gt;
 # &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;consisting of a set of genes and each row represents a cohort of samples based on specific clinical &lt;br /&gt;
 # or genetic features.&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; For each pair of a pathway and a feature, a continuous value of between &lt;br /&gt;
 # 1 and -1 is assigned to score positive or negative association, respectively.&lt;br /&gt;
 # A data frame with &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;215&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; rows and &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;117 variables&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 library(&amp;quot;dendsort&amp;quot;)&lt;br /&gt;
 data(sample_tcga)&lt;br /&gt;
 dataTable &amp;lt;- t(sample_tcga)&lt;br /&gt;
 head(dataTable)&lt;br /&gt;
 write.csv(dataTable, &amp;quot;E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\03_TCGA_Data_117x215.csv&amp;quot;)&lt;br /&gt;
 # data.new &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330393/download?download_frd=1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # install SPIA package: http://bioconductor.org/packages/2.6/bioc/html/SPIA.html &lt;br /&gt;
 # source(&amp;quot;http://bioconductor.org/biocLite.R&amp;quot;)&lt;br /&gt;
 # biocLite(&amp;quot;SPIA&amp;quot;)&lt;br /&gt;
 library(&amp;quot;SPIA&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # “top” Colorectal cancer dataset provided by SPIA package.&lt;br /&gt;
 data(Vessels)&lt;br /&gt;
 head(top)&lt;br /&gt;
 # pathway analysis based on combined evidence; &lt;br /&gt;
 # use nB=2000 or more for more accurate results&lt;br /&gt;
 res&amp;lt;-spia(de=DE_Vessels,all=ALL_Vessels,organism=&amp;quot;hsa&amp;quot;,nB=500,plots=FALSE,beta=NULL,verbose=FALSE)&lt;br /&gt;
 #make the output fit this screen&lt;br /&gt;
 res$\$$Name=substr(res$\$$Name,1,10)&lt;br /&gt;
 #show first 15 pathways, omitting KEGG links&lt;br /&gt;
 res[1:15,-12]&lt;br /&gt;
&lt;br /&gt;
==GIS/Distortion mapping==&lt;br /&gt;
&lt;br /&gt;
 # install the R GISTools package&lt;br /&gt;
 # install.packages(&amp;quot;GISTools&amp;quot;)&lt;br /&gt;
 library(&amp;quot;GISTools&amp;quot;)&lt;br /&gt;
 data(georgia)&lt;br /&gt;
 …&lt;br /&gt;
&lt;br /&gt;
Java Applet: http://www.socr.ucla.edu/htmls/SOCR_Cartograhy.html&lt;br /&gt;
Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_Cartography_Project &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Circos Connectogram/Table visualization==&lt;br /&gt;
&lt;br /&gt;
Circular chord/ribbon diagrams present a mechanism to visualize numeric tables containing information of directional relations. This type of chart visualizes tables in a circular way. Sectors of the plot is union(rownames(mat), colnames(mat)). When there is no rowname or colname, the chart assigns names for it (rows could be auto-named as &amp;quot;R1&amp;quot;, &amp;quot;R2&amp;quot;, ... and columns may be named as &amp;quot;C1&amp;quot;, &amp;quot;C2&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
*Circos: http://circos.ca &lt;br /&gt;
&lt;br /&gt;
*R circlize: http://cran.r-project.org/web/packages/circlize/circlize.pdf&lt;br /&gt;
&lt;br /&gt;
===Example Early-Onset Alzheimer’s Disease===&lt;br /&gt;
&lt;br /&gt;
Recent studies examined the Interactions between imaging (Structural Brain Change) and genetics (SNP) biomarkers in Early-Onset Alzheimer's Disease Subjects. Circular representation of the significant SNP-Neuroimaging interactions. The left and right parts of the graph contain the 15-ROI imaging markers and the 20-SNP genotypes, respectively. The strength of the connection between each SNP-ROI pair is presented as a ribbon, whose size, color and location are proportional to -log (p). Clearly, there are a lot of spurious effects (skinny red lines on background) and several significantly strong associations (thicker purple ribbons on foreground), e.g., purple association between SNP_5 (rs7718456) and ROI_10 (L_hippocampus, Volume). SNP: single nucleotide polymorphism, ROI: region of interest. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization44.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|SNPROI||ROI_1||ROI_2||ROI_3||ROI_4||ROI_5||ROI_6||ROI_7||ROI_8||ROI_9||ROI_10||ROI_11||ROI_12||ROI_13||ROI_14||ROI_15&lt;br /&gt;
|-&lt;br /&gt;
|rs17029131||10||10||10||10||10||10||10||10||10||10||188||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1822144||10||10||10||10||10||200||10||10||10||10||188||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs6446443||10||10||10||126||113||10||10||113||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12506164||10||10||10||10||10||167||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs7718456||10||202||144||206||10||10||10||169||225||321||10||10||290||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs9377090||10||145||10||10||10||10||10||153||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2776932||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs4933672||10||10||113||10||10||10||10||10||10||10||10||232||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193270||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193272||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193274||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12218153||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1338956||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1338025||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12101936||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs16964473||10||10||10||10||10||10||10||10||10||10||112||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12972537||10||10||10||10||10||10||125||10||10||10||126||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2212356||10||10||10||10||10||10||10||10||10||10||10||129||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2831165||10||10||10||10||10||10||10||10||10||10||10||10||10||10||169&lt;br /&gt;
|-&lt;br /&gt;
|rs1266320||10||120||10||10||10||10||10||10||10||145||10||10||10||10||129&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;circlize&amp;quot;)&lt;br /&gt;
 library(&amp;quot;circlize&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;03_CircularTable_EOAD_Data.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 EOAD_data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330388/download?download_frd=1&amp;quot;, sep=&amp;quot;,&amp;quot;,  row.names=1, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 rownames(EOAD_data) &lt;br /&gt;
 colnames(EOAD_data) &lt;br /&gt;
 EOAD_matrix &amp;lt;- as.matrix(EOAD_data)&lt;br /&gt;
&lt;br /&gt;
 ### graphics settings&lt;br /&gt;
 # par(mfrow = c(3, 2))&lt;br /&gt;
 # par(mar = c(1, 1, 1, 1))&lt;br /&gt;
 chordDiagram(EOAD_matrix)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 circos.par(gap.degree = c(rep(2, nrow(EOAD_matrix)-1), 10, rep(2, ncol(EOAD_matrix)-1), 10))&lt;br /&gt;
 chordDiagram(EOAD_matrix)	&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 circos.par(start.degree = 90)&lt;br /&gt;
 chordDiagram(EOAD_matrix)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 # chordDiagram(EOAD_matrix, order = c(&amp;quot;ROI_1&amp;quot;, &amp;quot;ROI_2&amp;quot;, &amp;quot;ROI_3&amp;quot;, &amp;quot;ROI_4&amp;quot;, &amp;quot;ROI_5&amp;quot;, &amp;quot;ROI_6&amp;quot;, &amp;quot;ROI_7&amp;quot;, &amp;quot;ROI_8&amp;quot;, &amp;quot;ROI_9&amp;quot;, &amp;quot;ROI_10&amp;quot;, &amp;quot;ROI_11&amp;quot;, &amp;quot;ROI_12&amp;quot;, &amp;quot;ROI_13&amp;quot;, &amp;quot;ROI_14&amp;quot;, &amp;quot;ROI_15&amp;quot;))&lt;br /&gt;
 chordDiagram(EOAD_matrix, directional = TRUE)&lt;br /&gt;
 chordDiagram(EOAD_matrix, directional = TRUE, diffHeight = 0.06)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
&lt;br /&gt;
 ### colors settings&lt;br /&gt;
 rand_color = function(n, alpha = 1) {&lt;br /&gt;
 return(rgb(runif(n), runif(n), runif(n), alpha = alpha))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 par(mfrow = c(2, 2))&lt;br /&gt;
 par(mar = c(1, 1, 1, 1))&lt;br /&gt;
 grid.col = NULL&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;random&amp;lt;/mark&amp;gt; grid/sector and ribbon/chord colors&lt;br /&gt;
 col_mat = rand_color(length(EOAD_matrix), alpha = 0.5)&lt;br /&gt;
 grid_col = rand_color(length(rownames(EOAD_matrix)) + length(colnames(EOAD_matrix)), alpha = 0.5)&lt;br /&gt;
 dim(col_mat) = dim(EOAD_matrix)&lt;br /&gt;
 chordDiagram(EOAD_matrix, grid.col = grid_col, col = col_mat)&lt;br /&gt;
&lt;br /&gt;
 # grid/sector and ribbon/chord colors according to cell values&lt;br /&gt;
 # Generate quantile values for the color mapping relative to table cell-values&lt;br /&gt;
 seqs &amp;lt;- seq(0.92, 1, 0.008)&lt;br /&gt;
&lt;br /&gt;
 chordDiagram(EOAD_matrix, grid.col = grid_col, col = colorRamp2(quantile(EOAD_matrix, seqs), rev(heat.colors(11))), transparency = 0.5)&lt;br /&gt;
 circos.clear()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization46.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Practice===&lt;br /&gt;
&lt;br /&gt;
Repeat these charts using the 03_NIPS_Baby_VitK_Shot_DataSummaryAnalysis_March2012_Short.csv dataset (Appendix), https://umich.instructure.com/files/330392/download?download_frd=1&lt;br /&gt;
&lt;br /&gt;
==Graphical Workflow Protocol Visualization==&lt;br /&gt;
&lt;br /&gt;
(1)	Brain Imaging &amp;amp; Genetics Data:&lt;br /&gt;
&lt;br /&gt;
a.	ADNI: http://adni.loni.usc.edu/&lt;br /&gt;
&lt;br /&gt;
b.	PPMI: http://ppmi-info.org/&lt;br /&gt;
&lt;br /&gt;
c.	XNAT Central: https://central.xnat.org/&lt;br /&gt;
&lt;br /&gt;
d.	Pipeline Data (see client library)&lt;br /&gt;
&lt;br /&gt;
e.	Cloud Services (AWS/Box/Drive)&lt;br /&gt;
&lt;br /&gt;
(2)	Pipeline Environment&lt;br /&gt;
&lt;br /&gt;
a.	http://pipeline.loni.usc.edu/&lt;br /&gt;
&lt;br /&gt;
b.	Web-Java Client: http://pipeline.loni.usc.edu/products-services/pws/ &lt;br /&gt;
&lt;br /&gt;
c.	Videos: http://pipeline.loni.usc.edu/learn/basic-videos/ &lt;br /&gt;
&lt;br /&gt;
d.	Publications: http://pipeline.loni.usc.edu/get-started/acknowledgmentscredits/ &lt;br /&gt;
&lt;br /&gt;
(3)	End-to-end Computational workflows&lt;br /&gt;
&lt;br /&gt;
a.	Navigator: http://pipeline.loni.usc.edu/explore/library-navigator/&lt;br /&gt;
&lt;br /&gt;
b.	Detailed Descriptions: http://wiki.loni.usc.edu/twiki/bin/view/CCB/PipelineWorkflows &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization47.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization48.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Neonate Infant Pain Score (NIPS) Data (Vitamin K shots) Dataset===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;A short version of the Neonate Infant Pain Score (NIPS) Data (Vitamin K shots) dataset, http://wiki.socr.umich.edu/index.php/SOCR_Data_NIPS_InfantVitK_ShotData&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|Index||Immediate||30_Sec||60_Sec||120_Sec||TotalCryTime&lt;br /&gt;
|-&lt;br /&gt;
|1||6||7||6||2||63&lt;br /&gt;
|-&lt;br /&gt;
|2||5||1||2||0||0&lt;br /&gt;
|-&lt;br /&gt;
|3||7||6||6||7||54&lt;br /&gt;
|-&lt;br /&gt;
|4||3||7||3||0||27&lt;br /&gt;
|-&lt;br /&gt;
|5||7||5||6||0||19&lt;br /&gt;
|-&lt;br /&gt;
|6||6||6||6||2||2&lt;br /&gt;
|-&lt;br /&gt;
|7||7||7||6||0||46&lt;br /&gt;
|-&lt;br /&gt;
|8||6||7||0||0||33&lt;br /&gt;
|-&lt;br /&gt;
|9||5||0||4||0||56&lt;br /&gt;
|-&lt;br /&gt;
|10||7||7||7||6||63&lt;br /&gt;
|-&lt;br /&gt;
|105||6||0||0||0||11&lt;br /&gt;
|-&lt;br /&gt;
|106||7||6||0||0||59&lt;br /&gt;
|-&lt;br /&gt;
|107||7||4||4||0||28&lt;br /&gt;
|-&lt;br /&gt;
|108||7||7||7||1||64&lt;br /&gt;
|-&lt;br /&gt;
|109||7||0||0||0||8&lt;br /&gt;
|-&lt;br /&gt;
|110||5||0||1||3||64&lt;br /&gt;
|-&lt;br /&gt;
|111||7||5||7||7||72&lt;br /&gt;
|-&lt;br /&gt;
|112||4||2||0||2||50&lt;br /&gt;
|-&lt;br /&gt;
|113||7||6||7||0||44&lt;br /&gt;
|-&lt;br /&gt;
|114||7||1||0||0||11&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
* [[SMHS_SciVisualization| Back to the Scientific Visualization section]]&lt;br /&gt;
* [[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16162</id>
		<title>SMHS SciVisualization SOCR Excel R Charts</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16162"/>
		<updated>2016-05-23T13:30:49Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Hyperbolic Visualization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - SOCR, Excel and R charts ==&lt;br /&gt;
&lt;br /&gt;
==SOCR Charts==&lt;br /&gt;
&lt;br /&gt;
*URL: http://socr.umich.edu/html/cha/ (Java applet)&lt;br /&gt;
&lt;br /&gt;
*About/List: http://wiki.stat.ucla.edu/socr/index.php/About_pages_for_SOCR_Chart_List &lt;br /&gt;
&lt;br /&gt;
*Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_ChartsActivities&lt;br /&gt;
&lt;br /&gt;
*Data: http://wiki.socr.umich.edu/index.php/SOCR_Data &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Excel Charts==&lt;br /&gt;
&lt;br /&gt;
MS Excel provides a large number of charts that can be used to quickly and effectively render complex multivariate data. For instance, the table below contains the principal component analysis (PCA) of 50 derived neuroimaging biomarkers (region of interest (ROI) by shape morphometry metric). The loadings of these 50 variables on the top 5 (most significant) principal component directions are shown in the table. Experiment with effective visualizations of these data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Hemi||ROI||measure||ROI_Measure||Dim.1||Dim.2||Dim.3||Dim.4||Dim.5&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||AvgMeanCurvature||L_insular_cortex_AvgMeanCurvature||0.72||0||0.06||0.06||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ComputeArea||L_insular_cortex_ComputeArea||0.77||0.06||0.04||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Volume||L_insular_cortex_Volume||0.72||0.09||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ShapeIndex||L_insular_cortex_ShapeIndex||0.46||0.06||0.01||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Curvedness||L_insular_cortex_Curvedness||0.78||0||0.05||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||AvgMeanCurvature||R_insular_cortex_AvgMeanCurvature||0.79||0||0.03||0.08||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ComputeArea||R_insular_cortex_ComputeArea||0.79||0.09||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Volume||R_insular_cortex_Volume||0.73||0.11||0.03||0.03||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ShapeIndex||R_insular_cortex_ShapeIndex||0.27||0.17||0||0.07||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Curvedness||R_insular_cortex_Curvedness||0.84||0.02||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||AvgMeanCurvature||L_cingulate_gyrus_AvgMeanCurvature||0.72||0||0.05||0.02||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ComputeArea||L_cingulate_gyrus_ComputeArea||0.74||0.05||0.06||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Volume||L_cingulate_gyrus_Volume||0.69||0.08||0.05||0.05||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ShapeIndex||L_cingulate_gyrus_ShapeIndex||0.53||0||0.05||0||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Curvedness||L_cingulate_gyrus_Curvedness||0.7||0.01||0.05||0.04||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||AvgMeanCurvature||R_cingulate_gyrus_AvgMeanCurvature||0.6||0||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ComputeArea||R_cingulate_gyrus_ComputeArea||0.73||0.06||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Volume||R_cingulate_gyrus_Volume||0.68||0.09||0.04||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ShapeIndex||R_cingulate_gyrus_ShapeIndex||0.56||0.01||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Curvedness||R_cingulate_gyrus_Curvedness||0.25||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||AvgMeanCurvature||L_caudate_AvgMeanCurvature||0.52||0||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ComputeArea||L_caudate_ComputeArea||0.51||0.09||0.03||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Volume||L_caudate_Volume||0.44||0.09||0.03||0.06||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ShapeIndex||L_caudate_ShapeIndex||0.2||0.03||0.04||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Curvedness||L_caudate_Curvedness||0.51||0.12||0.02||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||AvgMeanCurvature||R_caudate_AvgMeanCurvature||0.68||0.04||0.04||0.02||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ComputeArea||R_caudate_ComputeArea||0.67||0.17||0.03||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Volume||R_caudate_Volume||0.61||0.16||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ShapeIndex||R_caudate_ShapeIndex||0.18||0.02||0.03||0.11||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Curvedness||R_caudate_Curvedness||0.65||0.19||0.01||0||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||AvgMeanCurvature||L_putamen_AvgMeanCurvature||0.62||0||0.04||0.03||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ComputeArea||L_putamen_ComputeArea||0.56||0.05||0.04||0.03||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Volume||L_putamen_Volume||0.52||0.07||0.04||0.05||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ShapeIndex||L_putamen_ShapeIndex||0.06||0.13||0||0.15||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Curvedness||L_putamen_Curvedness||0.64||0.11||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||AvgMeanCurvature||R_putamen_AvgMeanCurvature||0.62||0||0.07||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ComputeArea||R_putamen_ComputeArea||0.66||0.08||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Volume||R_putamen_Volume||0.64||0.12||0.03||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ShapeIndex||R_putamen_ShapeIndex||0.15||0.24||0||0.08||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Curvedness||R_putamen_Curvedness||0.65||0.05||0.05||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||AvgMeanCurvature||L_hippocampus_AvgMeanCurvature||0.78||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ComputeArea||L_hippocampus_ComputeArea||0.75||0.07||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Volume||L_hippocampus_Volume||0.72||0.09||0.01||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ShapeIndex||L_hippocampus_ShapeIndex||0.45||0.17||0||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Curvedness||L_hippocampus_Curvedness||0.79||0.03||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||AvgMeanCurvature||R_hippocampus_AvgMeanCurvature||0.72||0||0||0.1||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ComputeArea||R_hippocampus_ComputeArea||0.71||0.09||0||0||0.05&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Volume||R_hippocampus_Volume||0.68||0.1||0||0||0.04&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ShapeIndex||R_hippocampus_ShapeIndex||0.37||0.18||0||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Curvedness||R_hippocampus_Curvedness||0.77||0.03||0||0.02||0.04&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==R-Charts==&lt;br /&gt;
&lt;br /&gt;
There are 100’s of packages and 1,000 of different charts, plots and graphs that can be generated using R. Such interactive visualizations enable deeper exploration of data, models and results. JavaScript libraries, e.g., D3, provide advantages for data visualization as these involve HTML5 and are easily shareable online. The R community is developing R interfaces to some popular JavaScript libraries to allow users to create interactive visualizations without detailed knowledge of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Examples of powerful R interactive visualization packages===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;ggplot2&amp;lt;/b&amp;gt; – http://ggplot2.org&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;ggvis&amp;lt;/b&amp;gt; – interactive plots extending the static ggplot2 charts, http://ggvis.rstudio.com&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;rCharts&amp;lt;/b&amp;gt; – R interface to multiple JavaScript charting libraries, http://rcharts.io&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;plotly&amp;lt;/b&amp;gt; – transforming ggplot2 charts into interactive plots, https://plot.ly/r &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;googleVis&amp;lt;/b&amp;gt; – Google Charts using R, http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;HTMLWidgets&amp;lt;/b&amp;gt;&lt;br /&gt;
** &amp;lt;b&amp;gt;leaflet&amp;lt;/b&amp;gt; – library for creating dynamic maps, supports panning and zooming, annotations, markers, polygons, etc. http://www.htmlwidgets.org/showcase_leaflet.html&lt;br /&gt;
** &amp;lt;b&amp;gt;dygraphs&amp;lt;/b&amp;gt; – provides mechanism for charting time-series data, supports interactive navigation features including series/point highlighting, zooming, and panning, http://www.htmlwidgets.org/showcase_dygraphs.html &lt;br /&gt;
** &amp;lt;b&amp;gt;networkD3&amp;lt;/b&amp;gt; – library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks, http://www.htmlwidgets.org/showcase_networkD3.html&lt;br /&gt;
** &amp;lt;b&amp;gt;DataTables&amp;lt;/b&amp;gt; – displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting, http://www.htmlwidgets.org/showcase_datatables.html&lt;br /&gt;
** &amp;lt;b&amp;gt;Rthreejs&amp;lt;/b&amp;gt; – features 3D scatterplots and globes based on WebGL, http://www.htmlwidgets.org/showcase_threejs.html&lt;br /&gt;
&lt;br /&gt;
*Other R graphic examples&lt;br /&gt;
** To write out plots out to file use:&lt;br /&gt;
 # pdf() command all graphs are redirected to test.pdf.  Also works with other common formats:  jpeg, png, ps, tiff.&lt;br /&gt;
 pdf(&amp;quot;C:\\Users\\Dinov\\Desktop\\test.pdf&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
 # Generates Scalable Vector Graphics (SVG) that can be edited by vector graphics software&lt;br /&gt;
 svg(&amp;quot;test.svg&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
&lt;br /&gt;
===Paired ScatterPlots===&lt;br /&gt;
&lt;br /&gt;
 set.seed(100)&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 describe(x)    # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 plot(x[,1], x[,2], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 text(x[,1]+0.03, x[,2], rownames(x))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pairs(x)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another way to generate scatterplots is by using &amp;lt;b&amp;gt;ggplot:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 x &amp;lt;- sample(1:20, 20); y &amp;lt;- sample(1:20, 20); cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), 5)  &lt;br /&gt;
 #vs. cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), each=5)&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 #  Case_03_MentalHealthServicesSurvey&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399128/download?download_frd=1&amp;amp;verifier=AG2e9QUKUm1jvDBpkX7D9jbEjKNc4irA0ECk0f7p', header=T)	&lt;br /&gt;
 head(data1)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 describe(data1)&lt;br /&gt;
&lt;br /&gt;
 plot(data1[,3], data1[,4], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 # text(data1 [,3]+0.03, data1 [,4], rownames(data1))&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # redo plots using majorfundtype FacilityType Ownership Focus&lt;br /&gt;
 # pairs(data1, na.action=na.omit)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Scatterplot with regression line. Use the “diamonds” dataset, which is a data frame with&lt;br /&gt;
 # 53,940 rows and 10 variables ()&lt;br /&gt;
 # describe(diamonds)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 # CaseStudy01_Divorce_YoungAdults&lt;br /&gt;
 # data1 &amp;lt;- read.csv('https://umich.instructure.com/files/399118/download?download_frd=1&amp;amp;verifier=ESACv31KcyiHbkPZPuT8Oo4V7XzPtgTTbs6PQLTv', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # plot variables: DIVYEAR momint dadint momclose depression livewithmom gethitched&lt;br /&gt;
&lt;br /&gt;
 set.seed(110)&lt;br /&gt;
 # par(mfrow=c(1,2))&lt;br /&gt;
 data.2 &amp;lt;- diamonds[sample(nrow(diamonds), 500), ]&lt;br /&gt;
 plot.2 &amp;lt;- qplot(price, depth, data = data.2, geom = c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), method = &amp;quot;lm&amp;quot;)&lt;br /&gt;
 plot.3 &amp;lt;- qplot(carat, price, data=data.2, geom=c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), span=0.4)&lt;br /&gt;
 print(plot.2); print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Barplots===&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 barplot(x[1:4,], ylim=c(0, max(x[1:4,])+0.3), beside=TRUE, legend.text = letters[1:4],&lt;br /&gt;
        args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:4,])),2), x=seq(1.5, 21, by=1) + sort(rep(c(0,1,2,3,4), 4)), y=as.vector(as.matrix(x[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to put error bars on barplot:&lt;br /&gt;
&lt;br /&gt;
 # 10 rows (a, b, c, …):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- rowMeans(x) * 10, ylim=c(0, 10))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Case_04_ChildTrauma&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399129/download?download_frd=1&amp;amp;verifier=Hmv0YW2Kie5ZTV9CKBUNArSHR66f3GWSmVzZDBxc', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 head(x)&lt;br /&gt;
 head(data1)&lt;br /&gt;
 # plot data&lt;br /&gt;
 data2 &amp;lt;- data1[,-5]   # remove the 5th columns text&lt;br /&gt;
 data1 &amp;lt;- data2[,-5]   # remove the 6th columns text&lt;br /&gt;
 # or data1 &amp;lt;- data1[,c(-5,-6)]&lt;br /&gt;
&lt;br /&gt;
 data2 &amp;lt;- as.data.frame(data1)&lt;br /&gt;
 Blacks &amp;lt;- data2[which(data2$\$$race==&amp;quot;black&amp;quot;),]&lt;br /&gt;
 Other &amp;lt;- data2[which(data2$\$$race==&amp;quot;other&amp;quot;),]&lt;br /&gt;
 Hispanic &amp;lt;- data2[which(data2$\$$race==&amp;quot;hispanic&amp;quot;),]&lt;br /&gt;
 White &amp;lt;- data2[which(data2$\$$race==&amp;quot;white&amp;quot;),]&lt;br /&gt;
&lt;br /&gt;
 A &amp;lt;- c(mean(Blacks$\$$age), mean(Blacks$\$$service))&lt;br /&gt;
 #colnames(A) &amp;lt;- c(&amp;quot;age &amp;quot;,&amp;quot; service &amp;quot;)  &lt;br /&gt;
 B &amp;lt;- c(mean(Other$\$$age), mean(Other$\$$service))&lt;br /&gt;
 C &amp;lt;- c(mean(Hispanic$\$$age), mean(Hispanic$\$$service))&lt;br /&gt;
 D &amp;lt;- c(mean(White$\$$age), mean(White$\$$service))&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- cbind(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
 bar &amp;lt;- barplot(x[1:2,], ylim=c(0, max(x[1:2,])+2.0), beside=TRUE, &lt;br /&gt;
 legend.text = c(&amp;quot;age&amp;quot;,&amp;quot;service&amp;quot;) ,  args.legend = list(x = &amp;quot;right&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:2,])),2), x=seq(1.4, 21, by=1.5), #y=as.vector(as.matrix(x[1:2,]))+0.3)&lt;br /&gt;
	y=11.5)&lt;br /&gt;
&lt;br /&gt;
 m &amp;lt;- x; stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 barplot(as.matrix(data1[1:4,]), ylim=c(0, max(data1[1:4,])+0.3), beside=TRUE, legend.text = data1[1:4,1], args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(data1[1:4,])),2), x=seq(1.5, 21, by=1), y=as.vector(as.matrix(data1[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Columns (A, B, C, D, E):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- colMeans(x) * 5, ylim=c(0, 5))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Histograms and Density Plots===&lt;br /&gt;
&lt;br /&gt;
 hist(x, freq=TRUE, breaks=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(density(x), lwd = 10, col=&amp;quot;green&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pie Chart===&lt;br /&gt;
&lt;br /&gt;
 # first , “A”, and second, “B”, columns&lt;br /&gt;
 par (mfrow=c(1,2))&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,2], col=rainbow(length(x[,2]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
 legend(&amp;quot;topleft&amp;quot;, legend=row.names(x), cex=1.3, bty=&amp;quot;n&amp;quot;, pch=15, pt.cex=1.8, col=rainbow(length(x[,2]), start=0.1, end=0.8), ncol=1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 You can export the data: &lt;br /&gt;
 write.table(x, &amp;quot; &amp;quot;, &amp;quot;data.txt&amp;quot;)&lt;br /&gt;
 # copy-paste it in SOCR Pie chart to generate another Pie view of data&lt;br /&gt;
&lt;br /&gt;
===Line Plots Using ggplot===&lt;br /&gt;
&lt;br /&gt;
 head(diamonds)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Carat||Cut||Color||Clarity||Depth||Table||Price||X||Y||Z&lt;br /&gt;
|-&lt;br /&gt;
|1||0.23||Ideal||E||SI2||61.5||55||326||3.95||3.98||2.43&lt;br /&gt;
|-&lt;br /&gt;
|2||0.21||Premium||E||SI1||59.8||61||326||3.89||3.84||2.31&lt;br /&gt;
|-&lt;br /&gt;
|3||0.23||Good||E||VS1||56.9||65||237||4.05||4.07||2.31&lt;br /&gt;
|-&lt;br /&gt;
|4||0.29||Premium||I||VS2||62.4||58||334||4.2||4.23||2.63&lt;br /&gt;
|-&lt;br /&gt;
|5||0.31||Good||J||SI2||63.3||58||335||4.34||4.35||4.75&lt;br /&gt;
|-&lt;br /&gt;
|6||0.24||VeryGood||J||VVS2||62.8||57||336||3.94||3.96||2.48&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(diamonds, aes(carat, price, group=cut, color=cut)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization17.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(data1, aes(age, service, group=race, color=race)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Faceting plot (geometrically, faceting (or facetting) is the process of removing parts of a polygon, polyhedron or polytope, without creating any new vertices)&lt;br /&gt;
 plot.3 &amp;lt;- ggplot(diamonds, aes(carat, price)) + geom_line(aes(color=cut), size=1) + &lt;br /&gt;
 facet_wrap(~cut, ncol=1)&lt;br /&gt;
 print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization18.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Barplots with ggplot===&lt;br /&gt;
&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization19.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 New_var &amp;lt;- service+rnorm(1000, 0,1)&lt;br /&gt;
 data1$\$$New_var &amp;lt;- int(New_var)&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(data1, aes(race, fill= traumatype)) + geom_bar() + facet_grid(. ~ New_var)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 plot.4a &amp;lt;- ggplot(diamonds, aes(color, price/carat, fill=color)) + geom_boxplot()&lt;br /&gt;
 print(plot.4a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization20.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Jitter plot===&lt;br /&gt;
&lt;br /&gt;
 plot.5 &amp;lt;- ggplot(diamonds, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))&lt;br /&gt;
 print(plot.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization21.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Density Plots===&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(color = cut))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization22.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(data1, aes(age, size=2)) + geom_density(aes(color = traumatype))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
 plot.7 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(fill = color))&lt;br /&gt;
 print(plot.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization23.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8 &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), binwidth=0.2) + geom_density()&lt;br /&gt;
 print(plot.8)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization24.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8a &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), stat=&amp;quot;identity&amp;quot;) + geom_density()&lt;br /&gt;
 print(plot.8a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization25.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heatmaps===&lt;br /&gt;
&lt;br /&gt;
 # Generating Dendogram Association Heatmap Plot (Genotype vs. Imaging phenotype)&lt;br /&gt;
 # http://stat.ethz.ch/R-manual/R-patched/library/stats/html/heatmap.html&lt;br /&gt;
 # http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4005931/ &lt;br /&gt;
	   &lt;br /&gt;
 AD_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330387/download?download_frd=1&amp;amp;verifier=gLk2ADgrLhXGeknI6mqIeJugi2ODr8RARsQlBUMe&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
&lt;br /&gt;
 MCI_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330390/download?download_frd=1&amp;amp;verifier=FczlJD6ISRPZhu69xvHuoZHx2c7gXX9YEvvPCTBG&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 require(grDevices)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
&lt;br /&gt;
 AD_Data &amp;lt;- AD_Associations_Data &lt;br /&gt;
 MCI_Data &amp;lt;- MCI_Associations_Data &lt;br /&gt;
 NC_Data &amp;lt;- NC_Associations_Data &lt;br /&gt;
&lt;br /&gt;
 AD_mat  &amp;lt;- as.matrix(AD_Data); class(AD_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 MCI_mat  &amp;lt;- as.matrix(MCI_Data); class(MCI_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 NC_mat  &amp;lt;- as.matrix(NC_Data); class(NC_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # set up the rol (rc) and column (cc) colors for each cohort&lt;br /&gt;
 rcAD &amp;lt;- rainbow(nrow(AD_mat), start = 0, end = 1.0); ccAD&amp;lt;-rainbow(ncol(AD_mat), start = 0, end = 1.0)&lt;br /&gt;
 rcMCI &amp;lt;- rainbow(nrow(MCI_mat), start = 0, end=1.0); ccMCI&amp;lt;-rainbow(ncol(MCI_mat),start=0,end=1.0)&lt;br /&gt;
 rcNC &amp;lt;- rainbow(nrow(NC_mat), start = 0, end = 1.0); ccNC&amp;lt;-rainbow(ncol(NC_mat), start = 0, end = 1.0)&lt;br /&gt;
&lt;br /&gt;
 # set up 1x3 graph display - par (mfrow=c(1,3)) – does not work with ‘heatmap’&lt;br /&gt;
 hvAD &amp;lt;- heatmap(AD_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcAD, ColSideColors = ccAD, margins = c(2,2), main=&amp;quot;AD Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvMCI &amp;lt;- heatmap(MCI_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcMCI, ColSideColors = ccMCI, margins = c(2,2), main=&amp;quot;MCI Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvNC &amp;lt;- heatmap(NC_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcNC, ColSideColors = ccNC, margins = c(2,2), main=&amp;quot;NC Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization26.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use the R package gplots&lt;br /&gt;
 install.packages(&amp;quot;gplots&amp;quot;)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
 ## col dendrogram plotted and col reordering done. &lt;br /&gt;
 # heatmap.2(AD_mat, keysize=2) &lt;br /&gt;
 ## A more decorative heatmap, with z-score scaling along columns &lt;br /&gt;
 heatmap.2(AD_mat, col=cm.colors(255), scale=&amp;quot;column&amp;quot;, RowSideColors=rcAD, ColSideColors=ccAD, margin=c(8, 7), xlab=&amp;quot;Imaging Biomarkers (ROI volume)&amp;quot;, ylab= &amp;quot;Genetics Biomarkers (SNPs)&amp;quot;, main=&amp;quot;AD Associations Heatmap (SNP-Imaging)&amp;quot;,     tracecol=&amp;quot;green&amp;quot;, density=&amp;quot;density&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization27.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Correlation Plots===&lt;br /&gt;
&lt;br /&gt;
 The &amp;lt;b&amp;gt;corrplot&amp;lt;/b&amp;gt; package is a graphical display of a correlation matrix and confidence intervals, with some tools for matrix reordering. There are seven visualization methods (parameter method) in corrplot package, named   &amp;quot;circle&amp;quot;, &amp;quot;square&amp;quot;, &amp;quot;ellipse&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;shade&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;pie&amp;quot;.&lt;br /&gt;
 # install.packages(&amp;quot;corrplot&amp;quot;)&lt;br /&gt;
 library(corrplot)&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
 M &amp;lt;- cor(NC_Associations_Data)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization28.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hyperbolic Visualization===&lt;br /&gt;
&lt;br /&gt;
*URL: http://socr.umich.edu/html/Navigators.html  &lt;br /&gt;
&lt;br /&gt;
*Tools:&lt;br /&gt;
** Java/Jar applet: http://socr.umich.edu/html/navigators/HW/jars/SOCR_HW_Viewer.jar&lt;br /&gt;
** JavaScript: http://socr.umich.edu/html/navigators/D3/SOCR_D3_Viewer.html (JSON)&lt;br /&gt;
&lt;br /&gt;
*Data Format&lt;br /&gt;
** XML data: http://socr.umich.edu/html/navigators/HW/SOCR_HyperTree.xml&lt;br /&gt;
** JSON data: http://socr.umich.edu/html/navigators/D3/xml/SOCR_HyperTree.json&lt;br /&gt;
&lt;br /&gt;
*D3 Visualization&lt;br /&gt;
** E:\Ivo.dir\Research\UMichigan\Education_Teaching_Curricula\2015_2016\HS_853_Fall_2015\Modules_docx\Tools\TreeViewer_JS&lt;br /&gt;
** treeJS.json&lt;br /&gt;
** flareD3.json&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization29.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization30.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*URL: https://github.com/mbostock/d3/wiki/Gallery&lt;br /&gt;
&lt;br /&gt;
*Source code: https://github.com/mbostock/d3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization31.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Motion Charts===&lt;br /&gt;
&lt;br /&gt;
*Video: http://www.socr.ucla.edu/SOCR_MotionCharts/SOCR_HTML5_MotionChart_Video2.gif&lt;br /&gt;
&lt;br /&gt;
*Java: http://www.socr.ucla.edu/SOCR_MotionCharts/ &lt;br /&gt;
&lt;br /&gt;
*HTML5: http://socr.umich.edu/HTML5/MotionChart/ &lt;br /&gt;
&lt;br /&gt;
*Activities: http://wiki.socr.umich.edu/index.php/SOCR_MotionCharts &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization32.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1D/2D/3D signal/area/volume/surface/model/atlas visualization===&lt;br /&gt;
&lt;br /&gt;
*1D: (See R/SOCR Visualization tools above)&lt;br /&gt;
&lt;br /&gt;
*2D: http://imagej.nih.gov/ij/ &lt;br /&gt;
&lt;br /&gt;
*3D: http://socr.umich.edu/HTML5/BrainViewer/ &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;Supported File Formats:&amp;lt;/b&amp;gt;&lt;br /&gt;
 Volumes (.nii / .nii.gz / .img&amp;amp;.hdr / .mgh / .mgz / .nrrd)&lt;br /&gt;
 Shapes (.dx / .vtk / .stl / FreeSurfer)&lt;br /&gt;
 Fibers (.trk)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization33.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trees and Graphs===&lt;br /&gt;
&lt;br /&gt;
*Trees/Hierarchies and general Graphs&lt;br /&gt;
&lt;br /&gt;
 # Install and load the APE package, needed for the phylogenetic tree rendering (as.phylo)&lt;br /&gt;
 # install.packages(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Load data &lt;br /&gt;
&lt;br /&gt;
 # Data: 02_Nof1_Data.csv&lt;br /&gt;
 data.1 &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clustering&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.1), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;,&amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA),&amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization34.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 (x &amp;lt;- identify(hc)) ##  Terminate with 2nd mouse button !!&lt;br /&gt;
 identify(hc, &amp;lt;mark&amp;gt;function(k)&amp;lt;/mark&amp;gt; print(table(data.1[k,5])))&lt;br /&gt;
&lt;br /&gt;
You can now cut the tree into branches. You can split the tree into 2 groups, by setting the number of cuts with the k=2 parameter, or by specifying height to cut the tree at (?cutree):&lt;br /&gt;
&lt;br /&gt;
k- an integer scalar or vector with the desired number of groups&lt;br /&gt;
&lt;br /&gt;
h- numeric scalar or vector with heights where the tree should be cut&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the clustering method &lt;br /&gt;
 # for the particular agglomeration.&lt;br /&gt;
 cutree(hc, h= 50) # cut at h=50&lt;br /&gt;
 table(cutree(hc, h= 50)) # cluster distribution&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=5; &lt;br /&gt;
 myClusters = sapply(2:10,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:10, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 groups.10 &amp;lt;- cutree(hc, k = 10)	&lt;br /&gt;
 sapply(unique(groups.10),function(g)data.1$\$$ID[groups.10 == g])&lt;br /&gt;
 #To see which Treatments (Tx) are in which clusters:&lt;br /&gt;
 groups.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.2),function(g)data.1$\$$Tx[groups.2 == g])&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.2, data.1$\$$Tx)&lt;br /&gt;
 # For a small number of observations, we can often interpret the cluster solution directly by looking &lt;br /&gt;
 # at the labels of the observations that are in each cluster. &lt;br /&gt;
 # This is hard for larger data sets. To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;aggregate&amp;lt;/b&amp;gt; function will compute stats (e.g., median) on many variables simultaneously. &lt;br /&gt;
&lt;br /&gt;
To look at the median values for the variables we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
&lt;br /&gt;
 aggregate(data.1, list(groups.10),median) # may have to &amp;lt;b&amp;gt;shrink data.1&amp;lt;/b&amp;gt; prior to clustering! &lt;br /&gt;
 # data.2 &amp;lt;- data.1[,-c(1,3)]  # Remove ID and Tx variables?&lt;br /&gt;
 aggregate(data.2, list(groups.2),median) # for only 2 clusters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Group||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 table(groups.2, data.1$\$$&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 describe(data.1$\$$PhyAct)&lt;br /&gt;
&lt;br /&gt;
 # It’s useful to add the numbers of observations in each group (aggregate returns a data frame, &lt;br /&gt;
 # that can be manipulated)&lt;br /&gt;
&lt;br /&gt;
 df.2 &amp;lt;- aggregate(data.1, list(groups.2),median)&lt;br /&gt;
&lt;br /&gt;
 data.frame(Cluster= df.2[,1], Freq=as.vector(table(groups.2)), df.2[,-1])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Cluster||&amp;lt;mark&amp;gt;Freq&amp;lt;/mark&amp;gt;||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||&amp;lt;mark&amp;gt;570&amp;lt;/mark&amp;gt;||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||&amp;lt;mark&amp;gt;330&amp;lt;/mark&amp;gt;||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
*This paper examines nasal and bronchial tissue cultures as appropriate in vitro models for the assessment of smoking-induced adverse effects in the respiratory system (doi: 10.1177/1091581814551647), using “hclust” package. No data.&lt;br /&gt;
&lt;br /&gt;
*This paper classified subtypes of gastric cancer based on epidemiologic and histologic and gene expression data. These new classifications of gastric cancer have implications for improving our understanding of disease biology and identification of unique molecular drivers for each gastric cancer subtype (doi: 10.1158/1078-0432.CCR-10-2203).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Repeat the clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # using centroids and squared Euclidean distance&lt;br /&gt;
 # cut the tree into 10 clusters and reconstruct the upper part of the tree from the cluster centers.&lt;br /&gt;
 hc &amp;lt;- hclust(dist(data.1), &amp;quot;cen&amp;quot;)&lt;br /&gt;
 mem &amp;lt;- cutree(hc, k = 10)&lt;br /&gt;
 cent &amp;lt;- NULL&lt;br /&gt;
 for(k in 1:10){&lt;br /&gt;
  		cent &amp;lt;- rbind(cent, colMeans(data.1[mem == k, , drop = FALSE]))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 hc1 &amp;lt;- hclust(dist(cent), method = &amp;quot;cen&amp;quot;, members = table(mem))&lt;br /&gt;
&lt;br /&gt;
 opar &amp;lt;- par(mfrow = c(1, 2))&lt;br /&gt;
 plot(hc,  labels = FALSE, hang = -1, main = &amp;quot;Original Tree&amp;quot;)&lt;br /&gt;
 plot(hc1, hang = -1, main = &amp;quot;Re-start from 10 clusters&amp;quot;)&lt;br /&gt;
 par(opar)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization35.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Identify subjects within each of the 10 classes&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rect.hclust(hc, h=10) &lt;br /&gt;
&lt;br /&gt;
 # To save the cluster numbers to a new variable in the dataset, use the cutree function.&lt;br /&gt;
 # data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct||&amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;CluserID&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53||1&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73||1&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23||2&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36||2&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21||2&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0||2&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Phylogenetic tree diagram&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc1), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;, tip.color = hsv(runif(15, 0.65, 0.95), 1, 1, 0.7), label.offset = 1, cex = log(data.1$\$$ID, 10), col = &amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization36.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization37.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity (Health Behavior Risks)===&lt;br /&gt;
&lt;br /&gt;
 # load data CaseStudy09_HealthBehaviorRisks_Data&lt;br /&gt;
 data.2 &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/399182/download?download_frd=1 &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # Classify the cases using these variables:  &amp;quot;AGE_G&amp;quot;    &amp;quot;SEX&amp;quot;      &amp;quot;RACEGR3&amp;quot;  &amp;quot;IMPEDUC&amp;quot;  &amp;quot;IMPMRTL&amp;quot;  &lt;br /&gt;
 #	&amp;quot;EMPLOY1&amp;quot;  &amp;quot;INCOMG&amp;quot;  &amp;quot;CVDINFR4&amp;quot; &amp;quot;CVDCRHD4&amp;quot; &amp;quot;CVDSTRK3&amp;quot; &amp;quot;DIABETE3&amp;quot; &amp;quot;RFSMOK3&amp;quot;  &lt;br /&gt;
 #	&amp;quot;FRTLT1&amp;quot;   &amp;quot;VEGLT1&amp;quot; &lt;br /&gt;
 data.raw &amp;lt;- data.2[,-c(1,14,17)]&lt;br /&gt;
&lt;br /&gt;
 # Does the classification match either of these: &lt;br /&gt;
 #	TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t know/Refused/Missing)&lt;br /&gt;
 #	RFDRHV4 (Heavy alcohol consumption, 1=No, 2=Yes, 9=Don’t know/Refused/Missing)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.raw), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;, &amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA), &amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
 &lt;br /&gt;
 summary(data.2$\$$TOTINDA); summary(data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the &lt;br /&gt;
 # clustering method for the particular agglomeration -- cutree(hc, h= 10)&lt;br /&gt;
&lt;br /&gt;
 table(cutree(hc, h= 10)) # cluster distribution&lt;br /&gt;
&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to sapply -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=4; &lt;br /&gt;
 myClusters = sapply(2:5,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:5, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 table(cutree(hc, k=2)) &lt;br /&gt;
 groups.k.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.k.2),function(g)data.2$\$$ID[groups.k.2 == g])&lt;br /&gt;
&lt;br /&gt;
 #To see which TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t &lt;br /&gt;
 # 	know/Refused/Missing) &amp;amp; whch RFDRHV4 are in which clusters:&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4[groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Perhaps there are intrinsically 3 groups here e.g., 1, 2 and 9 …&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4 [groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Note that there is quite a dependence between the outcome variables …&lt;br /&gt;
 plot(data.2$\$$RFDRHV4, data.2$\$$TOTINDA)&lt;br /&gt;
&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.k.3, data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 # To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. The aggregate function will compute stats&lt;br /&gt;
 # (e.g., median) on many variables simultaneously. To look at the median values for the variables &lt;br /&gt;
 # we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
 aggregate(data.2, list(groups.k.3),median) &lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
*[[SMHS_SciVisualization_NetworkViz|Next See the Complex Network Visualization section]]&lt;br /&gt;
*[[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16161</id>
		<title>SMHS SciVisualization SOCR Excel R Charts</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16161"/>
		<updated>2016-05-23T13:30:23Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Examples of powerful R interactive visualization packages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - SOCR, Excel and R charts ==&lt;br /&gt;
&lt;br /&gt;
==SOCR Charts==&lt;br /&gt;
&lt;br /&gt;
*URL: http://socr.umich.edu/html/cha/ (Java applet)&lt;br /&gt;
&lt;br /&gt;
*About/List: http://wiki.stat.ucla.edu/socr/index.php/About_pages_for_SOCR_Chart_List &lt;br /&gt;
&lt;br /&gt;
*Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_ChartsActivities&lt;br /&gt;
&lt;br /&gt;
*Data: http://wiki.socr.umich.edu/index.php/SOCR_Data &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Excel Charts==&lt;br /&gt;
&lt;br /&gt;
MS Excel provides a large number of charts that can be used to quickly and effectively render complex multivariate data. For instance, the table below contains the principal component analysis (PCA) of 50 derived neuroimaging biomarkers (region of interest (ROI) by shape morphometry metric). The loadings of these 50 variables on the top 5 (most significant) principal component directions are shown in the table. Experiment with effective visualizations of these data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Hemi||ROI||measure||ROI_Measure||Dim.1||Dim.2||Dim.3||Dim.4||Dim.5&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||AvgMeanCurvature||L_insular_cortex_AvgMeanCurvature||0.72||0||0.06||0.06||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ComputeArea||L_insular_cortex_ComputeArea||0.77||0.06||0.04||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Volume||L_insular_cortex_Volume||0.72||0.09||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ShapeIndex||L_insular_cortex_ShapeIndex||0.46||0.06||0.01||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Curvedness||L_insular_cortex_Curvedness||0.78||0||0.05||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||AvgMeanCurvature||R_insular_cortex_AvgMeanCurvature||0.79||0||0.03||0.08||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ComputeArea||R_insular_cortex_ComputeArea||0.79||0.09||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Volume||R_insular_cortex_Volume||0.73||0.11||0.03||0.03||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ShapeIndex||R_insular_cortex_ShapeIndex||0.27||0.17||0||0.07||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Curvedness||R_insular_cortex_Curvedness||0.84||0.02||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||AvgMeanCurvature||L_cingulate_gyrus_AvgMeanCurvature||0.72||0||0.05||0.02||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ComputeArea||L_cingulate_gyrus_ComputeArea||0.74||0.05||0.06||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Volume||L_cingulate_gyrus_Volume||0.69||0.08||0.05||0.05||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ShapeIndex||L_cingulate_gyrus_ShapeIndex||0.53||0||0.05||0||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Curvedness||L_cingulate_gyrus_Curvedness||0.7||0.01||0.05||0.04||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||AvgMeanCurvature||R_cingulate_gyrus_AvgMeanCurvature||0.6||0||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ComputeArea||R_cingulate_gyrus_ComputeArea||0.73||0.06||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Volume||R_cingulate_gyrus_Volume||0.68||0.09||0.04||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ShapeIndex||R_cingulate_gyrus_ShapeIndex||0.56||0.01||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Curvedness||R_cingulate_gyrus_Curvedness||0.25||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||AvgMeanCurvature||L_caudate_AvgMeanCurvature||0.52||0||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ComputeArea||L_caudate_ComputeArea||0.51||0.09||0.03||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Volume||L_caudate_Volume||0.44||0.09||0.03||0.06||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ShapeIndex||L_caudate_ShapeIndex||0.2||0.03||0.04||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Curvedness||L_caudate_Curvedness||0.51||0.12||0.02||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||AvgMeanCurvature||R_caudate_AvgMeanCurvature||0.68||0.04||0.04||0.02||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ComputeArea||R_caudate_ComputeArea||0.67||0.17||0.03||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Volume||R_caudate_Volume||0.61||0.16||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ShapeIndex||R_caudate_ShapeIndex||0.18||0.02||0.03||0.11||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Curvedness||R_caudate_Curvedness||0.65||0.19||0.01||0||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||AvgMeanCurvature||L_putamen_AvgMeanCurvature||0.62||0||0.04||0.03||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ComputeArea||L_putamen_ComputeArea||0.56||0.05||0.04||0.03||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Volume||L_putamen_Volume||0.52||0.07||0.04||0.05||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ShapeIndex||L_putamen_ShapeIndex||0.06||0.13||0||0.15||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Curvedness||L_putamen_Curvedness||0.64||0.11||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||AvgMeanCurvature||R_putamen_AvgMeanCurvature||0.62||0||0.07||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ComputeArea||R_putamen_ComputeArea||0.66||0.08||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Volume||R_putamen_Volume||0.64||0.12||0.03||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ShapeIndex||R_putamen_ShapeIndex||0.15||0.24||0||0.08||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Curvedness||R_putamen_Curvedness||0.65||0.05||0.05||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||AvgMeanCurvature||L_hippocampus_AvgMeanCurvature||0.78||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ComputeArea||L_hippocampus_ComputeArea||0.75||0.07||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Volume||L_hippocampus_Volume||0.72||0.09||0.01||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ShapeIndex||L_hippocampus_ShapeIndex||0.45||0.17||0||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Curvedness||L_hippocampus_Curvedness||0.79||0.03||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||AvgMeanCurvature||R_hippocampus_AvgMeanCurvature||0.72||0||0||0.1||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ComputeArea||R_hippocampus_ComputeArea||0.71||0.09||0||0||0.05&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Volume||R_hippocampus_Volume||0.68||0.1||0||0||0.04&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ShapeIndex||R_hippocampus_ShapeIndex||0.37||0.18||0||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Curvedness||R_hippocampus_Curvedness||0.77||0.03||0||0.02||0.04&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==R-Charts==&lt;br /&gt;
&lt;br /&gt;
There are 100’s of packages and 1,000 of different charts, plots and graphs that can be generated using R. Such interactive visualizations enable deeper exploration of data, models and results. JavaScript libraries, e.g., D3, provide advantages for data visualization as these involve HTML5 and are easily shareable online. The R community is developing R interfaces to some popular JavaScript libraries to allow users to create interactive visualizations without detailed knowledge of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Examples of powerful R interactive visualization packages===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;ggplot2&amp;lt;/b&amp;gt; – http://ggplot2.org&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;ggvis&amp;lt;/b&amp;gt; – interactive plots extending the static ggplot2 charts, http://ggvis.rstudio.com&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;rCharts&amp;lt;/b&amp;gt; – R interface to multiple JavaScript charting libraries, http://rcharts.io&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;plotly&amp;lt;/b&amp;gt; – transforming ggplot2 charts into interactive plots, https://plot.ly/r &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;googleVis&amp;lt;/b&amp;gt; – Google Charts using R, http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;HTMLWidgets&amp;lt;/b&amp;gt;&lt;br /&gt;
** &amp;lt;b&amp;gt;leaflet&amp;lt;/b&amp;gt; – library for creating dynamic maps, supports panning and zooming, annotations, markers, polygons, etc. http://www.htmlwidgets.org/showcase_leaflet.html&lt;br /&gt;
** &amp;lt;b&amp;gt;dygraphs&amp;lt;/b&amp;gt; – provides mechanism for charting time-series data, supports interactive navigation features including series/point highlighting, zooming, and panning, http://www.htmlwidgets.org/showcase_dygraphs.html &lt;br /&gt;
** &amp;lt;b&amp;gt;networkD3&amp;lt;/b&amp;gt; – library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks, http://www.htmlwidgets.org/showcase_networkD3.html&lt;br /&gt;
** &amp;lt;b&amp;gt;DataTables&amp;lt;/b&amp;gt; – displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting, http://www.htmlwidgets.org/showcase_datatables.html&lt;br /&gt;
** &amp;lt;b&amp;gt;Rthreejs&amp;lt;/b&amp;gt; – features 3D scatterplots and globes based on WebGL, http://www.htmlwidgets.org/showcase_threejs.html&lt;br /&gt;
&lt;br /&gt;
*Other R graphic examples&lt;br /&gt;
** To write out plots out to file use:&lt;br /&gt;
 # pdf() command all graphs are redirected to test.pdf.  Also works with other common formats:  jpeg, png, ps, tiff.&lt;br /&gt;
 pdf(&amp;quot;C:\\Users\\Dinov\\Desktop\\test.pdf&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
 # Generates Scalable Vector Graphics (SVG) that can be edited by vector graphics software&lt;br /&gt;
 svg(&amp;quot;test.svg&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
&lt;br /&gt;
===Paired ScatterPlots===&lt;br /&gt;
&lt;br /&gt;
 set.seed(100)&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 describe(x)    # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 plot(x[,1], x[,2], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 text(x[,1]+0.03, x[,2], rownames(x))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pairs(x)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another way to generate scatterplots is by using &amp;lt;b&amp;gt;ggplot:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 x &amp;lt;- sample(1:20, 20); y &amp;lt;- sample(1:20, 20); cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), 5)  &lt;br /&gt;
 #vs. cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), each=5)&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 #  Case_03_MentalHealthServicesSurvey&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399128/download?download_frd=1&amp;amp;verifier=AG2e9QUKUm1jvDBpkX7D9jbEjKNc4irA0ECk0f7p', header=T)	&lt;br /&gt;
 head(data1)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 describe(data1)&lt;br /&gt;
&lt;br /&gt;
 plot(data1[,3], data1[,4], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 # text(data1 [,3]+0.03, data1 [,4], rownames(data1))&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # redo plots using majorfundtype FacilityType Ownership Focus&lt;br /&gt;
 # pairs(data1, na.action=na.omit)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Scatterplot with regression line. Use the “diamonds” dataset, which is a data frame with&lt;br /&gt;
 # 53,940 rows and 10 variables ()&lt;br /&gt;
 # describe(diamonds)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 # CaseStudy01_Divorce_YoungAdults&lt;br /&gt;
 # data1 &amp;lt;- read.csv('https://umich.instructure.com/files/399118/download?download_frd=1&amp;amp;verifier=ESACv31KcyiHbkPZPuT8Oo4V7XzPtgTTbs6PQLTv', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # plot variables: DIVYEAR momint dadint momclose depression livewithmom gethitched&lt;br /&gt;
&lt;br /&gt;
 set.seed(110)&lt;br /&gt;
 # par(mfrow=c(1,2))&lt;br /&gt;
 data.2 &amp;lt;- diamonds[sample(nrow(diamonds), 500), ]&lt;br /&gt;
 plot.2 &amp;lt;- qplot(price, depth, data = data.2, geom = c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), method = &amp;quot;lm&amp;quot;)&lt;br /&gt;
 plot.3 &amp;lt;- qplot(carat, price, data=data.2, geom=c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), span=0.4)&lt;br /&gt;
 print(plot.2); print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Barplots===&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 barplot(x[1:4,], ylim=c(0, max(x[1:4,])+0.3), beside=TRUE, legend.text = letters[1:4],&lt;br /&gt;
        args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:4,])),2), x=seq(1.5, 21, by=1) + sort(rep(c(0,1,2,3,4), 4)), y=as.vector(as.matrix(x[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to put error bars on barplot:&lt;br /&gt;
&lt;br /&gt;
 # 10 rows (a, b, c, …):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- rowMeans(x) * 10, ylim=c(0, 10))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Case_04_ChildTrauma&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399129/download?download_frd=1&amp;amp;verifier=Hmv0YW2Kie5ZTV9CKBUNArSHR66f3GWSmVzZDBxc', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 head(x)&lt;br /&gt;
 head(data1)&lt;br /&gt;
 # plot data&lt;br /&gt;
 data2 &amp;lt;- data1[,-5]   # remove the 5th columns text&lt;br /&gt;
 data1 &amp;lt;- data2[,-5]   # remove the 6th columns text&lt;br /&gt;
 # or data1 &amp;lt;- data1[,c(-5,-6)]&lt;br /&gt;
&lt;br /&gt;
 data2 &amp;lt;- as.data.frame(data1)&lt;br /&gt;
 Blacks &amp;lt;- data2[which(data2$\$$race==&amp;quot;black&amp;quot;),]&lt;br /&gt;
 Other &amp;lt;- data2[which(data2$\$$race==&amp;quot;other&amp;quot;),]&lt;br /&gt;
 Hispanic &amp;lt;- data2[which(data2$\$$race==&amp;quot;hispanic&amp;quot;),]&lt;br /&gt;
 White &amp;lt;- data2[which(data2$\$$race==&amp;quot;white&amp;quot;),]&lt;br /&gt;
&lt;br /&gt;
 A &amp;lt;- c(mean(Blacks$\$$age), mean(Blacks$\$$service))&lt;br /&gt;
 #colnames(A) &amp;lt;- c(&amp;quot;age &amp;quot;,&amp;quot; service &amp;quot;)  &lt;br /&gt;
 B &amp;lt;- c(mean(Other$\$$age), mean(Other$\$$service))&lt;br /&gt;
 C &amp;lt;- c(mean(Hispanic$\$$age), mean(Hispanic$\$$service))&lt;br /&gt;
 D &amp;lt;- c(mean(White$\$$age), mean(White$\$$service))&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- cbind(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
 bar &amp;lt;- barplot(x[1:2,], ylim=c(0, max(x[1:2,])+2.0), beside=TRUE, &lt;br /&gt;
 legend.text = c(&amp;quot;age&amp;quot;,&amp;quot;service&amp;quot;) ,  args.legend = list(x = &amp;quot;right&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:2,])),2), x=seq(1.4, 21, by=1.5), #y=as.vector(as.matrix(x[1:2,]))+0.3)&lt;br /&gt;
	y=11.5)&lt;br /&gt;
&lt;br /&gt;
 m &amp;lt;- x; stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 barplot(as.matrix(data1[1:4,]), ylim=c(0, max(data1[1:4,])+0.3), beside=TRUE, legend.text = data1[1:4,1], args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(data1[1:4,])),2), x=seq(1.5, 21, by=1), y=as.vector(as.matrix(data1[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Columns (A, B, C, D, E):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- colMeans(x) * 5, ylim=c(0, 5))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Histograms and Density Plots===&lt;br /&gt;
&lt;br /&gt;
 hist(x, freq=TRUE, breaks=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(density(x), lwd = 10, col=&amp;quot;green&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pie Chart===&lt;br /&gt;
&lt;br /&gt;
 # first , “A”, and second, “B”, columns&lt;br /&gt;
 par (mfrow=c(1,2))&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,2], col=rainbow(length(x[,2]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
 legend(&amp;quot;topleft&amp;quot;, legend=row.names(x), cex=1.3, bty=&amp;quot;n&amp;quot;, pch=15, pt.cex=1.8, col=rainbow(length(x[,2]), start=0.1, end=0.8), ncol=1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 You can export the data: &lt;br /&gt;
 write.table(x, &amp;quot; &amp;quot;, &amp;quot;data.txt&amp;quot;)&lt;br /&gt;
 # copy-paste it in SOCR Pie chart to generate another Pie view of data&lt;br /&gt;
&lt;br /&gt;
===Line Plots Using ggplot===&lt;br /&gt;
&lt;br /&gt;
 head(diamonds)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Carat||Cut||Color||Clarity||Depth||Table||Price||X||Y||Z&lt;br /&gt;
|-&lt;br /&gt;
|1||0.23||Ideal||E||SI2||61.5||55||326||3.95||3.98||2.43&lt;br /&gt;
|-&lt;br /&gt;
|2||0.21||Premium||E||SI1||59.8||61||326||3.89||3.84||2.31&lt;br /&gt;
|-&lt;br /&gt;
|3||0.23||Good||E||VS1||56.9||65||237||4.05||4.07||2.31&lt;br /&gt;
|-&lt;br /&gt;
|4||0.29||Premium||I||VS2||62.4||58||334||4.2||4.23||2.63&lt;br /&gt;
|-&lt;br /&gt;
|5||0.31||Good||J||SI2||63.3||58||335||4.34||4.35||4.75&lt;br /&gt;
|-&lt;br /&gt;
|6||0.24||VeryGood||J||VVS2||62.8||57||336||3.94||3.96||2.48&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(diamonds, aes(carat, price, group=cut, color=cut)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization17.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(data1, aes(age, service, group=race, color=race)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Faceting plot (geometrically, faceting (or facetting) is the process of removing parts of a polygon, polyhedron or polytope, without creating any new vertices)&lt;br /&gt;
 plot.3 &amp;lt;- ggplot(diamonds, aes(carat, price)) + geom_line(aes(color=cut), size=1) + &lt;br /&gt;
 facet_wrap(~cut, ncol=1)&lt;br /&gt;
 print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization18.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Barplots with ggplot===&lt;br /&gt;
&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization19.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 New_var &amp;lt;- service+rnorm(1000, 0,1)&lt;br /&gt;
 data1$\$$New_var &amp;lt;- int(New_var)&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(data1, aes(race, fill= traumatype)) + geom_bar() + facet_grid(. ~ New_var)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 plot.4a &amp;lt;- ggplot(diamonds, aes(color, price/carat, fill=color)) + geom_boxplot()&lt;br /&gt;
 print(plot.4a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization20.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Jitter plot===&lt;br /&gt;
&lt;br /&gt;
 plot.5 &amp;lt;- ggplot(diamonds, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))&lt;br /&gt;
 print(plot.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization21.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Density Plots===&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(color = cut))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization22.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(data1, aes(age, size=2)) + geom_density(aes(color = traumatype))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
 plot.7 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(fill = color))&lt;br /&gt;
 print(plot.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization23.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8 &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), binwidth=0.2) + geom_density()&lt;br /&gt;
 print(plot.8)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization24.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8a &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), stat=&amp;quot;identity&amp;quot;) + geom_density()&lt;br /&gt;
 print(plot.8a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization25.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heatmaps===&lt;br /&gt;
&lt;br /&gt;
 # Generating Dendogram Association Heatmap Plot (Genotype vs. Imaging phenotype)&lt;br /&gt;
 # http://stat.ethz.ch/R-manual/R-patched/library/stats/html/heatmap.html&lt;br /&gt;
 # http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4005931/ &lt;br /&gt;
	   &lt;br /&gt;
 AD_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330387/download?download_frd=1&amp;amp;verifier=gLk2ADgrLhXGeknI6mqIeJugi2ODr8RARsQlBUMe&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
&lt;br /&gt;
 MCI_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330390/download?download_frd=1&amp;amp;verifier=FczlJD6ISRPZhu69xvHuoZHx2c7gXX9YEvvPCTBG&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 require(grDevices)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
&lt;br /&gt;
 AD_Data &amp;lt;- AD_Associations_Data &lt;br /&gt;
 MCI_Data &amp;lt;- MCI_Associations_Data &lt;br /&gt;
 NC_Data &amp;lt;- NC_Associations_Data &lt;br /&gt;
&lt;br /&gt;
 AD_mat  &amp;lt;- as.matrix(AD_Data); class(AD_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 MCI_mat  &amp;lt;- as.matrix(MCI_Data); class(MCI_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 NC_mat  &amp;lt;- as.matrix(NC_Data); class(NC_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # set up the rol (rc) and column (cc) colors for each cohort&lt;br /&gt;
 rcAD &amp;lt;- rainbow(nrow(AD_mat), start = 0, end = 1.0); ccAD&amp;lt;-rainbow(ncol(AD_mat), start = 0, end = 1.0)&lt;br /&gt;
 rcMCI &amp;lt;- rainbow(nrow(MCI_mat), start = 0, end=1.0); ccMCI&amp;lt;-rainbow(ncol(MCI_mat),start=0,end=1.0)&lt;br /&gt;
 rcNC &amp;lt;- rainbow(nrow(NC_mat), start = 0, end = 1.0); ccNC&amp;lt;-rainbow(ncol(NC_mat), start = 0, end = 1.0)&lt;br /&gt;
&lt;br /&gt;
 # set up 1x3 graph display - par (mfrow=c(1,3)) – does not work with ‘heatmap’&lt;br /&gt;
 hvAD &amp;lt;- heatmap(AD_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcAD, ColSideColors = ccAD, margins = c(2,2), main=&amp;quot;AD Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvMCI &amp;lt;- heatmap(MCI_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcMCI, ColSideColors = ccMCI, margins = c(2,2), main=&amp;quot;MCI Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvNC &amp;lt;- heatmap(NC_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcNC, ColSideColors = ccNC, margins = c(2,2), main=&amp;quot;NC Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization26.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use the R package gplots&lt;br /&gt;
 install.packages(&amp;quot;gplots&amp;quot;)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
 ## col dendrogram plotted and col reordering done. &lt;br /&gt;
 # heatmap.2(AD_mat, keysize=2) &lt;br /&gt;
 ## A more decorative heatmap, with z-score scaling along columns &lt;br /&gt;
 heatmap.2(AD_mat, col=cm.colors(255), scale=&amp;quot;column&amp;quot;, RowSideColors=rcAD, ColSideColors=ccAD, margin=c(8, 7), xlab=&amp;quot;Imaging Biomarkers (ROI volume)&amp;quot;, ylab= &amp;quot;Genetics Biomarkers (SNPs)&amp;quot;, main=&amp;quot;AD Associations Heatmap (SNP-Imaging)&amp;quot;,     tracecol=&amp;quot;green&amp;quot;, density=&amp;quot;density&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization27.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Correlation Plots===&lt;br /&gt;
&lt;br /&gt;
 The &amp;lt;b&amp;gt;corrplot&amp;lt;/b&amp;gt; package is a graphical display of a correlation matrix and confidence intervals, with some tools for matrix reordering. There are seven visualization methods (parameter method) in corrplot package, named   &amp;quot;circle&amp;quot;, &amp;quot;square&amp;quot;, &amp;quot;ellipse&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;shade&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;pie&amp;quot;.&lt;br /&gt;
 # install.packages(&amp;quot;corrplot&amp;quot;)&lt;br /&gt;
 library(corrplot)&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
 M &amp;lt;- cor(NC_Associations_Data)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization28.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hyperbolic Visualization===&lt;br /&gt;
&lt;br /&gt;
*URL: http://socr.umich.edu/html/Navigators.html  &lt;br /&gt;
&lt;br /&gt;
*Tools:&lt;br /&gt;
&lt;br /&gt;
** Java/Jar applet: http://socr.umich.edu/html/navigators/HW/jars/SOCR_HW_Viewer.jar&lt;br /&gt;
&lt;br /&gt;
** JavaScript: http://socr.umich.edu/html/navigators/D3/SOCR_D3_Viewer.html (JSON)&lt;br /&gt;
&lt;br /&gt;
*Data Format&lt;br /&gt;
&lt;br /&gt;
** XML data: http://socr.umich.edu/html/navigators/HW/SOCR_HyperTree.xml&lt;br /&gt;
&lt;br /&gt;
** JSON data: http://socr.umich.edu/html/navigators/D3/xml/SOCR_HyperTree.json&lt;br /&gt;
&lt;br /&gt;
*D3 Visualization&lt;br /&gt;
&lt;br /&gt;
** E:\Ivo.dir\Research\UMichigan\Education_Teaching_Curricula\2015_2016\HS_853_Fall_2015\Modules_docx\Tools\TreeViewer_JS&lt;br /&gt;
&lt;br /&gt;
** treeJS.json&lt;br /&gt;
&lt;br /&gt;
** flareD3.json&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization29.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization30.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*URL: https://github.com/mbostock/d3/wiki/Gallery&lt;br /&gt;
&lt;br /&gt;
*Source code: https://github.com/mbostock/d3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization31.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Motion Charts===&lt;br /&gt;
&lt;br /&gt;
*Video: http://www.socr.ucla.edu/SOCR_MotionCharts/SOCR_HTML5_MotionChart_Video2.gif&lt;br /&gt;
&lt;br /&gt;
*Java: http://www.socr.ucla.edu/SOCR_MotionCharts/ &lt;br /&gt;
&lt;br /&gt;
*HTML5: http://socr.umich.edu/HTML5/MotionChart/ &lt;br /&gt;
&lt;br /&gt;
*Activities: http://wiki.socr.umich.edu/index.php/SOCR_MotionCharts &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization32.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1D/2D/3D signal/area/volume/surface/model/atlas visualization===&lt;br /&gt;
&lt;br /&gt;
*1D: (See R/SOCR Visualization tools above)&lt;br /&gt;
&lt;br /&gt;
*2D: http://imagej.nih.gov/ij/ &lt;br /&gt;
&lt;br /&gt;
*3D: http://socr.umich.edu/HTML5/BrainViewer/ &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;Supported File Formats:&amp;lt;/b&amp;gt;&lt;br /&gt;
 Volumes (.nii / .nii.gz / .img&amp;amp;.hdr / .mgh / .mgz / .nrrd)&lt;br /&gt;
 Shapes (.dx / .vtk / .stl / FreeSurfer)&lt;br /&gt;
 Fibers (.trk)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization33.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trees and Graphs===&lt;br /&gt;
&lt;br /&gt;
*Trees/Hierarchies and general Graphs&lt;br /&gt;
&lt;br /&gt;
 # Install and load the APE package, needed for the phylogenetic tree rendering (as.phylo)&lt;br /&gt;
 # install.packages(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Load data &lt;br /&gt;
&lt;br /&gt;
 # Data: 02_Nof1_Data.csv&lt;br /&gt;
 data.1 &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clustering&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.1), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;,&amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA),&amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization34.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 (x &amp;lt;- identify(hc)) ##  Terminate with 2nd mouse button !!&lt;br /&gt;
 identify(hc, &amp;lt;mark&amp;gt;function(k)&amp;lt;/mark&amp;gt; print(table(data.1[k,5])))&lt;br /&gt;
&lt;br /&gt;
You can now cut the tree into branches. You can split the tree into 2 groups, by setting the number of cuts with the k=2 parameter, or by specifying height to cut the tree at (?cutree):&lt;br /&gt;
&lt;br /&gt;
k- an integer scalar or vector with the desired number of groups&lt;br /&gt;
&lt;br /&gt;
h- numeric scalar or vector with heights where the tree should be cut&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the clustering method &lt;br /&gt;
 # for the particular agglomeration.&lt;br /&gt;
 cutree(hc, h= 50) # cut at h=50&lt;br /&gt;
 table(cutree(hc, h= 50)) # cluster distribution&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=5; &lt;br /&gt;
 myClusters = sapply(2:10,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:10, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 groups.10 &amp;lt;- cutree(hc, k = 10)	&lt;br /&gt;
 sapply(unique(groups.10),function(g)data.1$\$$ID[groups.10 == g])&lt;br /&gt;
 #To see which Treatments (Tx) are in which clusters:&lt;br /&gt;
 groups.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.2),function(g)data.1$\$$Tx[groups.2 == g])&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.2, data.1$\$$Tx)&lt;br /&gt;
 # For a small number of observations, we can often interpret the cluster solution directly by looking &lt;br /&gt;
 # at the labels of the observations that are in each cluster. &lt;br /&gt;
 # This is hard for larger data sets. To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;aggregate&amp;lt;/b&amp;gt; function will compute stats (e.g., median) on many variables simultaneously. &lt;br /&gt;
&lt;br /&gt;
To look at the median values for the variables we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
&lt;br /&gt;
 aggregate(data.1, list(groups.10),median) # may have to &amp;lt;b&amp;gt;shrink data.1&amp;lt;/b&amp;gt; prior to clustering! &lt;br /&gt;
 # data.2 &amp;lt;- data.1[,-c(1,3)]  # Remove ID and Tx variables?&lt;br /&gt;
 aggregate(data.2, list(groups.2),median) # for only 2 clusters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Group||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 table(groups.2, data.1$\$$&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 describe(data.1$\$$PhyAct)&lt;br /&gt;
&lt;br /&gt;
 # It’s useful to add the numbers of observations in each group (aggregate returns a data frame, &lt;br /&gt;
 # that can be manipulated)&lt;br /&gt;
&lt;br /&gt;
 df.2 &amp;lt;- aggregate(data.1, list(groups.2),median)&lt;br /&gt;
&lt;br /&gt;
 data.frame(Cluster= df.2[,1], Freq=as.vector(table(groups.2)), df.2[,-1])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Cluster||&amp;lt;mark&amp;gt;Freq&amp;lt;/mark&amp;gt;||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||&amp;lt;mark&amp;gt;570&amp;lt;/mark&amp;gt;||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||&amp;lt;mark&amp;gt;330&amp;lt;/mark&amp;gt;||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
*This paper examines nasal and bronchial tissue cultures as appropriate in vitro models for the assessment of smoking-induced adverse effects in the respiratory system (doi: 10.1177/1091581814551647), using “hclust” package. No data.&lt;br /&gt;
&lt;br /&gt;
*This paper classified subtypes of gastric cancer based on epidemiologic and histologic and gene expression data. These new classifications of gastric cancer have implications for improving our understanding of disease biology and identification of unique molecular drivers for each gastric cancer subtype (doi: 10.1158/1078-0432.CCR-10-2203).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Repeat the clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # using centroids and squared Euclidean distance&lt;br /&gt;
 # cut the tree into 10 clusters and reconstruct the upper part of the tree from the cluster centers.&lt;br /&gt;
 hc &amp;lt;- hclust(dist(data.1), &amp;quot;cen&amp;quot;)&lt;br /&gt;
 mem &amp;lt;- cutree(hc, k = 10)&lt;br /&gt;
 cent &amp;lt;- NULL&lt;br /&gt;
 for(k in 1:10){&lt;br /&gt;
  		cent &amp;lt;- rbind(cent, colMeans(data.1[mem == k, , drop = FALSE]))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 hc1 &amp;lt;- hclust(dist(cent), method = &amp;quot;cen&amp;quot;, members = table(mem))&lt;br /&gt;
&lt;br /&gt;
 opar &amp;lt;- par(mfrow = c(1, 2))&lt;br /&gt;
 plot(hc,  labels = FALSE, hang = -1, main = &amp;quot;Original Tree&amp;quot;)&lt;br /&gt;
 plot(hc1, hang = -1, main = &amp;quot;Re-start from 10 clusters&amp;quot;)&lt;br /&gt;
 par(opar)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization35.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Identify subjects within each of the 10 classes&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rect.hclust(hc, h=10) &lt;br /&gt;
&lt;br /&gt;
 # To save the cluster numbers to a new variable in the dataset, use the cutree function.&lt;br /&gt;
 # data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct||&amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;CluserID&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53||1&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73||1&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23||2&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36||2&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21||2&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0||2&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Phylogenetic tree diagram&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc1), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;, tip.color = hsv(runif(15, 0.65, 0.95), 1, 1, 0.7), label.offset = 1, cex = log(data.1$\$$ID, 10), col = &amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization36.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization37.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity (Health Behavior Risks)===&lt;br /&gt;
&lt;br /&gt;
 # load data CaseStudy09_HealthBehaviorRisks_Data&lt;br /&gt;
 data.2 &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/399182/download?download_frd=1 &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # Classify the cases using these variables:  &amp;quot;AGE_G&amp;quot;    &amp;quot;SEX&amp;quot;      &amp;quot;RACEGR3&amp;quot;  &amp;quot;IMPEDUC&amp;quot;  &amp;quot;IMPMRTL&amp;quot;  &lt;br /&gt;
 #	&amp;quot;EMPLOY1&amp;quot;  &amp;quot;INCOMG&amp;quot;  &amp;quot;CVDINFR4&amp;quot; &amp;quot;CVDCRHD4&amp;quot; &amp;quot;CVDSTRK3&amp;quot; &amp;quot;DIABETE3&amp;quot; &amp;quot;RFSMOK3&amp;quot;  &lt;br /&gt;
 #	&amp;quot;FRTLT1&amp;quot;   &amp;quot;VEGLT1&amp;quot; &lt;br /&gt;
 data.raw &amp;lt;- data.2[,-c(1,14,17)]&lt;br /&gt;
&lt;br /&gt;
 # Does the classification match either of these: &lt;br /&gt;
 #	TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t know/Refused/Missing)&lt;br /&gt;
 #	RFDRHV4 (Heavy alcohol consumption, 1=No, 2=Yes, 9=Don’t know/Refused/Missing)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.raw), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;, &amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA), &amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
 &lt;br /&gt;
 summary(data.2$\$$TOTINDA); summary(data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the &lt;br /&gt;
 # clustering method for the particular agglomeration -- cutree(hc, h= 10)&lt;br /&gt;
&lt;br /&gt;
 table(cutree(hc, h= 10)) # cluster distribution&lt;br /&gt;
&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to sapply -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=4; &lt;br /&gt;
 myClusters = sapply(2:5,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:5, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 table(cutree(hc, k=2)) &lt;br /&gt;
 groups.k.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.k.2),function(g)data.2$\$$ID[groups.k.2 == g])&lt;br /&gt;
&lt;br /&gt;
 #To see which TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t &lt;br /&gt;
 # 	know/Refused/Missing) &amp;amp; whch RFDRHV4 are in which clusters:&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4[groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Perhaps there are intrinsically 3 groups here e.g., 1, 2 and 9 …&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4 [groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Note that there is quite a dependence between the outcome variables …&lt;br /&gt;
 plot(data.2$\$$RFDRHV4, data.2$\$$TOTINDA)&lt;br /&gt;
&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.k.3, data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 # To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. The aggregate function will compute stats&lt;br /&gt;
 # (e.g., median) on many variables simultaneously. To look at the median values for the variables &lt;br /&gt;
 # we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
 aggregate(data.2, list(groups.k.3),median) &lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
*[[SMHS_SciVisualization_NetworkViz|Next See the Complex Network Visualization section]]&lt;br /&gt;
*[[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16160</id>
		<title>SMHS SciVisualization SOCR Excel R Charts</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16160"/>
		<updated>2016-05-23T13:29:51Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - SOCR, Excel and R charts ==&lt;br /&gt;
&lt;br /&gt;
==SOCR Charts==&lt;br /&gt;
&lt;br /&gt;
*URL: http://socr.umich.edu/html/cha/ (Java applet)&lt;br /&gt;
&lt;br /&gt;
*About/List: http://wiki.stat.ucla.edu/socr/index.php/About_pages_for_SOCR_Chart_List &lt;br /&gt;
&lt;br /&gt;
*Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_ChartsActivities&lt;br /&gt;
&lt;br /&gt;
*Data: http://wiki.socr.umich.edu/index.php/SOCR_Data &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Excel Charts==&lt;br /&gt;
&lt;br /&gt;
MS Excel provides a large number of charts that can be used to quickly and effectively render complex multivariate data. For instance, the table below contains the principal component analysis (PCA) of 50 derived neuroimaging biomarkers (region of interest (ROI) by shape morphometry metric). The loadings of these 50 variables on the top 5 (most significant) principal component directions are shown in the table. Experiment with effective visualizations of these data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Hemi||ROI||measure||ROI_Measure||Dim.1||Dim.2||Dim.3||Dim.4||Dim.5&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||AvgMeanCurvature||L_insular_cortex_AvgMeanCurvature||0.72||0||0.06||0.06||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ComputeArea||L_insular_cortex_ComputeArea||0.77||0.06||0.04||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Volume||L_insular_cortex_Volume||0.72||0.09||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ShapeIndex||L_insular_cortex_ShapeIndex||0.46||0.06||0.01||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Curvedness||L_insular_cortex_Curvedness||0.78||0||0.05||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||AvgMeanCurvature||R_insular_cortex_AvgMeanCurvature||0.79||0||0.03||0.08||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ComputeArea||R_insular_cortex_ComputeArea||0.79||0.09||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Volume||R_insular_cortex_Volume||0.73||0.11||0.03||0.03||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ShapeIndex||R_insular_cortex_ShapeIndex||0.27||0.17||0||0.07||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Curvedness||R_insular_cortex_Curvedness||0.84||0.02||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||AvgMeanCurvature||L_cingulate_gyrus_AvgMeanCurvature||0.72||0||0.05||0.02||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ComputeArea||L_cingulate_gyrus_ComputeArea||0.74||0.05||0.06||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Volume||L_cingulate_gyrus_Volume||0.69||0.08||0.05||0.05||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ShapeIndex||L_cingulate_gyrus_ShapeIndex||0.53||0||0.05||0||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Curvedness||L_cingulate_gyrus_Curvedness||0.7||0.01||0.05||0.04||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||AvgMeanCurvature||R_cingulate_gyrus_AvgMeanCurvature||0.6||0||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ComputeArea||R_cingulate_gyrus_ComputeArea||0.73||0.06||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Volume||R_cingulate_gyrus_Volume||0.68||0.09||0.04||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ShapeIndex||R_cingulate_gyrus_ShapeIndex||0.56||0.01||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Curvedness||R_cingulate_gyrus_Curvedness||0.25||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||AvgMeanCurvature||L_caudate_AvgMeanCurvature||0.52||0||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ComputeArea||L_caudate_ComputeArea||0.51||0.09||0.03||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Volume||L_caudate_Volume||0.44||0.09||0.03||0.06||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ShapeIndex||L_caudate_ShapeIndex||0.2||0.03||0.04||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Curvedness||L_caudate_Curvedness||0.51||0.12||0.02||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||AvgMeanCurvature||R_caudate_AvgMeanCurvature||0.68||0.04||0.04||0.02||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ComputeArea||R_caudate_ComputeArea||0.67||0.17||0.03||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Volume||R_caudate_Volume||0.61||0.16||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ShapeIndex||R_caudate_ShapeIndex||0.18||0.02||0.03||0.11||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Curvedness||R_caudate_Curvedness||0.65||0.19||0.01||0||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||AvgMeanCurvature||L_putamen_AvgMeanCurvature||0.62||0||0.04||0.03||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ComputeArea||L_putamen_ComputeArea||0.56||0.05||0.04||0.03||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Volume||L_putamen_Volume||0.52||0.07||0.04||0.05||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ShapeIndex||L_putamen_ShapeIndex||0.06||0.13||0||0.15||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Curvedness||L_putamen_Curvedness||0.64||0.11||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||AvgMeanCurvature||R_putamen_AvgMeanCurvature||0.62||0||0.07||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ComputeArea||R_putamen_ComputeArea||0.66||0.08||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Volume||R_putamen_Volume||0.64||0.12||0.03||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ShapeIndex||R_putamen_ShapeIndex||0.15||0.24||0||0.08||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Curvedness||R_putamen_Curvedness||0.65||0.05||0.05||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||AvgMeanCurvature||L_hippocampus_AvgMeanCurvature||0.78||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ComputeArea||L_hippocampus_ComputeArea||0.75||0.07||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Volume||L_hippocampus_Volume||0.72||0.09||0.01||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ShapeIndex||L_hippocampus_ShapeIndex||0.45||0.17||0||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Curvedness||L_hippocampus_Curvedness||0.79||0.03||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||AvgMeanCurvature||R_hippocampus_AvgMeanCurvature||0.72||0||0||0.1||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ComputeArea||R_hippocampus_ComputeArea||0.71||0.09||0||0||0.05&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Volume||R_hippocampus_Volume||0.68||0.1||0||0||0.04&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ShapeIndex||R_hippocampus_ShapeIndex||0.37||0.18||0||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Curvedness||R_hippocampus_Curvedness||0.77||0.03||0||0.02||0.04&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==R-Charts==&lt;br /&gt;
&lt;br /&gt;
There are 100’s of packages and 1,000 of different charts, plots and graphs that can be generated using R. Such interactive visualizations enable deeper exploration of data, models and results. JavaScript libraries, e.g., D3, provide advantages for data visualization as these involve HTML5 and are easily shareable online. The R community is developing R interfaces to some popular JavaScript libraries to allow users to create interactive visualizations without detailed knowledge of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Examples of powerful R interactive visualization packages===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;ggplot2&amp;lt;/b&amp;gt; – http://ggplot2.org&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;ggvis&amp;lt;/b&amp;gt; – interactive plots extending the static ggplot2 charts, http://ggvis.rstudio.com&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;rCharts&amp;lt;/b&amp;gt; – R interface to multiple JavaScript charting libraries, http://rcharts.io&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;plotly&amp;lt;/b&amp;gt; – transforming ggplot2 charts into interactive plots, https://plot.ly/r &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;googleVis&amp;lt;/b&amp;gt; – Google Charts using R, http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;HTMLWidgets&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;b&amp;gt;leaflet&amp;lt;/b&amp;gt; – library for creating dynamic maps, supports panning and zooming, annotations, markers, polygons, etc. http://www.htmlwidgets.org/showcase_leaflet.html&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;b&amp;gt;dygraphs&amp;lt;/b&amp;gt; – provides mechanism for charting time-series data, supports interactive navigation features including series/point highlighting, zooming, and panning, http://www.htmlwidgets.org/showcase_dygraphs.html &lt;br /&gt;
&lt;br /&gt;
** &amp;lt;b&amp;gt;networkD3&amp;lt;/b&amp;gt; – library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks, http://www.htmlwidgets.org/showcase_networkD3.html&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;b&amp;gt;DataTables&amp;lt;/b&amp;gt; – displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting, http://www.htmlwidgets.org/showcase_datatables.html&lt;br /&gt;
&lt;br /&gt;
** &amp;lt;b&amp;gt;Rthreejs&amp;lt;/b&amp;gt; – features 3D scatterplots and globes based on WebGL, http://www.htmlwidgets.org/showcase_threejs.html&lt;br /&gt;
&lt;br /&gt;
*Other R graphic examples&lt;br /&gt;
** To write out plots out to file use:&lt;br /&gt;
 # pdf() command all graphs are redirected to test.pdf.  Also works with other common formats:  jpeg, png, ps, tiff.&lt;br /&gt;
 pdf(&amp;quot;C:\\Users\\Dinov\\Desktop\\test.pdf&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
 # Generates Scalable Vector Graphics (SVG) that can be edited by vector graphics software&lt;br /&gt;
 svg(&amp;quot;test.svg&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
&lt;br /&gt;
===Paired ScatterPlots===&lt;br /&gt;
&lt;br /&gt;
 set.seed(100)&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 describe(x)    # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 plot(x[,1], x[,2], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 text(x[,1]+0.03, x[,2], rownames(x))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pairs(x)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another way to generate scatterplots is by using &amp;lt;b&amp;gt;ggplot:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 x &amp;lt;- sample(1:20, 20); y &amp;lt;- sample(1:20, 20); cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), 5)  &lt;br /&gt;
 #vs. cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), each=5)&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 #  Case_03_MentalHealthServicesSurvey&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399128/download?download_frd=1&amp;amp;verifier=AG2e9QUKUm1jvDBpkX7D9jbEjKNc4irA0ECk0f7p', header=T)	&lt;br /&gt;
 head(data1)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 describe(data1)&lt;br /&gt;
&lt;br /&gt;
 plot(data1[,3], data1[,4], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 # text(data1 [,3]+0.03, data1 [,4], rownames(data1))&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # redo plots using majorfundtype FacilityType Ownership Focus&lt;br /&gt;
 # pairs(data1, na.action=na.omit)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Scatterplot with regression line. Use the “diamonds” dataset, which is a data frame with&lt;br /&gt;
 # 53,940 rows and 10 variables ()&lt;br /&gt;
 # describe(diamonds)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 # CaseStudy01_Divorce_YoungAdults&lt;br /&gt;
 # data1 &amp;lt;- read.csv('https://umich.instructure.com/files/399118/download?download_frd=1&amp;amp;verifier=ESACv31KcyiHbkPZPuT8Oo4V7XzPtgTTbs6PQLTv', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # plot variables: DIVYEAR momint dadint momclose depression livewithmom gethitched&lt;br /&gt;
&lt;br /&gt;
 set.seed(110)&lt;br /&gt;
 # par(mfrow=c(1,2))&lt;br /&gt;
 data.2 &amp;lt;- diamonds[sample(nrow(diamonds), 500), ]&lt;br /&gt;
 plot.2 &amp;lt;- qplot(price, depth, data = data.2, geom = c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), method = &amp;quot;lm&amp;quot;)&lt;br /&gt;
 plot.3 &amp;lt;- qplot(carat, price, data=data.2, geom=c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), span=0.4)&lt;br /&gt;
 print(plot.2); print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Barplots===&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 barplot(x[1:4,], ylim=c(0, max(x[1:4,])+0.3), beside=TRUE, legend.text = letters[1:4],&lt;br /&gt;
        args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:4,])),2), x=seq(1.5, 21, by=1) + sort(rep(c(0,1,2,3,4), 4)), y=as.vector(as.matrix(x[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to put error bars on barplot:&lt;br /&gt;
&lt;br /&gt;
 # 10 rows (a, b, c, …):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- rowMeans(x) * 10, ylim=c(0, 10))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Case_04_ChildTrauma&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399129/download?download_frd=1&amp;amp;verifier=Hmv0YW2Kie5ZTV9CKBUNArSHR66f3GWSmVzZDBxc', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 head(x)&lt;br /&gt;
 head(data1)&lt;br /&gt;
 # plot data&lt;br /&gt;
 data2 &amp;lt;- data1[,-5]   # remove the 5th columns text&lt;br /&gt;
 data1 &amp;lt;- data2[,-5]   # remove the 6th columns text&lt;br /&gt;
 # or data1 &amp;lt;- data1[,c(-5,-6)]&lt;br /&gt;
&lt;br /&gt;
 data2 &amp;lt;- as.data.frame(data1)&lt;br /&gt;
 Blacks &amp;lt;- data2[which(data2$\$$race==&amp;quot;black&amp;quot;),]&lt;br /&gt;
 Other &amp;lt;- data2[which(data2$\$$race==&amp;quot;other&amp;quot;),]&lt;br /&gt;
 Hispanic &amp;lt;- data2[which(data2$\$$race==&amp;quot;hispanic&amp;quot;),]&lt;br /&gt;
 White &amp;lt;- data2[which(data2$\$$race==&amp;quot;white&amp;quot;),]&lt;br /&gt;
&lt;br /&gt;
 A &amp;lt;- c(mean(Blacks$\$$age), mean(Blacks$\$$service))&lt;br /&gt;
 #colnames(A) &amp;lt;- c(&amp;quot;age &amp;quot;,&amp;quot; service &amp;quot;)  &lt;br /&gt;
 B &amp;lt;- c(mean(Other$\$$age), mean(Other$\$$service))&lt;br /&gt;
 C &amp;lt;- c(mean(Hispanic$\$$age), mean(Hispanic$\$$service))&lt;br /&gt;
 D &amp;lt;- c(mean(White$\$$age), mean(White$\$$service))&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- cbind(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
 bar &amp;lt;- barplot(x[1:2,], ylim=c(0, max(x[1:2,])+2.0), beside=TRUE, &lt;br /&gt;
 legend.text = c(&amp;quot;age&amp;quot;,&amp;quot;service&amp;quot;) ,  args.legend = list(x = &amp;quot;right&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:2,])),2), x=seq(1.4, 21, by=1.5), #y=as.vector(as.matrix(x[1:2,]))+0.3)&lt;br /&gt;
	y=11.5)&lt;br /&gt;
&lt;br /&gt;
 m &amp;lt;- x; stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 barplot(as.matrix(data1[1:4,]), ylim=c(0, max(data1[1:4,])+0.3), beside=TRUE, legend.text = data1[1:4,1], args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(data1[1:4,])),2), x=seq(1.5, 21, by=1), y=as.vector(as.matrix(data1[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Columns (A, B, C, D, E):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- colMeans(x) * 5, ylim=c(0, 5))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Histograms and Density Plots===&lt;br /&gt;
&lt;br /&gt;
 hist(x, freq=TRUE, breaks=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(density(x), lwd = 10, col=&amp;quot;green&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pie Chart===&lt;br /&gt;
&lt;br /&gt;
 # first , “A”, and second, “B”, columns&lt;br /&gt;
 par (mfrow=c(1,2))&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,2], col=rainbow(length(x[,2]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
 legend(&amp;quot;topleft&amp;quot;, legend=row.names(x), cex=1.3, bty=&amp;quot;n&amp;quot;, pch=15, pt.cex=1.8, col=rainbow(length(x[,2]), start=0.1, end=0.8), ncol=1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 You can export the data: &lt;br /&gt;
 write.table(x, &amp;quot; &amp;quot;, &amp;quot;data.txt&amp;quot;)&lt;br /&gt;
 # copy-paste it in SOCR Pie chart to generate another Pie view of data&lt;br /&gt;
&lt;br /&gt;
===Line Plots Using ggplot===&lt;br /&gt;
&lt;br /&gt;
 head(diamonds)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Carat||Cut||Color||Clarity||Depth||Table||Price||X||Y||Z&lt;br /&gt;
|-&lt;br /&gt;
|1||0.23||Ideal||E||SI2||61.5||55||326||3.95||3.98||2.43&lt;br /&gt;
|-&lt;br /&gt;
|2||0.21||Premium||E||SI1||59.8||61||326||3.89||3.84||2.31&lt;br /&gt;
|-&lt;br /&gt;
|3||0.23||Good||E||VS1||56.9||65||237||4.05||4.07||2.31&lt;br /&gt;
|-&lt;br /&gt;
|4||0.29||Premium||I||VS2||62.4||58||334||4.2||4.23||2.63&lt;br /&gt;
|-&lt;br /&gt;
|5||0.31||Good||J||SI2||63.3||58||335||4.34||4.35||4.75&lt;br /&gt;
|-&lt;br /&gt;
|6||0.24||VeryGood||J||VVS2||62.8||57||336||3.94||3.96||2.48&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(diamonds, aes(carat, price, group=cut, color=cut)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization17.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(data1, aes(age, service, group=race, color=race)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Faceting plot (geometrically, faceting (or facetting) is the process of removing parts of a polygon, polyhedron or polytope, without creating any new vertices)&lt;br /&gt;
 plot.3 &amp;lt;- ggplot(diamonds, aes(carat, price)) + geom_line(aes(color=cut), size=1) + &lt;br /&gt;
 facet_wrap(~cut, ncol=1)&lt;br /&gt;
 print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization18.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Barplots with ggplot===&lt;br /&gt;
&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization19.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 New_var &amp;lt;- service+rnorm(1000, 0,1)&lt;br /&gt;
 data1$\$$New_var &amp;lt;- int(New_var)&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(data1, aes(race, fill= traumatype)) + geom_bar() + facet_grid(. ~ New_var)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 plot.4a &amp;lt;- ggplot(diamonds, aes(color, price/carat, fill=color)) + geom_boxplot()&lt;br /&gt;
 print(plot.4a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization20.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Jitter plot===&lt;br /&gt;
&lt;br /&gt;
 plot.5 &amp;lt;- ggplot(diamonds, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))&lt;br /&gt;
 print(plot.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization21.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Density Plots===&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(color = cut))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization22.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(data1, aes(age, size=2)) + geom_density(aes(color = traumatype))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
 plot.7 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(fill = color))&lt;br /&gt;
 print(plot.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization23.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8 &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), binwidth=0.2) + geom_density()&lt;br /&gt;
 print(plot.8)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization24.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8a &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), stat=&amp;quot;identity&amp;quot;) + geom_density()&lt;br /&gt;
 print(plot.8a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization25.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heatmaps===&lt;br /&gt;
&lt;br /&gt;
 # Generating Dendogram Association Heatmap Plot (Genotype vs. Imaging phenotype)&lt;br /&gt;
 # http://stat.ethz.ch/R-manual/R-patched/library/stats/html/heatmap.html&lt;br /&gt;
 # http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4005931/ &lt;br /&gt;
	   &lt;br /&gt;
 AD_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330387/download?download_frd=1&amp;amp;verifier=gLk2ADgrLhXGeknI6mqIeJugi2ODr8RARsQlBUMe&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
&lt;br /&gt;
 MCI_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330390/download?download_frd=1&amp;amp;verifier=FczlJD6ISRPZhu69xvHuoZHx2c7gXX9YEvvPCTBG&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 require(grDevices)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
&lt;br /&gt;
 AD_Data &amp;lt;- AD_Associations_Data &lt;br /&gt;
 MCI_Data &amp;lt;- MCI_Associations_Data &lt;br /&gt;
 NC_Data &amp;lt;- NC_Associations_Data &lt;br /&gt;
&lt;br /&gt;
 AD_mat  &amp;lt;- as.matrix(AD_Data); class(AD_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 MCI_mat  &amp;lt;- as.matrix(MCI_Data); class(MCI_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 NC_mat  &amp;lt;- as.matrix(NC_Data); class(NC_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # set up the rol (rc) and column (cc) colors for each cohort&lt;br /&gt;
 rcAD &amp;lt;- rainbow(nrow(AD_mat), start = 0, end = 1.0); ccAD&amp;lt;-rainbow(ncol(AD_mat), start = 0, end = 1.0)&lt;br /&gt;
 rcMCI &amp;lt;- rainbow(nrow(MCI_mat), start = 0, end=1.0); ccMCI&amp;lt;-rainbow(ncol(MCI_mat),start=0,end=1.0)&lt;br /&gt;
 rcNC &amp;lt;- rainbow(nrow(NC_mat), start = 0, end = 1.0); ccNC&amp;lt;-rainbow(ncol(NC_mat), start = 0, end = 1.0)&lt;br /&gt;
&lt;br /&gt;
 # set up 1x3 graph display - par (mfrow=c(1,3)) – does not work with ‘heatmap’&lt;br /&gt;
 hvAD &amp;lt;- heatmap(AD_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcAD, ColSideColors = ccAD, margins = c(2,2), main=&amp;quot;AD Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvMCI &amp;lt;- heatmap(MCI_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcMCI, ColSideColors = ccMCI, margins = c(2,2), main=&amp;quot;MCI Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvNC &amp;lt;- heatmap(NC_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcNC, ColSideColors = ccNC, margins = c(2,2), main=&amp;quot;NC Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization26.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use the R package gplots&lt;br /&gt;
 install.packages(&amp;quot;gplots&amp;quot;)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
 ## col dendrogram plotted and col reordering done. &lt;br /&gt;
 # heatmap.2(AD_mat, keysize=2) &lt;br /&gt;
 ## A more decorative heatmap, with z-score scaling along columns &lt;br /&gt;
 heatmap.2(AD_mat, col=cm.colors(255), scale=&amp;quot;column&amp;quot;, RowSideColors=rcAD, ColSideColors=ccAD, margin=c(8, 7), xlab=&amp;quot;Imaging Biomarkers (ROI volume)&amp;quot;, ylab= &amp;quot;Genetics Biomarkers (SNPs)&amp;quot;, main=&amp;quot;AD Associations Heatmap (SNP-Imaging)&amp;quot;,     tracecol=&amp;quot;green&amp;quot;, density=&amp;quot;density&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization27.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Correlation Plots===&lt;br /&gt;
&lt;br /&gt;
 The &amp;lt;b&amp;gt;corrplot&amp;lt;/b&amp;gt; package is a graphical display of a correlation matrix and confidence intervals, with some tools for matrix reordering. There are seven visualization methods (parameter method) in corrplot package, named   &amp;quot;circle&amp;quot;, &amp;quot;square&amp;quot;, &amp;quot;ellipse&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;shade&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;pie&amp;quot;.&lt;br /&gt;
 # install.packages(&amp;quot;corrplot&amp;quot;)&lt;br /&gt;
 library(corrplot)&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
 M &amp;lt;- cor(NC_Associations_Data)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization28.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hyperbolic Visualization===&lt;br /&gt;
&lt;br /&gt;
*URL: http://socr.umich.edu/html/Navigators.html  &lt;br /&gt;
&lt;br /&gt;
*Tools:&lt;br /&gt;
&lt;br /&gt;
** Java/Jar applet: http://socr.umich.edu/html/navigators/HW/jars/SOCR_HW_Viewer.jar&lt;br /&gt;
&lt;br /&gt;
** JavaScript: http://socr.umich.edu/html/navigators/D3/SOCR_D3_Viewer.html (JSON)&lt;br /&gt;
&lt;br /&gt;
*Data Format&lt;br /&gt;
&lt;br /&gt;
** XML data: http://socr.umich.edu/html/navigators/HW/SOCR_HyperTree.xml&lt;br /&gt;
&lt;br /&gt;
** JSON data: http://socr.umich.edu/html/navigators/D3/xml/SOCR_HyperTree.json&lt;br /&gt;
&lt;br /&gt;
*D3 Visualization&lt;br /&gt;
&lt;br /&gt;
** E:\Ivo.dir\Research\UMichigan\Education_Teaching_Curricula\2015_2016\HS_853_Fall_2015\Modules_docx\Tools\TreeViewer_JS&lt;br /&gt;
&lt;br /&gt;
** treeJS.json&lt;br /&gt;
&lt;br /&gt;
** flareD3.json&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization29.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization30.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*URL: https://github.com/mbostock/d3/wiki/Gallery&lt;br /&gt;
&lt;br /&gt;
*Source code: https://github.com/mbostock/d3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization31.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Motion Charts===&lt;br /&gt;
&lt;br /&gt;
*Video: http://www.socr.ucla.edu/SOCR_MotionCharts/SOCR_HTML5_MotionChart_Video2.gif&lt;br /&gt;
&lt;br /&gt;
*Java: http://www.socr.ucla.edu/SOCR_MotionCharts/ &lt;br /&gt;
&lt;br /&gt;
*HTML5: http://socr.umich.edu/HTML5/MotionChart/ &lt;br /&gt;
&lt;br /&gt;
*Activities: http://wiki.socr.umich.edu/index.php/SOCR_MotionCharts &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization32.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1D/2D/3D signal/area/volume/surface/model/atlas visualization===&lt;br /&gt;
&lt;br /&gt;
*1D: (See R/SOCR Visualization tools above)&lt;br /&gt;
&lt;br /&gt;
*2D: http://imagej.nih.gov/ij/ &lt;br /&gt;
&lt;br /&gt;
*3D: http://socr.umich.edu/HTML5/BrainViewer/ &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;Supported File Formats:&amp;lt;/b&amp;gt;&lt;br /&gt;
 Volumes (.nii / .nii.gz / .img&amp;amp;.hdr / .mgh / .mgz / .nrrd)&lt;br /&gt;
 Shapes (.dx / .vtk / .stl / FreeSurfer)&lt;br /&gt;
 Fibers (.trk)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization33.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trees and Graphs===&lt;br /&gt;
&lt;br /&gt;
*Trees/Hierarchies and general Graphs&lt;br /&gt;
&lt;br /&gt;
 # Install and load the APE package, needed for the phylogenetic tree rendering (as.phylo)&lt;br /&gt;
 # install.packages(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Load data &lt;br /&gt;
&lt;br /&gt;
 # Data: 02_Nof1_Data.csv&lt;br /&gt;
 data.1 &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clustering&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.1), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;,&amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA),&amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization34.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 (x &amp;lt;- identify(hc)) ##  Terminate with 2nd mouse button !!&lt;br /&gt;
 identify(hc, &amp;lt;mark&amp;gt;function(k)&amp;lt;/mark&amp;gt; print(table(data.1[k,5])))&lt;br /&gt;
&lt;br /&gt;
You can now cut the tree into branches. You can split the tree into 2 groups, by setting the number of cuts with the k=2 parameter, or by specifying height to cut the tree at (?cutree):&lt;br /&gt;
&lt;br /&gt;
k- an integer scalar or vector with the desired number of groups&lt;br /&gt;
&lt;br /&gt;
h- numeric scalar or vector with heights where the tree should be cut&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the clustering method &lt;br /&gt;
 # for the particular agglomeration.&lt;br /&gt;
 cutree(hc, h= 50) # cut at h=50&lt;br /&gt;
 table(cutree(hc, h= 50)) # cluster distribution&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=5; &lt;br /&gt;
 myClusters = sapply(2:10,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:10, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 groups.10 &amp;lt;- cutree(hc, k = 10)	&lt;br /&gt;
 sapply(unique(groups.10),function(g)data.1$\$$ID[groups.10 == g])&lt;br /&gt;
 #To see which Treatments (Tx) are in which clusters:&lt;br /&gt;
 groups.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.2),function(g)data.1$\$$Tx[groups.2 == g])&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.2, data.1$\$$Tx)&lt;br /&gt;
 # For a small number of observations, we can often interpret the cluster solution directly by looking &lt;br /&gt;
 # at the labels of the observations that are in each cluster. &lt;br /&gt;
 # This is hard for larger data sets. To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;aggregate&amp;lt;/b&amp;gt; function will compute stats (e.g., median) on many variables simultaneously. &lt;br /&gt;
&lt;br /&gt;
To look at the median values for the variables we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
&lt;br /&gt;
 aggregate(data.1, list(groups.10),median) # may have to &amp;lt;b&amp;gt;shrink data.1&amp;lt;/b&amp;gt; prior to clustering! &lt;br /&gt;
 # data.2 &amp;lt;- data.1[,-c(1,3)]  # Remove ID and Tx variables?&lt;br /&gt;
 aggregate(data.2, list(groups.2),median) # for only 2 clusters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Group||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 table(groups.2, data.1$\$$&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 describe(data.1$\$$PhyAct)&lt;br /&gt;
&lt;br /&gt;
 # It’s useful to add the numbers of observations in each group (aggregate returns a data frame, &lt;br /&gt;
 # that can be manipulated)&lt;br /&gt;
&lt;br /&gt;
 df.2 &amp;lt;- aggregate(data.1, list(groups.2),median)&lt;br /&gt;
&lt;br /&gt;
 data.frame(Cluster= df.2[,1], Freq=as.vector(table(groups.2)), df.2[,-1])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Cluster||&amp;lt;mark&amp;gt;Freq&amp;lt;/mark&amp;gt;||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||&amp;lt;mark&amp;gt;570&amp;lt;/mark&amp;gt;||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||&amp;lt;mark&amp;gt;330&amp;lt;/mark&amp;gt;||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
*This paper examines nasal and bronchial tissue cultures as appropriate in vitro models for the assessment of smoking-induced adverse effects in the respiratory system (doi: 10.1177/1091581814551647), using “hclust” package. No data.&lt;br /&gt;
&lt;br /&gt;
*This paper classified subtypes of gastric cancer based on epidemiologic and histologic and gene expression data. These new classifications of gastric cancer have implications for improving our understanding of disease biology and identification of unique molecular drivers for each gastric cancer subtype (doi: 10.1158/1078-0432.CCR-10-2203).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Repeat the clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # using centroids and squared Euclidean distance&lt;br /&gt;
 # cut the tree into 10 clusters and reconstruct the upper part of the tree from the cluster centers.&lt;br /&gt;
 hc &amp;lt;- hclust(dist(data.1), &amp;quot;cen&amp;quot;)&lt;br /&gt;
 mem &amp;lt;- cutree(hc, k = 10)&lt;br /&gt;
 cent &amp;lt;- NULL&lt;br /&gt;
 for(k in 1:10){&lt;br /&gt;
  		cent &amp;lt;- rbind(cent, colMeans(data.1[mem == k, , drop = FALSE]))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 hc1 &amp;lt;- hclust(dist(cent), method = &amp;quot;cen&amp;quot;, members = table(mem))&lt;br /&gt;
&lt;br /&gt;
 opar &amp;lt;- par(mfrow = c(1, 2))&lt;br /&gt;
 plot(hc,  labels = FALSE, hang = -1, main = &amp;quot;Original Tree&amp;quot;)&lt;br /&gt;
 plot(hc1, hang = -1, main = &amp;quot;Re-start from 10 clusters&amp;quot;)&lt;br /&gt;
 par(opar)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization35.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Identify subjects within each of the 10 classes&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rect.hclust(hc, h=10) &lt;br /&gt;
&lt;br /&gt;
 # To save the cluster numbers to a new variable in the dataset, use the cutree function.&lt;br /&gt;
 # data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct||&amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;CluserID&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53||1&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73||1&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23||2&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36||2&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21||2&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0||2&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Phylogenetic tree diagram&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc1), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;, tip.color = hsv(runif(15, 0.65, 0.95), 1, 1, 0.7), label.offset = 1, cex = log(data.1$\$$ID, 10), col = &amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization36.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization37.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity (Health Behavior Risks)===&lt;br /&gt;
&lt;br /&gt;
 # load data CaseStudy09_HealthBehaviorRisks_Data&lt;br /&gt;
 data.2 &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/399182/download?download_frd=1 &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # Classify the cases using these variables:  &amp;quot;AGE_G&amp;quot;    &amp;quot;SEX&amp;quot;      &amp;quot;RACEGR3&amp;quot;  &amp;quot;IMPEDUC&amp;quot;  &amp;quot;IMPMRTL&amp;quot;  &lt;br /&gt;
 #	&amp;quot;EMPLOY1&amp;quot;  &amp;quot;INCOMG&amp;quot;  &amp;quot;CVDINFR4&amp;quot; &amp;quot;CVDCRHD4&amp;quot; &amp;quot;CVDSTRK3&amp;quot; &amp;quot;DIABETE3&amp;quot; &amp;quot;RFSMOK3&amp;quot;  &lt;br /&gt;
 #	&amp;quot;FRTLT1&amp;quot;   &amp;quot;VEGLT1&amp;quot; &lt;br /&gt;
 data.raw &amp;lt;- data.2[,-c(1,14,17)]&lt;br /&gt;
&lt;br /&gt;
 # Does the classification match either of these: &lt;br /&gt;
 #	TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t know/Refused/Missing)&lt;br /&gt;
 #	RFDRHV4 (Heavy alcohol consumption, 1=No, 2=Yes, 9=Don’t know/Refused/Missing)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.raw), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;, &amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA), &amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
 &lt;br /&gt;
 summary(data.2$\$$TOTINDA); summary(data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the &lt;br /&gt;
 # clustering method for the particular agglomeration -- cutree(hc, h= 10)&lt;br /&gt;
&lt;br /&gt;
 table(cutree(hc, h= 10)) # cluster distribution&lt;br /&gt;
&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to sapply -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=4; &lt;br /&gt;
 myClusters = sapply(2:5,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:5, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 table(cutree(hc, k=2)) &lt;br /&gt;
 groups.k.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.k.2),function(g)data.2$\$$ID[groups.k.2 == g])&lt;br /&gt;
&lt;br /&gt;
 #To see which TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t &lt;br /&gt;
 # 	know/Refused/Missing) &amp;amp; whch RFDRHV4 are in which clusters:&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4[groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Perhaps there are intrinsically 3 groups here e.g., 1, 2 and 9 …&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4 [groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Note that there is quite a dependence between the outcome variables …&lt;br /&gt;
 plot(data.2$\$$RFDRHV4, data.2$\$$TOTINDA)&lt;br /&gt;
&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.k.3, data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 # To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. The aggregate function will compute stats&lt;br /&gt;
 # (e.g., median) on many variables simultaneously. To look at the median values for the variables &lt;br /&gt;
 # we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
 aggregate(data.2, list(groups.k.3),median) &lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
*[[SMHS_SciVisualization_NetworkViz|Next See the Complex Network Visualization section]]&lt;br /&gt;
*[[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization&amp;diff=16157</id>
		<title>SMHS SciVisualization</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization&amp;diff=16157"/>
		<updated>2016-05-23T13:26:04Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Scientific Visualization ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
&lt;br /&gt;
*How and why should we “look” at data?&lt;br /&gt;
*What data characteristics are important for exploratory data analytics (EDAs)?&lt;br /&gt;
&lt;br /&gt;
Scientific Data-driven or Simulation-driven visualization methods may be classified in many alternative ways. Visualization techniques can be classified according to many criteria:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization1.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Data Type: structured/unstructured, small/large, complete/incomplete, time/space, ascii/binary, Euclidean/non-Euclidean, etc.&lt;br /&gt;
&lt;br /&gt;
*Task type: Task  type  is  one  of  the  aspects  considered  in classification  of  visualization  techniques,  which provides means of interaction between the researcher, the data and the display software/platform&lt;br /&gt;
&lt;br /&gt;
*Scalability:  Visualization   techniques   are   subject   to   some limitations, such as the amount of data that a particular technique can exhibit&lt;br /&gt;
    &lt;br /&gt;
*Dimensionality: Visualization   techniques   can   also   be   classified according to the number of attributes&lt;br /&gt;
&lt;br /&gt;
*Positioning and Attributes: the distribution   of   attributes   on   the   chart may affect the interpretation    of    the display representation, e.g., correlation analysis, where the relative distance among the plotted attributes is relevant for observation&lt;br /&gt;
&lt;br /&gt;
*Investigative Need: the specific scientific question or exploratory interest may also determine the type of visualization:&lt;br /&gt;
** Examining the composition of the data&lt;br /&gt;
** Exploring the distribution of the data&lt;br /&gt;
** Contrasting or comparing several data elements, relations, association&lt;br /&gt;
** Unsupervised exploratory data mining&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.socr.umich.edu/CSCD/html/Cores/Macore2/SciViz.html&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_SciVisualization_SOCR_Excel_R_Charts|SOCR, Excel and R Charts]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_SciVisualization_NetworkViz|Complex Network Visualization]]==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16156</id>
		<title>SMHS MethodsHeterogeneity CER</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16156"/>
		<updated>2016-05-23T13:24:50Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Comparative Effectiveness Research (CER) ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
==Observational Studies: Tips for the CER Practitioners==&lt;br /&gt;
&lt;br /&gt;
*Different study types can offer different understandings; neither should be discounted without closer examination.&lt;br /&gt;
&lt;br /&gt;
*RCTs provide an accurate understanding of the effect of a particular intervention in a well-defined patient group under “controlled” circumstances.&lt;br /&gt;
&lt;br /&gt;
*Observational studies provide an understanding of real-world care and its impact, but can be biased due to uncontrolled factors.&lt;br /&gt;
&lt;br /&gt;
*Observational studies differ in the types of databases used. These databases may lack clinical detail and contain incomplete or inaccurate data.&lt;br /&gt;
&lt;br /&gt;
*Before accepting the findings from an observational study, consider whether confounding factors may have influenced the results.&lt;br /&gt;
&lt;br /&gt;
*In this scenario, subgroup analysis was vital in clarifying both study designs; what is true for the many (e.g., overall, estrogen appeared to be detrimental) may not be true for the few (e.g., that for the younger post-menopausal woman, the benefits were greater and the harms less frequent).&lt;br /&gt;
&lt;br /&gt;
*Carefully examine the generalizability of the study. Do the study’s patients and intervention match those under consideration?&lt;br /&gt;
&lt;br /&gt;
*Observational studies can identify associations but cannot prove cause-and-effect relationships.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 1: The Cetuximab Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done and what was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cetuximab, an anti-epidermal growth factor receptor (EGFR) agent, has recently been added to the therapeutic armamentarium.  Two important CRTs examined its impact in patients with mCRC (metastatic-stage Colorectal cancer). In the first one, 56 centers in 11 European countries investigated the outcomes associated with cetuximab therapy in 329 mCRC patients who experienced disease progression either on irinotecan therapy or within 3 months thereafter. The study reported that the group on a combination of irinotecan and cetuximab had a significantly higher rate of overall response to treatment (primary endpoint) than the group on cetuximab alone: 22.9% (95% CI, 17.5-29.1%) vs. 10.8% (95% CI, 5.7-18.1%) (P=0.007), respectively. Similarly, the median time to progression was significantly longer in the combination therapy group (4.1 vs. 1.5 months, P&amp;lt;0.001). As these patients had already progressed on irinotecan prior to the study, any response was viewed as positive. Safety between the two treatment arms was similar: approximately 80% of patients in each arm experienced a rash. Grade 3 or 4 (the more severe) toxic effects on the skin were slightly more frequent in the combination-therapy group compared to cetuximab monotherapy, observed in 9.4% and 5.2% of participants, respectively. Other side effects, such as diarrhea and neutropenia observed in the combination-therapy arm, were considered to be in the range expected for irinotecan alone. Data from this study demonstrated the efficacy and safety of cetuximab and were instrumental in the FDA’s 2004 approval.&lt;br /&gt;
&lt;br /&gt;
A second CRT (2007) examined 572 patients and suggested efficacy of cetuximab in the treatment of mCRC. This study was a randomized, non-blinded, controlled trial that examined cetuximab monotherapy plus best supportive care compared to best supportive care alone in patients who had received and failed prior chemotherapy regimens. It reported that median overall survival (the primary endpoint) was significantly higher in patients receiving cetuximab plus best supportive care compared to best supportive care alone (6.1 vs. 4.6 months, respectively) (hazard ratio for death=0.77; 95% CI: 0.64- 0.92, P=0.005). This RCT described a greater incidence of adverse events in the cetuximab plus best supportive care group compared to best supportive care alone including (most significantly) rash, as well as edema, fatigue, nausea and vomiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These RCTs had fairly broad enrollment criteria and the cetuximab benefits were modest. Emerging scientific theories raised the possibility that genetically defined population subsets might experience a greater-than-average treatment benefit. One such area of inquiry entailed examining “biomarkers,” or genetic indicators of a patient’s greater response to therapy. Even as the above RCTs were being conducted, data emerged showing the importance of the KRAS gene.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the emerging biochemical evidence that the epidermal growth factor receptor (EGFR) treatment mechanism (Cetuximab) was even more finely detailed than previously understood, the study authors of the 2007 RCT undertook a retrospective subgroup analysis using tumor tissue samples preserved from their initial study. Following laboratory analysis, all viable tissue samples were classified as having a wild-type (non-mutated) or a mutated KRAS gene. Instead of the previous two study arms (cetuximab plus best supportive care vs. best supportive care alone), there were 4 for this new analysis: each of the two original study arms was further divided by wild-type vs. mutated KRAS status. Laboratory evaluation determined that 40.9% and 42.3% of all patients in the RCT had a KRAS mutation in the cetuximab plus best supportive care group compared to the best supportive care group alone, respectively. The efficacy of cetuximab was found to be significantly correlated with KRAS status: in patients with wild-type (non-mutated). KRAS genes, cetuximab plus best supportive care compared to best supportive care alone improved overall survival (median 9.5 vs. 4.8 months, respectively; hazard ratio  for death=0.55; 95% CI, 0.41-0.74, P&amp;lt;0.001), and progression-free survival (median 3.7 vs. 1.9 months, respectively; hazard ratio for progression or death=0.40; 95% CI, 0.30-0.54, P&amp;lt;0.001). Meanwhile, in patients with mutated KRAS tumors, the authors found no significant difference in outcome between cetuximab plus best supportive care vs. best supportive care alone.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on these and similar results from other studies, the FDA narrowed its product labeling in July 2009 to indicate that cetuximab is not recommended for mCRC patients with mutated KRAS tumors. This distinction reduces the relevant population by approximately 40%. Similarly, the American society of Clinical oncology released a provisional clinical recommendation that all mCRC patients have their tumors tested for KRAS status before receiving anti-EGFR therapy. The benefits of targeted treatment are many. Patients who previously underwent cetuximab therapy without knowing their genetic predisposition would no longer have to be exposed to the drug’s toxic effects if unnecessary, as the efficacy of cetuximab is markedly higher in the genetically defined appropriate patients. In a less-uncertain environment, clinicians can be more confident in advocating a course of action in their care of patients. And finally, knowledge that targeted therapy is possible suggests the potential for further innovation in treatment options. In fact, research continues to demonstrate options for targeted cetuximab treatment of mCRC at an even finer scale than seen with KRAS; and similar genetic targeting is being investigated, and advocated, in other cancer types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are generally viewed as the gold standard, results of one or even a series of trials may not accurately reflect the benefits experienced by an individual patient.  This case-study suggests that cetuximab initially appeared to have rather modest clinical benefits. Albeit, new information that became available and subsequent genetic subgroup assessments led to very different conclusions. Clinicians should be aware that the current knowledge is likely to evolve and any decisions about patient care should be carefully considered with that sense of uncertainty in mind. As in this case study, subgroup analyses (e.g., genetic subtypes) need a theoretical rationale. Ideally, the analyses should be determined at the time of original RCT design and should not just occur as explorations of the subsequent data. When improperly employed, post hoc analyses may lead to incorrect patient care conclusions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RCTs Tips for the CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*RCTs can determine whether an intervention can provide benefit in a very controlled environment.&lt;br /&gt;
&lt;br /&gt;
*The controlled nature of an RCT may limit its generalizability to a broader population.&lt;br /&gt;
&lt;br /&gt;
*No results are permanent; advances in scientific knowledge and understanding can influence how we view the effectiveness (or safety) of a therapeutic intervention.&lt;br /&gt;
&lt;br /&gt;
*Targeted therapy illuminated by carefully thought out subgroup analyses can improve the efficacious and safe use of an intervention.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 2: The Rosiglitazone Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-analysis&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Often the results for the same intervention differ across clinical trials and it may not be clear whether one therapy provides more benefit than another. As CER increases and more studies are conducted, clinicians and policymakers are more likely to encounter this scenario. In a systematic review, a researcher identifies similar studies and displays their results in a table, enabling qualitative comparisons across the studies. With a meta-analysis, the data from included studies are statistically combined into a single “result.” Merging the data from a number of studies increases the effective sample size of the investigation, providing a statistically stronger conclusion about the body of research. By so doing, investigators may detect low frequency events and demonstrate more subtle distinctions between therapeutic alternatives.&lt;br /&gt;
&lt;br /&gt;
When studies have been properly identified and combined, the meta-analysis produces a summary estimate of the findings and a confidence interval that can serve as a benchmark in medical opinion and practice. However, when done incorrectly, the quantitative and statistical analysis can create impressive “numbers” but biased results. The following are important criteria for properly conducted meta-analyses:&lt;br /&gt;
&lt;br /&gt;
1.	Carefully defining unbiased inclusion or exclusion criteria for study selection&lt;br /&gt;
&lt;br /&gt;
2.	Including only those studies that have similar design elements, such as patient population, drug regimen, outcomes being assessed, and time-frame&lt;br /&gt;
&lt;br /&gt;
3.	Applying correct statistical methods to combine and analyze the data&lt;br /&gt;
&lt;br /&gt;
Reporting this information is essential for the reader to determine whether the data were suitable to combine, and if the meta-analysis draws unbiased conclusions. Meta-analyses of randomized clinical trials are considered to be the highest level of medical evidence as they are based upon a synthesis of rigorously controlled trials that systematically reduce bias and confounding. This technique is useful in summarizing available evidence and will likely become more common in the era of publicly funded comparative effectiveness research. The following case study will examine several key principles that will be useful as the reader encounters these publications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Application&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Heart disease is the leading cause of mortality in the United States, resulting in approximately 20% of all deaths. Diabetics are particularly susceptible to heart disease, with more than 65% of deaths attributable to it. The nonfatal complications of diabetes are wide-ranging and include kidney failure, nerve damage, amputation, stroke and blindness, among other outcomes. In 2007, the total estimated cost of diabetes in the United States was $174B; $116B was derived from direct medical expenditures and the rest from the indirect cost of lost productivity due to the disease. With such serious health effects and heavy direct and indirect costs tied to diabetes, proper disease management is critical. Historically, diabetes treatment has focused on strict blood sugar control, assuming that this goal not only targets diabetes but also reduces other serious comorbidities of the disease.&lt;br /&gt;
&lt;br /&gt;
Anti-diabetic agents have long been associated with key questions as to their benefits/risks in the treatment of diabetes. The sulfonylurea tolbutamide, a first generation anti-diabetic drug, was found in a landmark study in the 1970s to significantly increase the CV mortality rate compared to patients not on this agent. Further analysis by external parties concluded that the methods employed in this trial were significantly flawed (e.g., use of an “arbitrary” definition of diabetes status, heterogeneous baseline characteristics of the populations studied, and incorrect statistical methods). Since these early studies, CV concerns continue to be an issue with selected oral hypoglycemic agents that have subsequently entered the marketplace.&lt;br /&gt;
&lt;br /&gt;
A class of drugs, thiazolidinedione (TZD), was approved in the late 1990s, as a solution to the problems associated with the older generation of sulfonylureas. Rosiglitazone, a member of the TZD class, was approved by the FDA in 1999 and was widely prescribed for the treatment of type-2 diabetes. A number of RCTs supported the benefit of rosiglitazone as an important new oral antidiabetic agent. However, safety concerns developed as the FDA received reports of adverse cardiac events potentially associated with rosiglitazone. It was in this setting that a meta-analysis by Nissen and Wolski was published in the New England Journal of Medicine in June 2007.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nissen and Wolski conducted a meta-analysis examining the impact of rosiglitazone on cardiac events and mortality compared to alternative therapeutic approaches. The study began with a broad search to locate potential studies for review. The authors screened published phase II, III, and IV trials; the FDA website; and the drug manufacturer’s clinical-trial registry for applicable data relating to rosiglitazone use. When the initial search was complete, the studies were further categorized by pre-stated inclusion criteria. Meta-analysis inclusion criteria were simple: studies had to include rosiglitazone and a randomized comparator group treated with either another drug or placebo, study arms had to show similar length of treatment, and all groups had to have received more than 24 weeks of exposure to the study drugs. The studies had to contain outcome data of interest including the rate of myocardial infarction (MI) or death from all CV causes. Out of 116 studies surveyed by the authors, 42 met their inclusion criteria and were included in the meta-analysis. Of the studies they included, 23 had durations of 26 weeks or less, and only five studies followed patients for more than a year. Until this point, the study’s authors were following a path similar to that of any reviewer interested in CV outcomes, examining the results of these 42 studies and comparing them qualitatively. Quantitatively combining the data, however, required the authors to make choices about the studies they could merge and the statistical methods they should apply for analysis. Those decisions greatly influenced the results that were reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the studies were combined, the meta-analysis contained data from 15,565 patients in the rosiglitazone group and 12,282 patients as comparators. Analyzing their data, the authors chose one particular statistical method (the Peto odds ratio method, a fixed-effect statistical approach), which calculates the odds of events occurring where the outcomes of interest are rare and small in number. In comparing rosiglitazone with a “control” group that included other drugs or placebo, the authors reported odds ratios of 1.43 (95% CI, 1.03-1.98; P=0.03) and 1.64 (95% CI,&lt;br /&gt;
0.98-2.74; P=0.06) for MI and death from CV causes, respectively. In other words, the odds of an MI or death from a CV cause are higher for rosiglitazone patients than for patients on other therapies or placebo. The authors reported that rosiglitazone was significantly associated with an increase in the risk of MI and had borderline significance in increasing the risk of death from all CV causes. These findings appeared online on the same day that the FDA issued a safety alert regarding rosiglitazone. Discussion of the meta-analysis was immediately featured prominently in the news media. By December 2007, prescription claims for the drug at retail pharmacies had fallen by more than 50%.&lt;br /&gt;
&lt;br /&gt;
As diabetic patients and their clinicians reacted to the news, a methodologic debate also ensued. This discussion included statistical issues pertaining to the conduct of the analysis, its implications for clinical care, and finally the FDA and drug manufacturer’s roles in overseeing and regulating rosiglitazone. The concern among patients with diabetes regarding treatment, continues in the medical community today.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should the studies have been combined? Commentators faulted the authors for including several studies that were not originally intended to investigate diabetes, and for combining both placebo and drug therapy data into one comparator arm. Some critics noted that despite the stated inclusion criteria, some data were derived from studies where the rosiglitazone arm was allowed a longer follow-up than the comparator arm. By failing to account for this longer follow-up period, commentators felt that the authors may have overestimated the effect of rosiglitazone on CV outcomes. Many reviewers were concerned that this meta-analysis excluded trials in which no patients suffered an MI or died from CV causes – the outcomes of greatest interest. Some reviewers also noted that the exclusion of zero-event trials from the pooled dataset not only gave an incomplete picture of the impact of rosiglitazone but could have increased the odds ratio estimate. In general, the pooled dataset was criticized by many for being a faulty microcosm of the information available regarding rosiglitazone.&lt;br /&gt;
&lt;br /&gt;
It is essential that a meta-analysis be based on similarity in the data sources. If studies differ in important areas such as the patient populations, interventions, or outcomes, combining their data may not be suitable. The researchers accepted studies and populations that were clinically heterogeneous, yet pooled them as if they were not. The study reported that the results were combined from a number of trials that were not initially intended to investigate CV outcomes. Furthermore, the available data did not allow for time-to-event analysis, an essential tool in comparing the impact of alternative treatment options. Reviewers considered the data to be insufficiently homogeneous, and the line of cause and effect to be murkier than the authors described.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Were the statistical methods optimal?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The statistical methods for this meta-analysis also came under significant criticism. The critiques focused on the authors’ use of the Peto method as being an incorrect choice because data were pooled from both small and very large studies, resulting in a potential overestimation of treatment effect. Others reviewers pointed that the Peto method should not have been used, as a number of the underlying studies did not have patients assigned equally to rosiglitazone and comparator groups. Finally, critics suggested that the heterogeneity of the included studies required an altogether different set of analytic techniques.&lt;br /&gt;
&lt;br /&gt;
Demonstrating the sensitivity of the authors’ initial analysis to the inclusion criteria and statistical tests used, a number of researchers reworked the data from this study. one researcher used the same studies but analyzed the data with a more commonly used statistical method (Mantel-Haenszel), and found no significant increase in the relative risk or common odds ratio with MI or CV death. When the pool of studies was expanded to include those originally eliminated because they had zero CV events, the odds ratios for MI and death from CV causes dropped from 1.43 to 1.26 (95% CI, 0.93-1.72) and from 1.64 to 1.14 (95% CI, 0.74-1.74), respectively. Neither of the recalculated odd ratios were significant for MI or CV death. Finally, several newer long-term studies have been published since the Nissen meta-analysis. Incorporating their results with the meta-analysis data showed that rosiglitazone is associated with an increased risk of MI but not of CV death. Thus, the findings from these meta-analyses varied with the methods employed, the studies included, and the addition of later trials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controversy surrounding the rosiglitazone meta-analysis authored by Nissen and Wolski forced an unplanned interim analysis of a long-term, randomized trial investigating the CV effects of rosiglitazone among patients with type 2 diabetes. The authors of the RECORD trial noted that even though the follow-up at 3.75 years was shorter than expected, rosiglitazone, when added to standard glucose-lowering therapy, was found to be associated with an increase in the risk of heart failure but was not associated with any increase in death from CV or other causes. Data at the time were found to be insufficient to determine the effect of rosiglitazone on an increase in the risk of MI. the final report of that trial, published in June 2009, confirmed the elevated risk of heart failure in people with type 2 diabetes treated with rosiglitazone in addition to glucose-lowering drugs, but continued to show inconclusive results about the effect of the drug therapy on the risk of MI. Further, the RECORD trial clarified that rosiglitazone does not result in an increased risk of CV morbidity or mortality compared to standard glucose-lowering drugs. Other trials conducted since the publishing of the meta-analysis have corroborated these results, casting further doubt on the findings of the meta-analysis published by Nissen and Wolski.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Now what?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some sources suggest that the original Nissen meta-analysis delivered more harm than benefit, and that a well-recognized medical journal may have erred in its process of peer review. Despite this criticism, it is important to note that subsequent publications support the risk of adverse CV events associated with rosiglitazone, although rosiglitazone use does not appear to increase deaths. These results and emerging data point to the need for further rigorous research to clarify the benefits and risks of rosiglitazone on a variety of outcomes, and the importance of directing the drug to the population that will maximally benefit from its use.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this Case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results from initial randomized trials that seem definitive at one time may not be conclusive, as further trials may emerge to clarify, redirect, or negate previously accepted results. A meta-analysis of those trials can lead to varying results based upon the timing of the analysis and the choices made in its performance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-Analysis: Tips for CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*The results of a meta-analysis are highly dependent on the studies included (and excluded). Are these criteria properly defined and relevant to the purposes of the meta-analysis? Were the combined studies sufficiently similar? Can results from this cohort be generalized to other populations of interest?&lt;br /&gt;
&lt;br /&gt;
*The statistical methodology can impact study results. Have there been reviews critiquing the methods used in the meta-analysis?&lt;br /&gt;
&lt;br /&gt;
*A variety of statistical tests should be considered, and perhaps reported, in the analysis of results. Do the authors mention their rationale in choosing a statistical method? Do they show the stability of their results across a spectrum of analytical methods?&lt;br /&gt;
&lt;br /&gt;
*Nothing is permanent. Emerging data may change the playing field, and meta- analysis results are only as good as the data and statistics from which they are derived.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 3: The Nurses’ Health Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;An observational study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An observational study is a very common type of research design in which the effects of a treatment or condition are studied without formally randomizing patients in an experimental design. Such studies can be done prospectively, wherein data are collected about a group of patients going forward in time; or retrospectively, in which the researcher looks into the past, mining existing databases for data that have already been collected. Latter studies are frequently performed by using an electronic database that contains, for example, administrative, “billing,” or claims data. Less commonly, observational research uses electronic health records, which have greater clinical information that more closely resembles the data collected in an RCT. Observational studies often take place in “real- world” environments, which allow researchers to collect data for a wide array of outcomes. Patients are not randomized in these studies, but the findings can be used to generate hypotheses for investigation in a more constrained experimental setting. Perhaps the best known observational study is the “Framingham study,” which collected demographic and health data for a group of individuals over many years (and continues to do so) and has provided an understanding of the key risk factors for heart disease and stroke.&lt;br /&gt;
&lt;br /&gt;
Observational studies present many advantages to the comparative effectiveness researcher. the study design can provide a unique glimpse of the use of a health care intervention in the “real world,” an essential step in gauging the gap between efficacy (can a treatment work in a controlled setting?) and effectiveness (does the treatment work in a real-life situation?). Furthermore, observational studies can be conducted at low cost, particularly if they involve the secondary analysis of existing data sources. CER often uses administrative databases, which are based upon the billing data submitted by providers during routine care. These databases typically have limited clinical information, may have errors in them, and generally do not undergo auditing.&lt;br /&gt;
&lt;br /&gt;
The uncontrolled nature of observational studies allows them to be subject to bias and confounding. For example, doctors may prescribe a new medication only for the sickest patients. Comparing these outcomes (without careful statistical adjustment) with those from less ill patients receiving alternative treatment may lead to misleading results. Observational studies can identify important associations but cannot prove cause and effect. These studies can generate hypotheses that may require RCTs for fuller demonstration of those relationships. Secondary analysis can also be problematic if researchers overwork datasets by doing multiple exploratory analyses (e.g., data-dredging): the more we look, the more we find, even if those findings are merely statistical aberrations. Unfortunately, the growing need for CER and the wide availability of administrative databases may lead to selection of research of poor quality with inaccurate findings.&lt;br /&gt;
&lt;br /&gt;
In comparative effectiveness research, observational studies are typically considered to be less conclusive than RCTs and meta-analyses. Nonetheless, they can be useful, especially because they examine typical care. Due to lower cost and improvements in health information, observational studies will become increasingly common. Critical assessment of whether the described results are helpful or biased (based upon how the study was performed) are necessary. This case will illustrate several characteristics of the types of studies that will assist in evaluating newly published work. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Applications&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cardiovascular diseases (CVD) are the leading cause of death in women older than   the age of 50. Epidemiologic evidence suggests that estrogen is a key mediator in the development of CVD. Estrogen is an ovarian hormone whose production decreases as women approach menopause. The steep increase in CVD in women at menopause and older and in women who have had hysterectomies further supports a relationship between estrogen and CVD. Building on this evidence of biologic plausibility, epidemiological and observational studies suggested that estrogen replacement therapy (a form of &amp;lt;b&amp;gt;hormone replacement therapy&amp;lt;/b&amp;gt;, or HRT) had positive effects on the risk of CVD in postmenopausal women, (albeit with some negative effects in its potential to increase the risk for breast cancer and stroke). Based on these findings, in the 1980s and 1990s HRT was routinely employed to treat menopausal symptoms and serve as prophylaxis against CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Nurses’ Health Study (NHS) began collecting data in 1976. In the study, researchers intended to examine a broad range of health effects in women over a long period of time, and a key goal was to clarify the role of HRT in heart disease. The cohort (i.e., the group being followed) included married registered nurses aged 30-55 in 1976 who lived in the 11 most populous states. To collect data, the researchers mailed the study participants a survey every 2 years that asked questions about topics such as smoking, hormone use, menopausal status, and less frequently, diet. Data were collected for key end points that included MI, coronary-artery bypass grafting or angioplasty, stroke, total CVD mortality, and deaths from all causes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a 10-year follow-up point, the NHS had a study pool of 48,470 women. The researchers found that estrogen use (alone, without progestin) in postmenopausal women was associated with a reduction in the incidence of CVD as well as in CVD mortality compared to non-users. Later, estrogen-progestin combination therapy was shown to be even more cardioprotective than estrogen monotherapy, and lower doses of estrogen replacement therapy were found to deliver equal cardioprotection and lower the risk for adverse events. NHS researchers were alert to the potential for bias in observational studies. Adjustment for risk factors such as age (a typical practice to eliminate confounding) did not change the reported findings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NHS was not unique in reporting the benefits associated with HRT; other observational studies corroborated the NHS findings. A secondary retrospective data analysis of the UK primary care electronic medical record database, for example, also showed the protective effect associated with HRT use. Researchers were aware of the fundamental limitations of observational studies, particularly with regard to selection bias. They and practicing clinicians were also aware of the potential negative health effects of HRT, which had to be constantly weighed against the potential cardioprotective benefits in deciding a patient’s course of treatment. As a large section of the population could experience the health effects of HRT, researchers began planning RCTs to verify the promising observational study results. It was highly anticipated that those RCTs would corroborate the belief that estrogen replacement can reduce CVD risk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Randomized Controlled Trial: The Women’s Health Initiative&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Women’s health Initiative (WHI) was a major study established by the National Institutes of health in 1992 to assess a broad range of health effects in postmenopausal women. The trial was intended to follow these women for 8 years, at a cost of millions of dollars in federal funding. Among its many facets, it included an RCT to confirm the results from the observational studies discussed above. To fully investigate earlier findings, the WHI had two subgroups. One subgroup consisted of women with prior hysterectomies; they received estrogen monotherapy. The second group consisted of women who had not undergone hysterectomy; they received estrogen in combination with progestin. The WHI enrolled 27,347 women in their HRT investigation: 10,739 in the estrogen-alone arm and 16,608 in the estrogen plus progestin arm. Within each arm, women were randomly assigned to receive either HRT or placebo. All women in the trial were postmenopausal and aged 50-79 years; the mean age was 63.6 years (a fact that would be important in later analysis). Some participants had experienced previous CV events. The primary outcome of both subgroups was coronary heart disease (CHD), as described by nonfatal MI or death due to CHD.&lt;br /&gt;
&lt;br /&gt;
The estrogen-progestin arm of the WHI was halted after a mean follow-up of 5.2 years, 3 years earlier than expected, as the HRT users in this arm were found to be at increased risk for CHD compared to those who received placebo. The study also noted elevated rates of breast cancer and stroke, among other poor outcomes. The estrogen-alone arm continued for an average follow-up of 6.8 years before being similarly discontinued ahead of schedule. Although this part of the study did not find an increased risk of CHD, it also did not find any cardioprotective effect. Beyond failing to locate any clear CV benefits, the WHI also found real evidence of harm, including increased risk of blood clots, breast cancer and stroke. Initial WHI publications therefore recommended against HRT being prescribed for the secondary prevention of CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What Next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scientists and the clinicians who relied on their data for guidance in treating patients, were faced with conflicting data: epidemiological and observational studies suggested that HRT was cardioprotective while the higher-quality evidence from RCTs strongly suggested the opposite. Clinicians primarily followed the WHI results, so prescriptions for HRT in postmenopausal women quickly declined. Meanwhile, researchers began to analyze the studies for potential discrepancies, and found that the women being followed in the NHS and the WHI differed in several important characteristics.&lt;br /&gt;
&lt;br /&gt;
First, the WHI population was older than the NHS cohort, and many had entered menopause at least 10 years before they enrolled in the RCT. Thus, the WHI enrollees experienced a long duration from the onset of menopause to the commencement of HRT. At the same time, many in the NHS population were closer to the onset of menopause and were still displaying hormonal symptoms when they began HRT. Second, although the NHS researchers adjusted the data for various confounding effects, their results could still have been subject to bias. In general, the NHS cohort was more highly educated and of a higher socioeconomic status than the WHI participants, and therefore more likely to see a physician regularly. The NHS women were also leaner and generally healthier than their RCT counterparts, and had been selected for their evident lack of pre-existing CV conditions. This selection bias in the NHS enrollment may have led to a “healthy woman” effect that in turn led to an overestimation of the benefits of therapy in the observational study. Third, researchers noted that dosing differences between the two study types may have contributed to the divergent results. The NHS reported beneficial results following low-dose estrogen therapy. The WHL, meanwhile, used a higher estrogen dose, exposing women to a larger dosage of hormones and increasing their risk for adverse events. The increased risk profile of the WHI women (e.g., older, more comorbidities, higher estrogen dose) could have contributed to the evidence of harm seen in the WHI results.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
In addition to identifying the inherent differences between the two study populations, researchers began a secondary analysis of the NHS and WHI trials. NHS researchers reported that women who began HRT close to the onset of menopause had a significantly reduced risk of CHD. In the subgroups of women that were older and had a similar duration after menopause compared with the WHI women, they found no significant relationship between HRT and CHD. Also, the WHI study further stratified these results by age, and found that women who began HRT close to their onset of menopause experienced some cardioprotection, while women who were further from the onset of menopause had a slightly elevated risk for CHD.&lt;br /&gt;
&lt;br /&gt;
Secondary analysis of both studies was therefore necessary to show that age and a short duration from the onset of menopause are crucial to HRT success as a cardioprotective agent. Neither study type provided “truth” or rather, both studies provided “truth” if viewed carefully (e.g., both produced valid and important results). The differences seen in the studies were rooted in the timing of HRT and the populations being studied.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are given a higher evidence grade, observational studies provide important clinical insights. In this example, the study populations differed. For policymakers and clinicians, it is crucial to examine whether the CER was based upon patients similar to those being considered. Any study with a dissimilar population may provide non-relevant results. Thus, readers of CER need to carefully examine the generalizability of the findings being reported.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
General Classification and Regression Tree (CART) data analysis steps part of the R package &amp;lt;b&amp;gt;rpart.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Growing the Tree===&lt;br /&gt;
&lt;br /&gt;
 # To grow a tree, use&lt;br /&gt;
 rpart(formula, data=, method=,control=), where&lt;br /&gt;
 formula 	is in the format outcome ~ predictor1+predictor2+...&lt;br /&gt;
 data= 	specifies the data frame&lt;br /&gt;
 method= 	&amp;quot;class&amp;quot; for a classification tree, use &amp;quot;anova&amp;quot; for a regression tree&lt;br /&gt;
 control= 	optional parameters for controlling tree growth. For example, control=rpart.control(minsplit=30, cp=0.001) requires that the minimum number of observations in a node be 30 before attempting a split and that a split      must decrease the overall lack of fit by a factor of 0.001 (cost complexity factor) before being attempted.&lt;br /&gt;
&lt;br /&gt;
===Examining Results===&lt;br /&gt;
&lt;br /&gt;
 # These functions help with examining the results.&lt;br /&gt;
 printcp(fit) 	display complexity parameter (cp) table&lt;br /&gt;
 plotcp(fit) 	plot cross-validation results&lt;br /&gt;
 rsq.rpart(fit) 	plot approximate R-squared and relative error for different splits (2 plots). labels are only appropriate for the &amp;quot;anova&amp;quot; method.&lt;br /&gt;
 print(fit) 		print results&lt;br /&gt;
 summary(fit) 	detailed results including surrogate splits&lt;br /&gt;
 plot(fit) 		plot decision tree&lt;br /&gt;
 text(fit) 		label the decision tree plot&lt;br /&gt;
 post(fit, file=) 	create postscript plot of decision tree&lt;br /&gt;
 # In trees created by rpart(), move to the LEFT branch when the stated condition is true.&lt;br /&gt;
&lt;br /&gt;
===Pruning Trees===&lt;br /&gt;
&lt;br /&gt;
 #In general, trees should be pruned back to avoid overfitting the data. The tree size should minimize the cross-#validated error – xerror column printed by printcp(). Pruning the tree is accomplished by:&lt;br /&gt;
 prune(fit, cp= )&lt;br /&gt;
 # use printcp( ) to examine the cross-validation error results, select the complexity parameter (CP) associated with minimum error, and insert the CP it into the prune() function. This (automatically selecting the complexity  parameter associated with the smallest cross-validated error) can be done succinctly by:&lt;br /&gt;
 fit$\$$cptable[which.min(fit$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===Compete Dataset for N-of-1 Example===&lt;br /&gt;
[[SMHS_MethodsHeterogeneity_CER_Nof1|This N-of-1 Dataset]] includes an example.&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_CER}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_MetaAnalysis&amp;diff=16155</id>
		<title>SMHS MethodsHeterogeneity MetaAnalysis</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_MetaAnalysis&amp;diff=16155"/>
		<updated>2016-05-23T13:23:30Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Meta-Analyses ==&lt;br /&gt;
&lt;br /&gt;
==Meta-analysis==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Meta-analysis is an approach to combine treatment effects across trials or studies into an aggregated treatment effect with higher statistical power than observed in each individual trials. It may detect HTE by testing for differences in treatment effects across similar RCTs. It requires that the individual treatment effects are similar to ensure pooling is meaningful. In the presence of large clinical or methodological differences between the trials, it may be to avoid meta-analyses. The presence of HTE across studies in a meta-analysis may be due to differences in the design or execution of the individual trials (e.g., randomization methods, patient selection criteria). &amp;lt;b&amp;gt;Cochran's Q is a methods for detection of heterogeneity, which is computed as the weighted sum of squared differences between each study's treatment effect and the pooled effects across the studies.&amp;lt;/b&amp;gt; It is a barometer of inter-trial differences impacting the observed study result.  A possible source of error in a meta-analysis is publication bias. Trial size may introduce publication bias since larger trials are more likely to be published. Language and accessibility represent other potential confounding factors. When the heterogeneity is not due to poor study design, it may be useful to optimize the treatment benefits for different cohorts of participants.	&lt;br /&gt;
&lt;br /&gt;
Cochran's Q statistics is the weighted sum of squares on a standardized scale. &amp;lt;b&amp;gt;The corresponding P value indicates the strength of the evidence of presence of heterogeneity.&amp;lt;/b&amp;gt; This test may have low power to detect heterogeneity sometimes and it is suggested to use a value of 0.10 as a cut-off for significance (Higgins et al., 2003). The Q statistics also may have too much power as a test of heterogeneity when the number of studies is large.&lt;br /&gt;
&lt;br /&gt;
===Simulation Example 1===&lt;br /&gt;
&lt;br /&gt;
 # Install and Load library&lt;br /&gt;
 install.packages(&amp;quot;meta&amp;quot;)&lt;br /&gt;
 library(meta)&lt;br /&gt;
 &lt;br /&gt;
 # Set number of studies&lt;br /&gt;
 n.studies = 15&lt;br /&gt;
 &lt;br /&gt;
 # number of treatments: case1, case2, control&lt;br /&gt;
 n.trt = 3&lt;br /&gt;
 &lt;br /&gt;
 # number of outcomes&lt;br /&gt;
 n.event = 2&lt;br /&gt;
 &lt;br /&gt;
 # simulate the (balanced) number of cases (case1 and case2) and controls in each study&lt;br /&gt;
 ctl.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
 case1.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
 case2.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
&lt;br /&gt;
 # Simulate the number of outcome events (e.g., deaths) and no events in the control group&lt;br /&gt;
 event.ctl.group = rbinom(n = n.studies, size = ctl.group, prob = rep(&amp;lt;mark&amp;gt;0.1&amp;lt;/mark&amp;gt;, length(ctl.group)))&lt;br /&gt;
 noevent.ctl.group = ctl.group - event.ctl.group&lt;br /&gt;
 &lt;br /&gt;
 # Simulate the number of events and no events in the case1 group&lt;br /&gt;
 event.case1.group = rbinom(n = n.studies, size = case1.group, prob = rep(&amp;lt;mark&amp;gt;0.5&amp;lt;/mark&amp;gt;, length(case1.group)))&lt;br /&gt;
 noevent.case1.group = case1.group - event.case1.group&lt;br /&gt;
&lt;br /&gt;
 # Simulate the number of events and no events in the case2 group&lt;br /&gt;
 event.case2.group = rbinom(n = n.studies, size = case2.group, prob = rep(&amp;lt;mark&amp;gt;0.6&amp;lt;/mark&amp;gt;, length(case2.group)))&lt;br /&gt;
 noevent.case2.group = case2.group - event.case2.group&lt;br /&gt;
&lt;br /&gt;
 # Run the univariate meta-analysis using &amp;lt;b&amp;gt;metabin()&amp;lt;/b&amp;gt;, Meta-analysis of binary outcome data – &lt;br /&gt;
 # Calculation of fixed and random effects estimates (risk ratio, odds ratio, risk difference or arcsine&lt;br /&gt;
 # difference) for meta-analyses with binary outcome data.   Mantel-Haenszel (MH), &lt;br /&gt;
 #  inverse variance and Peto method are available for pooling.&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;method&amp;lt;/b&amp;gt; = A character string indicating which method is to be used for pooling of studies. &lt;br /&gt;
 # one of &amp;quot;MH&amp;quot; , &amp;quot;Inverse&amp;quot; , or &amp;quot;Cochran&amp;quot;&lt;br /&gt;
 # sm = A character string indicating which summary measure (“OR”, &amp;quot;RR&amp;quot; &amp;quot;RD&amp;quot;=risk difference) is to be &lt;br /&gt;
 # used for pooling of studies&lt;br /&gt;
&lt;br /&gt;
 # Control vs. Case1, n.e and n.c are numbers in experimental and control groups&lt;br /&gt;
 meta.ctr_case1 &amp;lt;- metabin(event.e = &amp;lt;b&amp;gt;event.case1.group&amp;lt;/b&amp;gt;, n.e = case1.group, event.c = &amp;lt;b&amp;gt;event.ctl.group&amp;lt;/b&amp;gt;, &lt;br /&gt;
 n.c = ctl.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 # in this case we use Odds Ratio, of the odds of death in the experimental and control studies&lt;br /&gt;
 forest(meta.ctr_case1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Control vs. Case2&lt;br /&gt;
 meta.ctr_case2 &amp;lt;- metabin(event.e = event.case2.group, n.e = case2.group, event.c = event.ctl.group, &lt;br /&gt;
 n.c = ctl.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 forest(meta.ctr_case2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Case1 vs. Case2&lt;br /&gt;
 meta.case1_case2 &amp;lt;- metabin(event.e = event.case1.group, n.e = case1.group, event.c = event.case2.group, &lt;br /&gt;
 n.c = case2.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 forest(meta.case1_case2)&lt;br /&gt;
 summary(meta.case1_case2)&lt;br /&gt;
&lt;br /&gt;
 Test of heterogeneity:&lt;br /&gt;
     Q 	d.f.  	p-value&lt;br /&gt;
 11.99   	14   	0.6071&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;forest plo&amp;lt;/b&amp;gt;t shows the I2 test indicates the evidence to reject the null hypothesis (no study heterogeneity and the fixed effects model should be used).&lt;br /&gt;
&lt;br /&gt;
==Series of “N of 1” trials==&lt;br /&gt;
&lt;br /&gt;
This technique combines (a “series of”) n-of-1 trial data to identify HTE. An n-of-1 trial is a repeated crossover trial for a single patient, which randomly assigns the patient to one treatment vs. another for a given time period, after which the patient is re-randomized to treatment for the next time period, usually repeated for 4-6 time periods. Such trials are most feasibly done in chronic conditions, where little or no washout period is needed between treatments and treatment effects are identifiable in the short-term, such as pain or reliable surrogate markers. Combining data from identical n-of-1 trials across a set of patients enables the statistical analysis controlling for patient fixed or random effects, covariates, centers, or sequence effects, see &amp;lt;b&amp;gt;Figure&amp;lt;/b&amp;gt; below. These combined trials are often analyzed within a Bayesian context using shrinkage estimators that combine individual and group mean treatment effects to create a “posterior” individual mean treatment effect estimate which is a form of inverse variance-weighted average of the individual and group effects. Such trials are typically more expensive than standard RCTs on a per-patient basis, however, they require much smaller sample sizes, often less than 100 patients (due to the efficient individual-as-own-control design), and create individual treatment effect estimates that are not possible in a non-crossover design  . For the individual patient, the treatment effect can be re-estimated after each time period, and the trial stopped at any point when the more effective treatment is identified with reasonable statistical certainty.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
A study involving 8 participants collected data across 30 days, in which 15 treatment days and 15 control days are randomly assigned within each participant. The treatment effect is represented as a binary variable (control day=0; treatment day=1). The outcome variable represents the response to the intervention within each of the 8 participants. Study employed a fixed-effects modeling. By creating N − 1 dummy-coded variables representing the N=8 participants, where the last (i=8) participant serves as the reference (i.e., as the model intercept). So, each dummy-coded variable represents the difference between each participant (i) and the 8th participant. Thus, all other patients' values will be relative to the values of the 8th (reference) subject. The overall differences across participants in fixed effects can be evaluated with multiple &amp;lt;b&amp;gt;degree-of-freedom F-tests.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|...||...||...||...||...||...||...||...||...||...&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt; Complete data is available in the &amp;lt;b&amp;gt;Appendix.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Data Summary&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||Constant&lt;br /&gt;
|-&lt;br /&gt;
|Physical Activity||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|Intervention||Tx&lt;br /&gt;
|-&lt;br /&gt;
|WP Social Support||WPSS&lt;br /&gt;
|-&lt;br /&gt;
|PM Social Support (1-3)||PMss3&lt;br /&gt;
|-&lt;br /&gt;
|Self Efficacy||SelfEff25&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rm(list=ls())&lt;br /&gt;
 Nof1 &amp;lt;-read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q&amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)    # 02_Nof1_Data.csv&lt;br /&gt;
 attach(Nof1)&lt;br /&gt;
 head(Nof1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 df.1 = data.frame(PhyAct, Tx, WPSS, PMss3, SelfEff25) &lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;lme4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 lm.1 = model.lmer &amp;lt;- lmer(PhyAct ~ Tx + SelfEff + Tx*SelfEff + (1|Day) + (1|ID) , data= df.1)&lt;br /&gt;
 summary(lm.1)&lt;br /&gt;
&lt;br /&gt;
 Linear mixed model fit by REML ['lmerMod']&lt;br /&gt;
 Formula: PhyAct ~ Tx + SelfEff + Tx * SelfEff + (1 | Day) + (1 | ID)&lt;br /&gt;
   Data: df.1&lt;br /&gt;
&lt;br /&gt;
 REML criterion at convergence: 8820&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Scaled Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
|-2.7012||-0.6833||-0.0333||0.6542||3.9612&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Groups ||Name||Variance ||Std.Dev.&lt;br /&gt;
|-&lt;br /&gt;
| Day||(Intercept) ||0.0 || 0.00   &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|ID|| (Intercept)||601.5||24.53   &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 |Residual|| ||969.0 ||31.13  &lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 900, groups:  Day, 30; ID, 30&lt;br /&gt;
 &amp;lt;/center&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Estimate||Std.||Error||t value&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||38.3772||14.4738||2.651&lt;br /&gt;
|-&lt;br /&gt;
|Tx||4.0283||6.3745||0.632&lt;br /&gt;
|-&lt;br /&gt;
|SelfEff||0.5818||0.5942||0.979&lt;br /&gt;
|-&lt;br /&gt;
|Tx:SelfEff||0.9702||0.2617||3.708&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Correlation of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||(Intr)||Tx ||SlfEff&lt;br /&gt;
|-&lt;br /&gt;
| Tx|| -0.220|| ||               &lt;br /&gt;
|-&lt;br /&gt;
| SelfEff||-0.946 ||0.208 ||     &lt;br /&gt;
|-&lt;br /&gt;
| Tx:SelfEff ||0.208 ||-0.946 ||-0.220&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Model:  PhyAct = Tx + WPSS + PMss3 + Tx*WPSS + Tx*PMss3 + SelfEff25 + Tx*SelfEff25 + ε&lt;br /&gt;
 lm.2 = lm(PhyAct ~ Tx + WPSS + PMss3 + Tx*WPSS + Tx*PMss3 + SelfEff25 + Tx*SelfEff25, df.1) &lt;br /&gt;
 summary(lm.2)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = PhyAct ~ Tx + WPSS + PMss3 + Tx * WPSS + Tx * PMss3 + &lt;br /&gt;
    SelfEff25 + Tx * SelfEff25, data = df.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max               &lt;br /&gt;
|-&lt;br /&gt;
| -102.39||-28.24||-1.47||25.16||122.41    &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate||Std. Error||t value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||52.0067||1.8080||28.764||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|Tx||27.7366||2.5569||10.848||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|WPSS||1.9631||2.4272||0.809||0.418853 &lt;br /&gt;
|-   &lt;br /&gt;
|PMss3||13.5110||2.7853||4.851||1.45e-06 ***&lt;br /&gt;
|-&lt;br /&gt;
|SelfEff25||0.6289||0.2205||2.852||0.004439 ** &lt;br /&gt;
|-&lt;br /&gt;
|Tx:WPSS||9.9114||3.4320||2.888||0.003971 ** &lt;br /&gt;
|-&lt;br /&gt;
|Tx:PMss3||8.8422||3.9390||2.245||0.025025 *  &lt;br /&gt;
|-&lt;br /&gt;
|Tx:SelfEff25||1.0460||0.3118||3.354||0.000829 ***&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[Using SAS (StudyI_Analyses.sas, StudyIIab_Analyses.sas)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Type 3 Tests of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Effect&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Num DF&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Den DF&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;F Value&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;$Pr&amp;gt;F$&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Tx&amp;lt;/b&amp;gt;||1||224||67.46||&amp;lt;.0001          &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;ID&amp;lt;/b&amp;gt;||7||224||25.95||&amp;lt;.0001&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Tx*ID&amp;lt;/b&amp;gt;||7||224||2.92||0.0060&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quantile Treatment Effect (QTE)==&lt;br /&gt;
&lt;br /&gt;
QTE employs quantile regression estimation (QRE) to examine the central tendency and statistical dispersion of the treatment effect in a population. These may not be revealed by the conventional mean estimation in RCTs. For instance, patients with different comorbidity scores may respond differently to a treatment. Quantile regression has the ability to reveal HTE according to the ranking of patients’ comorbidity scores or some other relevant covariate by which patients may be ranked. Therefore, in an attempt to inform patient-centered care, quantile regression provides more information on the distribution of the treatment effect than typical conditional mean treatment effect estimation. QTE characterizes the heterogeneous treatment effect on individuals and groups across various positions in the distributions of different outcomes of interest. This unique feature has given quantile regression analysis substantial attention and has been employed across a wide range of applications, particularly when evaluating the economic effects of welfare reform.&lt;br /&gt;
&lt;br /&gt;
One caveat of applying QRE in clinical trials for examining HTE is that the QTE doesn’t demonstrate the treatment effect for a given patient. Instead, it focuses on the treatment effect among subjects within the qth quantile, such as those who are exactly at the top 10th percent in terms of blood pressure or a depression score for some covariate of interest, for example, comorbidity score. It is not uncommon for the qth quantiles to be two different sets of patients before and after the treatment. For this reason, we have to assume that these two groups of patients are homogeneous if they were in the same quantiles.&lt;br /&gt;
&lt;br /&gt;
Income-Food Expenditure Example: Let’s examine the Engel data (N=235) on the relationship between food expenditure (foodexp) and household income (income). We can plot the data and then explore the superposition of the six fitted quantile regression lines. &lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;quantreg&amp;quot;)&lt;br /&gt;
 library(quantreg)&lt;br /&gt;
 data(engel)&lt;br /&gt;
 attach(engel)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(engel)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Income||Foodexp&lt;br /&gt;
|-   &lt;br /&gt;
|1||420.1577||255.8394&lt;br /&gt;
|-&lt;br /&gt;
|2||541.4117||310.9587&lt;br /&gt;
|-&lt;br /&gt;
|3||901.1575||485.6800&lt;br /&gt;
|-   &lt;br /&gt;
|4||639.0802||402.9974&lt;br /&gt;
|-&lt;br /&gt;
|5||750.8756||495.5608&lt;br /&gt;
|-&lt;br /&gt;
|6||945.7989||633.7978&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;summary(engel)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Income||Foodexp&lt;br /&gt;
|-   &lt;br /&gt;
|Min||377.1||242.3&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.||638.9||429.7&lt;br /&gt;
|-&lt;br /&gt;
|Median||884.0||582.5&lt;br /&gt;
|-   &lt;br /&gt;
|Mean||982.5||624.2&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.||1164.0||743.9&lt;br /&gt;
|-&lt;br /&gt;
|Max||4957.8||2032.7&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: If &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt; be a real valued random variable with cumulative distribution function F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(y)=P(Y≤ y), then the τ-quantile of &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt; is given by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Q&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(τ)=F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;-1&amp;lt;/sup&amp;gt;(τ)=inf{ y:F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(y)≥τ} &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where 0≤τ≤1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (1) Graphics&lt;br /&gt;
 plot(income, foodexp, cex=.25, type=&amp;quot;n&amp;quot;, xlab=&amp;quot;Household Income&amp;quot;, ylab=&amp;quot;Food Expenditure&amp;quot;)&lt;br /&gt;
 points(income, foodexp, cex=.5, col=&amp;quot;blue&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # tau - the quantile(s) to be estimated, in the range from 0 to 1. An object &amp;quot;rq.process&amp;quot; and an object &amp;quot;rqs&amp;quot; &lt;br /&gt;
 # are returned containing the matrix of coefficient estimates at the specified quantiles.&lt;br /&gt;
 abline( rq(foodexp ~ income, tau=.5), col=&amp;quot;blue&amp;quot;)  	# Quantile Regression Model&lt;br /&gt;
&lt;br /&gt;
 abline( lm(foodexp ~ income), lty=2, lwd=3, col=&amp;quot;red&amp;quot;) 	# linear model&lt;br /&gt;
 taus &amp;lt;- c(0.05, 0.1, 0.25, 0.75, 0.90, 0.95)&lt;br /&gt;
 colors &amp;lt;- rainbow(length(taus))&lt;br /&gt;
&lt;br /&gt;
 models &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = length(taus)) # define a vector of models to store QR for diff taus&lt;br /&gt;
 model.names &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = length(taus)) # define a vector model names&lt;br /&gt;
&lt;br /&gt;
 for( i in 1:length(taus)){&lt;br /&gt;
 models[[i]] &amp;lt;-  rq(foodexp ~ income, tau=taus[i]) &lt;br /&gt;
 var &amp;lt;- taus[i]&lt;br /&gt;
 model.names[[i]] &amp;lt;- paste(&amp;quot;Model [&amp;quot;, i , &amp;quot;]: tau=&amp;quot;, var)&lt;br /&gt;
 abline( models[[i]], lwd=2, col= colors[[i]])&lt;br /&gt;
 }&lt;br /&gt;
 legend(3000, 1100, model.names, col= colors, pch= taus, bty='n', cex=.75)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (2) Inference about quantile regression coefficients.  As an alternative to the rank-inversion confidence intervals, we can obtain a table of coefficients, standard errors, t-statistics, and p-values using the summary function:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;summary(models[[3]], se = &amp;quot;nid&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Call: rq(formula = foodexp ~ income, tau = taus[i])&lt;br /&gt;
&lt;br /&gt;
 tau: [1] 0.25&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Value||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||95.48354||21.39237||4.46344||0.00001&lt;br /&gt;
|-&lt;br /&gt;
|Income||0.47410||0.02906||16.31729||0.00000&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use summary.rq to compute bootstrapped standard errors.&lt;br /&gt;
 summary.rq(models[[3]], se = &amp;quot;nid&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 Call: rq(formula = foodexp ~ income, tau = taus[i])&lt;br /&gt;
 tau: [1] 0.25&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Value||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||95.48354||21.39237||4.46344||0.00001&lt;br /&gt;
|-&lt;br /&gt;
|Income||0.47410||0.02906||16.31729||0.00000&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Nonparametric Regression Methods ==&lt;br /&gt;
&lt;br /&gt;
Nonparametric regression enables dealing with HTE in RCTs. Different nonparametric methods, such as kernel smoothing methods and series methods, can be used to generate test statistics for examining the presence of HTE. A kernel method is a weighting scheme based on a kernel function (e.g. uniform, Gaussian). When evaluating the treatment effect of a patient in RCTs, the kernel method assigns larger weights to those observations with similar covariates. This is done because it is assumed that patients with similar covariates provide more relevant data on predicted treatment response. Examining participants that have different backgrounds (e.g., demographic, clinical), kernel smoothing methods utilize information from highly divergent participants when estimating a particular subject’s treatment effect. Lower weights are assigned to very different subjects and the kernel methods require choosing a set of smoothing parameters to group patients according to their relative degree of similarities. A drawback is that the corresponding proposed test statistics may be sensitive to the chosen bandwidths, which inhibits the interpretation of the results. Series methods use approximating functions (splines or power series of the explanatory variables) to construct test statistics. Compared to kernel smoothing methods, series methods normally have the advantage of computational convenience; however, the precision of test statistics depends on the number of terms selected in the series. &lt;br /&gt;
&lt;br /&gt;
Canadian Wage Data Example: Nonparametric regression extends the classical parametric regression (e.g., lm, lmer) involving one continuous dependent variable, y, and (1 or more) continuous explanatory variable(s), x. Let’s start with a popular parametric model of a wage equation that we can extend to a fully nonparametric regression model. First, we will compare and contrast the parametric and nonparametric approach towards univariate regression and then proceed to multivariate regression.&lt;br /&gt;
&lt;br /&gt;
Let’s use the Canadian cross-section wage data (&amp;lt;b&amp;gt;cps71&amp;lt;/b&amp;gt;) consisting of a random sample taken from the 1971 Canadian Census for male individuals having common education (High-School). N=205 observations, 2 variables, the logarithm of the individual’s wage (logwage) and their age (age). The classical wage equation model includes a quadratic term of age.&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;np&amp;quot;)&lt;br /&gt;
 library(&amp;quot;np&amp;quot;)&lt;br /&gt;
 data(&amp;quot;cps71&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (1) Linear Model -&amp;gt; R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  = 0.2308&lt;br /&gt;
 model.lin &amp;lt;- lm( logwage ~ age + I(age^2), data = cps71)&lt;br /&gt;
 summary(model.lin)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = logwage ~ age + I(age^2), data = cps71)&lt;br /&gt;
&lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -2.4041 -0.1711  0.0884  0.3182  1.3940 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||10.0419773||0.4559986||22.022||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|Age||0.1731310||0.0238317|| 7.265||7.96e-12 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||-0.0019771||0.0002898||-6.822||1.02e-10 ***&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
 Residual standard error: 0.5608 on 202 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.2308,	Adjusted R-squared:  0.2232 &lt;br /&gt;
 F-statistic:  30.3 on 2 and 202 DF,  p-value: 3.103e-12&lt;br /&gt;
&lt;br /&gt;
 # (2) Next, we consider the local linear nonparametric method employing cross-validated &lt;br /&gt;
 # bandwidth selection and estimation in one step. Start with computing the least-squares&lt;br /&gt;
 #  cross-validated bandwidths for the local constant estimator (default).&lt;br /&gt;
 # Note that &amp;lt;b&amp;gt;R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; = 0.3108675&amp;lt;/b&amp;gt;&lt;br /&gt;
 bandwidth &amp;lt;- npregbw(formula= logwage ~ age, data = cps71)&lt;br /&gt;
 model.np &amp;lt;- npreg(bandwidth,  regtype = &amp;quot;ll&amp;quot;,  bwmethod = &amp;quot;cv.aic&amp;quot;, gradients = TRUE, data = cps71)&lt;br /&gt;
 summary(model.np)&lt;br /&gt;
&lt;br /&gt;
 Regression Data: 205 training points, in 1 variable(s) age&lt;br /&gt;
 Bandwidth(s): 1.892157&lt;br /&gt;
 Kernel Regression Estimator: Local-Constant&lt;br /&gt;
 Bandwidth Type: Fixed&lt;br /&gt;
 Residual standard error: 0.5307943&lt;br /&gt;
 R-squared: &amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;0.3108675&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
 Continuous Kernel Type: Second-Order Gaussian&lt;br /&gt;
 No. Continuous Explanatory Vars.: 1&lt;br /&gt;
&lt;br /&gt;
 # NP model significance may be tested by&lt;br /&gt;
 npsigtest(model.np)&lt;br /&gt;
&lt;br /&gt;
 Kernel Regression Significance Test&lt;br /&gt;
 Type I Test with IID Bootstrap (399 replications, Pivot=TRUE, joint=FALSE)&lt;br /&gt;
 Explanatory variables tested for significance: age (1)&lt;br /&gt;
&lt;br /&gt;
               age&lt;br /&gt;
 Bandwidth(s): 1.892157&lt;br /&gt;
&lt;br /&gt;
 Individual Significance Tests&lt;br /&gt;
 P Value: &lt;br /&gt;
 age &amp;lt; 2.22e-16 ***&lt;br /&gt;
&lt;br /&gt;
 # So, as was the case for the linear parametric model, Age is significant in the local linear NP-model&lt;br /&gt;
&lt;br /&gt;
 # (3) Graphical comparison of parametric and nonparametric models. &lt;br /&gt;
 plot(cps71$\$$age, cps71$\$$logwage, xlab = &amp;quot;age&amp;quot;, ylab = &amp;quot;log(wage)&amp;quot;, cex=.1)&lt;br /&gt;
 lines(cps71$\$$age, fitted(model.lin), lty = 2, col = &amp;quot; red&amp;quot;)&lt;br /&gt;
 lines(cps71$\$$age, fitted(model.np), lty = 1, col = &amp;quot;blue&amp;quot;)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, c(&amp;quot;Data&amp;quot;, &amp;quot;Linear&amp;quot;, &amp;quot;Non-linear&amp;quot;), col=c(&amp;quot;Black&amp;quot;, &amp;quot;Red&amp;quot;, &amp;quot;Blue&amp;quot;), pch = c(1, 1, 1), bty='n', cex=.75)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # some additional plots resenting the parametric (quadratic, dashed line) and the nonparametric estimates &lt;br /&gt;
 # (solid line) of the regression function for the cps71 data. &lt;br /&gt;
 plot(model.np, plot.errors.method = &amp;quot;asymptotic&amp;quot;)&lt;br /&gt;
 plot(model.np, gradients = TRUE)&lt;br /&gt;
 lines(cps71$\$$age, coef(model.lin)[2]+2*cps71$\$$age*coef(model.lin)[3], lty = 2, col = &amp;quot;red&amp;quot;)&lt;br /&gt;
 plot(model.np, gradients = TRUE, plot.errors.method = &amp;quot;asymptotic&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (4) using the Lin and NL models to generate predictions based on the obtained appropriate &lt;br /&gt;
 # bandwidths and estimated a nonparametric model. We need to create a set of explanatory&lt;br /&gt;
 # variables for which to generate predictions. These can be part of the original dataset or be&lt;br /&gt;
 # outside its scope. Typically, we don’t have the outcome for the evaluation data and need only &lt;br /&gt;
 # provide the explanatory variables for which predicted values are generated by the models.&lt;br /&gt;
 # Occasionally, splitting the dataset into two independent samples (training/testing), allows estimation&lt;br /&gt;
 # of a model on one sample, and evaluation of its performance on another.&lt;br /&gt;
&lt;br /&gt;
 cps.eval.data &amp;lt;- data.frame(age = seq(10,70, by=10)) # simulate some explanatory X values (ages)&lt;br /&gt;
 pred.lin &amp;lt;- predict(model.lin, newdata = cps.eval.data)		# Linear Prediction of log(Wage)&lt;br /&gt;
 pred.np &amp;lt;- predict(model.np, newdata = cps.eval.data)		# non-Linear Prediction of log(Wage)&lt;br /&gt;
 plot(pred.lin, pred.np)&lt;br /&gt;
 abline(lm(pred.np ~ pred.lin))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
==Predictive risk models ==&lt;br /&gt;
&lt;br /&gt;
Predictive risk models represent a class of methods for identifying potential for HTE when the individual patient risk for disease-related events at baseline depends on observed factors. For instance, common measures are disease staging criteria, such as those used in COPD or heart failure, Framingham risk scores for cardiovascular event risk, or genetic variations, e.g., HER2 for breast cancer. Initial predictive risk modeling, aka risk function estimation, is often performed without accounting for treatment effects. Least squares or Cox proportional hazards regression methods are appropriate in many cases and provide relatively more interpretable risk functions, but rely on linearity assumptions and may not provide optimal predictive metrics. Partial least squares is an extension of least squares methods that can reduce the dimensionality of the predictor space by interposing latent variables, predicted by linear combinations of observable characteristics, as the intermediate predictors of one or more outcomes. Recursive partitioning, such as random forests, support vector machines, and neural networks represent latter methods with better predictive power than linear methods. Risk function estimation can range from highly exploratory analyses to near meta-analytic model validation, and may be useful at any stage of product development.&lt;br /&gt;
&lt;br /&gt;
HIV Example: The &amp;lt;b&amp;gt;“hmohiv”&amp;lt;/b&amp;gt; dataset   represents a study of HIV positive patients examining whether there was a difference in survival times of HIV positive patients between a cohort using intravenous drugs (drug=1) and a cohort not using the IV drug (drug=0). The &amp;lt;b&amp;gt;hmohiv&amp;lt;/b&amp;gt; data includes the following variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID||Time||Age||Drug||Censor||Entdate||Enddate&lt;br /&gt;
|-   &lt;br /&gt;
|1||5||46||0||1||5/15/1990||10/14/1990&lt;br /&gt;
|-&lt;br /&gt;
|2||6||35||1||0||9/19/1989||3/20/1990&lt;br /&gt;
|-&lt;br /&gt;
|3||8||30||1||1||4/21/1991||12/20/1991&lt;br /&gt;
|-&lt;br /&gt;
|4||3||30||1||1||1/3/1991||4/4/1991&lt;br /&gt;
|-&lt;br /&gt;
|5||22||36||0||1||9/18/1989||7/19/1991&lt;br /&gt;
|-&lt;br /&gt;
|6||1||32||1||0||3/18/1991||4/17/1991&lt;br /&gt;
|-&lt;br /&gt;
|...||...||...||...||...||...||...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #cleaning up environment&lt;br /&gt;
 rm(list=ls())&lt;br /&gt;
&lt;br /&gt;
 # load survival library&lt;br /&gt;
 library(survival)&lt;br /&gt;
&lt;br /&gt;
 # load hmohiv data&lt;br /&gt;
 hmohiv&amp;lt;-read.table(&amp;quot;http://www.ats.ucla.edu/stat/r/examples/asa/hmohiv.csv&amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 attach(hmohiv)&lt;br /&gt;
&lt;br /&gt;
 # Fit Cox proportional hazards regression model&lt;br /&gt;
 cox.model &amp;lt;- coxph( Surv(time, censor) ~ drug, method=&amp;quot;breslow&amp;quot;)&lt;br /&gt;
 fit.1 &amp;lt;- survfit(cox.model, newdata=drug.new)&lt;br /&gt;
&lt;br /&gt;
 # construct a frame of the 2 cohorts IV_drug and no-IV-drug&lt;br /&gt;
 drug.new&amp;lt;-data.frame(drug=c(0,1))&lt;br /&gt;
&lt;br /&gt;
 # plot results&lt;br /&gt;
 plot(fit.1, xlab=&amp;quot;Survival Time (Months)&amp;quot;, ylab=&amp;quot;Survival Probability&amp;quot;)&lt;br /&gt;
 points(fit.1$\$$time, fit.1$\$$surv[,1], pch=1)&lt;br /&gt;
 points(fit.1$\$$time, fit.1$\$$surv[,2], pch=2)&lt;br /&gt;
 legend(40, .8, c(&amp;quot;Drug Absent&amp;quot;, &amp;quot;Drug Present&amp;quot;), pch=c(1,2))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to inslect the resulting Cox Proportional Hazard Model&lt;br /&gt;
 cox.model &lt;br /&gt;
 Call:&lt;br /&gt;
 coxph(formula = Surv(time, censor) ~ drug, method = &amp;quot;breslow&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      	    coef 	exp(coef) 	se(coef)   	z      	        p&lt;br /&gt;
 &amp;lt;b&amp;gt;drug&amp;lt;/b&amp;gt; 	0.779          2.18    		0.242 		3.22 	       &amp;lt;b&amp;gt;0.0013&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Likelihood ratio test=10.2  on 1 df, p=0.00141  n= 100, number of events= 80 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_CER|Next see: Comparative Effectiveness Research (CER)]]==&lt;br /&gt;
&lt;br /&gt;
*[[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_MetaAnalysis}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16153</id>
		<title>SMHS MethodsHeterogeneity HTE</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16153"/>
		<updated>2016-05-23T13:22:33Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Latent growth and growth mixture modeling (LGM/GMM) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Methods and Approaches for HTE Analytics ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Recursive partitioning is a data mining technique for exploring structure and patterns in complex data. It facilitates the visualization of decision rules for predicting categorical (classification tree) or continuous (regression tree) outcome variables. The R &amp;lt;b&amp;gt;rpart&amp;lt;/b&amp;gt; package   provides the tools for Classification and Regression Tree (CART) modeling, conditional inference trees, and random forests. Additional resources include an Introduction to Recursive Partitioning Using the RPART Routines  . The &amp;lt;b&amp;gt;Appendix&amp;lt;/b&amp;gt; includes description of the main CART analysis steps.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;install.packages(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CART===&lt;br /&gt;
Classification and Regression Tree (CART) is a decision-tree based technique that considers how variation observed in a given response variable (continuous or categorical) can be understood through a systematic deconstruction of the overall study population into subgroups, using explanatory variables of interest. For HTE analysis, CART is best suited for early-stage, exploratory analyses. Its relative simplicity can be powerful in identifying basic relationships between variables of interest, and thus identify potential subgroups for more advanced analyses. The key to CART is its ‘systematic’ approach to the development of the subgroups, which are constructed sequentially through repeated, binary splits of the population of interest, one explanatory variable at a time. In other words, each ‘parent’ group is divided into two ‘child’ groups, with the objective of creating increasingly homogeneous subgroups. The process is repeated and the subgroups are then further split, until no additional variables are available for further subgroup development. The resulting tree structure is oftentimes overgrown, but additional techniques are used to ‘trim’ the tree to a point at which its predictive power is balanced against issues of over-fitting. Because the CART approach does not make assumptions regarding the distribution of the dependent variable, it can be used in situations where other multivariate modeling techniques often used for exploratory predictive risk modeling would not be appropriate – namely in situations where data are not normally distributed. &lt;br /&gt;
&lt;br /&gt;
CART analyses are useful in situations where there is some evidence to suggest that HTE exists, but the subgroups defining the heterogeneous response are not well understood. CART allows for an exploration of response in a myriad of complex subpopulations, and more recently developed ensemble methods (such as Bayesian Additive Regression Trees) allow for more robust analyses through the combination of multiple CART analyses.&lt;br /&gt;
&lt;br /&gt;
====Example Fifth Dutch growth study====&lt;br /&gt;
&lt;br /&gt;
 # Let’s use the Fifth Dutch growth study (2009) &amp;lt;b&amp;gt;fdgs&amp;lt;/b&amp;gt;  . Is it true that “the world’s tallest nation has stopped growing taller: the height of Dutch children from 1955 to 2009”?&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 library(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 ?fdgs&lt;br /&gt;
 head(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID ||Reg ||Age ||Sex ||HGT ||WGT ||HGT.Z ||WGT.Z&lt;br /&gt;
|-&lt;br /&gt;
|1 ||100001||West||13.09514||boy||175.5||75.0||1.751||2.410&lt;br /&gt;
|-&lt;br /&gt;
|2 ||100003||West||13.81793 ||boy||148.4||40.0||2.292||1.494&lt;br /&gt;
|-&lt;br /&gt;
|3 ||100004||West||13.97125||boy||159.9||46.5||0.743||0.783&lt;br /&gt;
|-&lt;br /&gt;
|4 ||100005||West||13.98220 ||girl||159.7||46.5 ||0.743 ||0.783&lt;br /&gt;
|-&lt;br /&gt;
|5||100006||West||13.52225||girl||160.3||47.8||0.414||0.355&lt;br /&gt;
|-&lt;br /&gt;
|6||100018||East||10.21492||boy||157.8||39.7||2.025||0.823&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(fdgs)        &lt;br /&gt;
 summary(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID ||Reg ||Age ||Sex ||HGT&lt;br /&gt;
|-&lt;br /&gt;
|Min.:100001||North:732||Min.:0.008214||boy:4829||Min.:46.0&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.:106353||East:2528||1st Qu.:1.618754||girl:5201||1st Qu.:83.8&lt;br /&gt;
|-&lt;br /&gt;
|Median:203855||South:2931||Median:8.084873|| ||Median:131.5&lt;br /&gt;
|-&lt;br /&gt;
|Mean:180091||West:2578||Mean:8.157936|| ||Mean:123.9&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.210591||City:1261||3rd Qu.:13.547570|| ||3rd Qu.:162.3&lt;br /&gt;
|-&lt;br /&gt;
|Max:401955|| ||Max.:21.993155|| ||Max.:208.0&lt;br /&gt;
|-&lt;br /&gt;
| || || || ||NA's: 23&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1) Classification Tree&lt;br /&gt;
&lt;br /&gt;
Let's use the data frame fdgs to predict Region, from Age, Height, and Weight.&lt;br /&gt;
 # grow tree &lt;br /&gt;
 fit.1 &amp;lt;- rpart(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, data= fdgs[,-1])&lt;br /&gt;
&lt;br /&gt;
 printcp(fit.1) 	# display the results &lt;br /&gt;
 plotcp(fit.1) 	# visualize cross-validation results &lt;br /&gt;
 summary(fit.1) 	# detailed summary of splits&lt;br /&gt;
&lt;br /&gt;
 # plot tree &lt;br /&gt;
 par(oma=c(0,0,2,0))&lt;br /&gt;
 plot(fit.1, uniform=TRUE,  margin=0.3, main=&amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # create a better plot of the classification tree &lt;br /&gt;
 post(fit.1, title = &amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;, file = &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(2) Pruning the tree &lt;br /&gt;
&lt;br /&gt;
 pruned.fit.1&amp;lt;- prune(fit.1, cp=   fit.1$\$$cptable[which.min(fit.1$\$$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
 # plot the pruned tree &lt;br /&gt;
 plot(pruned.fit.1, uniform=TRUE,  main=&amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(pruned.fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
 post(pruned.fit.1,  title = &amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Not much change, as the initial tree is not complex!&lt;br /&gt;
&lt;br /&gt;
===Random Forests ===&lt;br /&gt;
Random forests may improve predictive accuracy by generating a large number of bootstrapped trees (based on random samples of variables). It classifies cases using each tree in this new &amp;quot;forest&amp;quot;, and decides the final predicted outcome by combining the results across all of the trees (an average in regression, a majority vote in classification). See the &amp;lt;b&amp;gt;randomForest&amp;lt;/b&amp;gt; package. &lt;br /&gt;
&lt;br /&gt;
 library(randomForest)&lt;br /&gt;
 fit.2 &amp;lt;- randomForest(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, na.action = na.omit, data= fdgs[,-1])&lt;br /&gt;
 print(fit.2) 		# view results &lt;br /&gt;
 importance(fit.2) 	# importance of each predictor &lt;br /&gt;
&lt;br /&gt;
Note on missing values/incomplete data: If the data have missing values, we have 3 choices:&lt;br /&gt;
&lt;br /&gt;
1.	Use a different tool (rpart handles missing values well)&lt;br /&gt;
&lt;br /&gt;
2.	Impute the missing values&lt;br /&gt;
&lt;br /&gt;
3.	For a small number of missing cases, we can use na.action = na.omit&lt;br /&gt;
&lt;br /&gt;
===Latent growth and growth mixture modeling (LGM/GMM)===&lt;br /&gt;
&lt;br /&gt;
LGM and GMM represent structural equation modeling techniques that capture inter-individual differences in longitudinal change corresponding to a particular treatment. For instance, patients’ different timing patterns of the treatment effects may represent the underlying sources of HTE. LGM distinguish if (yes/no) and how (fast/slow, temporary/lasting) patients respond to treatment. The heterogeneous individual growth trajectories are estimated from intra-individual changes over time by examining common population parameters, i.e., slopes, intercepts, and error variances. Suppose each individual has unique initial status (intercept) and response rate (slope) during a specific time interval. Then the variances of the individuals’ baseline measures (intercepts) and changes (slopes) in health outcomes will represent the degree of HTE. The LGM-identified HTE of individual growth curves can be attributed to observed predictors, including both fixed and time varying covariates.&lt;br /&gt;
&lt;br /&gt;
LGM assumes that all individuals are from the same population (too restrictive in some cases). If the HTE is due to observed demographic variables, such as age, gender, and marital status, one may utilize multiple-group LGM. Despite its successful applications for modeling longitudinal change, there may be multiple subpopulations with unobserved heterogeneities. Growth mixture modeling (GMM) extends LGM to allow the identification and prediction of unobserved subpopulations in longitudinal data analysis. Each unobserved subpopulation may constitute its own latent class and behave differently than individuals in other latent classes. Within each latent class, there are also different trajectories across individuals; however, different latent classes don’t share common population parameters. Suppose we are interested in studying retirees’ psychological well-being change trajectory when multiple unknown subpopulations exist. We can add another layer (a latent class variable) on the LGM framework so that the unobserved latent classes can be inferred from the data. The covariates in GMM are designed to affect growth factors distinctly across different latent classes. Therefore, there are two types of HTE: 1) the latent class variable in GMM divides individuals into groups with different growth curves; and 2) coefficient estimates vary across latent classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Latent variables&amp;lt;/b&amp;gt; are not directly observed – they are inferred (via a model) from other actually observed and directly measured variables. Models that explain observed variables in terms of latent variables are called latent variable models. Then the latent (unobserved) variable is discrete, it’s referred to as &amp;lt;b&amp;gt;latent class variable.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Breast Cancer Example: Recall the LMER package, earlier review discussions, where Linear Mixed Model (LMM) are used for longitudinal data to examine change over time of outcomes according relative to predictive covariates. LMM assumptions include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(i)&amp;lt;/b&amp;gt; continuous longitudinal outcome&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(ii)&amp;lt;/b&amp;gt; Gaussian random-effects and errors&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iii)&amp;lt;/b&amp;gt; linearity of the relationships with the outcome&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iv)&amp;lt;/b&amp;gt; homogeneous population&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(v)&amp;lt;/b&amp;gt; missing at random data&lt;br /&gt;
&lt;br /&gt;
The objectives of LGM/GMM models (see &amp;lt;b&amp;gt;Latent Class Mixed Models, lcmm&amp;lt;/b&amp;gt; R package) are to extend the linear mixed model estimation to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(i)&amp;lt;/b&amp;gt;	heterogeneous populations (relax (iv) above). Use &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; for latent class linear mixed models&amp;lt;/mark&amp;gt; (i.e. Gaussian continuous outcome)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(ii)&amp;lt;/b&amp;gt;	other types of longitudinal outcomes : ordinal, (bounded) quantitative non-Gaussian outcomes (relax (i), (ii), (iii), (iv)). Use &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; for general latent class mixed models with outcomes of different nature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iii)&amp;lt;/b&amp;gt;	joint analysis of a time-to-event (relax (iv), (v)). Use &amp;lt;b&amp;gt;Jointlcmm&amp;lt;/b&amp;gt; for joint latent class models with a longitudinal outcome and a right-censored (left-truncated) time-to-event&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s use these data (http://www.ats.ucla.edu/stat/data/hdp.csv), representing cancer phenotypes and predictors (e.g., &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;) and outcome measures (e.g., remission) collected on patients, nested within doctors (DID) and within hospitals (HID).&lt;br /&gt;
&lt;br /&gt;
We can illustrate the latent class linear mixed models implemented in &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; through a study of the quadratic trajectories of the response (remission) with TumorSize, adjusting for CO2*Pain interaction and assuming correlated random-effects for the functions of SmokingHx and Sex. To estimate the corresponding standard linear mixed model using 1 latent class where CO2 interacts with Pain:&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
 library(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 hdp &amp;lt;- read.csv(&amp;quot;http://www.ats.ucla.edu/stat/data/hdp.csv&amp;quot;)&lt;br /&gt;
 hdp &amp;lt;- within(hdp, {&lt;br /&gt;
 Married &amp;lt;- factor(Married, levels = 0:1, labels = c(&amp;quot;no&amp;quot;, &amp;quot;yes&amp;quot;))&lt;br /&gt;
 DID &amp;lt;- factor(DID)&lt;br /&gt;
 HID &amp;lt;- factor(HID)&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
add a new subject ID column (last column in the data, “ID”), this is necessary for the hmle call&lt;br /&gt;
hdp$\$$ID &amp;lt;- seq.int(nrow(hdp))&lt;br /&gt;
&lt;br /&gt;
 model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 summary(model.hlme)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Heterogenous linear mixed model &lt;br /&gt;
 fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 hlme(fixed = remission ~ IL6 + CRP + LengthofStay + Experience + &lt;br /&gt;
 I(tumorsize^2) + co2 * pain + I(tumorsize^2) * pain, random = ~SmokingHx + &lt;br /&gt;
 Sex, subject = &amp;quot;ID&amp;quot;, ng = 1, data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
 Dataset: hdp &lt;br /&gt;
 Number of subjects: 8525 &lt;br /&gt;
 Number of observations: 8525 &lt;br /&gt;
 Number of latent classes: 1 &lt;br /&gt;
 Number of parameters: 21  &lt;br /&gt;
 &lt;br /&gt;
 Iteration process: 	&lt;br /&gt;
 Convergence criteria satisfied &lt;br /&gt;
 Number of iterations:  34 &lt;br /&gt;
 Convergence criteria: parameters= 1.2e-09 &lt;br /&gt;
 : likelihood= 8.3e-06 &lt;br /&gt;
 : second derivatives= 2.7e-05 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
 maximum log-likelihood: -5223.9  &lt;br /&gt;
 AIC: 10489.79  &lt;br /&gt;
 BIC: 10637.86&lt;br /&gt;
&lt;br /&gt;
Maximum Likelihood Estimates: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Fixed effects in the Longitudinal Model:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||coef||Se||Wald||p-value&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||0.28636||0.24314||1.178||0.23890&lt;br /&gt;
|-&lt;br /&gt;
|IL6||-0.01134||0.00183||-6.184||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|CRP||-0.00674||0.00167||-4.043||0.00005&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||-0.04834||0.00463||-10.436||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|Experience||0.01695||0.00119||14.263||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2)||0.00000||0.00001||-0.076||0.93953&lt;br /&gt;
|-&lt;br /&gt;
|co2||-0.03549||0.16204||-0.219||0.82663&lt;br /&gt;
|-&lt;br /&gt;
|pain||0.03930||0.04278||0.919||0.35832&lt;br /&gt;
|-&lt;br /&gt;
|co2:pain||-0.01489||0.02871||-0.519||0.60395&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2):pain||0.00000||0.00000||0.553||0.58045&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Variance-covariance matrix of the random-effects&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||intercept||SmokingHxformer||SmokingHxnever||Sexmale&lt;br /&gt;
|-&lt;br /&gt;
|intercept||0.19310943|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxformer||-0.10617988||0.209155186|| ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxnever||-0.12388534||0.068342049||2.262655e-01|| &lt;br /&gt;
|-&lt;br /&gt;
|Sexmale||-0.08130975||-0.007353491||-1.873934e-05||0.1730187&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
                          &lt;br /&gt;
Residual standard error:&lt;br /&gt;
&lt;br /&gt;
coef: 0.1299767&lt;br /&gt;
&lt;br /&gt;
se: 1.187426&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Results interpretation:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1)	The first part of the summary provides information about the dataset, the number of subjects, observations, observations deleted (since by default, missing observations are deleted), number of latent classes and number of parameters. &lt;br /&gt;
&lt;br /&gt;
(2)	Next, details about the algorithm convergence is provided along with the number of iterations, the convergence criteria, and the information indicating if the model converged correctly: &amp;quot;convergence criteria satisfied&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
(3)	The maximum log-likelihood, Akaike criterion (AIC) and Bayesian Information criterion (BIC) are reported. &lt;br /&gt;
&lt;br /&gt;
(4)	Estimates of parameters, the estimated standard error, the Wald Test statistics (with Normal approximation) and the corresponding p-values are reported below. &lt;br /&gt;
&lt;br /&gt;
(5)	For the random-effect distribution, the estimated matrix of covariance of the random-effects is displayed.&lt;br /&gt;
&lt;br /&gt;
(6)	The standard error of the residuals is given along with its estimated standard error.&lt;br /&gt;
&lt;br /&gt;
(7)	The effect of &amp;lt;b&amp;gt;TumorSize&amp;lt;/b&amp;gt; seems not associated with change over Pain of Remission. This may be formally assessed using a multivariate Wald test:&lt;br /&gt;
&lt;br /&gt;
 WaldMult(model.hlme, pos=c(6,8)) &lt;br /&gt;
 # pos - a vector containing the indices in model.hlme of the parameters to test&lt;br /&gt;
 Wald Test p_value&lt;br /&gt;
 I(tumorsize^2) = pain = 0   0.85562 0.65193&lt;br /&gt;
&lt;br /&gt;
We may consider the model with an adjustment for CRP only on the intercept. Below we estimate the corresponding &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;models for a varying number of latent classes&amp;lt;/b&amp;gt;&amp;lt;/mark&amp;gt; (from 1 to 3) using the default initial values:&lt;br /&gt;
&lt;br /&gt;
 # Initial Model: model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
&lt;br /&gt;
 model.hlme.1 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 model.hlme.2 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=2)&lt;br /&gt;
 model.hlme.3 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=3)&lt;br /&gt;
&lt;br /&gt;
The estimation process for a varying number of latent classes can be summarized with &amp;lt;b&amp;gt;summarytable,&amp;lt;/b&amp;gt; which gives the &amp;lt;b&amp;gt;log-likelihood&amp;lt;/b&amp;gt;, the number of parameters, the Bayesian Information Criterion, and the posterior proportion of each class:&lt;br /&gt;
&lt;br /&gt;
 summarytable(model.hlme.1, model.hlme.2, model.hlme.3)&lt;br /&gt;
             G    loglik npm      BIC    %class1    %class2  %class3&lt;br /&gt;
 model.hlme.1 1 -33301.82   5 66648.89 100.000000                    &lt;br /&gt;
 model.hlme.2 2 -31592.79  11 63285.15  99.214076  0.7859238         &lt;br /&gt;
 model.hlme.3 3 -31589.55  15 63314.86   6.357771 82.2991202 11.34311&lt;br /&gt;
&lt;br /&gt;
The program took 404.65 seconds&lt;br /&gt;
&lt;br /&gt;
In this example, the optimal number of latent classes according to the BIC is two (the smallest BIC).  The posterior classification is described with:&lt;br /&gt;
&lt;br /&gt;
 postprob(model.hlme.2)&lt;br /&gt;
&lt;br /&gt;
 Posterior classification: &lt;br /&gt;
   class1 class2&lt;br /&gt;
 N 8458.00  67.00&lt;br /&gt;
 %   99.21   0.79&lt;br /&gt;
 &lt;br /&gt;
 Posterior classification table: &lt;br /&gt;
     --&amp;gt; mean of posterior probabilities in each class &lt;br /&gt;
        prob1  prob2&lt;br /&gt;
 class1 0.8555 0.1445&lt;br /&gt;
 class2 0.4362 0.5638&lt;br /&gt;
 &lt;br /&gt;
 Posterior probabilities above a threshold (%): &lt;br /&gt;
         class1 class2&lt;br /&gt;
 prob&amp;gt;0.7  92.48   2.99&lt;br /&gt;
 prob&amp;gt;0.8  77.38   0.00&lt;br /&gt;
 prob&amp;gt;0.9  38.53   0.00&lt;br /&gt;
&lt;br /&gt;
In this example, the first class includes a posteriori 8458 subjects (99%) while class 2 includes 67 (0.79%) subjects. Subjects were classified in class 1 with a mean posterior probability of 0.8555 %. &lt;br /&gt;
&lt;br /&gt;
In class 1, 92.48% were classified with a posterior probability above 0.7 while 2.99% of the subjects were classified in class 2 with a posterior probability above 0.7. Goodness-of-fit of the model can be assessed by displaying the residuals as in figure and the mean predictions of the model as in figure, according to the time variable given in &amp;lt;b&amp;gt;var.time&amp;lt;/b&amp;gt;:  &lt;br /&gt;
&lt;br /&gt;
 plot(model.hlme.2)&lt;br /&gt;
 # Figure (left panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2) &lt;br /&gt;
 # Figure (right panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2, marg=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The latent process mixed models implemented in &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; are illustrated through the study of the linear trajectory of &amp;lt;b&amp;gt;ntumors&amp;lt;/b&amp;gt; with Age adjusted for Sex and assuming correlated random-effects for the intercept and Age. Lines estimate the corresponding latent process mixed model with different link functions:&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', data=hdp)&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta')&lt;br /&gt;
 model.hlme.spl &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='splines')&lt;br /&gt;
 model.hlme.spl5q &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='5-quant-splines')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;link function&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;: An optional family of link functions. By default, &lt;br /&gt;
&lt;br /&gt;
*&amp;quot;linear&amp;quot; option specifies a linear link function leading to a standard linear mixed model (homogeneous or heterogeneous as estimated in hlme).&lt;br /&gt;
*&amp;quot;beta&amp;quot; for estimating a link function from the family of Beta cumulative distribution functions, &amp;quot;thresholds&amp;quot; for using a threshold model to describe the correspondence between each level of an ordinal outcome and the underlying latent process, and&lt;br /&gt;
*&amp;quot;Splines&amp;quot; for approximating the link function by I-splines. For this latter case, the number of nodes and the nodes location should be also specified. The number of nodes is first entered followed by,&lt;br /&gt;
* -, then the location is specified with &amp;quot;equi&amp;quot;, &amp;quot;quant&amp;quot; or &amp;quot;manual&amp;quot; for respectively equidistant nodes, nodes at quantiles of the marker distribution or interior nodes entered manually in argument&lt;br /&gt;
*intnodes. It is followed by - and finally &amp;quot;splines&amp;quot; is indicated. For example, &amp;quot;7-equi-splines&amp;quot; means I-splines with 7 equidistant nodes, &amp;quot;6-quant-splines&amp;quot; means I-splines with 6 nodes located at the quantiles of the marker distribution and &amp;quot;9-manual-splines&amp;quot; means I-splines with 9 nodes, the vector of 7 interior nodes being entered in the argument intnodes.&lt;br /&gt;
&lt;br /&gt;
 summary (model.hlme.lin)&lt;br /&gt;
&lt;br /&gt;
 General latent class mixed model fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 lcmm(fixed = ntumors ~ Age * Sex, random = ~Age, subject = &amp;quot;ID&amp;quot;,data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
     Dataset: hdp &lt;br /&gt;
     Number of subjects: 8525 &lt;br /&gt;
     Number of observations: 8525 &lt;br /&gt;
     Number of latent classes: 1 &lt;br /&gt;
     Number of parameters: 8  &lt;br /&gt;
     Link function: linear  &lt;br /&gt;
 &lt;br /&gt;
Iteration process: &lt;br /&gt;
     Maximum number of iteration reached without convergence &lt;br /&gt;
     Number of iterations:  100 &lt;br /&gt;
     Convergence criteria: parameters= 5.4e-10 &lt;br /&gt;
                         : likelihood= 5.5e-10 &lt;br /&gt;
                         : second derivatives= 1 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
     maximum log-likelihood: -19915.24  &lt;br /&gt;
     AIC: 39846.49  &lt;br /&gt;
     BIC: 39902.89  &lt;br /&gt;
 &lt;br /&gt;
     Discrete posterior log-likelihood: 0  &lt;br /&gt;
     Discrete AIC: 16  &lt;br /&gt;
 &lt;br /&gt;
     Mean discrete AIC per subject: 9e-04  &lt;br /&gt;
     Mean UACV per subject: 0  &lt;br /&gt;
     Mean discrete LL per subject: 0  &lt;br /&gt;
 &lt;br /&gt;
 Maximum Likelihood Estimates: &lt;br /&gt;
 &lt;br /&gt;
 Fixed effects in the longitudinal model:&lt;br /&gt;
&lt;br /&gt;
                              coef Se Wald p-value&lt;br /&gt;
 intercept (not estimated)  0.00000                &lt;br /&gt;
 Age                        0.09491                &lt;br /&gt;
 Sexmale                   -0.66303                &lt;br /&gt;
 Age:Sexmale                0.01132                &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Variance-covariance matrix of the random-effects:&lt;br /&gt;
           intercept         Age&lt;br /&gt;
 intercept 20.5013715            &lt;br /&gt;
 Age       -0.2889814 0.007696382&lt;br /&gt;
&lt;br /&gt;
 Residual standard error (not estimated) = 1&lt;br /&gt;
&lt;br /&gt;
 Parameters of the link function:&lt;br /&gt;
&lt;br /&gt;
                         coef Se Wald p-value&lt;br /&gt;
 Linear 1 (intercept) -0.36768                &lt;br /&gt;
 Linear 2 (std err)    0.71432           &lt;br /&gt;
&lt;br /&gt;
Objects &amp;lt;b&amp;gt;mlin, mbeta, mspl and mspl3eq&amp;lt;/b&amp;gt; are latent process mixed models that assume the exact same trajectory for the underlying latent process but respectively a linear, BetaCDF, I-splines with 5 equidistant knots (default with link=’splines’) and I-splines with 5 knots at percentiles. &amp;lt;b&amp;gt;mlin&amp;lt;/b&amp;gt; reduces to a standard linear mixed model (link=’linear’ by default). The only difference with a &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; object is the parameterization for the intercept and the residual standard error that are considered as rescaling parameters.&lt;br /&gt;
&lt;br /&gt;
 col &amp;lt;- rainbow(4)&lt;br /&gt;
 plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(model.hlme.beta, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[2], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[3], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl5q, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[4], lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;topleft&amp;quot;,legend=c(&amp;quot;linear&amp;quot;, &amp;quot;beta&amp;quot;,&amp;quot;splines (5equidistant)&amp;quot;, &amp;quot;splines (5 at quantiles)&amp;quot;), lty=1,col=col,bty=&amp;quot;n&amp;quot;,lwd=2)&lt;br /&gt;
&lt;br /&gt;
 # to obtain confidence bands use function predictlink &lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;Error in predictlink.lcmm(model.hlme.spl, ndraws = 2000):&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;No confidence intervals can be produced since the program did not converge properly&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;model.hlme.lin$\$$conv &amp;lt;mark&amp;gt;# double-check the convergence of the algorithm[1] 2&amp;lt;/mark&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# status of convergence:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =1 if the convergence criteria were satisfied,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =2 if the maximum number of iterations was reached,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =4 or 5 if a problem occured during optimisation&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', epsY = 0.5, convB = 1e-01, convL = 1e-01, &amp;lt;mark&amp;gt;convG = 1e-01&amp;lt;/mark&amp;gt;, maxiter=200, data=hdp); model.hlme.lin$conv&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;mark&amp;gt;# Now that we have convergence, we can obtain CI’s!!!&amp;lt;/mark&amp;gt;&lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 # plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(link.lin, add=TRUE, col=col[1], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for linear fit&amp;quot;), lty=c(2,NA), col=c(col[1],NA), bty=&amp;quot;n&amp;quot;, lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;Repeat using the other link functions … model.hlme.beta, model.hlme.spl, …&amp;lt;/mark&amp;gt;&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta', &lt;br /&gt;
 &amp;lt;mark&amp;gt;convB = 1e-01&amp;lt;/mark&amp;gt;, convL = 1e-01, convG = 1e-01, maxiter=200); model.hlme.beta$\$$conv&lt;br /&gt;
 link.beta &amp;lt;- predictlink(model.hlme.beta, ndraws=2000)&lt;br /&gt;
 plot(link.beta, add=TRUE, col=col[2], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for BETA fit&amp;quot;), lty=c(3,NA), col=c(col[2],NA), bty=&amp;quot;n&amp;quot;, lwd=1)&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity_MetaAnalysis|Next see: Meta-Analysis]]===&lt;br /&gt;
* [[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_HTE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity&amp;diff=16152</id>
		<title>SMHS MethodsHeterogeneity</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity&amp;diff=16152"/>
		<updated>2016-05-23T13:21:20Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research ==&lt;br /&gt;
&lt;br /&gt;
==Methods and Approaches for HTE Analytics==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;8&amp;quot; |Methods and Approaches for HTE Analytics ****&lt;br /&gt;
|-&lt;br /&gt;
|||Meta-analysis||CART*||N of 1 trials||LGM/GMM**||QTE***||Nonparametric||Predictive risk models&lt;br /&gt;
|-&lt;br /&gt;
|Intent of the Analysis||Exploratory and confirmatory||Exploratory||Exploratory and initial testing||&amp;quot;Exploratory, initial testing, and confirmatory&amp;quot;||&amp;quot;Exploratory, initial testing, &amp;amp; confirmatory&amp;quot;||Exploratory and confirmatory||Initial testing and confirmatory&lt;br /&gt;
|-&lt;br /&gt;
|Data Structure ||&amp;quot;Trial summary results, possibly with subgroup results&amp;quot;||Panel or cross-section||Repeated measures for a single patient: time series||Time series and panel||Panel and cross-sectional||&amp;quot;Panel, time series, and cross-sectional&amp;quot;||Panel or cross-sectional&lt;br /&gt;
|-&lt;br /&gt;
|Data Size Consideration ||Advantage of combining small sample sizes||Large sample sizes||Small sample sizes||LGM: small to large sample sizes; GMM: Large sample sizes ||Moderate to large sample sizes||Large sample sizes||Sample sizes depends on specific risk function&lt;br /&gt;
|-&lt;br /&gt;
|Key Strength(s)||Increase statistical power by pooling of results||Does not require assumptions around normality of distribution Can utilize different types of response variables; Possible to identify HTE across trials Possibility to measure and explain covariate's effect on treatment effect ||Patient is own control; Estimates patient-specific effects ||Accounting for unobserved characteristics Heterogeneous response across time||Robust to outcome outliers Heterogeneous response across quantiles||No functional form assumptions Flexible regressions||Multivariate approach to identifying risk factors or HTE&lt;br /&gt;
Estimates patient-specific effects&lt;br /&gt;
|-&lt;br /&gt;
|Key Limitation(s)||Included studies need to be similar enough to be meaningful Assumed distribution; Selection bias||Fairly sensitive to changes in underlying data May not fully identify additive impacts of multiple variables||Requires de novo study Not applicable to all conditions or treatments||Criteria for optimization solutions not clear||&amp;quot;Treatment effect designed for a quantile, not a specific patient&amp;quot;||Computationally demanding Smoothing parameters required for kernel methods||May be more or less interpretable or useful clinically&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* *CART: Classification and regression tree (CART) analysis&lt;br /&gt;
* LGM/GMM: Latent growth modeling/Growth mixture modeling.&lt;br /&gt;
* QTE: Quantile Treatment Effect.&lt;br /&gt;
* Standard meta-analysis like fixed and random effect models, and tests of heterogeneity, together with various plots and summaries, can be found in the [http://cran.r-project.org/web/packages/rmeta R-package rmeta]. Non-parametric R approaches are included in the [http://cran.r-project.org/web/packages/np/vignettes/np.pdf np package]. &lt;br /&gt;
&lt;br /&gt;
Additional details are provided in a paper entitled [http://dx.doi.org/10.1186/1471-2288-12-185 From concepts, theory, and evidence of heterogeneity of treatment effects to methodological approaches: a primer].&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_HTE |HTE Analytics, Latent growth and growth mixture modeling (LGM/GMM)]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_MetaAnalysis |Meta-analysis]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_CER| Comparative Effectiveness Research (CER)]]==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_HTE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization&amp;diff=16145</id>
		<title>SMHS SciVisualization</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization&amp;diff=16145"/>
		<updated>2016-05-23T13:01:44Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Scientific Visualization ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
&lt;br /&gt;
*How and why should we “look” at data?&lt;br /&gt;
*What data characteristics are important for exploratory data analytics (EDAs)?&lt;br /&gt;
&lt;br /&gt;
Scientific Data-driven or Simulation-driven visualization methods may be classified in many alternative ways. Visualization techniques can be classified according to many criteria:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization1.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Data Type: structured/unstructured, small/large, complete/incomplete, time/space, ascii/binary, Euclidean/non-Euclidean, etc.&lt;br /&gt;
&lt;br /&gt;
*Task type: Task  type  is  one  of  the  aspects  considered  in classification  of  visualization  techniques,  which provides means of interaction between the researcher, the data and the display software/platform&lt;br /&gt;
&lt;br /&gt;
*Scalability:  Visualization   techniques   are   subject   to   some limitations, such as the amount of data that a particular technique can exhibit&lt;br /&gt;
    &lt;br /&gt;
*Dimensionality: Visualization   techniques   can   also   be   classified according to the number of attributes&lt;br /&gt;
&lt;br /&gt;
*Positioning and Attributes: the distribution   of   attributes   on   the   chart may affect the interpretation    of    the display representation, e.g., correlation analysis, where the relative distance among the plotted attributes is relevant for observation&lt;br /&gt;
&lt;br /&gt;
*Investigative Need: the specific scientific question or exploratory interest may also determine the type of visualization:&lt;br /&gt;
&lt;br /&gt;
**Examining the composition of the data&lt;br /&gt;
&lt;br /&gt;
**Exploring the distribution of the data&lt;br /&gt;
&lt;br /&gt;
**Contrasting or comparing several data elements, relations, association&lt;br /&gt;
&lt;br /&gt;
**Unsupervised exploratory data mining&lt;br /&gt;
&lt;br /&gt;
http://www.socr.umich.edu/CSCD/html/Cores/Macore2/SciViz.html&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_SciVisualization_SOCR_Excel_R_Charts|SOCR, Excel and R Charts]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_SciVisualization_NetworkViz|Complex Network Visualization]]==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization&amp;diff=16144</id>
		<title>SMHS SciVisualization</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization&amp;diff=16144"/>
		<updated>2016-05-23T12:58:50Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Scientific Visualization ==&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
&lt;br /&gt;
*How and why should we “look” at data?&lt;br /&gt;
*What data characteristics are important for exploratory data analytics (EDAs)?&lt;br /&gt;
&lt;br /&gt;
Scientific Data-driven or Simulation-driven visualization methods may be classified in many alternative ways. Visualization techniques can be classified according to many criteria:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization1.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Data Type: structured/unstructured, small/large, complete/incomplete, time/space, ascii/binary, Euclidean/non-Euclidean, etc.&lt;br /&gt;
&lt;br /&gt;
*Task type: Task  type  is  one  of  the  aspects  considered  in classification  of  visualization  techniques,  which provides means of interaction between the researcher, the data and the display software/platform&lt;br /&gt;
&lt;br /&gt;
*Scalability:  Visualization   techniques   are   subject   to   some limitations, such as the amount of data that a particular technique can exhibit&lt;br /&gt;
    &lt;br /&gt;
*Dimensionality: Visualization   techniques   can   also   be   classified according to the number of attributes&lt;br /&gt;
&lt;br /&gt;
*Positioning and Attributes: the distribution   of   attributes   on   the   chart may affect the interpretation    of    the display representation, e.g., correlation analysis, where the relative distance among the plotted attributes is relevant for observation&lt;br /&gt;
&lt;br /&gt;
*Investigative Need: the specific scientific question or exploratory interest may also determine the type of visualization:&lt;br /&gt;
&lt;br /&gt;
**Examining the composition of the data&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
**Exploring the distribution of the data&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
**Contrasting or comparing several data elements, relations, association&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
**Unsupervised exploratory data mining&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.socr.umich.edu/CSCD/html/Cores/Macore2/SciViz.html&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_SciVisualization_SOCR_Excel_R_Charts|SOCR, Excel and R Charts]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_SciVisualization_NetworkViz|Complex Network Visualization]]==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MachineLearning&amp;diff=16143</id>
		<title>SMHS LinearModeling MachineLearning</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MachineLearning&amp;diff=16143"/>
		<updated>2016-05-23T12:57:26Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling|SMHS Linear Modeling]] - Machine Learning Algorithms==&lt;br /&gt;
&lt;br /&gt;
Scientific inference based on fixed and random effect models, assumptions, and mixed effects logistic regression. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Questions:&amp;lt;/b&amp;gt;&lt;br /&gt;
*How can we tie human intuition and computer-generated results to obtain reliable, effective, and efficient decision-support system (that facilitates, forecasting)?&lt;br /&gt;
*Niels Born – “It is difficult to make predictions, especially about the future”&lt;br /&gt;
*Can we unsupervisely classify the data?&lt;br /&gt;
&amp;lt;b&amp;gt;Prediction&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For most of the machine learning algorithms (including first-order linear regression), we:&lt;br /&gt;
*ﬁrst generate the model using training data, and then&lt;br /&gt;
*predict values for test/new data.&lt;br /&gt;
&lt;br /&gt;
Predictions are made using the R &amp;lt;b&amp;gt;predict&amp;lt;/b&amp;gt; function. (type &amp;lt;b&amp;gt;?predict.name&amp;lt;/b&amp;gt;), where &amp;lt;b&amp;gt;name&amp;lt;/b&amp;gt; is the function-name corresponding to the algorithm. The ﬁrst argument of predict often represents the variable storing the model, and the second argument is a matrix or data frame of test data that the model needs to be applied to. Calling predict can be done in 2 ways: type &amp;lt;b&amp;gt;predict&amp;lt;/b&amp;gt; or type of &amp;lt;b&amp;gt;predict.name.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #mydata &amp;lt;- read.table('https://umich.instructure.com/files/330381/download?download_frd=1&amp;amp;verifier=HpfmjfMFaMsk7rIpfPx0tmz960oTW7JA8ZonGvVC',as.is=T, header=T)  # 01a_data.txt&lt;br /&gt;
 # mydata &amp;lt;- read.table('data.txt',as.is=T, header=T)&lt;br /&gt;
&lt;br /&gt;
 # (1) First, there are different approaches to split the data (partition the data) into &lt;br /&gt;
 # training and testing sets.&lt;br /&gt;
 ## TRAINING: 75% of the sample size&lt;br /&gt;
 sample_size &amp;lt;- floor(0.75 * nrow(mydata))&lt;br /&gt;
 ## set the seed to make your partition reproductible&lt;br /&gt;
 set.seed(1234)&lt;br /&gt;
 train_ind &amp;lt;- sample(seq_len(nrow(mydata)), size = sample_size)&lt;br /&gt;
 train &amp;lt;- mydata[train_ind, ]&lt;br /&gt;
&lt;br /&gt;
 # TESTING DATA&lt;br /&gt;
 test &amp;lt;- mydata[-train_ind, ]&lt;br /&gt;
&lt;br /&gt;
 lin.mod &amp;lt;- lm(Weight ~ Height*Team, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;data=train&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;)&lt;br /&gt;
 predicted.values &amp;lt;-  predict(lin.mod, &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;newdata=test&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Data Modeling/Training&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Logistic Regression:&amp;lt;/b&amp;gt;&lt;br /&gt;
 glm_model &amp;lt;-glm(ifelse(Weight &amp;gt; 200,1,0) ~ Height*Team, family=binomial(link=&amp;quot;logit&amp;quot;), &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;data=train&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;K-Means Clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
 train.1 &amp;lt;- cbind(train$\$$Height, train$\$$Weight, train$\$$Age)&lt;br /&gt;
 test.1 &amp;lt;- cbind(test$\$$Height, test$\$$Weight, test$\$$Age)&lt;br /&gt;
 Weight.1 &amp;lt;- ifelse(train$\$$Weight &amp;gt; 200,1,0)&lt;br /&gt;
&lt;br /&gt;
 head(train.1)&lt;br /&gt;
 kmeans_model &amp;lt;- kmeans(&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;train.1&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;, 3)&lt;br /&gt;
 plot(train.1, col = kmeans_model$\$$cluster)&lt;br /&gt;
 points(kmeans_model$\$$centers, col = 1:2, pch = 8, cex = 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;K-Nearest Neighbor Classiﬁcation&amp;lt;/b&amp;gt;&lt;br /&gt;
 # install.packages(&amp;quot;class&amp;quot;)&lt;br /&gt;
 library(&amp;quot;class&amp;quot;)&lt;br /&gt;
 knn_model  &amp;lt;-  knn(train=train.1,  test=test.1,  cl=as.factor(Weight.1),  k=5)&lt;br /&gt;
 plot(knn_model)&lt;br /&gt;
 summary(knn_model)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Naïve Bayes Classifier&amp;lt;/b&amp;gt;&lt;br /&gt;
 install.packages(&amp;quot;e1071&amp;quot;)&lt;br /&gt;
 library(&amp;quot;e1071&amp;quot;)&lt;br /&gt;
 nbc_model &amp;lt;-  naiveBayes(Weight ~ Height*Age,  data=train.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Decision Trees (CART)&amp;lt;/b&amp;gt;&lt;br /&gt;
 #install.packages(&amp;quot;e1071&amp;quot;)&lt;br /&gt;
 library(&amp;quot;rpart&amp;quot;)&lt;br /&gt;
 cart_model &amp;lt;- rpart(Weight ~ Height+Age, data= as.data.frame(train.1), method=&amp;quot;class&amp;quot;)&lt;br /&gt;
 plot(cart_model)&lt;br /&gt;
 text(cart_model) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;AdaBoost&amp;lt;/b&amp;gt;&lt;br /&gt;
 install.packages(&amp;quot;ada&amp;quot;)&lt;br /&gt;
 # X be the matrix of features, and labels be a vector of 0-1 class labels.&lt;br /&gt;
 library(&amp;quot;ada&amp;quot;)&lt;br /&gt;
 boost_model &amp;lt;- ada(x= cbind(train$\$$Height, train$\$$Weight, train$\$$Age), y= Weight.1)&lt;br /&gt;
 plot(boost_model)&lt;br /&gt;
 boost_model&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Support Vector Machines (SVM)&amp;lt;/b&amp;gt;&lt;br /&gt;
 #install.packages(&amp;quot;e1071&amp;quot;)&lt;br /&gt;
 library(&amp;quot;rpart&amp;quot;)&lt;br /&gt;
 svm_model &amp;lt;- svm(x= cbind(train$\$$Height, train$\$$Weight, train$\$$Age), y=as.factor(Weight.1), &lt;br /&gt;
 kernel =&amp;quot;radial&amp;quot;)&lt;br /&gt;
 summary(svm_model)&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Example 1: Simulation (subject, day, treatment, observation)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;i&amp;gt;Obs ~ Treatment + Day + Subject(Treatment)+ Day*Subject(Treatment)+ ε.&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This model is accounts for:&amp;lt;BR&amp;gt;&lt;br /&gt;
Response = Obs&lt;br /&gt;
&lt;br /&gt;
Fixed effects:&amp;lt;BR&amp;gt;&lt;br /&gt;
Treatment (fixed)&amp;lt;BR&amp;gt;&lt;br /&gt;
Day (fixed)&amp;lt;BR&amp;gt;&lt;br /&gt;
Treatment*Day interaction&lt;br /&gt;
&lt;br /&gt;
Random Effects:&amp;lt;BR&amp;gt;&lt;br /&gt;
Subject nested within Treatment (random)&amp;lt;BR&amp;gt;&lt;br /&gt;
Day crossed with &amp;quot;Subject within Treatment&amp;quot; (random)&lt;br /&gt;
&lt;br /&gt;
 mydata &amp;lt;- data.frame(&lt;br /&gt;
 Subject  = c(13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, &lt;br /&gt;
 34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, &lt;br /&gt;
 19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, &lt;br /&gt;
 40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, &lt;br /&gt;
 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65), &lt;br /&gt;
 Day       = c(rep(c(&amp;quot;Day1&amp;quot;, &amp;quot;Day3&amp;quot;, &amp;quot;Day6&amp;quot;), each=28)), &lt;br /&gt;
 Treatment = c(rep(c(&amp;quot;B&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &lt;br /&gt;
 &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;), each = 4)), &lt;br /&gt;
 Obs       = c(6.472687, 7.017110, 6.200715, 6.613928, 6.829968, 7.387583, 7.367293, &lt;br /&gt;
 8.018853, 7.527408, 6.746739, 7.296910, 6.983360, 6.816621, 6.571689, &lt;br /&gt;
 5.911261, 6.954988, 7.624122, 7.669865, 7.676225, 7.263593, 7.704737, &lt;br /&gt;
 7.328716, 7.295610, 5.964180, 6.880814, 6.926342, 6.926342, 7.562293, &lt;br /&gt;
 6.677607, 7.023526, 6.441864, 7.020875, 7.478931, 7.495336, 7.427709, &lt;br /&gt;
 7.633020, 7.382091, 7.359731, 7.285889, 7.496863, 6.632403, 6.171196, &lt;br /&gt;
 6.306012, 7.253833, 7.594852, 6.915225, 7.220147, 7.298227, 7.573612, &lt;br /&gt;
 7.366550, 7.560513, 7.289078, 7.287802, 7.155336, 7.394452, 7.465383, &lt;br /&gt;
 6.976048, 7.222966, 6.584153, 7.013223, 7.569905, 7.459185, 7.504068, &lt;br /&gt;
 7.801867, 7.598728, 7.475841, 7.511873, 7.518384, 6.618589, 5.854754, &lt;br /&gt;
 6.125749, 6.962720, 7.540600, 7.379861, 7.344189, 7.362815, 7.805802, &lt;br /&gt;
 7.764172, 7.789844, 7.616437, NA, NA, NA, NA))&lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;lme4&amp;quot;)&lt;br /&gt;
 library(&amp;quot;lme4&amp;quot;, lib.loc=&amp;quot;~/R/win-library/3.1&amp;quot;)&lt;br /&gt;
 m1 &amp;lt;- lmer(Obs ~ Treatment * Day + (1 | Subject), mydata)&lt;br /&gt;
 m1&lt;br /&gt;
&lt;br /&gt;
Linear mixed model fit by REML ['lmerMod']&lt;br /&gt;
&lt;br /&gt;
Formula: Obs ~ Treatment * Day + (1 | Subject)&lt;br /&gt;
&lt;br /&gt;
Data: mydata&lt;br /&gt;
&lt;br /&gt;
REML criterion at convergence: 56.8669&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Groups||Name||Std. Dev.&lt;br /&gt;
|-&lt;br /&gt;
|Subject||(Intercept)||0.2163&lt;br /&gt;
|-&lt;br /&gt;
|Residual|| ||0.2602&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 80, groups:  Subject, 28 &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||TreatmentB||TreatmentC&lt;br /&gt;
|-&lt;br /&gt;
|7.1827||-0.6129||0.1658&lt;br /&gt;
|-&lt;br /&gt;
|DayDay3||DayDay6 ||TreatmentB: DayDay3&lt;br /&gt;
|-&lt;br /&gt;
|0.2446||0.4507||-0.1235&lt;br /&gt;
|-&lt;br /&gt;
|TreatmentC: DayDay3||TreatmentB: DayDay6||TreatmentC: DayDay6&lt;br /&gt;
|-&lt;br /&gt;
|-0.2740||-0.3508||-0.3327&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Index||Subject||Day||Treatment||Obs&lt;br /&gt;
|-&lt;br /&gt;
|1||13||Day1||B||6.472687&lt;br /&gt;
|-&lt;br /&gt;
|2||14||Day1||B||7.01711&lt;br /&gt;
|-&lt;br /&gt;
|3||15||Day1||B||6.200715&lt;br /&gt;
|-&lt;br /&gt;
|4||16||Day1||B||6.613928&lt;br /&gt;
|-&lt;br /&gt;
|5||17||Day1||A||6.829968&lt;br /&gt;
|-&lt;br /&gt;
|6||18||Day1||A||7.387583&lt;br /&gt;
|-&lt;br /&gt;
|7||19||Day1||A||7.367293&lt;br /&gt;
|-&lt;br /&gt;
|8||20||Day1||A||8.018853&lt;br /&gt;
|-&lt;br /&gt;
|9||21||Day1||C||7.527408&lt;br /&gt;
|-&lt;br /&gt;
|10||22||Day1||C||6.746739&lt;br /&gt;
|-&lt;br /&gt;
|11||23||Day1||C||7.29691&lt;br /&gt;
|-&lt;br /&gt;
|12||24||Day1||C||6.98336&lt;br /&gt;
|-&lt;br /&gt;
|13||29||Day1||B||6.816621&lt;br /&gt;
|-&lt;br /&gt;
|14||30||Day1||B||6.571689&lt;br /&gt;
|-&lt;br /&gt;
|15||31||Day1||B||5.911261&lt;br /&gt;
|-&lt;br /&gt;
|16||32||Day1||B||6.954988&lt;br /&gt;
|-&lt;br /&gt;
|17||33||Day1||C||7.624122&lt;br /&gt;
|-&lt;br /&gt;
|18||34||Day1||C||7.669865&lt;br /&gt;
|-&lt;br /&gt;
|19||35||Day1||C||7.676225&lt;br /&gt;
|-&lt;br /&gt;
|20||36||Day1||C||7.263593&lt;br /&gt;
|-&lt;br /&gt;
|21||37||Day1||A||7.704737&lt;br /&gt;
|-&lt;br /&gt;
|22||38||Day1||A||7.328716&lt;br /&gt;
|-&lt;br /&gt;
|23||39||Day1||A||7.29561&lt;br /&gt;
|-&lt;br /&gt;
|24||40||Day1||A||5.96418&lt;br /&gt;
|-&lt;br /&gt;
|25||62||Day1||A||6.880814&lt;br /&gt;
|-&lt;br /&gt;
|26||63||Day1||A||6.926342&lt;br /&gt;
|-&lt;br /&gt;
|27||64||Day1||A||6.926342&lt;br /&gt;
|-&lt;br /&gt;
|28||65||Day1||A||7.562293&lt;br /&gt;
|-&lt;br /&gt;
|29||13||Day3||B||6.677607&lt;br /&gt;
|-&lt;br /&gt;
|30||14||Day3||B||7.023526&lt;br /&gt;
|-&lt;br /&gt;
|31||15||Day3||B||6.441864&lt;br /&gt;
|-&lt;br /&gt;
|32||16||Day3||B||7.020875&lt;br /&gt;
|-&lt;br /&gt;
|33||17||Day3||A||7.478931&lt;br /&gt;
|-&lt;br /&gt;
|34||18||Day3||A||7.495336&lt;br /&gt;
|-&lt;br /&gt;
|35||19||Day3||A||7.427709&lt;br /&gt;
|-&lt;br /&gt;
|36||20||Day3||A||7.63302&lt;br /&gt;
|-&lt;br /&gt;
|37||21||Day3||C||7.382091&lt;br /&gt;
|-&lt;br /&gt;
|38||22||Day3||C||7.359731&lt;br /&gt;
|-&lt;br /&gt;
|39||23||Day3||C||7.285889&lt;br /&gt;
|-&lt;br /&gt;
|40||24||Day3||C||7.496863&lt;br /&gt;
|-&lt;br /&gt;
|41||29||Day3||B||6.632403&lt;br /&gt;
|-&lt;br /&gt;
|42||30||Day3||B||6.171196&lt;br /&gt;
|-&lt;br /&gt;
|43||31||Day3||B||6.306012&lt;br /&gt;
|-&lt;br /&gt;
|44||32||Day3||B||7.253833&lt;br /&gt;
|-&lt;br /&gt;
|45||33||Day3||C||7.594852&lt;br /&gt;
|-&lt;br /&gt;
|46||34||Day3||C||6.915225&lt;br /&gt;
|-&lt;br /&gt;
|47||35||Day3||C||7.220147&lt;br /&gt;
|-&lt;br /&gt;
|48||36||Day3||C||7.298227&lt;br /&gt;
|-&lt;br /&gt;
|49||37||Day3||A||7.573612&lt;br /&gt;
|-&lt;br /&gt;
|50||38||Day3||A||7.36655&lt;br /&gt;
|-&lt;br /&gt;
|51||39||Day3||A||7.560513&lt;br /&gt;
|-&lt;br /&gt;
|52||40||Day3||A||7.289078&lt;br /&gt;
|-&lt;br /&gt;
|53||62||Day3||A||7.287802&lt;br /&gt;
|-&lt;br /&gt;
|54||63||Day3||A||7.155336&lt;br /&gt;
|-&lt;br /&gt;
|55||64||Day3||A||7.394452&lt;br /&gt;
|-&lt;br /&gt;
|56||65||Day3||A||7.465383&lt;br /&gt;
|-&lt;br /&gt;
|57||13||Day6||B||6.976048&lt;br /&gt;
|-&lt;br /&gt;
|58||14||Day6||B||7.222966&lt;br /&gt;
|-&lt;br /&gt;
|59||15||Day6||B||6.584153&lt;br /&gt;
|-&lt;br /&gt;
|60||16||Day6||B||7.013223&lt;br /&gt;
|-&lt;br /&gt;
|61||17||Day6||A||7.569905&lt;br /&gt;
|-&lt;br /&gt;
|62||18||Day6||A||7.459185&lt;br /&gt;
|-&lt;br /&gt;
|63||19||Day6||A||7.504068&lt;br /&gt;
|-&lt;br /&gt;
|64||20||Day6||A||7.801867&lt;br /&gt;
|-&lt;br /&gt;
|65||21||Day6||C||7.598728&lt;br /&gt;
|-&lt;br /&gt;
|66||22||Day6||C||7.475841&lt;br /&gt;
|-&lt;br /&gt;
|67||23||Day6||C||7.511873&lt;br /&gt;
|-&lt;br /&gt;
|68||24||Day6||C||7.518384&lt;br /&gt;
|-&lt;br /&gt;
|69||29||Day6||B||6.618589&lt;br /&gt;
|-&lt;br /&gt;
|70||30||Day6||B||5.854754&lt;br /&gt;
|-&lt;br /&gt;
|71||31||Day6||B||6.125749&lt;br /&gt;
|-&lt;br /&gt;
|72||32||Day6||B||6.96272&lt;br /&gt;
|-&lt;br /&gt;
|73||33||Day6||C||7.5406&lt;br /&gt;
|-&lt;br /&gt;
|74||34||Day6||C||7.379861&lt;br /&gt;
|-&lt;br /&gt;
|75||35||Day6||C||7.344189&lt;br /&gt;
|-&lt;br /&gt;
|76||36||Day6||C||7.362815&lt;br /&gt;
|-&lt;br /&gt;
|77||37||Day6||A||7.805802&lt;br /&gt;
|-&lt;br /&gt;
|78||38||Day6||A||7.764172&lt;br /&gt;
|-&lt;br /&gt;
|79||39||Day6||A||7.789844&lt;br /&gt;
|-&lt;br /&gt;
|80||40||Day6||A||7.616437&lt;br /&gt;
|-&lt;br /&gt;
|81||62||Day6||A||NA&lt;br /&gt;
|-&lt;br /&gt;
|82||63||Day6||A||NA&lt;br /&gt;
|-&lt;br /&gt;
|83||64||Day6||A||NA&lt;br /&gt;
|-&lt;br /&gt;
|84||65||Day6||A||NA&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2: Genotype-phenotype===&lt;br /&gt;
&lt;br /&gt;
Save this data file as a tab-separated TXT file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Genotype||Race||Subject||Weight&lt;br /&gt;
|-&lt;br /&gt;
|A||1||1||8&lt;br /&gt;
|-&lt;br /&gt;
|A||1||2||9&lt;br /&gt;
|-&lt;br /&gt;
|A||1||3||11&lt;br /&gt;
|-&lt;br /&gt;
|A||1||4||12&lt;br /&gt;
|-&lt;br /&gt;
|A||1||5||10&lt;br /&gt;
|-&lt;br /&gt;
|A||2||1||17&lt;br /&gt;
|-&lt;br /&gt;
|A||2||2||17&lt;br /&gt;
|-&lt;br /&gt;
|A||2||3||16&lt;br /&gt;
|-&lt;br /&gt;
|A||2||4||15&lt;br /&gt;
|-&lt;br /&gt;
|A||2||5||19&lt;br /&gt;
|-&lt;br /&gt;
|A||2||6||18&lt;br /&gt;
|-&lt;br /&gt;
|A||2||7||18&lt;br /&gt;
|-&lt;br /&gt;
|A||2||8||18&lt;br /&gt;
|-&lt;br /&gt;
|A||2||9||24&lt;br /&gt;
|-&lt;br /&gt;
|A||3||1||12&lt;br /&gt;
|-&lt;br /&gt;
|A||3||2||12&lt;br /&gt;
|-&lt;br /&gt;
|A||3||3||16&lt;br /&gt;
|-&lt;br /&gt;
|A||3||4||15&lt;br /&gt;
|-&lt;br /&gt;
|A||3||5||15&lt;br /&gt;
|-&lt;br /&gt;
|A||3||6||14&lt;br /&gt;
|-&lt;br /&gt;
|A||4||1||17&lt;br /&gt;
|-&lt;br /&gt;
|A||4||2||20&lt;br /&gt;
|-&lt;br /&gt;
|A||4||3||20&lt;br /&gt;
|-&lt;br /&gt;
|A||4||4||19&lt;br /&gt;
|-&lt;br /&gt;
|A||4||5||19&lt;br /&gt;
|-&lt;br /&gt;
|A||4||6||18&lt;br /&gt;
|-&lt;br /&gt;
|A||4||7||20&lt;br /&gt;
|-&lt;br /&gt;
|A||4||8||19&lt;br /&gt;
|-&lt;br /&gt;
|A||4||9||19&lt;br /&gt;
|-&lt;br /&gt;
|B||5||1||9&lt;br /&gt;
|-&lt;br /&gt;
|B||5||2||12&lt;br /&gt;
|-&lt;br /&gt;
|B||5||3||13&lt;br /&gt;
|-&lt;br /&gt;
|B||5||4||16&lt;br /&gt;
|-&lt;br /&gt;
|B||5||5||14&lt;br /&gt;
|-&lt;br /&gt;
|B||5||6||14&lt;br /&gt;
|-&lt;br /&gt;
|B||6||1||10&lt;br /&gt;
|-&lt;br /&gt;
|B||6||2||10&lt;br /&gt;
|-&lt;br /&gt;
|B||6||3||9&lt;br /&gt;
|-&lt;br /&gt;
|B||6||4||8&lt;br /&gt;
|-&lt;br /&gt;
|B||6||5||13&lt;br /&gt;
|-&lt;br /&gt;
|B||6||6||9&lt;br /&gt;
|-&lt;br /&gt;
|B||6||7||11&lt;br /&gt;
|-&lt;br /&gt;
|B||7||1||12&lt;br /&gt;
|-&lt;br /&gt;
|B||7||2||16&lt;br /&gt;
|-&lt;br /&gt;
|B||7||3||17&lt;br /&gt;
|-&lt;br /&gt;
|B||7||4||15&lt;br /&gt;
|-&lt;br /&gt;
|B||7||5||15&lt;br /&gt;
|-&lt;br /&gt;
|B||7||6||15&lt;br /&gt;
|-&lt;br /&gt;
|B||8||1||9&lt;br /&gt;
|-&lt;br /&gt;
|B||8||2||6&lt;br /&gt;
|-&lt;br /&gt;
|B||8||3||8&lt;br /&gt;
|-&lt;br /&gt;
|B||8||4||8&lt;br /&gt;
|-&lt;br /&gt;
|B||8||5||13&lt;br /&gt;
|-&lt;br /&gt;
|B||8||6||9&lt;br /&gt;
|-&lt;br /&gt;
|B||8||7||9&lt;br /&gt;
|-&lt;br /&gt;
|B||8||8||10&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # data &amp;lt;- read.table('C:\\Users\\Dinov\\Desktop\\data.txt',as.is=T, header=T)&lt;br /&gt;
 data &amp;lt;- read.table('data.txt',as.is=T, header=T)&lt;br /&gt;
 names(data)&lt;br /&gt;
 attach(data)&lt;br /&gt;
 table(Genotype, Race)&lt;br /&gt;
 table(Race, Subject)&lt;br /&gt;
&lt;br /&gt;
 # for demonstration, construct a balanced data set &lt;br /&gt;
 #  5 subjects for each race &lt;br /&gt;
 data_balance &amp;lt;- data[data$\$$Subject &amp;lt;=5,]&lt;br /&gt;
&lt;br /&gt;
 # create factors &lt;br /&gt;
 data_balance$\$$g &amp;lt;- as.factor(data_balance$\$$Genotype)&lt;br /&gt;
 data_balance$\$$t &amp;lt;- as.factor(data_balance$\$$Race)&lt;br /&gt;
 data_balance$\$$s &amp;lt;- as.factor(data_balance$\$$Subject)&lt;br /&gt;
&lt;br /&gt;
 # fit the ANOVA &lt;br /&gt;
 anova.model &amp;lt;- lm(Weight ~ g+t, data= data_balance)&lt;br /&gt;
 # get the ANOVA table&lt;br /&gt;
 anova(anova.model) &lt;br /&gt;
&lt;br /&gt;
 # note that all F tests use MSE, subjects within race as denominator&lt;br /&gt;
 # will need to hand-calculate test for genotypes&lt;br /&gt;
&lt;br /&gt;
 # Random effects modeling estimation using REML&lt;br /&gt;
 library(lme4)&lt;br /&gt;
&lt;br /&gt;
 lme.model &amp;lt;- lmer(Weight~g+(1|t),data= data_balance)&lt;br /&gt;
 summary(lme.model)&lt;br /&gt;
 anova(lme.model)&lt;br /&gt;
&lt;br /&gt;
 # various extractor functions:&lt;br /&gt;
 fixef(lme.model)    	# estimates of fixed effects&lt;br /&gt;
 vcov(lme.model)     	# VC matrix for the fixed effects&lt;br /&gt;
 VarCorr(lme.model)  	# estimated variance(-covariance) for random effects&lt;br /&gt;
 ranef(lme.model)    	# predictions of random effects&lt;br /&gt;
 coef(lme.model)     	# fixed effects + pred's of random effects&lt;br /&gt;
 fitted(lme.model)   	# conditional means for each obs (X bhat + Z uhat)&lt;br /&gt;
 resid(lme.model)    	# conditional residuals (Y - fitted)&lt;br /&gt;
&lt;br /&gt;
 # REML is the default method for estimating variance components.&lt;br /&gt;
 # If want to use ML, can specify that&lt;br /&gt;
 lmer(Weight~g+(1|t),REML=F, data= data_balance)&lt;br /&gt;
&lt;br /&gt;
 # Now, to get p-values for the effects, or construct a ci&lt;br /&gt;
 #  inference on Subject weight focus is the difference between the two genotypes&lt;br /&gt;
 #  which is Cb for C = [0, 1] using the default R parameterization&lt;br /&gt;
 # following assumes lme4 library loaded, data frame is d&lt;br /&gt;
 #  uses full data set (unbalanced)&lt;br /&gt;
 # also assumes g and t are factors identifying genotypes and trays&lt;br /&gt;
&lt;br /&gt;
 # fit the model&lt;br /&gt;
 data$\$$g &amp;lt;- as.factor(data$\$$Genotype)&lt;br /&gt;
 data$\$$t &amp;lt;- as.factor(data$\$$Race)&lt;br /&gt;
 data$\$$s &amp;lt;- as.factor(data$\$$Subject)&lt;br /&gt;
&lt;br /&gt;
 # See R DATA TYPES: http://www.statmethods.net/input/datatypes.html&lt;br /&gt;
&lt;br /&gt;
 model.lmer &amp;lt;- lmer(Weight ~ g + (1|t), data= data)&lt;br /&gt;
 # get a confidence interval for g&lt;br /&gt;
 # slower, obvious programing&lt;br /&gt;
 nsim &amp;lt;- 10&lt;br /&gt;
 gdiff &amp;lt;- rep(NA, nsim)&lt;br /&gt;
 for (i in 1:nsim) {&lt;br /&gt;
 data$\$$y &amp;lt;- simulate(model.lmer)    # param bootstrap data set&lt;br /&gt;
 model.lmer.1 &amp;lt;- lmer(unlist(data$\$$y) ~ g + (1|t), data= data)&lt;br /&gt;
   # we need to turn the list of simulated values (y) into an atomic vector with unlist()&lt;br /&gt;
   # both data frames and models objects (e.g.,  produced by lm()) are lists&lt;br /&gt;
   #  http://adv-r.had.co.nz/Data-structures.html &lt;br /&gt;
 gdiff[i] &amp;lt;- fixef(model.lmer.1)[2]   # keep only the est diff&lt;br /&gt;
 }&lt;br /&gt;
 quantile(gdiff, c(0.025, 0.975)) &lt;br /&gt;
   # print 95% CI of the coefficient/effect-size of genotype(g)&lt;br /&gt;
&lt;br /&gt;
 # print model summary&lt;br /&gt;
 summary(model.lmer)&lt;br /&gt;
&lt;br /&gt;
 # two ways to speed up CI construction and increase simulations to 1K&lt;br /&gt;
 # use apply to avoid the for loop&lt;br /&gt;
 # use refit() to avoid the setup time before fitting the LME&lt;br /&gt;
&lt;br /&gt;
 yall &amp;lt;- simulate(model.lmer, nsim=1000)&lt;br /&gt;
 gdiff &amp;lt;- apply(yall, 2, function(y) {fixef(refit(model.lmer, y))[2]})&lt;br /&gt;
 quantile(gdiff, c(0.025, 0.975))&lt;br /&gt;
&lt;br /&gt;
 # To get both the estimate and the SE&lt;br /&gt;
 #  which are in the fixed effect table returned by summary()&lt;br /&gt;
 #  use the extractor functions fixef() and vcov()&lt;br /&gt;
&lt;br /&gt;
 yall &amp;lt;- simulate(model.lmer, nsim=1000)&lt;br /&gt;
 gdt &amp;lt;- apply(yall, 2, function(y) { &lt;br /&gt;
 model.lmer.2 &amp;lt;- refit(model.lmer, y); &lt;br /&gt;
 c(fixef(model.lmer.2)[2], sqrt(vcov(model.lmer.2)[2,2]) ) &lt;br /&gt;
 })&lt;br /&gt;
 gdt &amp;lt;- t(gdt)    # because result of apply is 2 rows, nsim cols&lt;br /&gt;
&lt;br /&gt;
 # Using gdt, we can obtain a parametric bootstrap-t interval&lt;br /&gt;
&lt;br /&gt;
 # Hypothesis testing: here we need to simulate under &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;H0: g = 0&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
 # To find the t statistic and the F statistic&lt;br /&gt;
 #  t statistic is in the @coefs table&lt;br /&gt;
 #  F statistic is a value in the anova() output&lt;br /&gt;
 #    if more than one test, need to subscript (unless you want all F's)&lt;br /&gt;
 #    need to reference as a list to avoid R issues&lt;br /&gt;
&lt;br /&gt;
 # Complete model with genotypes&lt;br /&gt;
 model.lmer &amp;lt;- lmer(Weight ~ g + (1|t), data= data)&lt;br /&gt;
&lt;br /&gt;
 model.lmer.0 &amp;lt;- lmer(Weight ~ (1|t), data=data)&lt;br /&gt;
 yall &amp;lt;- simulate(model.lmer.0, nsim=1000)&lt;br /&gt;
 #  NB: simulate data under model.lmer.0&lt;br /&gt;
 gdt0 &amp;lt;- apply(yall, 2, function(y) {&lt;br /&gt;
 model.lmer.2 &amp;lt;- refit(model.lmer, y); # but analyze under alt. model (model.lmer)&lt;br /&gt;
 c(summary(model.lmer.2), anova(model.lmer.2)$\$$'F value' )&lt;br /&gt;
 })&lt;br /&gt;
 gdt0 &amp;lt;- t(gdt0)&lt;br /&gt;
&lt;br /&gt;
 # obs t = 1.438179, p-value using t statistic:&lt;br /&gt;
 coef(summary(model.lmer))&lt;br /&gt;
 mean(abs(gdt0[,1]$\$$sim_1$\$$residuals) &amp;gt;= 1.438179)&lt;br /&gt;
 # p-value = 0.125&lt;br /&gt;
&lt;br /&gt;
 # obs F = 2.0684&lt;br /&gt;
 anova(model.lmer)&lt;br /&gt;
   mean(gdt0[,2]$\$$sim_2$\$$residuals &amp;gt;= 2.0684)&lt;br /&gt;
 # p-value = 0.01785714&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Baseball data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://wiki.socr.umich.edu/index.php/SOCR_Data_MLB_HeightsWeights&lt;br /&gt;
&lt;br /&gt;
 data &amp;lt;- read.table('E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\01a_data.txt',as.is=T, header=T)&lt;br /&gt;
 boxplot(Weight ~ Position, data = data, xlab = &amp;quot;Position&amp;quot;, ylab = &amp;quot;Weight&amp;quot;,&lt;br /&gt;
 main = &amp;quot;MLB Weight Distribution by Position&amp;quot;)&lt;br /&gt;
 boxplot(Weight ~ Team, data = data, xlab = &amp;quot;Team&amp;quot;, ylab = &amp;quot;Weight&amp;quot;,&lt;br /&gt;
 main = &amp;quot;MLB Team Weight Distributions&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
Bates, D.M., Maechler, M., &amp;amp; Bolker, B.  (2012). lme4:  Linear mixed-effects models using S4 classes. R package version 0.999999-0.&lt;br /&gt;
&lt;br /&gt;
Baayen, R.H. (2008). Analyzing Linguistic Data: A Practical Introduction to Statistics Using R. Cambridge: Cambridge University Press.&lt;br /&gt;
&lt;br /&gt;
Baayen, R.H., Davidson, D.J., Bates, D.M. (2008). Mixed-effects modeling with crossed random effects for subjects and items. Journal of Memory and Language, 59, 390-412.&lt;br /&gt;
&lt;br /&gt;
Barr, D.J., Levy, R., Scheepers, C., &amp;amp; Tilly, H. J. (2013). Random effects structure for confirmatory hypothesis testing: Keep it maximal. Journal of Memory and Language, 68, 255–278.&lt;br /&gt;
&lt;br /&gt;
Bolker, B. M., Brooks, M. E., Clark, C. J., Geange, S. W., Poulsen, J. R., Stevens, M. H. H., &amp;amp; White, J. S. S. (2009). Generalized linear mixed models: a practical guide for ecology and evolution. Trends in Ecology &amp;amp; Evolution, 24(3), 127-135.&lt;br /&gt;
&lt;br /&gt;
Wike, E.L., &amp;amp; Church, J.D. (1976). Comments on Clark’s “The language-as-fixed-effect fallacy”. Journal of Verbal Learning &amp;amp; Verbal Behavior, 15, 249-255.&lt;br /&gt;
&lt;br /&gt;
Winter, B. (2013). Linear models and linear mixed effects models in R with linguistic applications. arXiv:1308.5499. [http://arxiv.org/pdf/1308.5499.pdf]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
....&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MachineLearning}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM&amp;diff=16142</id>
		<title>SMHS LinearModeling LMM</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM&amp;diff=16142"/>
		<updated>2016-05-23T12:56:21Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling| SMHS Linear Modeling]] - Linear Mixed Effects Analyses==&lt;br /&gt;
&lt;br /&gt;
Scientific inference based on fixed and random effect models, assumptions, and mixed effects logistic regression.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;Questions:&amp;lt;/B&amp;gt;&lt;br /&gt;
*What happens if data are not independent and identically distributed (IIDs)?&lt;br /&gt;
*How to model multiple observations for the case/subject (across time, conditions, etc.)?&lt;br /&gt;
&lt;br /&gt;
===Fixed and Random Effects===&lt;br /&gt;
&lt;br /&gt;
Linear models express relationships between data elements (variables) in terms of a (linear) function. For example, we can model weight as a function of height.&lt;br /&gt;
&lt;br /&gt;
Weight ~ Height + ε&lt;br /&gt;
&lt;br /&gt;
Here, “height” is a fixed effect, and ε is our “error term” representing the deviations between the model predictions and observations (of weight) due to “random” factors that we cannot control experimentally. This tem (ε) is the “probabilistic” or “stochastic” part of the model. Let’s try to unpack “ε” and add complexity to it. In mixed (fixed and random effect) models, everything in the “systematic” part of your model works just like with linear models. If we change the random aspect of our model this leaves the systematic part (height) unchanged.&lt;br /&gt;
&lt;br /&gt;
Suppose we’re looking at the Baseball data   and try to identify a relationship that looks like this:&lt;br /&gt;
&lt;br /&gt;
Weight ~ position + ε&lt;br /&gt;
&lt;br /&gt;
Position (player field position) is treated as a categorical factor with several levels (e.g., Catcher, First-Baseman, etc.) On top of that, we also have an additional fixed effect, Height, and so our bivariate linear model looks more like this:&lt;br /&gt;
&lt;br /&gt;
Weight ~ Height + position + ε&lt;br /&gt;
&lt;br /&gt;
This model expansion is nice, but it complicates a bit the data analytics and scientific inference. If the study design involved taking multiple measures per player, say across time/age, each player would yield multiple position, height and weight responses. According to the assumptions of the linear model, this would violate the independence assumption, as multiple responses from the same subject cannot be regarded as independent from one another. Every player has a slightly different weight, and this is going to be an idiosyncratic factor that affects all responses from the same player, thus rendering these different responses inter-dependent (within player) instead of independent, as required by the model assumptions.&lt;br /&gt;
&lt;br /&gt;
A way to resolve this model assumption violation is to add a &amp;lt;B&amp;gt;random effect&amp;lt;/B&amp;gt; for players. This allows us to account for inter-independences by assuming a different &amp;lt;B&amp;gt;“baseline”&amp;lt;/B&amp;gt; weight value for each player. For example, player 1 may have a mean weight 200 pounds across different times, and player 2 may have a mean weight of 350 pounds. Here’s a visual depiction of how this looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Team A_Player1&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team A_Playe2&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team A_Player3&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team A_Player4&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team A_Player5&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team B_Player1&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team B_Player2&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Team B_Player 3&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|160||340||240||340||180||200||240||180&lt;br /&gt;
|-&lt;br /&gt;
|180||340||240||400||240||200||320||120&lt;br /&gt;
|-&lt;br /&gt;
|220||320||320||400||260||180||340||160&lt;br /&gt;
|-&lt;br /&gt;
|240||300||300||380||320||160||300||160&lt;br /&gt;
|-&lt;br /&gt;
|200||380||300||380||280||260||300||260&lt;br /&gt;
|-&lt;br /&gt;
|220||360||280||360||280||180||300||180&lt;br /&gt;
|-&lt;br /&gt;
|260||360||320||400||260||240||320||180&lt;br /&gt;
|-&lt;br /&gt;
|200||360||280||380||300||220||320||200&lt;br /&gt;
|-&lt;br /&gt;
|220||480||260||380||280||180||300||220&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig26.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig27.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SOCR Charts generated these plots (http://www.socr.umich.edu/html/cha/). The same data may similarly be plotted using R:&lt;br /&gt;
&lt;br /&gt;
 data &amp;lt;- read.table('C:\\Users\\Dinov\\Desktop\\01a_data.txt',as.is=T, header=T)&lt;br /&gt;
 # data &amp;lt;- read.table('https://umich.instructure.com/files/330381/download?download_frd=1&amp;amp;verifier=HpfmjfMFaMsk7rIpfPx0tmz960oTW7JA8ZonGvVC',as.is=T, header=T)	&lt;br /&gt;
 attach(data)&lt;br /&gt;
 boxplot(TeamA_Player1, TeamA_Player2, TeamA_Player3, TeamA_Player4, TeamA_Player5, TeamB_Player1, TeamB_Player2, TeamB_Player3, col=c(&amp;quot;white&amp;quot;,&amp;quot;lightgray&amp;quot;))&lt;br /&gt;
 boxplot(data, las = 2)&lt;br /&gt;
 boxplot(data, las = 2, par(mar = c(8, 5, 4, 2)+ 0.1))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig28.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can model these individual differences by assuming different &amp;lt;I&amp;gt;&amp;lt;b&amp;gt;random intercepts&amp;lt;/b&amp;gt;&amp;lt;/I&amp;gt; for each player. In other words, each player will be assigned a different intercept value, and the mixed model estimates these intercept values.&lt;br /&gt;
&lt;br /&gt;
The (fixed effects) linear models include several fixed effects and a general error term “ε”. Linear modeling segregates the world into things that we understand as systematic, i.e., fixed effects or the explanatory variables, and things that we cannot control for or poorly understand (error, ε). Statistical inference requires that the unsystematic part (ε) of the model does not have any interesting structure or pattern – it should represent random white noise with common (iid) across-the-board characteristics.&lt;br /&gt;
&lt;br /&gt;
In mixed modeling, we add one or more terms to the fixed effects to account for random effects. These random effects essentially generalize the model (make it more applicable in situations when the error term does have structure) – that is, the random effect models pull out structure from the error term “ε”. For instance, in the baseball weights example, we add a random effect for “player”, and this characterizes idiosyncratic variation that is due to individual body build differences. The intertwining of fixed and random effects is what makes these models mixed-effect models.&lt;br /&gt;
&lt;br /&gt;
Our updated formula looks like this:&lt;br /&gt;
&lt;br /&gt;
M1: Weight ~ Height + position + ε1&amp;lt;BR&amp;gt;&lt;br /&gt;
M2: Weight ~ Height + position + (1|player) + ε2&lt;br /&gt;
&lt;br /&gt;
“(1|player)” is the R notation for random player effects. It assumes an intercept that’s different for each player”, and “1” stands for the constant-term or intercept. This formula explicitly states that the model should account for (inter-player dependencies) multiple responses per player (say over time) – i.e., account for different baselines for each player. This effectively resolves the conflict with weight-dependences within players that stem from multiple weight observations.&lt;br /&gt;
&lt;br /&gt;
The mixed effect model still contains a general error term “ε”, because although it accounts for individual by-player variation, there are still going to be “random” differences between different body-size measurements (e.g., weight) from the same player (noise).&lt;br /&gt;
&lt;br /&gt;
The player position represents an additional source of non-independence that may need to be accounted for. Similarly to the case of by-player variation, we may expect by-position variation. For instance, there might be some special body-size demands for different positions that may lead to overall higher/lower weight. The weight measurements for different players may be similarly affected by this random factor due to game-position-specific idiosyncrasies. Thus, the different responses to one position may not always be independent. There may be some similarities in multiple weight measurements for the same play-position – even if these come from different players. Disregarding these interdependencies, we may violate the linear model independence assumptions. Below is an exemplary visual representation of the by-position variability in weight.&lt;br /&gt;
&lt;br /&gt;
 data &amp;lt;- read.table('https://umich.instructure.com/files/330381/download?download_frd=1&amp;amp;verifier=HpfmjfMFaMsk7rIpfPx0tmz960oTW7JA8ZonGvVC',as.is=T, header=T)&lt;br /&gt;
 library(&amp;quot;reshape2&amp;quot;)&lt;br /&gt;
 # melting by &amp;quot;Position&amp;quot;. `melt is from the reshape2 package. &lt;br /&gt;
 # do ?melt for help&lt;br /&gt;
 data.m &amp;lt;- melt(data[,-c(1:2)], id.var = &amp;quot;Position&amp;quot;)&lt;br /&gt;
 #&lt;br /&gt;
 require(ggplot2)&lt;br /&gt;
 ggplot(data = data.m, aes(x=variable, y=value)) + geom_boxplot(aes(fill=Position))&lt;br /&gt;
&lt;br /&gt;
 ggplot(data = data.m, aes(x=Position, y=value)) + &lt;br /&gt;
         geom_boxplot() + facet_wrap(~variable,ncol = 4)&lt;br /&gt;
&lt;br /&gt;
 p &amp;lt;- ggplot(data = data.m, aes(x=variable, y=value)) &lt;br /&gt;
 p &amp;lt;- p + geom_boxplot(aes(fill = Position))&lt;br /&gt;
 # to color the points replace group with color=Position&lt;br /&gt;
 p &amp;lt;- p + geom_point(aes(y=value, group=Position), position = position_dodge(width=0.75))&lt;br /&gt;
 p &amp;lt;- p + facet_wrap( ~ variable, scales=&amp;quot;free&amp;quot;)&lt;br /&gt;
 p &amp;lt;- p + xlab(&amp;quot;x-axis&amp;quot;) + ylab(&amp;quot;y-axis&amp;quot;) + ggtitle(&amp;quot;Title&amp;quot;)&lt;br /&gt;
 p &amp;lt;- p + guides(fill=guide_legend(title=&amp;quot;Legend_Title&amp;quot;))&lt;br /&gt;
 p&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig29.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The variation between positions may be different from the variation between players!&lt;br /&gt;
&lt;br /&gt;
To add an additional random effect for position we expand the model:&lt;br /&gt;
&lt;br /&gt;
Weight ~ Height + position + (1|player) + (1|position) + ε&lt;br /&gt;
&lt;br /&gt;
Note that a similar argument may be made for “Team”, there could be error-term dependencies or patterns reflecting the between-team random effects on weight – some teams may be bulkier than others. This is really well documented in sports (e.g., top notch Serbian and Spanish water polo teams have a vastly different physiques).&lt;br /&gt;
 &lt;br /&gt;
 data.m2 &amp;lt;- melt(data[,-c(1,3)], id.var = &amp;quot;Team&amp;quot;)&lt;br /&gt;
 # require(ggplot2)&lt;br /&gt;
 p &amp;lt;- ggplot(data = data.m2, aes(x=variable, y=value)) + geom_boxplot(aes(fill=Team))&lt;br /&gt;
 p + facet_wrap( ~ variable, scales=&amp;quot;free&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig30.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus, in addition to modeling different intercepts for different players, we may include, as necessary, different intercepts for different positions or teams. This “resolves” dependencies in the linear model, potentially accounting for multiple responses per player, position or team, and we correctly representing the model by-player and by-position variation in overall weight.&lt;br /&gt;
&lt;br /&gt;
Prior to the advent of mixed linear models, researchers used the averages of all multiple records. For example, in nursing, researchers may average the vital signs (e.g., heart rates, temperatures, etc.) of their patients over time or condition for a patient-based analysis where each data point is assumed to be derived from one subject, assuring independence. Then researchers may also average over subjects for a diagnostic condition type analysis, where each data point comes from one condition. There are advantages and disadvantages of this averaging approach.&lt;br /&gt;
Whereas traditional analyses based on averaging are in principle correct, mixed models provide more flexibility and take the complete data into account. In a patient-based analysis (averaging over conditions/Dx), we basically disregard the by-condition variability.   Conversely, in a condition-based analysis, we may disregard by-patient variation. A mixed-effect model would account for both sources of variation in a single analysis.&lt;br /&gt;
&lt;br /&gt;
Let’s apply this understanding of the linear mixed effects modeling via R.&lt;br /&gt;
&lt;br /&gt;
R commands for mixed-effect modeling&lt;br /&gt;
(See appendix for complete R script) Open RStudio&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;  and install the R package lme4&amp;lt;sup&amp;gt;10&amp;lt;/sup&amp;gt;  :&lt;br /&gt;
&lt;br /&gt;
 install.packages(“lme4”)&lt;br /&gt;
 library(lme4)&lt;br /&gt;
&lt;br /&gt;
This makes available the function lmer(), which is the mixed model equivalent of the function lm()  in the fixed-effect model. Load some data in RStudio&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt;,&amp;lt;sup&amp;gt;12&amp;lt;/sup&amp;gt; .&lt;br /&gt;
 data = read.csv(file.choose( ))&lt;br /&gt;
 attach(data)&lt;br /&gt;
&lt;br /&gt;
You can also try the R QCC package (for quality control, see the first section of this tutorial):&lt;br /&gt;
 install.packages(&amp;quot;qcc&amp;quot;)&lt;br /&gt;
 library(&amp;quot;qcc&amp;quot;, lib.loc=&amp;quot;~/R/win-library/3.1&amp;quot;)&lt;br /&gt;
 data(orangejuice)&lt;br /&gt;
 attach(orangejuice)&lt;br /&gt;
 qcc(D[trial], sizes=size[trial], type=&amp;quot;p&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig31.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test the data-import and get a summary by using head(), tail(), summary(), str(), colnames(), or whatever commands you commonly use to get an overview of a dataset. Also, it is always good to check for missing values:&lt;br /&gt;
&lt;br /&gt;
which(is.na(Team)==T)&lt;br /&gt;
&lt;br /&gt;
If there are missing values, there are no problems for the mixed-effect modeling.&lt;br /&gt;
&lt;br /&gt;
Using the MLB Baseball data&amp;lt;sup&amp;gt;13&amp;lt;/sup&amp;gt; we can explore relationship between variables (e.g., Height and Weight) by means of boxplots:&lt;br /&gt;
		&lt;br /&gt;
 # data &amp;lt;- read.table('E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\01a_data.txt',as.is=T, header=T)&lt;br /&gt;
 data &amp;lt;- read.table('data.txt',as.is=T, header=T)&lt;br /&gt;
 boxplot(Weight ~ Height, col=c(&amp;quot;white&amp;quot;,&amp;quot;lightgray&amp;quot;))&lt;br /&gt;
 boxplot(Weight ~ Height*team, col=c(&amp;quot;white&amp;quot;,&amp;quot;lightgray&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig32.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Is the thick median line in the middle of the boxplot lower for the light than the heavier players? &lt;br /&gt;
&lt;br /&gt;
To construct the mixed model try the command below …&lt;br /&gt;
&lt;br /&gt;
 lmer(Weight ~ Height, data=data)&lt;br /&gt;
&lt;br /&gt;
You will get an error that should look like this:&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Error: No random effects terms specified in formula&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is because the model needs at least 1 random effect however we only specified a single fixed effect (Height). So, let’s add random intercepts for subjects and items (remember that items are called “scenarios” here):&lt;br /&gt;
&lt;br /&gt;
 model.lmer &amp;lt;- lmer(Weight ~ Height + (1|Team) + (1|Position), data= data)&lt;br /&gt;
&lt;br /&gt;
This command creates a model that includes a fixed effect “Height” to predict Weight, controlling for by-team and by-position variability. The model is saved in an object model.lmer. To see the model type in model.lmer – this will print the output in the shell. Note that in the classical fixed effect model, lm(), we need to use summary()  to get this output.&lt;br /&gt;
&lt;br /&gt;
This is the full output:&lt;br /&gt;
 summary(model.lmer)&lt;br /&gt;
 &lt;br /&gt;
 Linear mixed model fit by REML ['lmerMod']&lt;br /&gt;
 Formula: Weight ~ Height + (1 | Team) + (1 | Position)&lt;br /&gt;
   Data: data&lt;br /&gt;
 &lt;br /&gt;
 REML criterion at convergence: 8841.4&lt;br /&gt;
 &lt;br /&gt;
 Scaled residuals:     &lt;br /&gt;
   Min      1Q   Median      3Q     Max &lt;br /&gt;
 -2.9396 -0.6885 -0.0222  0.6010  4.1358  &lt;br /&gt;
 &lt;br /&gt;
 Random effects:  &lt;br /&gt;
 Groups   Name      Variance   Std.Dev.  &lt;br /&gt;
 Team    (Intercept)   1.285   1.133    &lt;br /&gt;
 Position (Intercept)  56.218   7.498    &lt;br /&gt;
 Residual             295.652  17.195   &lt;br /&gt;
 Number of obs: 1034, groups:  Team, 30; Position, 9  &lt;br /&gt;
 &lt;br /&gt;
 Fixed effects: &lt;br /&gt;
 Estimate Std. Error t value &lt;br /&gt;
 (Intercept) -142.8215    19.0160  -7.511 &lt;br /&gt;
 Height         4.6973     0.2571  18.271  &lt;br /&gt;
 &lt;br /&gt;
 Correlation of Fixed Effects:        &lt;br /&gt;
   (Intr) &lt;br /&gt;
 Height -0.991 &lt;br /&gt;
&lt;br /&gt;
The output starts with the user-specified model and data. Then, there’s the restricted maximum likelihood (ReML) criterion, summary of the model residuals (ε), followed by random and fixed effects.&lt;br /&gt;
&lt;br /&gt;
The ''standard deviation column'' represents a measure of the variability for each random effect included in the model. “Team” has much less variability than Position. The &amp;lt;u&amp;gt;Residual row represents the variability that’s not due to either Team or Position.&amp;lt;/u&amp;gt; This is the ε term – random deviations from the predicted values that are not due to Team or Position. This reflects the fact that body-size has some factors that affect Weight that are outside of the observations we have in this experiment. Similarly, to the fixed effect models, the fixed effects output in this mixed model output includes estimates, SE and T-statistic.&lt;br /&gt;
&lt;br /&gt;
The coefficient of “Height” (4.6973) is the slope for this variable. Finally, the Correlation of the Fixed Effects (H vs. Intercept) is reported to be negative! &amp;lt;u&amp;gt;The output under &amp;quot;''correlation of fixed effects''&amp;quot; has a different interpretation from the intuitive meaning.&amp;lt;/u&amp;gt; It is not about the correlation of the variables, but about the &amp;lt;u&amp;gt;“expected correlation of the regression coefficients”.&amp;lt;/u&amp;gt; This may, or may not, be related to multicollinearity. In this case, ''corr(H,Intrc)''= -0.991 suggests that &amp;lt;u&amp;gt;if we redo the experiment again a decrease of the Height coefficient will increase the intercept&amp;lt;/u&amp;gt;, and vice-versa, an increase of the Height coefficient is expected to drive down the intercept term (which is currently =-142.8215). &lt;br /&gt;
&lt;br /&gt;
 plot(Height, Weight, main=&amp;quot;Scatterplot Height vs. Weight&amp;quot;, xlab=&amp;quot;Height &amp;quot;, ylab=&amp;quot;Weight &amp;quot;, pch=19) &lt;br /&gt;
 # Add fit lines&lt;br /&gt;
 abline(lm(Weight~Height), col=&amp;quot;red&amp;quot;) # regression line (W~H) &lt;br /&gt;
 lines(lowess(Height,Weight), col=&amp;quot;blue&amp;quot;) # lowess line (H,W), (locally weighted scatterplot smoothing)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig33.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Inference on LMER coefficients:&amp;lt;/b&amp;gt; The Satterthwaite approximation, implemented in the &amp;lt;b&amp;gt;lmerTest&amp;lt;/b&amp;gt; package, overloads the &amp;lt;b&amp;gt;lmerM&amp;lt;/b&amp;gt; function, using exactly the same model, but the &amp;lt;b&amp;gt;summary&amp;lt;/b&amp;gt;() will include approximate degrees of freedom and p-values for all predictors.&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;lmerTest&amp;quot;) &lt;br /&gt;
 library(lmerTest)&lt;br /&gt;
 &lt;br /&gt;
 # re-fit model&lt;br /&gt;
 model.lmer &amp;lt;- lmer(Weight ~ Height + (1|Team) + (1|Position), data= data, REML = FALSE)&lt;br /&gt;
 coeffs &amp;lt;- data.frame(coef(summary(model.lmer)))&lt;br /&gt;
 &lt;br /&gt;
 # get Satterthwaite-approximated degrees of freedom&lt;br /&gt;
 coeffs$\$$df.Satt &amp;lt;- coef(summary(model.lmer))[, 3]&lt;br /&gt;
 # get approximate p-values&lt;br /&gt;
 coeffs$\$$p.Satt &amp;lt;- coef(summary(model.lmer))[, 5]&lt;br /&gt;
 coeffs&lt;br /&gt;
 &lt;br /&gt;
               Estimate  Std..Error   df     t.value     Pr...t..   df.Satt &lt;br /&gt;
 (Intercept) -143.26916 18.9698712  977.2059 -7.552458 9.792167e-14  977.2059 &lt;br /&gt;
 Height         4.70294  0.2567663 1030.9565 18.316031   0.000000e+00 1030.9565                   &lt;br /&gt;
                p.Satt &lt;br /&gt;
 (Intercept)    9.792167e-14 &lt;br /&gt;
 Height         0.000000e+00 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For categorical variables, like in the fixed effect model, lm(), the mixed effect model, lmer(), takes whatever comes first in the alphabet to be the reference level. “A” comes before “C”, so the slope representing the change from “A” to “C” for a categorical variable (e.g., Team) is in that direction. If the interpretation requires the reference category to be “C”, rather than “A”, then we need to change how we interpret the sign of the slope coefficient. However, interpretation of standard errors and significance would remain unchanged (as there are sign agnostic).&lt;br /&gt;
&lt;br /&gt;
As the earlier model (model.lmer &amp;lt;- lmer(Weight ~ Height + (1|Team) + (1|Position), data= data)) did not account for age, the intercept may be biased between different age groups. If there are age effects – e.g., the distribution of weights may be bimodal (for younger and older players) – then the average weight may not be representative at all. Think of a study of mammals including 10 bipedal (humans) and 10 quadrupedal (dogs) where the mean number of legs of a mammal would be 3 ((10*2+10*4)/20=3), which is not informative and actually incorrect for mammals.&lt;br /&gt;
&lt;br /&gt;
Adding Age as an additional fixed effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.2 = lmer(Weight ~ Height + Age + (1|Team) + (1|Position), data=data)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This expands the original model object lmer.model with an age predictor. “Age” is added as a fixed effect, because the relationship between Age and Weight is systematic and predictable (not random). Older players are expected to have higher weights. &lt;br /&gt;
&lt;br /&gt;
 plot(Age, Weight, main=&amp;quot;Scatterplot Age vs. Weight&amp;quot;, xlab=&amp;quot;Age &amp;quot;, ylab=&amp;quot;Weight &amp;quot;, pch=19) &lt;br /&gt;
 abline(lm(Weight~Age), col=&amp;quot;red&amp;quot;) # regression line (W~A) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig34.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that Age is different from the random effects for Team and Position, where the relationship between these and Weight is more unpredictable or stochastic.&lt;br /&gt;
&lt;br /&gt;
Look at the residuals of lmer.model.2 output:&lt;br /&gt;
&lt;br /&gt;
summary(lmer.model.2)&lt;br /&gt;
Linear mixed model fit by REML ['lmerMod']&lt;br /&gt;
Formula: Weight ~ Height + Age + (1 | Team) + (1 | Position)&lt;br /&gt;
Data: data&lt;br /&gt;
&lt;br /&gt;
REML criterion at convergence: 8792.2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
Scaled Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
| -2.9434||-0.6454||-0.0414||0.6022||4.4715&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|Groups Name||Variance||Std. Dev.&lt;br /&gt;
|-&lt;br /&gt;
|Team (Intercept)||1.136||1.066&lt;br /&gt;
|-		&lt;br /&gt;
|Position (Intercept)||47.935||6.924&lt;br /&gt;
|-&lt;br /&gt;
|Residual||281.805||16.787&lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 1034, groups:  Team, 30; Position, 9&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||Estimate Std.||Error||t Value&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||-176.4537||19.0913||-9.243&lt;br /&gt;
|-		&lt;br /&gt;
|Height||4.8043||0.2512||19.125&lt;br /&gt;
|-		&lt;br /&gt;
|Age||0.8888||0.1222||7.273&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
Correlation of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
|||(Intr)||Height&lt;br /&gt;
|-&lt;br /&gt;
|Height||-0.974||&lt;br /&gt;
|-&lt;br /&gt;
|Age||-0.240||0.056&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that compared to our earlier model without the fixed effect for Age, the variation that’s associated with the random effects for “Team” and “Position” are reduced. This is because the variation due to Age may be confounded with the variation that’s due to Team/Position. As the initial model didn’t know about Age, its predictions were relatively more varying, producing larger residuals.&lt;br /&gt;
&lt;br /&gt;
Exploring the fixed effect coefficients:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||Estimate Std.||Error||t Value&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||-176.4537||19.0913||-9.243&lt;br /&gt;
|-		&lt;br /&gt;
|Height||4.8043||0.2512||19.125&lt;br /&gt;
|-		&lt;br /&gt;
|Age||0.8888||0.1222||7.273&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see that the impact of Age on Weight is about 0.9, with an intercept of -176 (pounds). The coefficient for the fixed effect of Height changed slightly, from 4.6973 to 4.8.&lt;br /&gt;
&lt;br /&gt;
===Scientific Inference===&lt;br /&gt;
&lt;br /&gt;
Reporting LME models requires explicit quantitative estimation of probability values expressing the statistical significance of these estimates. &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;Interpretation of p-values for mixed models is different from their counterparts in fixed-effects linear models. The Likelihood Ratio Test provides one approach to obtain the p-values.&amp;lt;/span&amp;gt; Likelihood is the (conditional) probability of seeing the observed data given a model. The likelihood ratio test compares the (ratio of) two likelihoods corresponding to two alternative models. For instance, suppose we are interested in quantifying the significance of a factor A. The model without the factor A (the null model), will be compared to the model with the factor A.&lt;br /&gt;
&lt;br /&gt;
Suppose we are comparing the following 2 models aiming to assess the significance of the impact of Age on Weight.&lt;br /&gt;
&lt;br /&gt;
m1: Weight ~ Height + Age&amp;lt;BR&amp;gt;&lt;br /&gt;
m2: Weight ~ Height&lt;br /&gt;
&lt;br /&gt;
A significant difference between “m2” and “m1” would yield that Age matters as a predictor of Weight. Similarly, to estimate the effect of the Height, you would have to do a similar comparison:&lt;br /&gt;
&lt;br /&gt;
m1’: Weight ~ Height + Age&amp;lt;BR&amp;gt;&lt;br /&gt;
m2’: Weight ~ Age&lt;br /&gt;
&lt;br /&gt;
In both cases, we compared a full model (with the fixed effects in question) against a reduced model without the variable of interest explicitly modeled. A fixed effect would be significant if the ratio between the likelihoods of these two models is significant. In R, we start by constructing the null model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.0 &amp;lt;- lmer(Weight ~ Height + (1|Team) + (1|Position), data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the added the argument REML=FALSE that changes the calculation of the likelihood estimator, which is required when comparing models using the likelihood ratio test. Then, we re-do the full model, also with REML=FALSE:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.1 &amp;lt;- lmer(Weight ~ Height + &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;Age&amp;lt;/span&amp;gt;+ (1|Team) + (1|Position), data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compare the two models (the full model with the effect in question with the null model without the effect), we perform the likelihood ratio test using the anova() function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;anova(lmer.model.0, lmer.model.1)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output of this call is:&lt;br /&gt;
&lt;br /&gt;
 Data: data&lt;br /&gt;
 Models:&lt;br /&gt;
 lmer.model.0: Weight ~ Height + (1 | Team) + (1 | Position)&lt;br /&gt;
 lmer.model.1: Weight ~ Height + Age + (1 | Team) + (1 | Position)&lt;br /&gt;
 Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(&amp;gt;Chisq)    &lt;br /&gt;
 lmer.model.0  5 8854.3 8879.0 -4422.1   8844.3                             &lt;br /&gt;
 lmer.model.1  6 8804.5 8834.1 -4396.2   8792.5 51.795      1   6.16e-13 ***&lt;br /&gt;
 ---&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
The report starts with the formulas of the two models, computes a Chi-Square statistics with associated degrees of freedom (2-1), and reports the p-value representing the strength of the data-driven evidence to reject the null-model (and hence to accept the significance of the factor of interest, &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;Age&amp;lt;/span&amp;gt;, as impactful on Weight). The qualitative interpretation of these quantitative results may be stated as:&lt;br /&gt;
&lt;br /&gt;
“… Age affects Weight ''X''&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;(1)=51.79, p&amp;lt; 10&amp;lt;sup&amp;gt;-12&amp;lt;/sup&amp;gt;), increasing it (annually) by about 0.89 lb ± 0.1222 (standard error) …”&lt;br /&gt;
&lt;br /&gt;
We are using a Chi-Square test because Wilk’s Theorem   states that $-2log(\frac{Likelihood\_Null\_model(m0)}{Likelihood\_full\_model(m1)}$) approaches a Chi-Square distribution with degrees of freedom equal to the number of parameters that differ between the models (in this case, only “Age”, so ''df''=1).&lt;br /&gt;
&lt;br /&gt;
This likelihood-based inference approach is somewhat different from the classical t-tests, ANOVA and linear model inference. Instead of obtaining a p-value directly from the MLE model, we need to run a second-order analysis (in this case ANOVA on the 2 models) to compare them and derive a p-value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note that the “Height” predictor was present in both models (null and full models) as we aimed to assess the impact of Age using the likelihood ratio test. In this test, we think of the covariate “Height” as a control variable and of “Age” as the test variable.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens if we compare the following two models:&lt;br /&gt;
&lt;br /&gt;
m0: Weight ~ 1                  # intercept only constant model estimating the mean only&amp;lt;BR&amp;gt;&lt;br /&gt;
m1: Weight ~ Height + Age	# Intercept and 2 covariates model&lt;br /&gt;
&lt;br /&gt;
Suppose the likelihood-ration test suggest significant differences between the 2 models, this would suggest that “m1” (full) and “m0” (null) are significantly different from one another. However, it would not attribute this difference to “Height” or “Age” alone. We may not be able to tease out conclusively which one of the two variables (or both) was crucial.&lt;br /&gt;
&lt;br /&gt;
How about the possibility of having an Age-by-Height interaction effect? For instance, “Height” effect on Weight may be modulated through “Age”. If such inter-dependence between two factors (an interaction) is present or suspected, its impact may be assessed the same way:&lt;br /&gt;
&lt;br /&gt;
full model: Weight ~ Height * Age&amp;lt;BR&amp;gt;&lt;br /&gt;
reduced model: Weight ~ Height + Age&lt;br /&gt;
&lt;br /&gt;
Interactions between two factors are commonly specified with a “*” rather than a “+”. Comparing these models via the likelihood ratio test and the anova() function yields a p-value quantifying the significance of the interaction term (Height * Age). A significant result implies that Height and Age are strongly inter-dependent on each other. An insignificant result implies that there is no strong evidence in these data for inter-dependence.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
lm.1 &amp;lt;- lm(y ~ x:z) 	# includes only the interaction (colon, “:”) between x &amp;amp; z,&lt;br /&gt;
&amp;amp;#35; but not the original variables x and z &amp;lt;BR&amp;gt;&lt;br /&gt;
lm.2 &amp;lt;- lm(y ~ x + z + x:z) # this is a complete model for y using x &amp;amp; z&lt;br /&gt;
 &lt;br /&gt;
&amp;amp;#35;In regressions with a lot of variables, the product (*) notation provides a shortcut to minimize typing.&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;#35; We can indicate this using a simple multiplication symbol (*):&amp;lt;BR&amp;gt;&lt;br /&gt;
lm.3 &amp;lt;- lm(y ~ x*z)	# equivalent to model lm.2, but shorter.&lt;br /&gt;
&lt;br /&gt;
Using this code, R will automatically include both variables in the regression in addition to the interaction between the two&lt;br /&gt;
&lt;br /&gt;
We can experiment with computing alternative likelihoods to contrast different models using these, or other, datasets. For instance, compare “Height*Age” vs. “Height + Age” vs. simply “1” (intercept only model). We need to specify REML=FALSE in the models to be able to use the log-likelihood ratio test.&lt;br /&gt;
&lt;br /&gt;
'''Interpreting effect-sizes for random effects''' (random slopes vs. random intercepts)&lt;br /&gt;
&lt;br /&gt;
Let’s inspect the coefficients of the mixed model by Team and by Position:&lt;br /&gt;
&lt;br /&gt;
 coef&amp;lt;b&amp;gt;(lmer.model.1)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
$\$$Team&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|||(Intercept)||Height||Age&lt;br /&gt;
|-		&lt;br /&gt;
|ANA||-176.9872||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|ARZ||-176.2895||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|ATL||-177.2084||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|BAL||-177.6145||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|BOS||-177.0276||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|CHC||-176.9496||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|CIN||-176.7425||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|CLE||-177.1519||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|COL||-177.4466||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|CWS||-176.4970||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|DET||-176.7084||4.810485||0.8900941	&lt;br /&gt;
|-&lt;br /&gt;
|FLA||-176.7071||4.810485||0.8900941	&lt;br /&gt;
|-&lt;br /&gt;
|HOU||-177.0758||4.810485||0.8900941	&lt;br /&gt;
|-&lt;br /&gt;
|KC||-177.5616||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|LA||-176.6696||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|MIN||-176.7251||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|MLW||-176.4952||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|NYM||-177.2486||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|NYY||-176.7923||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|OAK||-177.0576||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|PHI||-177.8202||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|PIT||-176.4746||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|SD||-176.6908||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|SEA||-177.1092||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|SF||-176.8983||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|STL||-177.1223||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|TB||-177.2853||4.810485||0.8900941	&lt;br /&gt;
|-&lt;br /&gt;
|TEX||-177.0813||4.810485||0.8900941&lt;br /&gt;
|-	&lt;br /&gt;
|TOR||-176.8177||4.810485||0.8900941	&lt;br /&gt;
|-	&lt;br /&gt;
|WAS||-177.2275||4.810485||0.8900941&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
$\$$Position&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||(Intercept)||Height||Age&lt;br /&gt;
|-&lt;br /&gt;
|Catcher||-172.2235||4.810485||0.8900941&lt;br /&gt;
|-		&lt;br /&gt;
|Designated_Hitter||-166.9709||4.810485||0.8900941&lt;br /&gt;
|-		&lt;br /&gt;
|First_Baseman||-169.9896||4.810485||0.8900941&lt;br /&gt;
|-&lt;br /&gt;
|Outfielder||-177.8433||4.810485||0.8900941&lt;br /&gt;
|-		&lt;br /&gt;
|Relief_Pitcher||-179.5896||4.810485||0.8900941&lt;br /&gt;
|-		&lt;br /&gt;
|Second_Baseman||-183.9341||4.810485||0.8900941&lt;br /&gt;
|-&lt;br /&gt;
|Shortstop||-186.9628||4.810485||0.8900941&lt;br /&gt;
|-		&lt;br /&gt;
|Starting_Pitcher||-179.2067||4.810485||0.8900941&lt;br /&gt;
|-		&lt;br /&gt;
|Third_Baseman||-176.1245||4.810485||0.8900941&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 attr(,&amp;quot;class&amp;quot;)&lt;br /&gt;
 [1] &amp;quot;coef.mer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
As expected from a mixed-effect model, each Team and each Position is assigned a different intercept, as we specified the model with “(1|Team)” and “(1|Position)” to take into account by-Team and by-Position variability:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.1 &amp;lt;- lmer(Weight ~ Height + Age + (1|Team) + (1|Position), data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The fixed effects &amp;lt;b&amp;gt;(Height + Age)&amp;lt;/b&amp;gt; are all the same for all Team and Positions, as this model is a random intercept model where we account for baseline-differences in Weight assuming whatever the effect of Height is, it’s the same for all Teams and Positions.&lt;br /&gt;
&lt;br /&gt;
This assumption may not always be valid – some Positions may demand more or less Weight. The Weight effect may be different for different Positions. Similarly, the Weight effect may be different for different Teams (recall the Water Polo National teams – Spain vs. Serbia).&lt;br /&gt;
&lt;br /&gt;
Thus, we may need a random slope model, where Team and Positions may have differing intercepts as well as different slopes for the Weight. In R this can be coded as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.2 = lmer(Weight ~ Height + Age + (1+Height|Team) + (1+Height|Position), data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This new model only includes more complicated random effects. In this case, the notation “(1+Height|Team)” means that the model expects differing baseline-levels of Weight (the intercept, represented by 1) &amp;lt;b&amp;gt;and&amp;lt;/b&amp;gt; differing levels of “Height”. The same is true for Position.&lt;br /&gt;
&lt;br /&gt;
Examining the coefficients of this updated model:&lt;br /&gt;
&lt;br /&gt;
 coef&amp;lt;b&amp;gt;(lmer.model.2)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generates the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
$\$$Team&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||(Intercept)||Height||Age&lt;br /&gt;
|-&lt;br /&gt;
|ANA||-184.5752||4.913632||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|ARZ||-157.6363||4.564806||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|ATL||-185.3436||4.923583||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|BAL||-193.6560||5.031218||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|BOS||-183.8410||4.904126||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|CHC||-181.9705||4.879904||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|CIN||-176.1931||4.805094||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|CLE||-195.5968||5.056349||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|COL||-193.8297||5.033467||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|CWS||-174.9203||4.788613||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|DET||-168.4951||4.705414||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|FLA||-180.6757||4.863139||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|HOU||-191.5622||5.004105||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|KC||-204.9527||5.177497||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|LA||-166.8079||4.683568||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|MIN||-182.1954||4.882816||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|MLW||-164.4339||4.652826||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|NYM||-184.1068||4.907567||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|NYY||-186.9822||4.944800||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|OAK||-184.9647||4.918675||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|PHI||-208.3698||5.221744||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|PIT||-176.5423||4.809616||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|SD||-169.8045||4.722369||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|SEA||-183.9884||4.906034||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|SF||-180.9398||4.866558||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|STL||-183.5529||4.900395||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|TB||-186.5983||4.939829||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|TEX||-182.5549||4.887472||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|TOR||-193.1088||5.024132||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|WAS||-203.4900||5.158557||0.8799488&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
$\$$Position&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
|-		&lt;br /&gt;
| ||(Intercept)||Height||Age&lt;br /&gt;
|-&lt;br /&gt;
|Catcher||-209.6130||5.323756||0.8799488&lt;br /&gt;
|-		&lt;br /&gt;
|Designated_Hitter||-236.8530||5.766876||0.8799488&lt;br /&gt;
|-		&lt;br /&gt;
|First_Baseman||-219.8348||5.490036||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|Outfielder||-180.9668||4.857761||0.8799488&lt;br /&gt;
|-		&lt;br /&gt;
|Relief_Pitcher||-172.6381||4.722276||0.8799488&lt;br /&gt;
|-		&lt;br /&gt;
|Second_Baseman||-141.1982||4.210837||0.8799488&lt;br /&gt;
|-&lt;br /&gt;
|Shortstop||-127.4526||3.987233||0.8799488&lt;br /&gt;
|-		&lt;br /&gt;
|Starting_Pitcher||-173.4682||4.735780||0.8799488&lt;br /&gt;
|-		&lt;br /&gt;
|Third_Baseman||-191.4820||5.028815||0.8799488&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 attr(,&amp;quot;class&amp;quot;)&lt;br /&gt;
 [1] &amp;quot;coef.mer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note that the columns containing the by-team and by-position coefficients for the effect of “Height” are different for each Team and each Position.&amp;lt;/b&amp;gt; The fact that this column's values are always positive (quite similar to one another) implies that despite variation between teams/positions there is consistency in how Height impacts Weight. In other words, the Weight of all Players tends to go UP with Height, which is to be expected, albeit for some positions Weight may go UP slightly more than for other positions (e.g., Designated_Hitter=5.766876 vs. Shortstop=3.987233). On the other hand, the coefficients for Age remain static across positions and teams – why? Because the model &amp;lt;b&amp;gt;(lmer.model.2)&amp;lt;/b&amp;gt; didn’t specify random slopes for the by-Position or by-Team effect of Age.&lt;br /&gt;
&lt;br /&gt;
Next, we need to address the significance of these effects (i.e., compute the corresponding p-values using the likelihood ration test). We keep our model from above &amp;lt;b&amp;gt;(lmer.model.2)&amp;lt;/b&amp;gt; and compare it to a new null model &amp;lt;b&amp;gt;(lmer.model.0)&amp;lt;/b&amp;gt; using the likelihood ratio test:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.0 = lmer(Weight ~  Age + &amp;lt;U&amp;gt;(1+Height|Team) + (1+Height|Position)&amp;lt;/U&amp;gt;, data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.2 = lmer(Weight ~ &amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;Height&amp;lt;/span&amp;gt; + Age + &amp;lt;U&amp;gt;(1+Height|Team) + (1+Height|Position)&amp;lt;/U&amp;gt;, data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The null model &amp;lt;b&amp;gt;(lmer.model.0)&amp;lt;/b&amp;gt; needs to have the same random effects structure as the full model &amp;lt;b&amp;gt;(lmer.model.2).&amp;lt;/b&amp;gt; That is, all random slope parameters included in the full model must be present in the null model.&lt;br /&gt;
&lt;br /&gt;
Let’s now do the likelihood ratio test:&lt;br /&gt;
&lt;br /&gt;
 anova&amp;lt;b&amp;gt;(lmer.model.0, lmer.model.2)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Models:&lt;br /&gt;
 lmer.model.0: Weight ~ Age + (1 + Height | Team) + (1 + Height | Position)&lt;br /&gt;
 lmer.model.2: Weight ~ Height + Age + (1 + Height | Team) + (1 + Height | Position)&lt;br /&gt;
 Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(&amp;gt;Chisq)    &lt;br /&gt;
 lmer.model.0  9 8876.4 8920.8 -4429.2   8858.4                             &lt;br /&gt;
 lmer.model.2 10 8809.3 8858.7 -4394.6   8789.3 69.082      1  &amp;lt; 2.2e-16 ***&lt;br /&gt;
 ---&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
Model differences are statistically significant. In general, ask: do we need random effects? and if so, which random slopes to include in the model? It’s a bit easier to work with random effect models that only include random intercept. However, it may be best to always include the random slopes in the models, as if these are insignificant, so we can determine that and reduce the model. In general, we can expect that the effect of an experimental manipulation (e.g., player position, team, etc.) may not be static across items (e.g., locations). There is some evidence from simulation studies that mixed models excluding random slopes may be too liberal - their Type I error rate may be higher than expected (i.e., we can find significant effects which are actually due to chance alone).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;background-color: #FFFF00&amp;quot;&amp;gt;The full model &amp;lt;b&amp;gt;(lmer.model.2)&amp;lt;/b&amp;gt; is focused on baseball players’ Weight. As Age is not a variable we are interested in studying, albeit it may affect Weight, we need to control for Age. Thus &amp;lt;b&amp;gt;lmer.model.&amp;lt;/b&amp;gt;2 has random slopes for the effect of &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;Height&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt; (by Team and Position) but not the effect of Age. In other words, we only modeled by-Team and by-Position variability in how Height affects Weight.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;lmer.model.2 = lmer(Weight ~ Height + Age + &amp;lt;u&amp;gt;(1+Height|Team) + (1+Height|Position)&amp;lt;/u&amp;gt;, data=data, REML=FALSE)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; http://www.rstudio.com/products/rstudio/download/  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;10&amp;lt;/sup&amp;gt; http://cran.r-project.org/web/packages/lme4/lme4.pdf  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt; http://www.r-tutor.com/r-introduction/data-frame/data-import &lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;12&amp;lt;/sup&amp;gt; http://www.statmethods.net/input/importingdata.html  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;13&amp;lt;/sup&amp;gt; http://wiki.socr.umich.edu/index.php/SOCR_Data_MLB_HeightsWeights&lt;br /&gt;
&lt;br /&gt;
==Next See==&lt;br /&gt;
* [[SMHS_LinearModeling_LMM_Assumptions|Mixed Effect Model Assumptions section]]&lt;br /&gt;
* [[SMHS_LinearModeling_MachineLearning|Machine Learning Algorithms section]] for data modeling, training , testing, forecasting, prediction, and simulation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_LMM}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR&amp;diff=16141</id>
		<title>SMHS LinearModeling MLR</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR&amp;diff=16141"/>
		<updated>2016-05-23T12:55:19Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling|SMHS Linear Modeling]] - Multiple Linear Regression ==&lt;br /&gt;
&lt;br /&gt;
In this section, we expand our [[SMHS#Chapter_III:_Linear_Modeling |previous discussion of linear modeling]], review, and demonstrate computing and visualizing the regression-model coefficients (effect-sizes), (fixed-effect) linear model assumptions, examination of residual plots, and independence.&lt;br /&gt;
&lt;br /&gt;
'''Questions''':&lt;br /&gt;
*Are there (linear) associations between predictors and a response variable(s)?&lt;br /&gt;
*When to look for linear relations and what assumptions play role?&lt;br /&gt;
&lt;br /&gt;
Let’s use some of the data included in the Appendix. Snapshots of the first few rows in the data are shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Genotype||Race||Subject||Weight||Index||Subject||Day||Treatment||Obs&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||1||8||&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;||13||Day1 ||B||6.472687&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||2||9||&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;||14||Day1 ||B||7.01711&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||3||11||&amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;||15||Day1 ||B||6.2007154&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||4||12||&amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;||16||Day1 ||B||6.6139285&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||5||10||&amp;lt;b&amp;gt;5&amp;lt;/b&amp;gt;||17||Day1 ||A||6.8299686&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||2||1||17||&amp;lt;b&amp;gt;6&amp;lt;/b&amp;gt;||18||Day1 ||A||7.387583&lt;br /&gt;
|-&lt;br /&gt;
|...||||||||...||||||||&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Eyeballing the data may suggest that Race &amp;quot;2&amp;quot; subjects may have higher &amp;quot;Weights&amp;quot; (first dataset), or &amp;quot;Treatment A&amp;quot; yields higher &amp;quot;Observations&amp;quot; (second dataset). However, this cursory observation may be incorrect, as we may be looking at a small/exceptional sub-sample of the entire population. Data-driven linear modeling allows us to quantify such patterns and compute probability values expressing the strength of the evidence in the data to make such conclusions. In a nutshell, we express relationships of interest (e.g., weight as a function of race, or Observation as a function of treatment) using a linear function as an analytical representation of these inter-variable relations:&lt;br /&gt;
&lt;br /&gt;
Weight ~ Race, Weight ~ Genotype, Obs ~ Treatment, Obs ~ Day, etc.&amp;lt;BR&amp;gt;&lt;br /&gt;
W = a +b*R,&lt;br /&gt;
&lt;br /&gt;
This &amp;quot;~&amp;quot; (tilde) notation implies &amp;quot;Weight predicted by Race&amp;quot; or &amp;quot;Observation as a linear function of Treatment&amp;quot;. The &amp;quot;dependent variable&amp;quot; (a measurable response) on the left is predicted by the factor on the right acting as an &amp;quot;independent variable&amp;quot;, co-variate, predictor, &amp;quot;explanatory variable&amp;quot;, or &amp;quot;fixed effect&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Often times inter-dependencies may not be perfect, deterministic, or rigid (like in the case of predicting the Area of a disk knowing its radius, or predicting the 3D spatial location of a planet having a precise date and time). Weight may not be completely and uniquely determined by Race alone, as many different factors play role (genetics, environment, aging, etc.) Even if we can measure all factors we can identify as potentially influencing Weight, there will still be intrinsic random variability into the observed Weight measures, which can’t be control for. This intrinsic random variation may be captured and accounted for using &amp;quot;random&amp;quot; term at the end.&lt;br /&gt;
&lt;br /&gt;
Weight ~ Race + ε~ D(m=0, s).&lt;br /&gt;
&lt;br /&gt;
Epsilon &amp;quot;ε&amp;quot; represents the error term of predicting Weight by Gender alone and summarizes the aggregate impact of all factors aside from Race that impact individual’s Weight, which are experimentally uncontrollable or random. This formula is a schematic analytic representation of a linear model that we’re going to estimate, quantify, and use for prediction and inference. The right hand side splits the knowledge representation of Weight into 2 complementary components - a &amp;quot;fixed effect&amp;quot; for Race, which we understand and expect, and a &amp;quot;random effect&amp;quot; (&amp;quot;ε&amp;quot;) what we don’t know well. (W ~ R represents the &amp;quot;structural&amp;quot; or &amp;quot;systematic&amp;quot; part of the linear model and &amp;quot;ε&amp;quot; stands for the &amp;quot;random&amp;quot; or &amp;quot;probabilistic&amp;quot; part of the model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;R Experiment (See Appendix)&amp;lt;/B&amp;gt;&lt;br /&gt;
 mydata1 &amp;lt;- data.frame(&lt;br /&gt;
     Subject  = c(13, 14, 15, 16, 17, 18), &lt;br /&gt;
     Day       = c(&amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day2&amp;quot;, &amp;quot;Day2&amp;quot;, &amp;quot;Day2&amp;quot;), &lt;br /&gt;
     Treatment = c(&amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;), &lt;br /&gt;
     Obs       = c(6.472687, 7.017110, 6.200715, 6.613928, 6.829968, 7.387583)&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
We construct an R frame object&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; concatenating 3 data-elements for 6 subjects, and saving it into &amp;quot;mydata1.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|Subject||Day||Treatment||Obs&lt;br /&gt;
|-&lt;br /&gt;
|13||Day1||B||6.472687&lt;br /&gt;
|-&lt;br /&gt;
|14||Day1||B||7.017110&lt;br /&gt;
|-&lt;br /&gt;
|15||Day1||B||6.200715&lt;br /&gt;
|-&lt;br /&gt;
|16||Day2||A||6.613928&lt;br /&gt;
|-&lt;br /&gt;
|17||Day2||A||6.829968&lt;br /&gt;
|-&lt;br /&gt;
|18||Day2||A||7.387583&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the linear model Obs ~ Treatment + ε, we can invoke the linear modeling function&lt;br /&gt;
lm()&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; . The &amp;quot;ε&amp;quot; term is implicit in all models so it need not be specified.&lt;br /&gt;
&lt;br /&gt;
 lm.1 &amp;lt;- lm(Obs ~ Treatment, mydata1)&lt;br /&gt;
&lt;br /&gt;
The assignment operator &amp;quot;&amp;lt;-&amp;quot; stores the linear model result in object lm.1. For these data (the data object is &amp;quot;mydata1&amp;quot;), this model expresses Obs as a function of Treatment. To inspect the result of the linear model use the &amp;quot;summarize&amp;quot; function summary():&lt;br /&gt;
&lt;br /&gt;
 AIC(lm.1); BIC(lm.1)&lt;br /&gt;
 summary(lm.1)&lt;br /&gt;
&lt;br /&gt;
The result is:&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Obs ~ Treatment, data = mydata1)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 1        2        3        4        5        6&lt;br /&gt;
 -0.10342  0.44100 -0.37540  0.03782 -0.27881  0.27881 &lt;br /&gt;
 &lt;br /&gt;
 Coefficients:&lt;br /&gt;
         Estimate Std. Error t value Pr(&amp;gt;|t|)    &lt;br /&gt;
 (Intercept)   7.1088     0.2507  28.350 9.21e-06 ***&lt;br /&gt;
 TreatmentB   -0.5327     0.3071  -1.734    0.158    &lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 0.3546 on 4 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.4293,	Adjusted R-squared:  0.2866&lt;br /&gt;
 F-statistic: 3.008 on 1 and 4 DF,  p-value: 0.1579&lt;br /&gt;
&lt;br /&gt;
The report shows:&lt;br /&gt;
*The model analytical formula specified by the lm() call. &lt;br /&gt;
*The residuals (errors, discrepancies between observed and model-predicted outcomes). &lt;br /&gt;
*The coefficients of the fixed effects (predictors, explanatory variables). &lt;br /&gt;
*And finally, the overall model quality (describing the ability of the model to describe the linear relations in these data).  &amp;quot;Multiple R-squared&amp;quot; refers to the R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; statistic that measures the &amp;quot;variance explained by the model&amp;quot; or &amp;quot;variance accounted for by the model&amp;quot;. 0≤R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;≤1, in our result, R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; = 0.4293, which is good, but not great. In essence, 42.93% of the data variability may be explained by this specific (best linear fit) model. In this case, the model solely relies on &amp;quot;Treatment&amp;quot; (fixed effect) to explain Obs (outcome). So, the R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; reflects how much of the Obs variance is accounted for by different Treatments (A or B).&lt;br /&gt;
&lt;br /&gt;
Models with high R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; values are preferred, subject to 2 conditions:&lt;br /&gt;
*What is considered a high R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; value is relative and depends on study/application.&lt;br /&gt;
*When the study phenomenon is highly deterministic, R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; values can approach 1. &lt;br /&gt;
&lt;br /&gt;
Higher number of explanatory variable and higher model-complexity tend to yield higher R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; values, but are more difficult to interpret.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Adjusted R-squared&amp;quot; value is a modified R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; value that normalizes the total variance &amp;quot;explained&amp;quot; by the model by the number of fixed effects included in the model. Larger number predictors will lower the &amp;quot;Adjusted R-squared&amp;quot;. The adjusted R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;adj = 0.2866, but in general, R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;adj  can be much lower when the model includes many fixed effects.&lt;br /&gt;
&lt;br /&gt;
The statistical test of &amp;quot;model significance&amp;quot; is quantified by the output &amp;quot;F-statistic: 3.008 on 1 and 4 DF,  p-value: 0.1579&amp;quot;. Under a null hypothesis where the model captures little or no information about the process, the probability value quantifies the data-driven evidence to reject the null and accept an alternative stating that this model does capture useful patterns in the data. Specifically, the p-value represents the conditional probability under the condition that the null hypothesis is true. In this case, &lt;br /&gt;
&lt;br /&gt;
*The null hypothesis is Ho: &amp;quot;Treatment has no effect on Obs&amp;quot;.&lt;br /&gt;
*Alternative research Hypothesis is H1: &amp;quot;Treatment has effect on Obs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This p-value is 0.1579, and the linear model fails to reject the null hypothesis. This leaves open the possibility that Treatment may have no effect on Obs (just based on using these 6 data points). &amp;lt;BR&amp;gt;&lt;br /&gt;
However, if the p-value was much smaller, and assuming Ho were true, then this data would be less likely to be observed in reality (hence we would interpret small p-values as showing that the alternative hypothesis &amp;quot;Treatment affects Obs&amp;quot; as more likely and the model result is &amp;quot;statistically significant&amp;quot;). &amp;lt;BR&amp;gt;&lt;br /&gt;
There is a distinction between the overall &amp;quot;model-significance&amp;quot; (as quantified by the p-value at the very bottom of the output, which considers all effects together) and the p-value of individual effects (coefficients table including significance for each predictor). &lt;br /&gt;
The model F-statistic and the degrees of freedom are in 1-1 correspondence with the p-value – the latter is computed as the right tail probability for an F(df1,df2) distribution corresponding to the F-statistics (critical value). To report the overall model inference in this case, we can state:&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;I&amp;gt;&amp;quot;Using a simple linear model of Obs as a function of Treatment, the model was not significant (F(1,4)=3.001, p&amp;gt;0.15), which indicates that &amp;quot;Treatment&amp;quot; may not be a critical explanatory factor describing the &amp;quot;Obs&amp;quot; outcome.&amp;quot;&amp;lt;/I&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To examine the coefficient table for (lm.1 model). &amp;lt;BR&amp;gt;&lt;br /&gt;
Coefficients:&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;Estimate Std. Error t value Pr(&amp;gt;|t|)&amp;lt;br&amp;gt;&lt;br /&gt;
(Intercept)   7.1088     0.2507  28.350 9.21e-06 ***&amp;lt;BR&amp;gt;&lt;br /&gt;
TreatmentB   -0.5327     0.3071  -1.734    0.158&lt;br /&gt;
&lt;br /&gt;
The overall model p-value (0.1579) is similar to the p-value quantifying the significance of the &amp;quot;Treatment&amp;quot; factor to explain Obs. This is because the model had only one fixed effect (&amp;quot;Treatment&amp;quot; itself). So, the significance of the overall model is the same as the significance for this coefficient (subject to rounding error). &lt;br /&gt;
&lt;br /&gt;
In the presence of multiple fixed effects, the overall model significance will be different from the significance of each coefficient corresponding to a specific covariate.&lt;br /&gt;
&lt;br /&gt;
Why does the report show &amp;quot;TreatmentB&amp;quot; not &amp;quot;Treatment&amp;quot;? The estimate of the &amp;quot;(Intercept)&amp;quot; is &amp;lt;u&amp;gt;7.1088.&amp;lt;/u&amp;gt; Let’s look at the mean Obs values within each of the 2 Treatment groups (A and B):&lt;br /&gt;
&lt;br /&gt;
 # Model: lm.1 &amp;lt;- lm(Obs ~ Treatment, mydata1)&lt;br /&gt;
 mean(mydata1[mydata1$\$$Treatment==&amp;quot;A&amp;quot;,]$\$$Obs)&lt;br /&gt;
 &amp;gt; 7.108776&amp;lt;BR&amp;gt;&lt;br /&gt;
 mean(mydata1[mydata1$\$$Treatment==&amp;quot;B&amp;quot;,]$\$$Obs)&lt;br /&gt;
 &amp;gt; 6.57611&lt;br /&gt;
 # in general, subsetting&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; can be accomplished by:&lt;br /&gt;
 subset_data &amp;lt;- mydata1[ which(mydata1$\$$Treatment=='A' &amp;amp; &lt;br /&gt;
 mydata1$\$$Day=='Day2'),]&lt;br /&gt;
&lt;br /&gt;
The mean of the Obs values for {Treatment=A} is the same as the &amp;quot;Intercept&amp;quot; term.&lt;br /&gt;
&lt;br /&gt;
The estimate for &amp;quot;TreatmentB&amp;quot; is negative (-0.5327). Note that:&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;U&amp;gt;7.108776&amp;lt;/U&amp;gt; - 0.5327 = 6.57611,&lt;br /&gt;
&lt;br /&gt;
which is the mean of the &amp;quot;TreatmentB&amp;quot; cohort. Thus, &amp;lt;BR&amp;gt;&lt;br /&gt;
the estimate for &amp;quot;(Intercept)&amp;quot; represents for the &amp;quot;TreatmentA&amp;quot; category, and &amp;lt;BR&amp;gt;&lt;br /&gt;
the estimate for &amp;quot;TreatmentB&amp;quot; represents the difference between the &amp;quot;Treatment&amp;quot; &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; categories.&lt;br /&gt;
&lt;br /&gt;
Analytically, the linear models represent &amp;quot;linear&amp;quot; associations, as in the plot below:&lt;br /&gt;
&lt;br /&gt;
 mydata2 &amp;lt;- data.frame(&lt;br /&gt;
     Subject  = c(13, 14, 15, 16, 17, 18), &lt;br /&gt;
     Day       = c(&amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;), &lt;br /&gt;
     Treatment = c(2, 2, 2, 2, 1, 1), &lt;br /&gt;
     Obs       = c(6.472687, 7.017110, 6.200715, 6.613928, 6.829968, 7.387583)&lt;br /&gt;
 )&lt;br /&gt;
 plot(mydata2$\$$Treatment, mydata2$\$$Obs, main=&amp;quot;Scatterplot Treatment vs. Obs&amp;quot;, &lt;br /&gt;
   xlab=&amp;quot;Treatment&amp;quot;, ylab=&amp;quot;Obs &amp;quot;, pch=19) &lt;br /&gt;
 # Add fit lines&lt;br /&gt;
 abline(lm(mydata2$\$$Obs~mydata2$\$$Treatment), col=&amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig14.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The linear model represents the difference between Treatments &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; as a slope. Going From Treatment &amp;quot;A&amp;quot; to &amp;quot;B&amp;quot; we go down -0.5327 (in terms of the units measuring the &amp;quot;Obs&amp;quot; variable), which is exactly the &amp;quot;TreatmentB&amp;quot; coefficient, relative to Treatment &amp;quot;A&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
Treatment &amp;quot;A&amp;quot; acts as baseline (center of the local coordinate system) and is represented by the &amp;quot;(Intercept)&amp;quot;. The difference between Treatments &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; is expressed as a slope heading down from &amp;lt;u&amp;gt;7.108776&amp;lt;/u&amp;gt; by &amp;lt;u&amp;gt;0.5327&amp;lt;/u&amp;gt;. The p-values in the coefficient table correspond to the significance that each coefficient (intercept or Treatment) is &amp;quot;non-trivial&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
In our case, the Intercept is significant (10-5), but the Treatment change (from A to B) is not (0.15). By default, the lm() function takes lexicographical ordering to determine which level (A or B) of the predictor (Treatment) comes first to label Treatment &amp;quot;A&amp;quot; as the intercept and &amp;quot;B&amp;quot; as the slope. Categorical differences like Treatment &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; can be expressed as slopes because &amp;lt;u&amp;gt;difference&amp;lt;/u&amp;gt; between two categories is directly correlated with the &amp;lt;u&amp;gt;slope&amp;lt;/u&amp;gt; between the two categories. &lt;br /&gt;
&lt;br /&gt;
The advantage of representing difference between two categories as lines crossing the two categories is that it allows us to use the same computational principles for numeric and categorical variables. That is the same interpretations can be made for Treatment as for continuous (e.g., age) or discrete (e.g., dosage) covariates. &lt;br /&gt;
&lt;br /&gt;
For example, using the MBL Data, we can examine player’s Weight as a function of Age. Save the data table as a text file &amp;quot;01a_data.txt&amp;quot; and load it in RStudio:&lt;br /&gt;
&lt;br /&gt;
 # data &amp;lt;- read.table('C:\\Users\\Dinov\\Desktop\\01a_data.txt',as.is=T, header=T)&lt;br /&gt;
 # Data: https://umich.instructure.com/courses/38100/files/folder/data &lt;br /&gt;
 data &amp;lt;- read.table('https://umich.instructure.com/courses/38100/files/folder/data/01a_data.txt',as.is=T, header=T)	&lt;br /&gt;
 attach(data)&lt;br /&gt;
&lt;br /&gt;
 # Weight = Age + e&lt;br /&gt;
 df.2 = data.frame(Age, Weight) &lt;br /&gt;
 lm.2 = lm(Weight ~ Age, df.2) &lt;br /&gt;
 summary(lm.2)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Weight ~ Age, data = df.2)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max  &lt;br /&gt;
 -52.479 -14.489  -0.814  13.400  89.915 &lt;br /&gt;
 &lt;br /&gt;
 Coefficients:&lt;br /&gt;
 Estimate Std. Error t value Pr(&amp;gt;|t|)&lt;br /&gt;
 (Intercept) 179.6684     4.3418  41.381  &amp;lt; 2e-16 ***&lt;br /&gt;
 Age           0.7672     0.1494   5.135 &amp;lt;MARK&amp;gt;3.37e-07&amp;lt;/MARK&amp;gt; ***&lt;br /&gt;
 ---&amp;lt;BR&amp;gt;&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 20.75 on 1032 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  &amp;lt;MARK&amp;gt;0.02492&amp;lt;/MARK&amp;gt;,	Adjusted R-squared:  0.02397 &lt;br /&gt;
 F-statistic: 26.37 on 1 and 1032 DF,  p-value: &amp;lt;MARK&amp;gt;3.368e-07&amp;lt;/MARK&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The significance of the intercept is not very interesting, as it just specifies the baseline.  However, the p-value in each (predictor) row evaluates whether the corresponding coefficient is significantly non-trivial. Trivial coefficients can be removed from the model. The intercept (179.6684) represents the predicted Weight for a player at Age 0, which doesn’t make sense for Baseball players, but it captures the constant impact of Age on Weight.&lt;br /&gt;
&lt;br /&gt;
The interesting part is the coefficient of ''Age'' (0.7672), which is a significant ''predictor'' of Weight ($3.368\times 10^{-7}$). Thus, for every increase of age by 1 year, The Weight is expected to go up by 0.7 to 0.8 lbs.&lt;br /&gt;
&lt;br /&gt;
The regression line in the scatterplot represents the model-predicted mean Weight-gain with Age. The y-intercept (179.6684), for Age=0, and slope (0.7672) of the line represents the corresponding (Intercept and Age) coefficients of the model output.&lt;br /&gt;
&lt;br /&gt;
 plot(Age, Weight, main=&amp;quot;Scatterplot Age vs. Weight&amp;quot;, xlab=&amp;quot;Age&amp;quot;, ylab=&amp;quot;Weight&amp;quot;, pch=19) &lt;br /&gt;
 abline(lm(Weight ~ Age), col=&amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;CENTER&amp;gt;[[Image:SMHS_LinearModeling_Fig15.png|500px]]&amp;lt;/CENTER&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interpreting Model Intercepts'''&amp;lt;BR&amp;gt;&lt;br /&gt;
The model estimates of the intercept may not always be useful. For instance, if we subtract the mean Age from each player's Age:&lt;br /&gt;
&lt;br /&gt;
 df.2$\$$Age.centered = df.2$\$$Age - mean(df.2$\$$Age) &lt;br /&gt;
 lm.2a = lm(Weight ~ Age.centered, df.2) &lt;br /&gt;
 summary(lm.2a)&lt;br /&gt;
&lt;br /&gt;
This creates a new column in the data.frame (df.2) called ''Age.centered'' representing the Age variable with the mean subtracted from it. This is the resulting coefficient table from running a linear model analysis of this ''centered'' data:&lt;br /&gt;
&lt;br /&gt;
Coefficients:&amp;lt;BR&amp;gt;&lt;br /&gt;
Estimate Std. Error t value Pr(&amp;gt;|t|) &amp;lt;BR&amp;gt;   &lt;br /&gt;
(Intercept)  201.7166     0.6452 312.648  &amp;lt; 2e-16 ***&amp;lt;BR&amp;gt;&lt;br /&gt;
Age.centered   0.7672     0.1494   5.135 3.37e-07 ***&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Residual standard error: 20.75 on 1032 degrees of freedom&amp;lt;BR&amp;gt;&lt;br /&gt;
Multiple R-squared:  0.02492,	Adjusted R-squared:  0.02397&amp;lt;BR&amp;gt; &lt;br /&gt;
F-statistic: 26.37 on 1 and 1032 DF,  p-value: 3.368e-07&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The intercept estimate has changed from 179.6684 (predicted Player Weight at birth, Age=0) to 201.7166   (predicted player Weight at mean Age). However, the slope and its significance (0.7672, 3.37x10&amp;lt;SUP&amp;gt;-07&amp;lt;/SUP&amp;gt;) are unchanged and neither is the significance of the full model&lt;br /&gt;
(3.368x10&amp;lt;SUP&amp;gt;-07&amp;lt;/SUP&amp;gt;). So, centering the Age does not impact the nature of the linear model, it just changed the intercept that now points to the Weight at the mean Age.&lt;br /&gt;
&lt;br /&gt;
As we have additional information for each MLB player, e.g., ''Team'', ''Position'', ''Height'', ''Weight'', ''Age'') we can include additional factors into the linear model (lm.2a) to increase its explanatory power (R2 = 0.02492). We can start by adding:&lt;br /&gt;
&lt;br /&gt;
 Weight ~ Age + Height + e.&lt;br /&gt;
 lm.3 = lm(Weight ~ Age.centered + Height, df.2)&lt;br /&gt;
 summary(lm.3)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Weight ~ Age.centered + Height, data = df.2)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -50.818 -12.148  -0.344  10.720  74.175 &lt;br /&gt;
 &lt;br /&gt;
 Coefficients:&lt;br /&gt;
           Estimate Std. Error t value Pr(&amp;gt;|t|)    &lt;br /&gt;
 (Intercept)  -164.0141    17.2897  -9.486  &amp;lt; 2e-16 ***&lt;br /&gt;
 Age.centered    0.9624     0.1252   7.690 3.43e-14 ***&lt;br /&gt;
 Height          4.9626     0.2345  21.163  &amp;lt; 2e-16 ***&lt;br /&gt;
 ---&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 17.33 on 1031 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  &amp;lt;MARK&amp;gt;0.3202&amp;lt;/MARK&amp;gt;,	Adjusted R-squared:  0.3189&lt;br /&gt;
 F-statistic: 242.8 on 2 and 1031 DF,  p-value: &amp;lt; 2.2e-16&lt;br /&gt;
&lt;br /&gt;
And them adding additional factors: &lt;br /&gt;
&lt;br /&gt;
 Weight ~ Age + Height + Position + Team + e.&lt;br /&gt;
 lm.4 = lm(Weight ~ Age.centered + Height+ Position + Team, df.2) &lt;br /&gt;
 summary(lm.4)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Weight ~ Age.centered + Height + Position + Team, &lt;br /&gt;
 data = df.2)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -48.692 -10.909  -0.778   9.858  73.649 &lt;br /&gt;
  &lt;br /&gt;
 Coefficients:&lt;br /&gt;
 Estimate Std. Error t value Pr(&amp;gt;|t|)   &lt;br /&gt;
 (Intercept)               -139.4055    18.8556  -7.393 3.04e-13 ***&lt;br /&gt;
 Age.centered                 0.8906     0.1259   7.075 2.82e-12 ***&lt;br /&gt;
 Height                       4.7175     0.2563  18.405  &amp;lt; 2e-16 ***&lt;br /&gt;
 PositionDesignated_Hitter    8.9037     4.4533   1.999 0.045842 *  &lt;br /&gt;
 PositionFirst_Baseman        2.4237     3.0058   0.806 0.420236    &lt;br /&gt;
 PositionOutfielder          -6.2636     2.2784  -2.749 0.006084 ** &lt;br /&gt;
 PositionRelief_Pitcher      -7.7695     2.1959  -3.538 0.000421 ***&lt;br /&gt;
 PositionSecond_Baseman     -13.0843     2.9638  -4.415 1.12e-05 ***&lt;br /&gt;
 PositionShortstop          -16.9562     3.0406  -5.577 3.16e-08 ***&lt;br /&gt;
 PositionStarting_Pitcher    -7.3599     2.2976  -3.203 0.001402 ** &lt;br /&gt;
 PositionThird_Baseman       -4.6035     3.1689  -1.453 0.146613    &lt;br /&gt;
 TeamARZ                      7.1881     4.2590   1.688 0.091777  &lt;br /&gt;
 TeamATL                     -1.5631     3.9757  -0.393 0.694278    &lt;br /&gt;
 TeamBAL                     -5.3128     4.0193  -1.322 0.186533    &lt;br /&gt;
 TeamBOS                     -0.2838     4.0034  -0.071 0.943492    &lt;br /&gt;
 TeamCHC                      0.4026     3.9949   0.101 0.919749    &lt;br /&gt;
 TeamCIN                      2.1051     3.9934   0.527 0.598211    &lt;br /&gt;
 TeamCLE                     -1.3160     4.0356  -0.326 0.744423    &lt;br /&gt;
 TeamCOL                     -3.7836     4.0287  -0.939 0.347881    &lt;br /&gt;
 TeamCWS                      4.2944     4.1022   1.047 0.295413    &lt;br /&gt;
 TeamDET                      2.3024     3.9725   0.580 0.562326    &lt;br /&gt;
 TeamFLA                      2.6985     4.1336   0.653 0.514028    &lt;br /&gt;
 TeamHOU                     -0.6808     4.0634  -0.168 0.866976    &lt;br /&gt;
 TeamKC                      -4.7664     4.0242  -1.184 0.236525    &lt;br /&gt;
 TeamLA                       2.8598     4.0817   0.701 0.483686    &lt;br /&gt;
 TeamMIN                      2.1269     4.0947   0.519 0.603579    &lt;br /&gt;
 TeamMLW                      4.2897     4.0243   1.066 0.286706    &lt;br /&gt;
 TeamNYM                     -1.9736     3.9493  -0.500 0.617370    &lt;br /&gt;
 TeamNYY                      1.7483     4.1234   0.424 0.671655    &lt;br /&gt;
 TeamOAK                     -0.5464     3.9672  -0.138 0.890474    &lt;br /&gt;
 TeamPHI                     -6.8486     3.9949  -1.714 0.086778  &lt;br /&gt;
 TeamPIT                      4.3023     4.0210   1.070 0.284890    &lt;br /&gt;
 TeamSD                       2.6133     4.0915   0.639 0.523148    &lt;br /&gt;
 TeamSEA                     -0.9147     4.0516  -0.226 0.821436    &lt;br /&gt;
 TeamSF                       0.8411     4.0520   0.208 0.835593    &lt;br /&gt;
 TeamSTL                     -1.1341     4.1193  -0.275 0.783132    &lt;br /&gt;
 TeamTB                      -2.6616     4.0944  -0.650 0.515798    &lt;br /&gt;
 TeamTEX                     -0.7695     4.0283  -0.191 0.848556    &lt;br /&gt;
 TeamTOR                      1.3943     4.0681   0.343 0.731871    &lt;br /&gt;
 TeamWAS                     -1.7555     4.0038  -0.438 0.661142    &lt;br /&gt;
 ---&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 16.78 on 994 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.3858,	Adjusted R-squared:  0.3617 &lt;br /&gt;
 F-statistic: 16.01 on 39 and 994 DF,  p-value: &amp;lt; 2.2e-16&lt;br /&gt;
&lt;br /&gt;
Notice the linear model coefficients, the corresponding p-values, and the overall model quality, at the bottom of the output change. Are these changed between the 2 models? &lt;br /&gt;
*new model (Weight ~ Age + Height + Position + Team + e.) vs. &lt;br /&gt;
*old model   (Weight ~ Age + Height + e)? &lt;br /&gt;
&lt;br /&gt;
These examples illustrate &amp;quot;multiple linear regression&amp;quot; as a linear modeling technique involving 1 response (dependent) variable expressed as a (affine) function of multiple predictor (independent) variables.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;http://www.statmethods.net/input/datatypes.html &amp;lt;br&amp;gt;  &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;http://www.statmethods.net/advstats/glm.html &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;http://www.statmethods.net/management/subset.html  &lt;br /&gt;
&lt;br /&gt;
===See next===&lt;br /&gt;
* [[SMHS_LinearModeling_MLR_VizModelCoeff|Visualizing the Regression-Model coefficients (effect-sizes) section]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR&amp;diff=16140</id>
		<title>SMHS LinearModeling MLR</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR&amp;diff=16140"/>
		<updated>2016-05-23T12:52:49Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling|SMHS Linear Modeling]] - Multiple Linear Regression ==&lt;br /&gt;
&lt;br /&gt;
In this section, we expand our [[SMHS#Chapter_III:_Linear_Modeling |previous discussion of linear modeling]], review, and demonstrate computing and visualizing the regression-model coefficients (effect-sizes), (fixed-effect) linear model assumptions, examination of residual plots, and independence.&lt;br /&gt;
&lt;br /&gt;
'''Questions''':&lt;br /&gt;
*Are there (linear) associations between predictors and a response variable(s)?&lt;br /&gt;
*When to look for linear relations and what assumptions play role?&lt;br /&gt;
&lt;br /&gt;
Let’s use some of the data included in the Appendix. Snapshots of the first few rows in the data are shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Genotype||Race||Subject||Weight||Index||Subject||Day||Treatment||Obs&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||1||8||&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;||13||Day1 ||B||6.472687&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||2||9||&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;||14||Day1 ||B||7.01711&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||3||11||&amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;||15||Day1 ||B||6.2007154&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||4||12||&amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;||16||Day1 ||B||6.6139285&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||1||5||10||&amp;lt;b&amp;gt;5&amp;lt;/b&amp;gt;||17||Day1 ||A||6.8299686&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;A&amp;lt;/b&amp;gt;||2||1||17||&amp;lt;b&amp;gt;6&amp;lt;/b&amp;gt;||18||Day1 ||A||7.387583&lt;br /&gt;
|-&lt;br /&gt;
|...||||||||...||||||||&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Eyeballing the data may suggest that Race &amp;quot;2&amp;quot; subjects may have higher &amp;quot;Weights&amp;quot; (first dataset), or &amp;quot;Treatment A&amp;quot; yields higher &amp;quot;Observations&amp;quot; (second dataset). However, this cursory observation may be incorrect, as we may be looking at a small/exceptional sub-sample of the entire population. Data-driven linear modeling allows us to quantify such patterns and compute probability values expressing the strength of the evidence in the data to make such conclusions. In a nutshell, we express relationships of interest (e.g., weight as a function of race, or Observation as a function of treatment) using a linear function as an analytical representation of these inter-variable relations:&lt;br /&gt;
&lt;br /&gt;
Weight ~ Race, Weight ~ Genotype, Obs ~ Treatment, Obs ~ Day, etc.&amp;lt;BR&amp;gt;&lt;br /&gt;
W = a +b*R,&lt;br /&gt;
&lt;br /&gt;
This &amp;quot;~&amp;quot; (tilde) notation implies &amp;quot;Weight predicted by Race&amp;quot; or &amp;quot;Observation as a linear function of Treatment&amp;quot;. The &amp;quot;dependent variable&amp;quot; (a measurable response) on the left is predicted by the factor on the right acting as an &amp;quot;independent variable&amp;quot;, co-variate, predictor, &amp;quot;explanatory variable&amp;quot;, or &amp;quot;fixed effect&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Often times inter-dependencies may not be perfect, deterministic, or rigid (like in the case of predicting the Area of a disk knowing its radius, or predicting the 3D spatial location of a planet having a precise date and time). Weight may not be completely and uniquely determined by Race alone, as many different factors play role (genetics, environment, aging, etc.) Even if we can measure all factors we can identify as potentially influencing Weight, there will still be intrinsic random variability into the observed Weight measures, which can’t be control for. This intrinsic random variation may be captured and accounted for using &amp;quot;random&amp;quot; term at the end.&lt;br /&gt;
&lt;br /&gt;
Weight ~ Race + ε~ D(m=0, s).&lt;br /&gt;
&lt;br /&gt;
Epsilon &amp;quot;ε&amp;quot; represents the error term of predicting Weight by Gender alone and summarizes the aggregate impact of all factors aside from Race that impact individual’s Weight, which are experimentally uncontrollable or random. This formula is a schematic analytic representation of a linear model that we’re going to estimate, quantify, and use for prediction and inference. The right hand side splits the knowledge representation of Weight into 2 complementary components - a &amp;quot;fixed effect&amp;quot; for Race, which we understand and expect, and a &amp;quot;random effect&amp;quot; (&amp;quot;ε&amp;quot;) what we don’t know well. (W ~ R represents the &amp;quot;structural&amp;quot; or &amp;quot;systematic&amp;quot; part of the linear model and &amp;quot;ε&amp;quot; stands for the &amp;quot;random&amp;quot; or &amp;quot;probabilistic&amp;quot; part of the model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;R Experiment (See Appendix)&amp;lt;/B&amp;gt;&lt;br /&gt;
 mydata1 &amp;lt;- data.frame(&lt;br /&gt;
     Subject  = c(13, 14, 15, 16, 17, 18), &lt;br /&gt;
     Day       = c(&amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day2&amp;quot;, &amp;quot;Day2&amp;quot;, &amp;quot;Day2&amp;quot;), &lt;br /&gt;
     Treatment = c(&amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;), &lt;br /&gt;
     Obs       = c(6.472687, 7.017110, 6.200715, 6.613928, 6.829968, 7.387583)&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
We construct an R frame object&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; concatenating 3 data-elements for 6 subjects, and saving it into &amp;quot;mydata1.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|Subject||Day||Treatment||Obs&lt;br /&gt;
|-&lt;br /&gt;
|13||Day1||B||6.472687&lt;br /&gt;
|-&lt;br /&gt;
|14||Day1||B||7.017110&lt;br /&gt;
|-&lt;br /&gt;
|15||Day1||B||6.200715&lt;br /&gt;
|-&lt;br /&gt;
|16||Day2||A||6.613928&lt;br /&gt;
|-&lt;br /&gt;
|17||Day2||A||6.829968&lt;br /&gt;
|-&lt;br /&gt;
|18||Day2||A||7.387583&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the linear model Obs ~ Treatment + ε, we can invoke the linear modeling function&lt;br /&gt;
lm()&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; . The &amp;quot;ε&amp;quot; term is implicit in all models so it need not be specified.&lt;br /&gt;
&lt;br /&gt;
 lm.1 &amp;lt;- lm(Obs ~ Treatment, mydata1)&lt;br /&gt;
&lt;br /&gt;
The assignment operator &amp;quot;&amp;lt;-&amp;quot; stores the linear model result in object lm.1. For these data (the data object is &amp;quot;mydata1&amp;quot;), this model expresses Obs as a function of Treatment. To inspect the result of the linear model use the &amp;quot;summarize&amp;quot; function summary():&lt;br /&gt;
&lt;br /&gt;
 AIC(lm.1); BIC(lm.1)&lt;br /&gt;
 summary(lm.1)&lt;br /&gt;
&lt;br /&gt;
The result is:&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Obs ~ Treatment, data = mydata1)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 1        2        3        4        5        6&lt;br /&gt;
 -0.10342  0.44100 -0.37540  0.03782 -0.27881  0.27881 &lt;br /&gt;
 &lt;br /&gt;
 Coefficients:&lt;br /&gt;
         Estimate Std. Error t value Pr(&amp;gt;|t|)    &lt;br /&gt;
 (Intercept)   7.1088     0.2507  28.350 9.21e-06 ***&lt;br /&gt;
 TreatmentB   -0.5327     0.3071  -1.734    0.158    &lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 0.3546 on 4 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.4293,	Adjusted R-squared:  0.2866&lt;br /&gt;
 F-statistic: 3.008 on 1 and 4 DF,  p-value: 0.1579&lt;br /&gt;
&lt;br /&gt;
The report shows:&lt;br /&gt;
&amp;lt;li&amp;gt;The model analytical formula specified by the lm() call. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The residuals (errors, discrepancies between observed and model-predicted outcomes). &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The coefficients of the fixed effects (predictors, explanatory variables). &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;And finally, the overall model quality (describing the ability of the model to describe the linear relations in these data).  &amp;quot;Multiple R-squared&amp;quot; refers to the R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; statistic that measures the &amp;quot;variance explained by the model&amp;quot; or &amp;quot;variance accounted for by the model&amp;quot;. 0≤R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;≤1, in our result, R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; = 0.4293, which is good, but not great. In essence, 42.93% of the data variability may be explained by this specific (best linear fit) model. In this case, the model solely relies on &amp;quot;Treatment&amp;quot; (fixed effect) to explain Obs (outcome). So, the R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; reflects how much of the Obs variance is accounted for by different Treatments (A or B).&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Models with high R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; values are preferred, subject to 2 conditions:&lt;br /&gt;
&amp;lt;li&amp;gt;What is considered a high R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; value is relative and depends on study/application.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When the study phenomenon is highly deterministic, R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; values can approach 1. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Higher number of explanatory variable and higher model-complexity tend to yield higher R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; values, but are more difficult to interpret.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Adjusted R-squared&amp;quot; value is a modified R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; value that normalizes the total variance &amp;quot;explained&amp;quot; by the model by the number of fixed effects included in the model. Larger number predictors will lower the &amp;quot;Adjusted R-squared&amp;quot;. The adjusted R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;adj = 0.2866, but in general, R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;adj  can be much lower when the model includes many fixed effects.&lt;br /&gt;
&lt;br /&gt;
The statistical test of &amp;quot;model significance&amp;quot; is quantified by the output &amp;quot;F-statistic: 3.008 on 1 and 4 DF,  p-value: 0.1579&amp;quot;. Under a null hypothesis where the model captures little or no information about the process, the probability value quantifies the data-driven evidence to reject the null and accept an alternative stating that this model does capture useful patterns in the data. Specifically, the p-value represents the conditional probability under the condition that the null hypothesis is true. In this case, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The null hypothesis is Ho: &amp;quot;Treatment has no effect on Obs&amp;quot;. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Alternative research Hypothesis is H1: &amp;quot;Treatment has effect on Obs&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This p-value is 0.1579, and the linear model fails to reject the null hypothesis. This leaves open the possibility that Treatment may have no effect on Obs (just based on using these 6 data points). &amp;lt;BR&amp;gt;&lt;br /&gt;
However, if the p-value was much smaller, and assuming Ho were true, then this data would be less likely to be observed in reality (hence we would interpret small p-values as showing that the alternative hypothesis &amp;quot;Treatment affects Obs&amp;quot; as more likely and the model result is &amp;quot;statistically significant&amp;quot;). &amp;lt;BR&amp;gt;&lt;br /&gt;
There is a distinction between the overall &amp;quot;model-significance&amp;quot; (as quantified by the p-value at the very bottom of the output, which considers all effects together) and the p-value of individual effects (coefficients table including significance for each predictor). &lt;br /&gt;
The model F-statistic and the degrees of freedom are in 1-1 correspondence with the p-value – the latter is computed as the right tail probability for an F(df1,df2) distribution corresponding to the F-statistics (critical value). To report the overall model inference in this case, we can state:&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;I&amp;gt;&amp;quot;Using a simple linear model of Obs as a function of Treatment, the model was not significant (F(1,4)=3.001, p&amp;gt;0.15), which indicates that &amp;quot;Treatment&amp;quot; may not be a critical explanatory factor describing the &amp;quot;Obs&amp;quot; outcome.&amp;quot;&amp;lt;/I&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To examine the coefficient table for (lm.1 model). &amp;lt;BR&amp;gt;&lt;br /&gt;
Coefficients:&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;Estimate Std. Error t value Pr(&amp;gt;|t|)&amp;lt;br&amp;gt;&lt;br /&gt;
(Intercept)   7.1088     0.2507  28.350 9.21e-06 ***&amp;lt;BR&amp;gt;&lt;br /&gt;
TreatmentB   -0.5327     0.3071  -1.734    0.158&lt;br /&gt;
&lt;br /&gt;
The overall model p-value (0.1579) is similar to the p-value quantifying the significance of the &amp;quot;Treatment&amp;quot; factor to explain Obs. This is because the model had only one fixed effect (&amp;quot;Treatment&amp;quot; itself). So, the significance of the overall model is the same as the significance for this coefficient (subject to rounding error). &lt;br /&gt;
&lt;br /&gt;
In the presence of multiple fixed effects, the overall model significance will be different from the significance of each coefficient corresponding to a specific covariate.&lt;br /&gt;
&lt;br /&gt;
Why does the report show &amp;quot;TreatmentB&amp;quot; not &amp;quot;Treatment&amp;quot;? The estimate of the &amp;quot;(Intercept)&amp;quot; is &amp;lt;u&amp;gt;7.1088.&amp;lt;/u&amp;gt; Let’s look at the mean Obs values within each of the 2 Treatment groups (A and B):&lt;br /&gt;
&lt;br /&gt;
 # Model: lm.1 &amp;lt;- lm(Obs ~ Treatment, mydata1)&lt;br /&gt;
 mean(mydata1[mydata1$\$$Treatment==&amp;quot;A&amp;quot;,]$\$$Obs)&lt;br /&gt;
 &amp;gt; 7.108776&amp;lt;BR&amp;gt;&lt;br /&gt;
 mean(mydata1[mydata1$\$$Treatment==&amp;quot;B&amp;quot;,]$\$$Obs)&lt;br /&gt;
 &amp;gt; 6.57611&lt;br /&gt;
 # in general, subsetting&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; can be accomplished by:&lt;br /&gt;
 subset_data &amp;lt;- mydata1[ which(mydata1$\$$Treatment=='A' &amp;amp; &lt;br /&gt;
 mydata1$\$$Day=='Day2'),]&lt;br /&gt;
&lt;br /&gt;
The mean of the Obs values for {Treatment=A} is the same as the &amp;quot;Intercept&amp;quot; term.&lt;br /&gt;
&lt;br /&gt;
The estimate for &amp;quot;TreatmentB&amp;quot; is negative (-0.5327). Note that:&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;U&amp;gt;7.108776&amp;lt;/U&amp;gt; - 0.5327 = 6.57611,&lt;br /&gt;
&lt;br /&gt;
which is the mean of the &amp;quot;TreatmentB&amp;quot; cohort. Thus, &amp;lt;BR&amp;gt;&lt;br /&gt;
the estimate for &amp;quot;(Intercept)&amp;quot; represents for the &amp;quot;TreatmentA&amp;quot; category, and &amp;lt;BR&amp;gt;&lt;br /&gt;
the estimate for &amp;quot;TreatmentB&amp;quot; represents the difference between the &amp;quot;Treatment&amp;quot; &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; categories.&lt;br /&gt;
&lt;br /&gt;
Analytically, the linear models represent &amp;quot;linear&amp;quot; associations, as in the plot below:&lt;br /&gt;
&lt;br /&gt;
 mydata2 &amp;lt;- data.frame(&lt;br /&gt;
     Subject  = c(13, 14, 15, 16, 17, 18), &lt;br /&gt;
     Day       = c(&amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;, &amp;quot;Day1&amp;quot;), &lt;br /&gt;
     Treatment = c(2, 2, 2, 2, 1, 1), &lt;br /&gt;
     Obs       = c(6.472687, 7.017110, 6.200715, 6.613928, 6.829968, 7.387583)&lt;br /&gt;
 )&lt;br /&gt;
 plot(mydata2$\$$Treatment, mydata2$\$$Obs, main=&amp;quot;Scatterplot Treatment vs. Obs&amp;quot;, &lt;br /&gt;
   xlab=&amp;quot;Treatment&amp;quot;, ylab=&amp;quot;Obs &amp;quot;, pch=19) &lt;br /&gt;
 # Add fit lines&lt;br /&gt;
 abline(lm(mydata2$\$$Obs~mydata2$\$$Treatment), col=&amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig14.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The linear model represents the difference between Treatments &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; as a slope. Going From Treatment &amp;quot;A&amp;quot; to &amp;quot;B&amp;quot; we go down -0.5327 (in terms of the units measuring the &amp;quot;Obs&amp;quot; variable), which is exactly the &amp;quot;TreatmentB&amp;quot; coefficient, relative to Treatment &amp;quot;A&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
Treatment &amp;quot;A&amp;quot; acts as baseline (center of the local coordinate system) and is represented by the &amp;quot;(Intercept)&amp;quot;. The difference between Treatments &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; is expressed as a slope heading down from &amp;lt;u&amp;gt;7.108776&amp;lt;/u&amp;gt; by &amp;lt;u&amp;gt;0.5327&amp;lt;/u&amp;gt;. The p-values in the coefficient table correspond to the significance that each coefficient (intercept or Treatment) is &amp;quot;non-trivial&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
In our case, the Intercept is significant (10-5), but the Treatment change (from A to B) is not (0.15). By default, the lm() function takes lexicographical ordering to determine which level (A or B) of the predictor (Treatment) comes first to label Treatment &amp;quot;A&amp;quot; as the intercept and &amp;quot;B&amp;quot; as the slope. Categorical differences like Treatment &amp;quot;A&amp;quot; and &amp;quot;B&amp;quot; can be expressed as slopes because &amp;lt;u&amp;gt;difference&amp;lt;/u&amp;gt; between two categories is directly correlated with the &amp;lt;u&amp;gt;slope&amp;lt;/u&amp;gt; between the two categories. &lt;br /&gt;
&lt;br /&gt;
The advantage of representing difference between two categories as lines crossing the two categories is that it allows us to use the same computational principles for numeric and categorical variables. That is the same interpretations can be made for Treatment as for continuous (e.g., age) or discrete (e.g., dosage) covariates. &lt;br /&gt;
&lt;br /&gt;
For example, using the MBL Data, we can examine player’s Weight as a function of Age. Save the data table as a text file &amp;quot;01a_data.txt&amp;quot; and load it in RStudio:&lt;br /&gt;
&lt;br /&gt;
 # data &amp;lt;- read.table('C:\\Users\\Dinov\\Desktop\\01a_data.txt',as.is=T, header=T)&lt;br /&gt;
 # Data: https://umich.instructure.com/courses/38100/files/folder/data &lt;br /&gt;
 data &amp;lt;- read.table('https://umich.instructure.com/courses/38100/files/folder/data/01a_data.txt',as.is=T, header=T)	&lt;br /&gt;
 attach(data)&lt;br /&gt;
&lt;br /&gt;
 # Weight = Age + e&lt;br /&gt;
 df.2 = data.frame(Age, Weight) &lt;br /&gt;
 lm.2 = lm(Weight ~ Age, df.2) &lt;br /&gt;
 summary(lm.2)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Weight ~ Age, data = df.2)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max  &lt;br /&gt;
 -52.479 -14.489  -0.814  13.400  89.915 &lt;br /&gt;
 &lt;br /&gt;
 Coefficients:&lt;br /&gt;
 Estimate Std. Error t value Pr(&amp;gt;|t|)&lt;br /&gt;
 (Intercept) 179.6684     4.3418  41.381  &amp;lt; 2e-16 ***&lt;br /&gt;
 Age           0.7672     0.1494   5.135 &amp;lt;MARK&amp;gt;3.37e-07&amp;lt;/MARK&amp;gt; ***&lt;br /&gt;
 ---&amp;lt;BR&amp;gt;&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 20.75 on 1032 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  &amp;lt;MARK&amp;gt;0.02492&amp;lt;/MARK&amp;gt;,	Adjusted R-squared:  0.02397 &lt;br /&gt;
 F-statistic: 26.37 on 1 and 1032 DF,  p-value: &amp;lt;MARK&amp;gt;3.368e-07&amp;lt;/MARK&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The significance of the intercept is not very interesting, as it just specifies the baseline.  However, the p-value in each (predictor) row evaluates whether the corresponding coefficient is significantly non-trivial. Trivial coefficients can be removed from the model. The intercept (179.6684) represents the predicted Weight for a player at Age 0, which doesn’t make sense for Baseball players, but it captures the constant impact of Age on Weight.&lt;br /&gt;
&lt;br /&gt;
The interesting part is the coefficient of ''Age'' (0.7672), which is a significant ''predictor'' of Weight ($3.368\times 10^{-7}$). Thus, for every increase of age by 1 year, The Weight is expected to go up by 0.7 to 0.8 lbs.&lt;br /&gt;
&lt;br /&gt;
The regression line in the scatterplot represents the model-predicted mean Weight-gain with Age. The y-intercept (179.6684), for Age=0, and slope (0.7672) of the line represents the corresponding (Intercept and Age) coefficients of the model output.&lt;br /&gt;
&lt;br /&gt;
 plot(Age, Weight, main=&amp;quot;Scatterplot Age vs. Weight&amp;quot;, xlab=&amp;quot;Age&amp;quot;, ylab=&amp;quot;Weight&amp;quot;, pch=19) &lt;br /&gt;
 abline(lm(Weight ~ Age), col=&amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;CENTER&amp;gt;[[Image:SMHS_LinearModeling_Fig15.png|500px]]&amp;lt;/CENTER&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interpreting Model Intercepts'''&amp;lt;BR&amp;gt;&lt;br /&gt;
The model estimates of the intercept may not always be useful. For instance, if we subtract the mean Age from each player's Age:&lt;br /&gt;
&lt;br /&gt;
 df.2$\$$Age.centered = df.2$\$$Age - mean(df.2$\$$Age) &lt;br /&gt;
 lm.2a = lm(Weight ~ Age.centered, df.2) &lt;br /&gt;
 summary(lm.2a)&lt;br /&gt;
&lt;br /&gt;
This creates a new column in the data.frame (df.2) called ''Age.centered'' representing the Age variable with the mean subtracted from it. This is the resulting coefficient table from running a linear model analysis of this ''centered'' data:&lt;br /&gt;
&lt;br /&gt;
Coefficients:&amp;lt;BR&amp;gt;&lt;br /&gt;
Estimate Std. Error t value Pr(&amp;gt;|t|) &amp;lt;BR&amp;gt;   &lt;br /&gt;
(Intercept)  201.7166     0.6452 312.648  &amp;lt; 2e-16 ***&amp;lt;BR&amp;gt;&lt;br /&gt;
Age.centered   0.7672     0.1494   5.135 3.37e-07 ***&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Residual standard error: 20.75 on 1032 degrees of freedom&amp;lt;BR&amp;gt;&lt;br /&gt;
Multiple R-squared:  0.02492,	Adjusted R-squared:  0.02397&amp;lt;BR&amp;gt; &lt;br /&gt;
F-statistic: 26.37 on 1 and 1032 DF,  p-value: 3.368e-07&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The intercept estimate has changed from 179.6684 (predicted Player Weight at birth, Age=0) to 201.7166   (predicted player Weight at mean Age). However, the slope and its significance (0.7672, 3.37x10&amp;lt;SUP&amp;gt;-07&amp;lt;/SUP&amp;gt;) are unchanged and neither is the significance of the full model&lt;br /&gt;
(3.368x10&amp;lt;SUP&amp;gt;-07&amp;lt;/SUP&amp;gt;). So, centering the Age does not impact the nature of the linear model, it just changed the intercept that now points to the Weight at the mean Age.&lt;br /&gt;
&lt;br /&gt;
As we have additional information for each MLB player, e.g., ''Team'', ''Position'', ''Height'', ''Weight'', ''Age'') we can include additional factors into the linear model (lm.2a) to increase its explanatory power (R2 = 0.02492). We can start by adding:&lt;br /&gt;
&lt;br /&gt;
 Weight ~ Age + Height + e.&lt;br /&gt;
 lm.3 = lm(Weight ~ Age.centered + Height, df.2)&lt;br /&gt;
 summary(lm.3)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Weight ~ Age.centered + Height, data = df.2)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -50.818 -12.148  -0.344  10.720  74.175 &lt;br /&gt;
 &lt;br /&gt;
 Coefficients:&lt;br /&gt;
           Estimate Std. Error t value Pr(&amp;gt;|t|)    &lt;br /&gt;
 (Intercept)  -164.0141    17.2897  -9.486  &amp;lt; 2e-16 ***&lt;br /&gt;
 Age.centered    0.9624     0.1252   7.690 3.43e-14 ***&lt;br /&gt;
 Height          4.9626     0.2345  21.163  &amp;lt; 2e-16 ***&lt;br /&gt;
 ---&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 17.33 on 1031 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  &amp;lt;MARK&amp;gt;0.3202&amp;lt;/MARK&amp;gt;,	Adjusted R-squared:  0.3189&lt;br /&gt;
 F-statistic: 242.8 on 2 and 1031 DF,  p-value: &amp;lt; 2.2e-16&lt;br /&gt;
&lt;br /&gt;
And them adding additional factors: &lt;br /&gt;
&lt;br /&gt;
 Weight ~ Age + Height + Position + Team + e.&lt;br /&gt;
 lm.4 = lm(Weight ~ Age.centered + Height+ Position + Team, df.2) &lt;br /&gt;
 summary(lm.4)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = Weight ~ Age.centered + Height + Position + Team, &lt;br /&gt;
 data = df.2)&lt;br /&gt;
 &lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -48.692 -10.909  -0.778   9.858  73.649 &lt;br /&gt;
  &lt;br /&gt;
 Coefficients:&lt;br /&gt;
 Estimate Std. Error t value Pr(&amp;gt;|t|)   &lt;br /&gt;
 (Intercept)               -139.4055    18.8556  -7.393 3.04e-13 ***&lt;br /&gt;
 Age.centered                 0.8906     0.1259   7.075 2.82e-12 ***&lt;br /&gt;
 Height                       4.7175     0.2563  18.405  &amp;lt; 2e-16 ***&lt;br /&gt;
 PositionDesignated_Hitter    8.9037     4.4533   1.999 0.045842 *  &lt;br /&gt;
 PositionFirst_Baseman        2.4237     3.0058   0.806 0.420236    &lt;br /&gt;
 PositionOutfielder          -6.2636     2.2784  -2.749 0.006084 ** &lt;br /&gt;
 PositionRelief_Pitcher      -7.7695     2.1959  -3.538 0.000421 ***&lt;br /&gt;
 PositionSecond_Baseman     -13.0843     2.9638  -4.415 1.12e-05 ***&lt;br /&gt;
 PositionShortstop          -16.9562     3.0406  -5.577 3.16e-08 ***&lt;br /&gt;
 PositionStarting_Pitcher    -7.3599     2.2976  -3.203 0.001402 ** &lt;br /&gt;
 PositionThird_Baseman       -4.6035     3.1689  -1.453 0.146613    &lt;br /&gt;
 TeamARZ                      7.1881     4.2590   1.688 0.091777  &lt;br /&gt;
 TeamATL                     -1.5631     3.9757  -0.393 0.694278    &lt;br /&gt;
 TeamBAL                     -5.3128     4.0193  -1.322 0.186533    &lt;br /&gt;
 TeamBOS                     -0.2838     4.0034  -0.071 0.943492    &lt;br /&gt;
 TeamCHC                      0.4026     3.9949   0.101 0.919749    &lt;br /&gt;
 TeamCIN                      2.1051     3.9934   0.527 0.598211    &lt;br /&gt;
 TeamCLE                     -1.3160     4.0356  -0.326 0.744423    &lt;br /&gt;
 TeamCOL                     -3.7836     4.0287  -0.939 0.347881    &lt;br /&gt;
 TeamCWS                      4.2944     4.1022   1.047 0.295413    &lt;br /&gt;
 TeamDET                      2.3024     3.9725   0.580 0.562326    &lt;br /&gt;
 TeamFLA                      2.6985     4.1336   0.653 0.514028    &lt;br /&gt;
 TeamHOU                     -0.6808     4.0634  -0.168 0.866976    &lt;br /&gt;
 TeamKC                      -4.7664     4.0242  -1.184 0.236525    &lt;br /&gt;
 TeamLA                       2.8598     4.0817   0.701 0.483686    &lt;br /&gt;
 TeamMIN                      2.1269     4.0947   0.519 0.603579    &lt;br /&gt;
 TeamMLW                      4.2897     4.0243   1.066 0.286706    &lt;br /&gt;
 TeamNYM                     -1.9736     3.9493  -0.500 0.617370    &lt;br /&gt;
 TeamNYY                      1.7483     4.1234   0.424 0.671655    &lt;br /&gt;
 TeamOAK                     -0.5464     3.9672  -0.138 0.890474    &lt;br /&gt;
 TeamPHI                     -6.8486     3.9949  -1.714 0.086778  &lt;br /&gt;
 TeamPIT                      4.3023     4.0210   1.070 0.284890    &lt;br /&gt;
 TeamSD                       2.6133     4.0915   0.639 0.523148    &lt;br /&gt;
 TeamSEA                     -0.9147     4.0516  -0.226 0.821436    &lt;br /&gt;
 TeamSF                       0.8411     4.0520   0.208 0.835593    &lt;br /&gt;
 TeamSTL                     -1.1341     4.1193  -0.275 0.783132    &lt;br /&gt;
 TeamTB                      -2.6616     4.0944  -0.650 0.515798    &lt;br /&gt;
 TeamTEX                     -0.7695     4.0283  -0.191 0.848556    &lt;br /&gt;
 TeamTOR                      1.3943     4.0681   0.343 0.731871    &lt;br /&gt;
 TeamWAS                     -1.7555     4.0038  -0.438 0.661142    &lt;br /&gt;
 ---&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
 &lt;br /&gt;
 Residual standard error: 16.78 on 994 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.3858,	Adjusted R-squared:  0.3617 &lt;br /&gt;
 F-statistic: 16.01 on 39 and 994 DF,  p-value: &amp;lt; 2.2e-16&lt;br /&gt;
&lt;br /&gt;
Notice the linear model coefficients, the corresponding p-values, and the overall model quality, at the bottom of the output change. Are these changed between the 2 models? &lt;br /&gt;
&amp;lt;LI&amp;gt;new model (Weight ~ Age + Height + Position + Team + e.) vs. &amp;lt;/LI&amp;gt;&lt;br /&gt;
&amp;lt;LI&amp;gt;old model   (Weight ~ Age + Height + e)? &amp;lt;/LI&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These examples illustrate &amp;quot;multiple linear regression&amp;quot; as a linear modeling technique involving 1 response (dependent) variable expressed as a (affine) function of multiple predictor (independent) variables.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;http://www.statmethods.net/input/datatypes.html &amp;lt;br&amp;gt;  &amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;http://www.statmethods.net/advstats/glm.html &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;http://www.statmethods.net/management/subset.html  &lt;br /&gt;
&lt;br /&gt;
===See next===&lt;br /&gt;
* [[SMHS_LinearModeling_MLR_VizModelCoeff|Visualizing the Regression-Model coefficients (effect-sizes) section]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_MLR}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_QC&amp;diff=16139</id>
		<title>SMHS LinearModeling QC</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_QC&amp;diff=16139"/>
		<updated>2016-05-23T12:51:55Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_LinearModeling|SMHS Linear Modeling]] - Quality Control ==&lt;br /&gt;
&lt;br /&gt;
Discussion of data Quality Control (QC) and Quality Assurance (QA), which represent important components of data-driven modeling, analytics, and visualization.&lt;br /&gt;
&lt;br /&gt;
'''Questions:&lt;br /&gt;
*Is the data what it’s supposed to be (does it represent the study cohort/population)?&lt;br /&gt;
*How to inspect the quality of the data?&lt;br /&gt;
&lt;br /&gt;
Data Quality Control (QC) and Quality Assurance (QA) represent important components of all modeling, analytics, and visualization that precede all subsequent data processing steps. QC and QA may be performed manually or automatically. Statistical quality control involves quantitative methods for monitoring and controlling a process or data derived from observing a natural phenomenon. For example, is there evidence in the plots below of a change in the mean of these processes?&lt;br /&gt;
&lt;br /&gt;
 # simulate data with base value of 100 w/ normally distributed error&lt;br /&gt;
 # install.packages(&amp;quot;qcc&amp;quot;)&lt;br /&gt;
 library(qcc)&lt;br /&gt;
 demo.data.1 &amp;lt;- rep(100, 1000) + rnorm(1000, mean=0, sd=2)&lt;br /&gt;
 qcc(demo.data.1, type=&amp;quot;xbar.one&amp;quot;, center=100, add.stats=FALSE,&lt;br /&gt;
    title=&amp;quot;Simulation 1&amp;quot;, xlab=&amp;quot;Index&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig003.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now let’s introduce a trend.&lt;br /&gt;
&lt;br /&gt;
 # first 800 points have base value of 100 w/ normally distributed error,&lt;br /&gt;
 # next 100 points have base value of 105 w/ normally distributed error&lt;br /&gt;
 # last 100 points have base value of 110 w/ normally distributed error&lt;br /&gt;
 M &amp;lt;- 110&lt;br /&gt;
 SD=5&lt;br /&gt;
 demo.data.2 &amp;lt;- c(rep(100, 800), rep(M, 100), rep(100+(M-100)/2, 100)) + rnorm(1000, mean=0, sd=SD)&lt;br /&gt;
 qcc(demo.data.2, type=&amp;quot;xbar.one&amp;quot;, center=100, add.stats=FALSE,&lt;br /&gt;
    title=&amp;quot;Simulation 2&amp;quot;, xlab=&amp;quot;Index&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig004.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our goal is to use statistical quality control to automatically identify issues with the data.  The qcc package in R provides methods for statistical quality control – given the data, it identifies candidate points as outliers based on the Shewhart Rules. Color-coding the data also helps point out irregular points. &lt;br /&gt;
&lt;br /&gt;
The Shewhart control charts rules (cf. 1930’s) are based on monitoring events that are unlikely when the controlled process is stable. Incidences of such atypical events are alarm signals, suggesting that stability of the process may be compromised and the process is changed. &lt;br /&gt;
&lt;br /&gt;
An instance of such an unlikely event would be the situation in which the upper/lower control limits (UCL or LCL) are exceeded. UCL and LCL are constructed as ±3? limits, indicating that the process is under control within them. Additional warning limits (LWL and UWL) are constructed at ±2? or ±?. Other rules specifying events having low probability when the process is under control can be constructed: &lt;br /&gt;
&lt;br /&gt;
1.  One point exceeds LCL/UCL.&lt;br /&gt;
&lt;br /&gt;
2.  Nine points above/below the central line.&lt;br /&gt;
&lt;br /&gt;
3.  Six consecutive points show increasing/decreasing trend.&lt;br /&gt;
&lt;br /&gt;
4.  Difference of consecutive values alternates in sign for fourteen points.&lt;br /&gt;
&lt;br /&gt;
5.  Two out of three points exceed LWL or UWL limits.&lt;br /&gt;
&lt;br /&gt;
6.  Four out of five points are above/below the central line and exceed ±? limit.&lt;br /&gt;
&lt;br /&gt;
7.  Fifteen points are within ±? limits.&lt;br /&gt;
&lt;br /&gt;
8.  Eight consecutive values are beyond ±? limits.&lt;br /&gt;
&lt;br /&gt;
We can define training/testing dataset within qcc by adding the data we want to calibrate it with as the first parameter (demo.data.1), followed by the new data (demo.data.2) representing the test data.&lt;br /&gt;
&lt;br /&gt;
 #example using holdout/test sets&lt;br /&gt;
 demo.data.1 &amp;lt;- rep(100, 1000) + rnorm(1000, mean=0, sd=2)&lt;br /&gt;
 demo.data.2 &amp;lt;- c(rep(100, 800), rep(105, 100), rep(110, 100)) + rnorm(100, mean=0, sd=2)&lt;br /&gt;
 MyQC &amp;lt;- qcc(demo.data.1, newdata=demo.data.2, type=&amp;quot;xbar.one&amp;quot;, center=100, add.stats=FALSE, title=&amp;quot;Simulation 1 vs. 2&amp;quot;, xlab=&amp;quot;Index&amp;quot;)&lt;br /&gt;
 plot(MyQC) # , chart.all=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig005.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # add warning limits at 2 std. deviations&lt;br /&gt;
 MyQC2 &amp;lt;- qcc(demo.data.1, newdata=demo.data.2, type=&amp;quot;xbar.one&amp;quot;, center=100, add.stats=FALSE,  title=&amp;quot;Second Simulation 1 vs. 2&amp;quot;, xlab=&amp;quot;Index&amp;quot;)&lt;br /&gt;
 warn.limits &amp;lt;- limits.xbar(MyQC2$\$$center, MyQC2$\$$std.dev, MyQC2$\$$sizes, 0.95)&lt;br /&gt;
 plot(MyQC2, restore.par = FALSE)&lt;br /&gt;
 abline(h = warn.limits, lty = 2, lwd=2, col = &amp;quot;blue&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
 ## limits.xbar(center, std.dev, sizes, conf)&lt;br /&gt;
 Center = sample/group center statistic&lt;br /&gt;
 Sizes= samples sizes. &lt;br /&gt;
 std.dev= within group standard deviation. &lt;br /&gt;
 Conf= a numeric value used to compute control limits, specifying the number of standard deviations (if conf &amp;gt; 1) or the confidence level (if 0 &amp;lt; conf &amp;lt; 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig006.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Natural processes may have errors that are non-normally distributed. However, using (appropriate) transformations we can often normalize the errors. &lt;br /&gt;
&lt;br /&gt;
We can use thresholds to define zones in the data where each zone represents, say, one standard deviation span of the range of the dataset. &lt;br /&gt;
&lt;br /&gt;
 find_zones &amp;lt;- function(x) {&lt;br /&gt;
  x.mean &amp;lt;- mean(x)&lt;br /&gt;
  x.sd &amp;lt;- sd(x)&lt;br /&gt;
  boundaries &amp;lt;- seq(-3, 3)&lt;br /&gt;
  # creates a set of zones for each point in x&lt;br /&gt;
  zones &amp;lt;- sapply(boundaries, function(i) {&lt;br /&gt;
    i * rep(x.sd, length(x))&lt;br /&gt;
  })&lt;br /&gt;
  zones + x.mean&lt;br /&gt;
 }&lt;br /&gt;
 head(find_zones(demo.data.2))&lt;br /&gt;
&lt;br /&gt;
 evaluate_zones &amp;lt;- function(x) {&lt;br /&gt;
  zones &amp;lt;- find_zones(x)&lt;br /&gt;
  colnames(zones) &amp;lt;- paste(&amp;quot;zone&amp;quot;, -3:3, sep=&amp;quot;_&amp;quot;)&lt;br /&gt;
  x.zones &amp;lt;- rowSums(x &amp;gt; zones) - 3&lt;br /&gt;
  x.zones&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 evaluate_zones(demo.data.2)&lt;br /&gt;
&lt;br /&gt;
 find_violations &amp;lt;- function(x.zones, i) {&lt;br /&gt;
  values &amp;lt;- x.zones[max(i-8, 1):i]&lt;br /&gt;
  # rule4 &amp;lt;- ifelse(any(values &amp;gt; 0), 1,&lt;br /&gt;
  rule4 &amp;lt;- ifelse(all(values &amp;gt; 0), 1,&lt;br /&gt;
                  ifelse(all(values &amp;lt; 0), -1,&lt;br /&gt;
                         0))&lt;br /&gt;
  values &amp;lt;- x.zones[max(i-5, 1):i]&lt;br /&gt;
  rule3 &amp;lt;- ifelse(sum(values &amp;gt;= 2) &amp;gt;= 2, 1,&lt;br /&gt;
                  ifelse(sum(values &amp;lt;= -2) &amp;gt;= 2, -1,&lt;br /&gt;
                         0))&lt;br /&gt;
  values &amp;lt;- x.zones[max(i-3, 1):i]&lt;br /&gt;
  rule2 &amp;lt;- ifelse(mean(values &amp;gt;= 3) &amp;gt;= 1, 1,&lt;br /&gt;
                  ifelse(mean(values &amp;lt;= -3) &amp;gt;= 1, -1,&lt;br /&gt;
                         0))&lt;br /&gt;
  #values &amp;lt;- x.zones[]&lt;br /&gt;
 values &amp;lt;- x.zones[max(i-3, 1):i]&lt;br /&gt;
 rule1 &amp;lt;- ifelse(any(values &amp;gt; 2), 1,&lt;br /&gt;
                  ifelse(any(values &amp;lt; -2), -1,&lt;br /&gt;
                         0))&lt;br /&gt;
  c(&amp;quot;rule1&amp;quot;=rule1, &amp;quot;rule2&amp;quot;=rule2, &amp;quot;rule3&amp;quot;=rule3, &amp;quot;rule4&amp;quot;=rule4)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 find_violations(evaluate_zones(demo.data.2), 20)&lt;br /&gt;
&lt;br /&gt;
Now we can compute the rules for each point and assign a color to any violations.&lt;br /&gt;
&lt;br /&gt;
 library(&amp;quot;plyr&amp;quot;)&lt;br /&gt;
 compute_violations &amp;lt;- function(x, start=1) {&lt;br /&gt;
  x.zones &amp;lt;- evaluate_zones(x)&lt;br /&gt;
  results &amp;lt;- ldply (start:length(x), function(i) {&lt;br /&gt;
    find_violations(x.zones, i)&lt;br /&gt;
  })&lt;br /&gt;
  results$\$$color &amp;lt;- ifelse(results$\$$rule1!=0, &amp;quot;pink&amp;quot;,&lt;br /&gt;
                          ifelse(results$\$$rule2!=0, &amp;quot;red&amp;quot;,&lt;br /&gt;
                                 ifelse(results$\$$rule3!=0, &amp;quot;orange&amp;quot;,&lt;br /&gt;
                                        ifelse(results$\$$rule4!=0, &amp;quot;yellow&amp;quot;,&lt;br /&gt;
                                               &amp;quot;black&amp;quot;))))&lt;br /&gt;
  results&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 tail(compute_violations(demo.data.2))&lt;br /&gt;
&lt;br /&gt;
Now let’s make a quality control chart.&lt;br /&gt;
&lt;br /&gt;
 plot.qcc &amp;lt;- function(x, holdout) {&lt;br /&gt;
  my.qcc &amp;lt;- compute_violations(x, length(x) - holdout)&lt;br /&gt;
  bands &amp;lt;- find_zones(x)&lt;br /&gt;
  plot.data &amp;lt;- x[(length(x) - holdout):length(x)]&lt;br /&gt;
  plot(plot.data, col= my.qcc$\$$color, type='b', pch=19, &lt;br /&gt;
       ylim=c(min(bands), max(bands)),&lt;br /&gt;
       main=&amp;quot;QC Chart&amp;quot;,&lt;br /&gt;
       xlab=&amp;quot;&amp;quot;, ylab=&amp;quot;&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  for (i in 1:7) {&lt;br /&gt;
    lines(bands[,i], col= my.qcc$\$$color[i], lwd=0.75, lty=2)&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 demo.data.4 &amp;lt;- c(rep(10, 90), rep(11, 10)) + rnorm(100, mean=0, sd=0.5)&lt;br /&gt;
 plot.qcc (demo.data.4, 100)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig007.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s use the &amp;quot;Student's Sleep Data&amp;quot; (sleep) data.&lt;br /&gt;
&lt;br /&gt;
 library(&amp;quot;qcc&amp;quot;)&lt;br /&gt;
 attach(sleep)&lt;br /&gt;
 q &amp;lt;- qcc.groups(extra, group)&lt;br /&gt;
 dim(q)&lt;br /&gt;
 obj_avg_test_1_2  &amp;lt;-  qcc(q[1:2,],  type=&amp;quot;xbar&amp;quot;)&lt;br /&gt;
 obj_avg_test_1_5  &amp;lt;-  qcc(q[,1:5],  type=&amp;quot;xbar&amp;quot;)&lt;br /&gt;
 summary(obj_avg_test_1_5)&lt;br /&gt;
 obj_avg_test_train &amp;lt;-  qcc(q[,1:5],  type=&amp;quot;xbar&amp;quot;, newdata=q[,6:10])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig008.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # How is this different from this?&lt;br /&gt;
 obj_avg_new &amp;lt;-  qcc(q[,1:10],  type=&amp;quot;xbar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
This control chart has the solid horizontal line (center), the upper and lower control limits (dashed lines), and the sample group statistics (e.g., mean; drawn as a piece-wise line connecting the points). The bottom of the plot includes summary statistics and the number of points beyond control limits and the number of violating runs. If the process is &amp;quot;in-control&amp;quot;, we can use estimated limits for monitoring prospective (new) data sampled from the same process/protocol. For instance,&lt;br /&gt;
&lt;br /&gt;
 obj_test_1_10_train_11_20  &amp;lt;-  qcc(sleep[1:10,],  type=&amp;quot;xbar&amp;quot;, newdata=sleep[11:20,])&lt;br /&gt;
plots the X chart for training and testing (11-20) sleep data where the statistics and the control limits are based on the first 10 (training) samples.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig009.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Now try (range) QCC plot&lt;br /&gt;
 obj_R  &amp;lt;-  qcc(q[,1:5],  type=&amp;quot;R&amp;quot;, newdata=q[,6:10])&lt;br /&gt;
&lt;br /&gt;
A control chart aims to enhance our ability to monitor and track a process proxied by the data. When special causes of variation (random or not) are present, the data may be considered &amp;quot;out of control&amp;quot;. Corresponding action may need to be taken to identify, control for, or eliminate such causes. A process is declared to be &amp;quot;controlled&amp;quot; if the plot of all data points are randomly spread out within the control limits. These Lower and Upper Control Limits (LCL, UCL) are usually computed as ±3s from the center (e.g., mean). The QCC default limits can be changed using the argument nsigmas or by specifying the confidence level via the confidence level  argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:left; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;8&amp;quot; |&amp;lt;b&amp;gt;Control Chart Variables&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;xbar&amp;quot;||Sample means are plotted to control the mean level of a continuous process variable.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;xbar.one&amp;quot;||Sample values from a one–at–a-time data process to control the mean level of a continuous process variable.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;R&amp;quot;||Sample ranges are plotted to control the variability of a continuous process variable.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;S&amp;quot;||Sample standard deviations are plotted to control the variability of a continuous process variable.&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;8&amp;quot; |&amp;lt;b&amp;gt;Control Charts for Attributes&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;p&amp;quot;||The proportion of nonconforming units is plotted. Control limits are based on the binomial distribution.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;np&amp;quot;||The number of nonconforming units is plotted.  Control limits are based on the binomial distribution.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;c&amp;quot;||The number of defectives per unit are plotted. This chart assumes that defects of the quality attribute are rare, and the control limits are computed based on the Poisson distribution.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;u&amp;quot;||The average number of defectives per unit is plotted. The Poisson distribution is used to compute control limits; but, unlike the c chart, this chart does not require a constant number of units.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the process is governed by a Gaussian distribution, the ±3s limits correspond to a two-tails probability of p=0.0027.&lt;br /&gt;
&lt;br /&gt;
Finally, an operating characteristic (OC) curve shows the probability of not detecting a shift in the process (false-negative, type II error); i.e., the probability of erroneously accepting a process as being &amp;quot;in control&amp;quot;, when in fact, it’s out of control.&lt;br /&gt;
&lt;br /&gt;
 # par(mfrow=c(1,1))&lt;br /&gt;
 oc.curves(obj_test_1_10_train_11_20)&lt;br /&gt;
 # oc.curves(obj_test_1_10_train_11_20, identify=TRUE) # to manually identify specific OC points&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_LinearModeling_Fig11.png|500px]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function oc.curves returns a matrix or a vector of probabilities values representing the type II errors for different sample-sizes. See help (oc.curves), e.g., identify=TRUE, which allows to interactively identify values on the plot, for all options.&lt;br /&gt;
&lt;br /&gt;
Notice that the OC curve is &amp;quot;S&amp;quot;-shaped. As expected, this is because as the percent of non-conforming values increases, the probability of acceptance decreases. A small sub-sample, instead of inspecting the entire data, may be used to determine the quality of a process. We can accept the data as in-control as long as the process percent nonconforming is below a predefined level. &lt;br /&gt;
&lt;br /&gt;
===Next see===&lt;br /&gt;
[[SMHS_LinearModeling_MLR|Multiple Linear Regression]] for a review and demonstration of computing and visualizing the regression-model coefficients (effect-sizes), (fixed-effect) linear model assumptions, examination of residual plots, and independence. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_LinearModeling_QC}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16106</id>
		<title>SMHS MethodsHeterogeneity CER</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16106"/>
		<updated>2016-05-20T14:50:24Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Comparative Effectiveness Research (CER) ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
==Observational Studies: Tips for the CER Practitioners==&lt;br /&gt;
&lt;br /&gt;
•	Different study types can offer different understandings; neither should be discounted without closer examination.&lt;br /&gt;
&lt;br /&gt;
•	RCTs provide an accurate understanding of the effect of a particular intervention in a well-defined patient group under “controlled” circumstances.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies provide an understanding of real-world care and its impact, but can be biased due to uncontrolled factors.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies differ in the types of databases used. These databases may lack clinical detail and contain incomplete or inaccurate data.&lt;br /&gt;
&lt;br /&gt;
•	Before accepting the findings from an observational study, consider whether confounding factors may have influenced the results.&lt;br /&gt;
&lt;br /&gt;
•	In this scenario, subgroup analysis was vital in clarifying both study designs; what is true for the many (e.g., overall, estrogen appeared to be detrimental) may not be true for the few (e.g., that for the younger post-menopausal woman, the benefits were greater and the harms less frequent).&lt;br /&gt;
&lt;br /&gt;
•	Carefully examine the generalizability of the study. Do the study’s patients and intervention match those under consideration?&lt;br /&gt;
&lt;br /&gt;
•	Observational studies can identify associations but cannot prove cause-and-effect relationships.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 1: The Cetuximab Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done and what was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cetuximab, an anti-epidermal growth factor receptor (EGFR) agent, has recently been added to the therapeutic armamentarium.  Two important CRTs examined its impact in patients with mCRC (metastatic-stage Colorectal cancer). In the first one, 56 centers in 11 European countries investigated the outcomes associated with cetuximab therapy in 329 mCRC patients who experienced disease progression either on irinotecan therapy or within 3 months thereafter. The study reported that the group on a combination of irinotecan and cetuximab had a significantly higher rate of overall response to treatment (primary endpoint) than the group on cetuximab alone: 22.9% (95% CI, 17.5-29.1%) vs. 10.8% (95% CI, 5.7-18.1%) (P=0.007), respectively. Similarly, the median time to progression was significantly longer in the combination therapy group (4.1 vs. 1.5 months, P&amp;lt;0.001). As these patients had already progressed on irinotecan prior to the study, any response was viewed as positive. Safety between the two treatment arms was similar: approximately 80% of patients in each arm experienced a rash. Grade 3 or 4 (the more severe) toxic effects on the skin were slightly more frequent in the combination-therapy group compared to cetuximab monotherapy, observed in 9.4% and 5.2% of participants, respectively. Other side effects, such as diarrhea and neutropenia observed in the combination-therapy arm, were considered to be in the range expected for irinotecan alone. Data from this study demonstrated the efficacy and safety of cetuximab and were instrumental in the FDA’s 2004 approval.&lt;br /&gt;
&lt;br /&gt;
A second CRT (2007) examined 572 patients and suggested efficacy of cetuximab in the treatment of mCRC. This study was a randomized, non-blinded, controlled trial that examined cetuximab monotherapy plus best supportive care compared to best supportive care alone in patients who had received and failed prior chemotherapy regimens. It reported that median overall survival (the primary endpoint) was significantly higher in patients receiving cetuximab plus best supportive care compared to best supportive care alone (6.1 vs. 4.6 months, respectively) (hazard ratio for death=0.77; 95% CI: 0.64- 0.92, P=0.005). This RCT described a greater incidence of adverse events in the cetuximab plus best supportive care group compared to best supportive care alone including (most significantly) rash, as well as edema, fatigue, nausea and vomiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These RCTs had fairly broad enrollment criteria and the cetuximab benefits were modest. Emerging scientific theories raised the possibility that genetically defined population subsets might experience a greater-than-average treatment benefit. One such area of inquiry entailed examining “biomarkers,” or genetic indicators of a patient’s greater response to therapy. Even as the above RCTs were being conducted, data emerged showing the importance of the KRAS gene.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the emerging biochemical evidence that the epidermal growth factor receptor (EGFR) treatment mechanism (Cetuximab) was even more finely detailed than previously understood, the study authors of the 2007 RCT undertook a retrospective subgroup analysis using tumor tissue samples preserved from their initial study. Following laboratory analysis, all viable tissue samples were classified as having a wild-type (non-mutated) or a mutated KRAS gene. Instead of the previous two study arms (cetuximab plus best supportive care vs. best supportive care alone), there were 4 for this new analysis: each of the two original study arms was further divided by wild-type vs. mutated KRAS status. Laboratory evaluation determined that 40.9% and 42.3% of all patients in the RCT had a KRAS mutation in the cetuximab plus best supportive care group compared to the best supportive care group alone, respectively. The efficacy of cetuximab was found to be significantly correlated with KRAS status: in patients with wild-type (non-mutated). KRAS genes, cetuximab plus best supportive care compared to best supportive care alone improved overall survival (median 9.5 vs. 4.8 months, respectively; hazard ratio  for death=0.55; 95% CI, 0.41-0.74, P&amp;lt;0.001), and progression-free survival (median 3.7 vs. 1.9 months, respectively; hazard ratio for progression or death=0.40; 95% CI, 0.30-0.54, P&amp;lt;0.001). Meanwhile, in patients with mutated KRAS tumors, the authors found no significant difference in outcome between cetuximab plus best supportive care vs. best supportive care alone.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on these and similar results from other studies, the FDA narrowed its product labeling in July 2009 to indicate that cetuximab is not recommended for mCRC patients with mutated KRAS tumors. This distinction reduces the relevant population by approximately 40%. Similarly, the American society of Clinical oncology released a provisional clinical recommendation that all mCRC patients have their tumors tested for KRAS status before receiving anti-EGFR therapy. The benefits of targeted treatment are many. Patients who previously underwent cetuximab therapy without knowing their genetic predisposition would no longer have to be exposed to the drug’s toxic effects if unnecessary, as the efficacy of cetuximab is markedly higher in the genetically defined appropriate patients. In a less-uncertain environment, clinicians can be more confident in advocating a course of action in their care of patients. And finally, knowledge that targeted therapy is possible suggests the potential for further innovation in treatment options. In fact, research continues to demonstrate options for targeted cetuximab treatment of mCRC at an even finer scale than seen with KRAS; and similar genetic targeting is being investigated, and advocated, in other cancer types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are generally viewed as the gold standard, results of one or even a series of trials may not accurately reflect the benefits experienced by an individual patient.  This case-study suggests that cetuximab initially appeared to have rather modest clinical benefits. Albeit, new information that became available and subsequent genetic subgroup assessments led to very different conclusions. Clinicians should be aware that the current knowledge is likely to evolve and any decisions about patient care should be carefully considered with that sense of uncertainty in mind. As in this case study, subgroup analyses (e.g., genetic subtypes) need a theoretical rationale. Ideally, the analyses should be determined at the time of original RCT design and should not just occur as explorations of the subsequent data. When improperly employed, post hoc analyses may lead to incorrect patient care conclusions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RCTs Tips for the CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	RCTs can determine whether an intervention can provide benefit in a very controlled environment.&lt;br /&gt;
&lt;br /&gt;
•	The controlled nature of an RCT may limit its generalizability to a broader population.&lt;br /&gt;
&lt;br /&gt;
•	No results are permanent; advances in scientific knowledge and understanding can influence how we view the effectiveness (or safety) of a therapeutic intervention.&lt;br /&gt;
&lt;br /&gt;
•	Targeted therapy illuminated by carefully thought out subgroup analyses can improve the efficacious and safe use of an intervention.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 2: The Rosiglitazone Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-analysis&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Often the results for the same intervention differ across clinical trials and it may not be clear whether one therapy provides more benefit than another. As CER increases and more studies are conducted, clinicians and policymakers are more likely to encounter this scenario. In a systematic review, a researcher identifies similar studies and displays their results in a table, enabling qualitative comparisons across the studies. With a meta-analysis, the data from included studies are statistically combined into a single “result.” Merging the data from a number of studies increases the effective sample size of the investigation, providing a statistically stronger conclusion about the body of research. By so doing, investigators may detect low frequency events and demonstrate more subtle distinctions between therapeutic alternatives.&lt;br /&gt;
&lt;br /&gt;
When studies have been properly identified and combined, the meta-analysis produces a summary estimate of the findings and a confidence interval that can serve as a benchmark in medical opinion and practice. However, when done incorrectly, the quantitative and statistical analysis can create impressive “numbers” but biased results. The following are important criteria for properly conducted meta-analyses:&lt;br /&gt;
&lt;br /&gt;
1.	Carefully defining unbiased inclusion or exclusion criteria for study selection&lt;br /&gt;
&lt;br /&gt;
2.	Including only those studies that have similar design elements, such as patient population, drug regimen, outcomes being assessed, and time-frame&lt;br /&gt;
&lt;br /&gt;
3.	Applying correct statistical methods to combine and analyze the data&lt;br /&gt;
&lt;br /&gt;
Reporting this information is essential for the reader to determine whether the data were suitable to combine, and if the meta-analysis draws unbiased conclusions. Meta-analyses of randomized clinical trials are considered to be the highest level of medical evidence as they are based upon a synthesis of rigorously controlled trials that systematically reduce bias and confounding. This technique is useful in summarizing available evidence and will likely become more common in the era of publicly funded comparative effectiveness research. The following case study will examine several key principles that will be useful as the reader encounters these publications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Application&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Heart disease is the leading cause of mortality in the United States, resulting in approximately 20% of all deaths. Diabetics are particularly susceptible to heart disease, with more than 65% of deaths attributable to it. The nonfatal complications of diabetes are wide-ranging and include kidney failure, nerve damage, amputation, stroke and blindness, among other outcomes. In 2007, the total estimated cost of diabetes in the United States was $174B; $116B was derived from direct medical expenditures and the rest from the indirect cost of lost productivity due to the disease. With such serious health effects and heavy direct and indirect costs tied to diabetes, proper disease management is critical. Historically, diabetes treatment has focused on strict blood sugar control, assuming that this goal not only targets diabetes but also reduces other serious comorbidities of the disease.&lt;br /&gt;
&lt;br /&gt;
Anti-diabetic agents have long been associated with key questions as to their benefits/risks in the treatment of diabetes. The sulfonylurea tolbutamide, a first generation anti-diabetic drug, was found in a landmark study in the 1970s to significantly increase the CV mortality rate compared to patients not on this agent. Further analysis by external parties concluded that the methods employed in this trial were significantly flawed (e.g., use of an “arbitrary” definition of diabetes status, heterogeneous baseline characteristics of the populations studied, and incorrect statistical methods). Since these early studies, CV concerns continue to be an issue with selected oral hypoglycemic agents that have subsequently entered the marketplace.&lt;br /&gt;
&lt;br /&gt;
A class of drugs, thiazolidinedione (TZD), was approved in the late 1990s, as a solution to the problems associated with the older generation of sulfonylureas. Rosiglitazone, a member of the TZD class, was approved by the FDA in 1999 and was widely prescribed for the treatment of type-2 diabetes. A number of RCTs supported the benefit of rosiglitazone as an important new oral antidiabetic agent. However, safety concerns developed as the FDA received reports of adverse cardiac events potentially associated with rosiglitazone. It was in this setting that a meta-analysis by Nissen and Wolski was published in the New England Journal of Medicine in June 2007.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nissen and Wolski conducted a meta-analysis examining the impact of rosiglitazone on cardiac events and mortality compared to alternative therapeutic approaches. The study began with a broad search to locate potential studies for review. The authors screened published phase II, III, and IV trials; the FDA website; and the drug manufacturer’s clinical-trial registry for applicable data relating to rosiglitazone use. When the initial search was complete, the studies were further categorized by pre-stated inclusion criteria. Meta-analysis inclusion criteria were simple: studies had to include rosiglitazone and a randomized comparator group treated with either another drug or placebo, study arms had to show similar length of treatment, and all groups had to have received more than 24 weeks of exposure to the study drugs. The studies had to contain outcome data of interest including the rate of myocardial infarction (MI) or death from all CV causes. Out of 116 studies surveyed by the authors, 42 met their inclusion criteria and were included in the meta-analysis. Of the studies they included, 23 had durations of 26 weeks or less, and only five studies followed patients for more than a year. Until this point, the study’s authors were following a path similar to that of any reviewer interested in CV outcomes, examining the results of these 42 studies and comparing them qualitatively. Quantitatively combining the data, however, required the authors to make choices about the studies they could merge and the statistical methods they should apply for analysis. Those decisions greatly influenced the results that were reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the studies were combined, the meta-analysis contained data from 15,565 patients in the rosiglitazone group and 12,282 patients as comparators. Analyzing their data, the authors chose one particular statistical method (the Peto odds ratio method, a fixed-effect statistical approach), which calculates the odds of events occurring where the outcomes of interest are rare and small in number. In comparing rosiglitazone with a “control” group that included other drugs or placebo, the authors reported odds ratios of 1.43 (95% CI, 1.03-1.98; P=0.03) and 1.64 (95% CI,&lt;br /&gt;
0.98-2.74; P=0.06) for MI and death from CV causes, respectively. In other words, the odds of an MI or death from a CV cause are higher for rosiglitazone patients than for patients on other therapies or placebo. The authors reported that rosiglitazone was significantly associated with an increase in the risk of MI and had borderline significance in increasing the risk of death from all CV causes. These findings appeared online on the same day that the FDA issued a safety alert regarding rosiglitazone. Discussion of the meta-analysis was immediately featured prominently in the news media. By December 2007, prescription claims for the drug at retail pharmacies had fallen by more than 50%.&lt;br /&gt;
&lt;br /&gt;
As diabetic patients and their clinicians reacted to the news, a methodologic debate also ensued. This discussion included statistical issues pertaining to the conduct of the analysis, its implications for clinical care, and finally the FDA and drug manufacturer’s roles in overseeing and regulating rosiglitazone. The concern among patients with diabetes regarding treatment, continues in the medical community today.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should the studies have been combined? Commentators faulted the authors for including several studies that were not originally intended to investigate diabetes, and for combining both placebo and drug therapy data into one comparator arm. Some critics noted that despite the stated inclusion criteria, some data were derived from studies where the rosiglitazone arm was allowed a longer follow-up than the comparator arm. By failing to account for this longer follow-up period, commentators felt that the authors may have overestimated the effect of rosiglitazone on CV outcomes. Many reviewers were concerned that this meta-analysis excluded trials in which no patients suffered an MI or died from CV causes – the outcomes of greatest interest. Some reviewers also noted that the exclusion of zero-event trials from the pooled dataset not only gave an incomplete picture of the impact of rosiglitazone but could have increased the odds ratio estimate. In general, the pooled dataset was criticized by many for being a faulty microcosm of the information available regarding rosiglitazone.&lt;br /&gt;
&lt;br /&gt;
It is essential that a meta-analysis be based on similarity in the data sources. If studies differ in important areas such as the patient populations, interventions, or outcomes, combining their data may not be suitable. The researchers accepted studies and populations that were clinically heterogeneous, yet pooled them as if they were not. The study reported that the results were combined from a number of trials that were not initially intended to investigate CV outcomes. Furthermore, the available data did not allow for time-to-event analysis, an essential tool in comparing the impact of alternative treatment options. Reviewers considered the data to be insufficiently homogeneous, and the line of cause and effect to be murkier than the authors described.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Were the statistical methods optimal?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The statistical methods for this meta-analysis also came under significant criticism. The critiques focused on the authors’ use of the Peto method as being an incorrect choice because data were pooled from both small and very large studies, resulting in a potential overestimation of treatment effect. Others reviewers pointed that the Peto method should not have been used, as a number of the underlying studies did not have patients assigned equally to rosiglitazone and comparator groups. Finally, critics suggested that the heterogeneity of the included studies required an altogether different set of analytic techniques.&lt;br /&gt;
&lt;br /&gt;
Demonstrating the sensitivity of the authors’ initial analysis to the inclusion criteria and statistical tests used, a number of researchers reworked the data from this study. one researcher used the same studies but analyzed the data with a more commonly used statistical method (Mantel-Haenszel), and found no significant increase in the relative risk or common odds ratio with MI or CV death. When the pool of studies was expanded to include those originally eliminated because they had zero CV events, the odds ratios for MI and death from CV causes dropped from 1.43 to 1.26 (95% CI, 0.93-1.72) and from 1.64 to 1.14 (95% CI, 0.74-1.74), respectively. Neither of the recalculated odd ratios were significant for MI or CV death. Finally, several newer long-term studies have been published since the Nissen meta-analysis. Incorporating their results with the meta-analysis data showed that rosiglitazone is associated with an increased risk of MI but not of CV death. Thus, the findings from these meta-analyses varied with the methods employed, the studies included, and the addition of later trials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controversy surrounding the rosiglitazone meta-analysis authored by Nissen and Wolski forced an unplanned interim analysis of a long-term, randomized trial investigating the CV effects of rosiglitazone among patients with type 2 diabetes. The authors of the RECORD trial noted that even though the follow-up at 3.75 years was shorter than expected, rosiglitazone, when added to standard glucose-lowering therapy, was found to be associated with an increase in the risk of heart failure but was not associated with any increase in death from CV or other causes. Data at the time were found to be insufficient to determine the effect of rosiglitazone on an increase in the risk of MI. the final report of that trial, published in June 2009, confirmed the elevated risk of heart failure in people with type 2 diabetes treated with rosiglitazone in addition to glucose-lowering drugs, but continued to show inconclusive results about the effect of the drug therapy on the risk of MI. Further, the RECORD trial clarified that rosiglitazone does not result in an increased risk of CV morbidity or mortality compared to standard glucose-lowering drugs. Other trials conducted since the publishing of the meta-analysis have corroborated these results, casting further doubt on the findings of the meta-analysis published by Nissen and Wolski.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Now what?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some sources suggest that the original Nissen meta-analysis delivered more harm than benefit, and that a well-recognized medical journal may have erred in its process of peer review. Despite this criticism, it is important to note that subsequent publications support the risk of adverse CV events associated with rosiglitazone, although rosiglitazone use does not appear to increase deaths. These results and emerging data point to the need for further rigorous research to clarify the benefits and risks of rosiglitazone on a variety of outcomes, and the importance of directing the drug to the population that will maximally benefit from its use.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this Case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results from initial randomized trials that seem definitive at one time may not be conclusive, as further trials may emerge to clarify, redirect, or negate previously accepted results. A meta-analysis of those trials can lead to varying results based upon the timing of the analysis and the choices made in its performance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-Analysis: Tips for CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	The results of a meta-analysis are highly dependent on the studies included (and excluded). Are these criteria properly defined and relevant to the purposes of the meta-analysis? Were the combined studies sufficiently similar? Can results from this cohort be generalized to other populations of interest?&lt;br /&gt;
&lt;br /&gt;
•	The statistical methodology can impact study results. Have there been reviews critiquing the methods used in the meta-analysis?&lt;br /&gt;
&lt;br /&gt;
•	A variety of statistical tests should be considered, and perhaps reported, in the analysis of results. Do the authors mention their rationale in choosing a statistical method? Do they show the stability of their results across a spectrum of analytical methods?&lt;br /&gt;
&lt;br /&gt;
•	Nothing is permanent. Emerging data may change the playing field, and meta- analysis results are only as good as the data and statistics from which they are derived.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 3: The Nurses’ Health Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;An observational study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An observational study is a very common type of research design in which the effects of a treatment or condition are studied without formally randomizing patients in an experimental design. Such studies can be done prospectively, wherein data are collected about a group of patients going forward in time; or retrospectively, in which the researcher looks into the past, mining existing databases for data that have already been collected. Latter studies are frequently performed by using an electronic database that contains, for example, administrative, “billing,” or claims data. Less commonly, observational research uses electronic health records, which have greater clinical information that more closely resembles the data collected in an RCT. Observational studies often take place in “real- world” environments, which allow researchers to collect data for a wide array of outcomes. Patients are not randomized in these studies, but the findings can be used to generate hypotheses for investigation in a more constrained experimental setting. Perhaps the best known observational study is the “Framingham study,” which collected demographic and health data for a group of individuals over many years (and continues to do so) and has provided an understanding of the key risk factors for heart disease and stroke.&lt;br /&gt;
&lt;br /&gt;
Observational studies present many advantages to the comparative effectiveness researcher. the study design can provide a unique glimpse of the use of a health care intervention in the “real world,” an essential step in gauging the gap between efficacy (can a treatment work in a controlled setting?) and effectiveness (does the treatment work in a real-life situation?). Furthermore, observational studies can be conducted at low cost, particularly if they involve the secondary analysis of existing data sources. CER often uses administrative databases, which are based upon the billing data submitted by providers during routine care. These databases typically have limited clinical information, may have errors in them, and generally do not undergo auditing.&lt;br /&gt;
&lt;br /&gt;
The uncontrolled nature of observational studies allows them to be subject to bias and confounding. For example, doctors may prescribe a new medication only for the sickest patients. Comparing these outcomes (without careful statistical adjustment) with those from less ill patients receiving alternative treatment may lead to misleading results. Observational studies can identify important associations but cannot prove cause and effect. These studies can generate hypotheses that may require RCTs for fuller demonstration of those relationships. Secondary analysis can also be problematic if researchers overwork datasets by doing multiple exploratory analyses (e.g., data-dredging): the more we look, the more we find, even if those findings are merely statistical aberrations. Unfortunately, the growing need for CER and the wide availability of administrative databases may lead to selection of research of poor quality with inaccurate findings.&lt;br /&gt;
&lt;br /&gt;
In comparative effectiveness research, observational studies are typically considered to be less conclusive than RCTs and meta-analyses. Nonetheless, they can be useful, especially because they examine typical care. Due to lower cost and improvements in health information, observational studies will become increasingly common. Critical assessment of whether the described results are helpful or biased (based upon how the study was performed) are necessary. This case will illustrate several characteristics of the types of studies that will assist in evaluating newly published work. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Applications&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cardiovascular diseases (CVD) are the leading cause of death in women older than   the age of 50. Epidemiologic evidence suggests that estrogen is a key mediator in the development of CVD. Estrogen is an ovarian hormone whose production decreases as women approach menopause. The steep increase in CVD in women at menopause and older and in women who have had hysterectomies further supports a relationship between estrogen and CVD. Building on this evidence of biologic plausibility, epidemiological and observational studies suggested that estrogen replacement therapy (a form of &amp;lt;b&amp;gt;hormone replacement therapy&amp;lt;/b&amp;gt;, or HRT) had positive effects on the risk of CVD in postmenopausal women, (albeit with some negative effects in its potential to increase the risk for breast cancer and stroke). Based on these findings, in the 1980s and 1990s HRT was routinely employed to treat menopausal symptoms and serve as prophylaxis against CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Nurses’ Health Study (NHS) began collecting data in 1976. In the study, researchers intended to examine a broad range of health effects in women over a long period of time, and a key goal was to clarify the role of HRT in heart disease. The cohort (i.e., the group being followed) included married registered nurses aged 30-55 in 1976 who lived in the 11 most populous states. To collect data, the researchers mailed the study participants a survey every 2 years that asked questions about topics such as smoking, hormone use, menopausal status, and less frequently, diet. Data were collected for key end points that included MI, coronary-artery bypass grafting or angioplasty, stroke, total CVD mortality, and deaths from all causes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a 10-year follow-up point, the NHS had a study pool of 48,470 women. The researchers found that estrogen use (alone, without progestin) in postmenopausal women was associated with a reduction in the incidence of CVD as well as in CVD mortality compared to non-users. Later, estrogen-progestin combination therapy was shown to be even more cardioprotective than estrogen monotherapy, and lower doses of estrogen replacement therapy were found to deliver equal cardioprotection and lower the risk for adverse events. NHS researchers were alert to the potential for bias in observational studies. Adjustment for risk factors such as age (a typical practice to eliminate confounding) did not change the reported findings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NHS was not unique in reporting the benefits associated with HRT; other observational studies corroborated the NHS findings. A secondary retrospective data analysis of the UK primary care electronic medical record database, for example, also showed the protective effect associated with HRT use. Researchers were aware of the fundamental limitations of observational studies, particularly with regard to selection bias. They and practicing clinicians were also aware of the potential negative health effects of HRT, which had to be constantly weighed against the potential cardioprotective benefits in deciding a patient’s course of treatment. As a large section of the population could experience the health effects of HRT, researchers began planning RCTs to verify the promising observational study results. It was highly anticipated that those RCTs would corroborate the belief that estrogen replacement can reduce CVD risk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Randomized Controlled Trial: The Women’s Health Initiative&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Women’s health Initiative (WHI) was a major study established by the National Institutes of health in 1992 to assess a broad range of health effects in postmenopausal women. The trial was intended to follow these women for 8 years, at a cost of millions of dollars in federal funding. Among its many facets, it included an RCT to confirm the results from the observational studies discussed above. To fully investigate earlier findings, the WHI had two subgroups. One subgroup consisted of women with prior hysterectomies; they received estrogen monotherapy. The second group consisted of women who had not undergone hysterectomy; they received estrogen in combination with progestin. The WHI enrolled 27,347 women in their HRT investigation: 10,739 in the estrogen-alone arm and 16,608 in the estrogen plus progestin arm. Within each arm, women were randomly assigned to receive either HRT or placebo. All women in the trial were postmenopausal and aged 50-79 years; the mean age was 63.6 years (a fact that would be important in later analysis). Some participants had experienced previous CV events. The primary outcome of both subgroups was coronary heart disease (CHD), as described by nonfatal MI or death due to CHD.&lt;br /&gt;
&lt;br /&gt;
The estrogen-progestin arm of the WHI was halted after a mean follow-up of 5.2 years, 3 years earlier than expected, as the HRT users in this arm were found to be at increased risk for CHD compared to those who received placebo. The study also noted elevated rates of breast cancer and stroke, among other poor outcomes. The estrogen-alone arm continued for an average follow-up of 6.8 years before being similarly discontinued ahead of schedule. Although this part of the study did not find an increased risk of CHD, it also did not find any cardioprotective effect. Beyond failing to locate any clear CV benefits, the WHI also found real evidence of harm, including increased risk of blood clots, breast cancer and stroke. Initial WHI publications therefore recommended against HRT being prescribed for the secondary prevention of CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What Next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scientists and the clinicians who relied on their data for guidance in treating patients, were faced with conflicting data: epidemiological and observational studies suggested that HRT was cardioprotective while the higher-quality evidence from RCTs strongly suggested the opposite. Clinicians primarily followed the WHI results, so prescriptions for HRT in postmenopausal women quickly declined. Meanwhile, researchers began to analyze the studies for potential discrepancies, and found that the women being followed in the NHS and the WHI differed in several important characteristics.&lt;br /&gt;
&lt;br /&gt;
First, the WHI population was older than the NHS cohort, and many had entered menopause at least 10 years before they enrolled in the RCT. Thus, the WHI enrollees experienced a long duration from the onset of menopause to the commencement of HRT. At the same time, many in the NHS population were closer to the onset of menopause and were still displaying hormonal symptoms when they began HRT. Second, although the NHS researchers adjusted the data for various confounding effects, their results could still have been subject to bias. In general, the NHS cohort was more highly educated and of a higher socioeconomic status than the WHI participants, and therefore more likely to see a physician regularly. The NHS women were also leaner and generally healthier than their RCT counterparts, and had been selected for their evident lack of pre-existing CV conditions. This selection bias in the NHS enrollment may have led to a “healthy woman” effect that in turn led to an overestimation of the benefits of therapy in the observational study. Third, researchers noted that dosing differences between the two study types may have contributed to the divergent results. The NHS reported beneficial results following low-dose estrogen therapy. The WHL, meanwhile, used a higher estrogen dose, exposing women to a larger dosage of hormones and increasing their risk for adverse events. The increased risk profile of the WHI women (e.g., older, more comorbidities, higher estrogen dose) could have contributed to the evidence of harm seen in the WHI results.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
In addition to identifying the inherent differences between the two study populations, researchers began a secondary analysis of the NHS and WHI trials. NHS researchers reported that women who began HRT close to the onset of menopause had a significantly reduced risk of CHD. In the subgroups of women that were older and had a similar duration after menopause compared with the WHI women, they found no significant relationship between HRT and CHD. Also, the WHI study further stratified these results by age, and found that women who began HRT close to their onset of menopause experienced some cardioprotection, while women who were further from the onset of menopause had a slightly elevated risk for CHD.&lt;br /&gt;
&lt;br /&gt;
Secondary analysis of both studies was therefore necessary to show that age and a short duration from the onset of menopause are crucial to HRT success as a cardioprotective agent. Neither study type provided “truth” or rather, both studies provided “truth” if viewed carefully (e.g., both produced valid and important results). The differences seen in the studies were rooted in the timing of HRT and the populations being studied.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are given a higher evidence grade, observational studies provide important clinical insights. In this example, the study populations differed. For policymakers and clinicians, it is crucial to examine whether the CER was based upon patients similar to those being considered. Any study with a dissimilar population may provide non-relevant results. Thus, readers of CER need to carefully examine the generalizability of the findings being reported.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
General Classification and Regression Tree (CART) data analysis steps part of the R package &amp;lt;b&amp;gt;rpart.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Growing the Tree===&lt;br /&gt;
&lt;br /&gt;
 # To grow a tree, use&lt;br /&gt;
 rpart(formula, data=, method=,control=), where&lt;br /&gt;
 formula 	is in the format outcome ~ predictor1+predictor2+...&lt;br /&gt;
 data= 	specifies the data frame&lt;br /&gt;
 method= 	&amp;quot;class&amp;quot; for a classification tree, use &amp;quot;anova&amp;quot; for a regression tree&lt;br /&gt;
 control= 	optional parameters for controlling tree growth. For example, control=rpart.control(minsplit=30, cp=0.001) requires that the minimum number of observations in a node be 30 before attempting a split and that a split      must decrease the overall lack of fit by a factor of 0.001 (cost complexity factor) before being attempted.&lt;br /&gt;
&lt;br /&gt;
===Examining Results===&lt;br /&gt;
&lt;br /&gt;
 # These functions help with examining the results.&lt;br /&gt;
 printcp(fit) 	display complexity parameter (cp) table&lt;br /&gt;
 plotcp(fit) 	plot cross-validation results&lt;br /&gt;
 rsq.rpart(fit) 	plot approximate R-squared and relative error for different splits (2 plots). labels are only appropriate for the &amp;quot;anova&amp;quot; method.&lt;br /&gt;
 print(fit) 		print results&lt;br /&gt;
 summary(fit) 	detailed results including surrogate splits&lt;br /&gt;
 plot(fit) 		plot decision tree&lt;br /&gt;
 text(fit) 		label the decision tree plot&lt;br /&gt;
 post(fit, file=) 	create postscript plot of decision tree&lt;br /&gt;
 # In trees created by rpart(), move to the LEFT branch when the stated condition is true.&lt;br /&gt;
&lt;br /&gt;
===Pruning Trees===&lt;br /&gt;
&lt;br /&gt;
 #In general, trees should be pruned back to avoid overfitting the data. The tree size should minimize the cross-#validated error – xerror column printed by printcp(). Pruning the tree is accomplished by:&lt;br /&gt;
 prune(fit, cp= )&lt;br /&gt;
 # use printcp( ) to examine the cross-validation error results, select the complexity parameter (CP) associated with minimum error, and insert the CP it into the prune() function. This (automatically selecting the complexity  parameter associated with the smallest cross-validated error) can be done succinctly by:&lt;br /&gt;
 fit$\$$cptable[which.min(fit$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===Compete Dataset for N-of-1 Example===&lt;br /&gt;
[[SMHS_MethodsHeterogeneity_CER_Nof1|This N-of-1 Dataset]] includes an example.&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_CER}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_MetaAnalysis&amp;diff=16105</id>
		<title>SMHS MethodsHeterogeneity MetaAnalysis</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_MetaAnalysis&amp;diff=16105"/>
		<updated>2016-05-20T14:44:21Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Quantile Treatment Effect (QTE) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Meta-Analyses ==&lt;br /&gt;
&lt;br /&gt;
==Meta-analysis==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Meta-analysis is an approach to combine treatment effects across trials or studies into an aggregated treatment effect with higher statistical power than observed in each individual trials. It may detect HTE by testing for differences in treatment effects across similar RCTs. It requires that the individual treatment effects are similar to ensure pooling is meaningful. In the presence of large clinical or methodological differences between the trials, it may be to avoid meta-analyses. The presence of HTE across studies in a meta-analysis may be due to differences in the design or execution of the individual trials (e.g., randomization methods, patient selection criteria). &amp;lt;b&amp;gt;Cochran's Q is a methods for detection of heterogeneity, which is computed as the weighted sum of squared differences between each study's treatment effect and the pooled effects across the studies.&amp;lt;/b&amp;gt; It is a barometer of inter-trial differences impacting the observed study result.  A possible source of error in a meta-analysis is publication bias. Trial size may introduce publication bias since larger trials are more likely to be published. Language and accessibility represent other potential confounding factors. When the heterogeneity is not due to poor study design, it may be useful to optimize the treatment benefits for different cohorts of participants.	&lt;br /&gt;
&lt;br /&gt;
Cochran's Q statistics is the weighted sum of squares on a standardized scale. &amp;lt;b&amp;gt;The corresponding P value indicates the strength of the evidence of presence of heterogeneity.&amp;lt;/b&amp;gt; This test may have low power to detect heterogeneity sometimes and it is suggested to use a value of 0.10 as a cut-off for significance (Higgins et al., 2003). The Q statistics also may have too much power as a test of heterogeneity when the number of studies is large.&lt;br /&gt;
&lt;br /&gt;
===Simulation Example 1===&lt;br /&gt;
&lt;br /&gt;
 # Install and Load library&lt;br /&gt;
 install.packages(&amp;quot;meta&amp;quot;)&lt;br /&gt;
 library(meta)&lt;br /&gt;
 &lt;br /&gt;
 # Set number of studies&lt;br /&gt;
 n.studies = 15&lt;br /&gt;
 &lt;br /&gt;
 # number of treatments: case1, case2, control&lt;br /&gt;
 n.trt = 3&lt;br /&gt;
 &lt;br /&gt;
 # number of outcomes&lt;br /&gt;
 n.event = 2&lt;br /&gt;
 &lt;br /&gt;
 # simulate the (balanced) number of cases (case1 and case2) and controls in each study&lt;br /&gt;
 ctl.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
 case1.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
 case2.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
&lt;br /&gt;
 # Simulate the number of outcome events (e.g., deaths) and no events in the control group&lt;br /&gt;
 event.ctl.group = rbinom(n = n.studies, size = ctl.group, prob = rep(&amp;lt;mark&amp;gt;0.1&amp;lt;/mark&amp;gt;, length(ctl.group)))&lt;br /&gt;
 noevent.ctl.group = ctl.group - event.ctl.group&lt;br /&gt;
 &lt;br /&gt;
 # Simulate the number of events and no events in the case1 group&lt;br /&gt;
 event.case1.group = rbinom(n = n.studies, size = case1.group, prob = rep(&amp;lt;mark&amp;gt;0.5&amp;lt;/mark&amp;gt;, length(case1.group)))&lt;br /&gt;
 noevent.case1.group = case1.group - event.case1.group&lt;br /&gt;
&lt;br /&gt;
 # Simulate the number of events and no events in the case2 group&lt;br /&gt;
 event.case2.group = rbinom(n = n.studies, size = case2.group, prob = rep(&amp;lt;mark&amp;gt;0.6&amp;lt;/mark&amp;gt;, length(case2.group)))&lt;br /&gt;
 noevent.case2.group = case2.group - event.case2.group&lt;br /&gt;
&lt;br /&gt;
 # Run the univariate meta-analysis using &amp;lt;b&amp;gt;metabin()&amp;lt;/b&amp;gt;, Meta-analysis of binary outcome data – &lt;br /&gt;
 # Calculation of fixed and random effects estimates (risk ratio, odds ratio, risk difference or arcsine&lt;br /&gt;
 # difference) for meta-analyses with binary outcome data.   Mantel-Haenszel (MH), &lt;br /&gt;
 #  inverse variance and Peto method are available for pooling.&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;method&amp;lt;/b&amp;gt; = A character string indicating which method is to be used for pooling of studies. &lt;br /&gt;
 # one of &amp;quot;MH&amp;quot; , &amp;quot;Inverse&amp;quot; , or &amp;quot;Cochran&amp;quot;&lt;br /&gt;
 # sm = A character string indicating which summary measure (“OR”, &amp;quot;RR&amp;quot; &amp;quot;RD&amp;quot;=risk difference) is to be &lt;br /&gt;
 # used for pooling of studies&lt;br /&gt;
&lt;br /&gt;
 # Control vs. Case1, n.e and n.c are numbers in experimental and control groups&lt;br /&gt;
 meta.ctr_case1 &amp;lt;- metabin(event.e = &amp;lt;b&amp;gt;event.case1.group&amp;lt;/b&amp;gt;, n.e = case1.group, event.c = &amp;lt;b&amp;gt;event.ctl.group&amp;lt;/b&amp;gt;, &lt;br /&gt;
 n.c = ctl.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 # in this case we use Odds Ratio, of the odds of death in the experimental and control studies&lt;br /&gt;
 forest(meta.ctr_case1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Control vs. Case2&lt;br /&gt;
 meta.ctr_case2 &amp;lt;- metabin(event.e = event.case2.group, n.e = case2.group, event.c = event.ctl.group, &lt;br /&gt;
 n.c = ctl.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 forest(meta.ctr_case2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Case1 vs. Case2&lt;br /&gt;
 meta.case1_case2 &amp;lt;- metabin(event.e = event.case1.group, n.e = case1.group, event.c = event.case2.group, &lt;br /&gt;
 n.c = case2.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 forest(meta.case1_case2)&lt;br /&gt;
 summary(meta.case1_case2)&lt;br /&gt;
&lt;br /&gt;
 Test of heterogeneity:&lt;br /&gt;
     Q 	d.f.  	p-value&lt;br /&gt;
 11.99   	14   	0.6071&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;forest plo&amp;lt;/b&amp;gt;t shows the I2 test indicates the evidence to reject the null hypothesis (no study heterogeneity and the fixed effects model should be used).&lt;br /&gt;
&lt;br /&gt;
==Series of “N of 1” trials==&lt;br /&gt;
&lt;br /&gt;
This technique combines (a “series of”) n-of-1 trial data to identify HTE. An n-of-1 trial is a repeated crossover trial for a single patient, which randomly assigns the patient to one treatment vs. another for a given time period, after which the patient is re-randomized to treatment for the next time period, usually repeated for 4-6 time periods. Such trials are most feasibly done in chronic conditions, where little or no washout period is needed between treatments and treatment effects are identifiable in the short-term, such as pain or reliable surrogate markers. Combining data from identical n-of-1 trials across a set of patients enables the statistical analysis controlling for patient fixed or random effects, covariates, centers, or sequence effects, see &amp;lt;b&amp;gt;Figure&amp;lt;/b&amp;gt; below. These combined trials are often analyzed within a Bayesian context using shrinkage estimators that combine individual and group mean treatment effects to create a “posterior” individual mean treatment effect estimate which is a form of inverse variance-weighted average of the individual and group effects. Such trials are typically more expensive than standard RCTs on a per-patient basis, however, they require much smaller sample sizes, often less than 100 patients (due to the efficient individual-as-own-control design), and create individual treatment effect estimates that are not possible in a non-crossover design  . For the individual patient, the treatment effect can be re-estimated after each time period, and the trial stopped at any point when the more effective treatment is identified with reasonable statistical certainty.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
A study involving 8 participants collected data across 30 days, in which 15 treatment days and 15 control days are randomly assigned within each participant. The treatment effect is represented as a binary variable (control day=0; treatment day=1). The outcome variable represents the response to the intervention within each of the 8 participants. Study employed a fixed-effects modeling. By creating N − 1 dummy-coded variables representing the N=8 participants, where the last (i=8) participant serves as the reference (i.e., as the model intercept). So, each dummy-coded variable represents the difference between each participant (i) and the 8th participant. Thus, all other patients' values will be relative to the values of the 8th (reference) subject. The overall differences across participants in fixed effects can be evaluated with multiple &amp;lt;b&amp;gt;degree-of-freedom F-tests.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|...||...||...||...||...||...||...||...||...||...&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt; Complete data is available in the &amp;lt;b&amp;gt;Appendix.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Data Summary&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||Constant&lt;br /&gt;
|-&lt;br /&gt;
|Physical Activity||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|Intervention||Tx&lt;br /&gt;
|-&lt;br /&gt;
|WP Social Support||WPSS&lt;br /&gt;
|-&lt;br /&gt;
|PM Social Support (1-3)||PMss3&lt;br /&gt;
|-&lt;br /&gt;
|Self Efficacy||SelfEff25&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rm(list=ls())&lt;br /&gt;
 Nof1 &amp;lt;-read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q&amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)    # 02_Nof1_Data.csv&lt;br /&gt;
 attach(Nof1)&lt;br /&gt;
 head(Nof1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 df.1 = data.frame(PhyAct, Tx, WPSS, PMss3, SelfEff25) &lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;lme4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 lm.1 = model.lmer &amp;lt;- lmer(PhyAct ~ Tx + SelfEff + Tx*SelfEff + (1|Day) + (1|ID) , data= df.1)&lt;br /&gt;
 summary(lm.1)&lt;br /&gt;
&lt;br /&gt;
 Linear mixed model fit by REML ['lmerMod']&lt;br /&gt;
 Formula: PhyAct ~ Tx + SelfEff + Tx * SelfEff + (1 | Day) + (1 | ID)&lt;br /&gt;
   Data: df.1&lt;br /&gt;
&lt;br /&gt;
 REML criterion at convergence: 8820&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Scaled Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
|-2.7012||-0.6833||-0.0333||0.6542||3.9612&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Groups ||Name||Variance ||Std.Dev.&lt;br /&gt;
|-&lt;br /&gt;
| Day||(Intercept) ||0.0 || 0.00   &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|ID|| (Intercept)||601.5||24.53   &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 |Residual|| ||969.0 ||31.13  &lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 900, groups:  Day, 30; ID, 30&lt;br /&gt;
 &amp;lt;/center&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Estimate||Std.||Error||t value&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||38.3772||14.4738||2.651&lt;br /&gt;
|-&lt;br /&gt;
|Tx||4.0283||6.3745||0.632&lt;br /&gt;
|-&lt;br /&gt;
|SelfEff||0.5818||0.5942||0.979&lt;br /&gt;
|-&lt;br /&gt;
|Tx:SelfEff||0.9702||0.2617||3.708&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Correlation of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||(Intr)||Tx ||SlfEff&lt;br /&gt;
|-&lt;br /&gt;
| Tx|| -0.220|| ||               &lt;br /&gt;
|-&lt;br /&gt;
| SelfEff||-0.946 ||0.208 ||     &lt;br /&gt;
|-&lt;br /&gt;
| Tx:SelfEff ||0.208 ||-0.946 ||-0.220&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Model:  PhyAct = Tx + WPSS + PMss3 + Tx*WPSS + Tx*PMss3 + SelfEff25 + Tx*SelfEff25 + ε&lt;br /&gt;
 lm.2 = lm(PhyAct ~ Tx + WPSS + PMss3 + Tx*WPSS + Tx*PMss3 + SelfEff25 + Tx*SelfEff25, df.1) &lt;br /&gt;
 summary(lm.2)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = PhyAct ~ Tx + WPSS + PMss3 + Tx * WPSS + Tx * PMss3 + &lt;br /&gt;
    SelfEff25 + Tx * SelfEff25, data = df.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max               &lt;br /&gt;
|-&lt;br /&gt;
| -102.39||-28.24||-1.47||25.16||122.41    &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate||Std. Error||t value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||52.0067||1.8080||28.764||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|Tx||27.7366||2.5569||10.848||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|WPSS||1.9631||2.4272||0.809||0.418853 &lt;br /&gt;
|-   &lt;br /&gt;
|PMss3||13.5110||2.7853||4.851||1.45e-06 ***&lt;br /&gt;
|-&lt;br /&gt;
|SelfEff25||0.6289||0.2205||2.852||0.004439 ** &lt;br /&gt;
|-&lt;br /&gt;
|Tx:WPSS||9.9114||3.4320||2.888||0.003971 ** &lt;br /&gt;
|-&lt;br /&gt;
|Tx:PMss3||8.8422||3.9390||2.245||0.025025 *  &lt;br /&gt;
|-&lt;br /&gt;
|Tx:SelfEff25||1.0460||0.3118||3.354||0.000829 ***&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[Using SAS (StudyI_Analyses.sas, StudyIIab_Analyses.sas)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Type 3 Tests of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Effect&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Num DF&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Den DF&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;F Value&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;$Pr&amp;gt;F$&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Tx&amp;lt;/b&amp;gt;||1||224||67.46||&amp;lt;.0001          &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;ID&amp;lt;/b&amp;gt;||7||224||25.95||&amp;lt;.0001&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Tx*ID&amp;lt;/b&amp;gt;||7||224||2.92||0.0060&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quantile Treatment Effect (QTE)==&lt;br /&gt;
&lt;br /&gt;
QTE employs quantile regression estimation (QRE) to examine the central tendency and statistical dispersion of the treatment effect in a population. These may not be revealed by the conventional mean estimation in RCTs. For instance, patients with different comorbidity scores may respond differently to a treatment. Quantile regression has the ability to reveal HTE according to the ranking of patients’ comorbidity scores or some other relevant covariate by which patients may be ranked. Therefore, in an attempt to inform patient-centered care, quantile regression provides more information on the distribution of the treatment effect than typical conditional mean treatment effect estimation. QTE characterizes the heterogeneous treatment effect on individuals and groups across various positions in the distributions of different outcomes of interest. This unique feature has given quantile regression analysis substantial attention and has been employed across a wide range of applications, particularly when evaluating the economic effects of welfare reform.&lt;br /&gt;
&lt;br /&gt;
One caveat of applying QRE in clinical trials for examining HTE is that the QTE doesn’t demonstrate the treatment effect for a given patient. Instead, it focuses on the treatment effect among subjects within the qth quantile, such as those who are exactly at the top 10th percent in terms of blood pressure or a depression score for some covariate of interest, for example, comorbidity score. It is not uncommon for the qth quantiles to be two different sets of patients before and after the treatment. For this reason, we have to assume that these two groups of patients are homogeneous if they were in the same quantiles.&lt;br /&gt;
&lt;br /&gt;
Income-Food Expenditure Example: Let’s examine the Engel data (N=235) on the relationship between food expenditure (foodexp) and household income (income). We can plot the data and then explore the superposition of the six fitted quantile regression lines. &lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;quantreg&amp;quot;)&lt;br /&gt;
 library(quantreg)&lt;br /&gt;
 data(engel)&lt;br /&gt;
 attach(engel)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(engel)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Income||Foodexp&lt;br /&gt;
|-   &lt;br /&gt;
|1||420.1577||255.8394&lt;br /&gt;
|-&lt;br /&gt;
|2||541.4117||310.9587&lt;br /&gt;
|-&lt;br /&gt;
|3||901.1575||485.6800&lt;br /&gt;
|-   &lt;br /&gt;
|4||639.0802||402.9974&lt;br /&gt;
|-&lt;br /&gt;
|5||750.8756||495.5608&lt;br /&gt;
|-&lt;br /&gt;
|6||945.7989||633.7978&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;summary(engel)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Income||Foodexp&lt;br /&gt;
|-   &lt;br /&gt;
|Min||377.1||242.3&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.||638.9||429.7&lt;br /&gt;
|-&lt;br /&gt;
|Median||884.0||582.5&lt;br /&gt;
|-   &lt;br /&gt;
|Mean||982.5||624.2&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.||1164.0||743.9&lt;br /&gt;
|-&lt;br /&gt;
|Max||4957.8||2032.7&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: If &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt; be a real valued random variable with cumulative distribution function F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(y)=P(Y≤ y), then the τ-quantile of &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt; is given by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Q&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(τ)=F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;-1&amp;lt;/sup&amp;gt;(τ)=inf{ y:F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(y)≥τ} &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where 0≤τ≤1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (1) Graphics&lt;br /&gt;
 plot(income, foodexp, cex=.25, type=&amp;quot;n&amp;quot;, xlab=&amp;quot;Household Income&amp;quot;, ylab=&amp;quot;Food Expenditure&amp;quot;)&lt;br /&gt;
 points(income, foodexp, cex=.5, col=&amp;quot;blue&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # tau - the quantile(s) to be estimated, in the range from 0 to 1. An object &amp;quot;rq.process&amp;quot; and an object &amp;quot;rqs&amp;quot; &lt;br /&gt;
 # are returned containing the matrix of coefficient estimates at the specified quantiles.&lt;br /&gt;
 abline( rq(foodexp ~ income, tau=.5), col=&amp;quot;blue&amp;quot;)  	# Quantile Regression Model&lt;br /&gt;
&lt;br /&gt;
 abline( lm(foodexp ~ income), lty=2, lwd=3, col=&amp;quot;red&amp;quot;) 	# linear model&lt;br /&gt;
 taus &amp;lt;- c(0.05, 0.1, 0.25, 0.75, 0.90, 0.95)&lt;br /&gt;
 colors &amp;lt;- rainbow(length(taus))&lt;br /&gt;
&lt;br /&gt;
 models &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = length(taus)) # define a vector of models to store QR for diff taus&lt;br /&gt;
 model.names &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = length(taus)) # define a vector model names&lt;br /&gt;
&lt;br /&gt;
 for( i in 1:length(taus)){&lt;br /&gt;
 models[[i]] &amp;lt;-  rq(foodexp ~ income, tau=taus[i]) &lt;br /&gt;
 var &amp;lt;- taus[i]&lt;br /&gt;
 model.names[[i]] &amp;lt;- paste(&amp;quot;Model [&amp;quot;, i , &amp;quot;]: tau=&amp;quot;, var)&lt;br /&gt;
 abline( models[[i]], lwd=2, col= colors[[i]])&lt;br /&gt;
 }&lt;br /&gt;
 legend(3000, 1100, model.names, col= colors, pch= taus, bty='n', cex=.75)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (2) Inference about quantile regression coefficients.  As an alternative to the rank-inversion confidence intervals, we can obtain a table of coefficients, standard errors, t-statistics, and p-values using the summary function:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;summary(models[[3]], se = &amp;quot;nid&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Call: rq(formula = foodexp ~ income, tau = taus[i])&lt;br /&gt;
&lt;br /&gt;
 tau: [1] 0.25&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Value||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||95.48354||21.39237||4.46344||0.00001&lt;br /&gt;
|-&lt;br /&gt;
|Income||0.47410||0.02906||16.31729||0.00000&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use summary.rq to compute bootstrapped standard errors.&lt;br /&gt;
 summary.rq(models[[3]], se = &amp;quot;nid&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 Call: rq(formula = foodexp ~ income, tau = taus[i])&lt;br /&gt;
 tau: [1] 0.25&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Value||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||95.48354||21.39237||4.46344||0.00001&lt;br /&gt;
|-&lt;br /&gt;
|Income||0.47410||0.02906||16.31729||0.00000&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Nonparametric Regression Methods ==&lt;br /&gt;
&lt;br /&gt;
Nonparametric regression enables dealing with HTE in RCTs. Different nonparametric methods, such as kernel smoothing methods and series methods, can be used to generate test statistics for examining the presence of HTE. A kernel method is a weighting scheme based on a kernel function (e.g. uniform, Gaussian). When evaluating the treatment effect of a patient in RCTs, the kernel method assigns larger weights to those observations with similar covariates. This is done because it is assumed that patients with similar covariates provide more relevant data on predicted treatment response. Examining participants that have different backgrounds (e.g., demographic, clinical), kernel smoothing methods utilize information from highly divergent participants when estimating a particular subject’s treatment effect. Lower weights are assigned to very different subjects and the kernel methods require choosing a set of smoothing parameters to group patients according to their relative degree of similarities. A drawback is that the corresponding proposed test statistics may be sensitive to the chosen bandwidths, which inhibits the interpretation of the results. Series methods use approximating functions (splines or power series of the explanatory variables) to construct test statistics. Compared to kernel smoothing methods, series methods normally have the advantage of computational convenience; however, the precision of test statistics depends on the number of terms selected in the series. &lt;br /&gt;
&lt;br /&gt;
Canadian Wage Data Example: Nonparametric regression extends the classical parametric regression (e.g., lm, lmer) involving one continuous dependent variable, y, and (1 or more) continuous explanatory variable(s), x. Let’s start with a popular parametric model of a wage equation that we can extend to a fully nonparametric regression model. First, we will compare and contrast the parametric and nonparametric approach towards univariate regression and then proceed to multivariate regression.&lt;br /&gt;
&lt;br /&gt;
Let’s use the Canadian cross-section wage data (&amp;lt;b&amp;gt;cps71&amp;lt;/b&amp;gt;) consisting of a random sample taken from the 1971 Canadian Census for male individuals having common education (High-School). N=205 observations, 2 variables, the logarithm of the individual’s wage (logwage) and their age (age). The classical wage equation model includes a quadratic term of age.&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;np&amp;quot;)&lt;br /&gt;
 library(&amp;quot;np&amp;quot;)&lt;br /&gt;
 data(&amp;quot;cps71&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (1) Linear Model -&amp;gt; R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  = 0.2308&lt;br /&gt;
 model.lin &amp;lt;- lm( logwage ~ age + I(age^2), data = cps71)&lt;br /&gt;
 summary(model.lin)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = logwage ~ age + I(age^2), data = cps71)&lt;br /&gt;
&lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -2.4041 -0.1711  0.0884  0.3182  1.3940 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||10.0419773||0.4559986||22.022||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|Age||0.1731310||0.0238317|| 7.265||7.96e-12 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||-0.0019771||0.0002898||-6.822||1.02e-10 ***&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
 Residual standard error: 0.5608 on 202 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.2308,	Adjusted R-squared:  0.2232 &lt;br /&gt;
 F-statistic:  30.3 on 2 and 202 DF,  p-value: 3.103e-12&lt;br /&gt;
&lt;br /&gt;
 # (2) Next, we consider the local linear nonparametric method employing cross-validated &lt;br /&gt;
 # bandwidth selection and estimation in one step. Start with computing the least-squares&lt;br /&gt;
 #  cross-validated bandwidths for the local constant estimator (default).&lt;br /&gt;
 # Note that &amp;lt;b&amp;gt;R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; = 0.3108675&amp;lt;/b&amp;gt;&lt;br /&gt;
 bandwidth &amp;lt;- npregbw(formula= logwage ~ age, data = cps71)&lt;br /&gt;
 model.np &amp;lt;- npreg(bandwidth,  regtype = &amp;quot;ll&amp;quot;,  bwmethod = &amp;quot;cv.aic&amp;quot;, gradients = TRUE, data = cps71)&lt;br /&gt;
 summary(model.np)&lt;br /&gt;
&lt;br /&gt;
 Regression Data: 205 training points, in 1 variable(s) age&lt;br /&gt;
 Bandwidth(s): 1.892157&lt;br /&gt;
 Kernel Regression Estimator: Local-Constant&lt;br /&gt;
 Bandwidth Type: Fixed&lt;br /&gt;
 Residual standard error: 0.5307943&lt;br /&gt;
 R-squared: &amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;0.3108675&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
 Continuous Kernel Type: Second-Order Gaussian&lt;br /&gt;
 No. Continuous Explanatory Vars.: 1&lt;br /&gt;
&lt;br /&gt;
 # NP model significance may be tested by&lt;br /&gt;
 npsigtest(model.np)&lt;br /&gt;
&lt;br /&gt;
 Kernel Regression Significance Test&lt;br /&gt;
 Type I Test with IID Bootstrap (399 replications, Pivot=TRUE, joint=FALSE)&lt;br /&gt;
 Explanatory variables tested for significance: age (1)&lt;br /&gt;
&lt;br /&gt;
               age&lt;br /&gt;
 Bandwidth(s): 1.892157&lt;br /&gt;
&lt;br /&gt;
 Individual Significance Tests&lt;br /&gt;
 P Value: &lt;br /&gt;
 age &amp;lt; 2.22e-16 ***&lt;br /&gt;
&lt;br /&gt;
 # So, as was the case for the linear parametric model, Age is significant in the local linear NP-model&lt;br /&gt;
&lt;br /&gt;
 # (3) Graphical comparison of parametric and nonparametric models. &lt;br /&gt;
 plot(cps71$\$$age, cps71$\$$logwage, xlab = &amp;quot;age&amp;quot;, ylab = &amp;quot;log(wage)&amp;quot;, cex=.1)&lt;br /&gt;
 lines(cps71$\$$age, fitted(model.lin), lty = 2, col = &amp;quot; red&amp;quot;)&lt;br /&gt;
 lines(cps71$\$$age, fitted(model.np), lty = 1, col = &amp;quot;blue&amp;quot;)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, c(&amp;quot;Data&amp;quot;, &amp;quot;Linear&amp;quot;, &amp;quot;Non-linear&amp;quot;), col=c(&amp;quot;Black&amp;quot;, &amp;quot;Red&amp;quot;, &amp;quot;Blue&amp;quot;), pch = c(1, 1, 1), bty='n', cex=.75)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # some additional plots resenting the parametric (quadratic, dashed line) and the nonparametric estimates &lt;br /&gt;
 # (solid line) of the regression function for the cps71 data. &lt;br /&gt;
 plot(model.np, plot.errors.method = &amp;quot;asymptotic&amp;quot;)&lt;br /&gt;
 plot(model.np, gradients = TRUE)&lt;br /&gt;
 lines(cps71$\$$age, coef(model.lin)[2]+2*cps71$\$$age*coef(model.lin)[3], lty = 2, col = &amp;quot;red&amp;quot;)&lt;br /&gt;
 plot(model.np, gradients = TRUE, plot.errors.method = &amp;quot;asymptotic&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (4) using the Lin and NL models to generate predictions based on the obtained appropriate &lt;br /&gt;
 # bandwidths and estimated a nonparametric model. We need to create a set of explanatory&lt;br /&gt;
 # variables for which to generate predictions. These can be part of the original dataset or be&lt;br /&gt;
 # outside its scope. Typically, we don’t have the outcome for the evaluation data and need only &lt;br /&gt;
 # provide the explanatory variables for which predicted values are generated by the models.&lt;br /&gt;
 # Occasionally, splitting the dataset into two independent samples (training/testing), allows estimation&lt;br /&gt;
 # of a model on one sample, and evaluation of its performance on another.&lt;br /&gt;
&lt;br /&gt;
 cps.eval.data &amp;lt;- data.frame(age = seq(10,70, by=10)) # simulate some explanatory X values (ages)&lt;br /&gt;
 pred.lin &amp;lt;- predict(model.lin, newdata = cps.eval.data)		# Linear Prediction of log(Wage)&lt;br /&gt;
 pred.np &amp;lt;- predict(model.np, newdata = cps.eval.data)		# non-Linear Prediction of log(Wage)&lt;br /&gt;
 plot(pred.lin, pred.np)&lt;br /&gt;
 abline(lm(pred.np ~ pred.lin))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
==Predictive risk models ==&lt;br /&gt;
&lt;br /&gt;
Predictive risk models represent a class of methods for identifying potential for HTE when the individual patient risk for disease-related events at baseline depends on observed factors. For instance, common measures are disease staging criteria, such as those used in COPD or heart failure, Framingham risk scores for cardiovascular event risk, or genetic variations, e.g., HER2 for breast cancer. Initial predictive risk modeling, aka risk function estimation, is often performed without accounting for treatment effects. Least squares or Cox proportional hazards regression methods are appropriate in many cases and provide relatively more interpretable risk functions, but rely on linearity assumptions and may not provide optimal predictive metrics. Partial least squares is an extension of least squares methods that can reduce the dimensionality of the predictor space by interposing latent variables, predicted by linear combinations of observable characteristics, as the intermediate predictors of one or more outcomes. Recursive partitioning, such as random forests, support vector machines, and neural networks represent latter methods with better predictive power than linear methods. Risk function estimation can range from highly exploratory analyses to near meta-analytic model validation, and may be useful at any stage of product development.&lt;br /&gt;
&lt;br /&gt;
HIV Example: The &amp;lt;b&amp;gt;“hmohiv”&amp;lt;/b&amp;gt; dataset   represents a study of HIV positive patients examining whether there was a difference in survival times of HIV positive patients between a cohort using intravenous drugs (drug=1) and a cohort not using the IV drug (drug=0). The &amp;lt;b&amp;gt;hmohiv&amp;lt;/b&amp;gt; data includes the following variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID||Time||Age||Drug||Censor||Entdate||Enddate&lt;br /&gt;
|-   &lt;br /&gt;
|1||5||46||0||1||5/15/1990||10/14/1990&lt;br /&gt;
|-&lt;br /&gt;
|2||6||35||1||0||9/19/1989||3/20/1990&lt;br /&gt;
|-&lt;br /&gt;
|3||8||30||1||1||4/21/1991||12/20/1991&lt;br /&gt;
|-&lt;br /&gt;
|4||3||30||1||1||1/3/1991||4/4/1991&lt;br /&gt;
|-&lt;br /&gt;
|5||22||36||0||1||9/18/1989||7/19/1991&lt;br /&gt;
|-&lt;br /&gt;
|6||1||32||1||0||3/18/1991||4/17/1991&lt;br /&gt;
|-&lt;br /&gt;
|...||...||...||...||...||...||...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #cleaning up environment&lt;br /&gt;
 rm(list=ls())&lt;br /&gt;
&lt;br /&gt;
 # load survival library&lt;br /&gt;
 library(survival)&lt;br /&gt;
&lt;br /&gt;
 # load hmohiv data&lt;br /&gt;
 hmohiv&amp;lt;-read.table(&amp;quot;http://www.ats.ucla.edu/stat/r/examples/asa/hmohiv.csv&amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 attach(hmohiv)&lt;br /&gt;
&lt;br /&gt;
 # Fit Cox proportional hazards regression model&lt;br /&gt;
 cox.model &amp;lt;- coxph( Surv(time, censor) ~ drug, method=&amp;quot;breslow&amp;quot;)&lt;br /&gt;
 fit.1 &amp;lt;- survfit(cox.model, newdata=drug.new)&lt;br /&gt;
&lt;br /&gt;
 # construct a frame of the 2 cohorts IV_drug and no-IV-drug&lt;br /&gt;
 drug.new&amp;lt;-data.frame(drug=c(0,1))&lt;br /&gt;
&lt;br /&gt;
 # plot results&lt;br /&gt;
 plot(fit.1, xlab=&amp;quot;Survival Time (Months)&amp;quot;, ylab=&amp;quot;Survival Probability&amp;quot;)&lt;br /&gt;
 points(fit.1$\$$time, fit.1$\$$surv[,1], pch=1)&lt;br /&gt;
 points(fit.1$\$$time, fit.1$\$$surv[,2], pch=2)&lt;br /&gt;
 legend(40, .8, c(&amp;quot;Drug Absent&amp;quot;, &amp;quot;Drug Present&amp;quot;), pch=c(1,2))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to inslect the resulting Cox Proportional Hazard Model&lt;br /&gt;
 cox.model &lt;br /&gt;
 Call:&lt;br /&gt;
 coxph(formula = Surv(time, censor) ~ drug, method = &amp;quot;breslow&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      	    coef 	exp(coef) 	se(coef)   	z      	        p&lt;br /&gt;
 &amp;lt;b&amp;gt;drug&amp;lt;/b&amp;gt; 	0.779          2.18    		0.242 		3.22 	       &amp;lt;b&amp;gt;0.0013&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Likelihood ratio test=10.2  on 1 df, p=0.00141  n= 100, number of events= 80 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_CER|Next see: Comparative Effectiveness Research (CER)]]==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_MetaAnalysis}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16091</id>
		<title>SMHS MethodsHeterogeneity CER</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16091"/>
		<updated>2016-05-19T20:46:35Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Case-Study 3: The Nurses’ Health Study */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Comparative Effectiveness Research (CER) ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
==Observational Studies: Tips for the CER Practitioners==&lt;br /&gt;
&lt;br /&gt;
•	Different study types can offer different understandings; neither should be discounted without closer examination.&lt;br /&gt;
&lt;br /&gt;
•	RCTs provide an accurate understanding of the effect of a particular intervention in a well-defined patient group under “controlled” circumstances.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies provide an understanding of real-world care and its impact, but can be biased due to uncontrolled factors.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies differ in the types of databases used. These databases may lack clinical detail and contain incomplete or inaccurate data.&lt;br /&gt;
&lt;br /&gt;
•	Before accepting the findings from an observational study, consider whether confounding factors may have influenced the results.&lt;br /&gt;
&lt;br /&gt;
•	In this scenario, subgroup analysis was vital in clarifying both study designs; what is true for the many (e.g., overall, estrogen appeared to be detrimental) may not be true for the few (e.g., that for the younger post-menopausal woman, the benefits were greater and the harms less frequent).&lt;br /&gt;
&lt;br /&gt;
•	Carefully examine the generalizability of the study. Do the study’s patients and intervention match those under consideration?&lt;br /&gt;
&lt;br /&gt;
•	Observational studies can identify associations but cannot prove cause-and-effect relationships.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 1: The Cetuximab Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done and what was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cetuximab, an anti-epidermal growth factor receptor (EGFR) agent, has recently been added to the therapeutic armamentarium.  Two important CRTs examined its impact in patients with mCRC (metastatic-stage Colorectal cancer). In the first one, 56 centers in 11 European countries investigated the outcomes associated with cetuximab therapy in 329 mCRC patients who experienced disease progression either on irinotecan therapy or within 3 months thereafter. The study reported that the group on a combination of irinotecan and cetuximab had a significantly higher rate of overall response to treatment (primary endpoint) than the group on cetuximab alone: 22.9% (95% CI, 17.5-29.1%) vs. 10.8% (95% CI, 5.7-18.1%) (P=0.007), respectively. Similarly, the median time to progression was significantly longer in the combination therapy group (4.1 vs. 1.5 months, P&amp;lt;0.001). As these patients had already progressed on irinotecan prior to the study, any response was viewed as positive. Safety between the two treatment arms was similar: approximately 80% of patients in each arm experienced a rash. Grade 3 or 4 (the more severe) toxic effects on the skin were slightly more frequent in the combination-therapy group compared to cetuximab monotherapy, observed in 9.4% and 5.2% of participants, respectively. Other side effects, such as diarrhea and neutropenia observed in the combination-therapy arm, were considered to be in the range expected for irinotecan alone. Data from this study demonstrated the efficacy and safety of cetuximab and were instrumental in the FDA’s 2004 approval.&lt;br /&gt;
&lt;br /&gt;
A second CRT (2007) examined 572 patients and suggested efficacy of cetuximab in the treatment of mCRC. This study was a randomized, non-blinded, controlled trial that examined cetuximab monotherapy plus best supportive care compared to best supportive care alone in patients who had received and failed prior chemotherapy regimens. It reported that median overall survival (the primary endpoint) was significantly higher in patients receiving cetuximab plus best supportive care compared to best supportive care alone (6.1 vs. 4.6 months, respectively) (hazard ratio for death=0.77; 95% CI: 0.64- 0.92, P=0.005). This RCT described a greater incidence of adverse events in the cetuximab plus best supportive care group compared to best supportive care alone including (most significantly) rash, as well as edema, fatigue, nausea and vomiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These RCTs had fairly broad enrollment criteria and the cetuximab benefits were modest. Emerging scientific theories raised the possibility that genetically defined population subsets might experience a greater-than-average treatment benefit. One such area of inquiry entailed examining “biomarkers,” or genetic indicators of a patient’s greater response to therapy. Even as the above RCTs were being conducted, data emerged showing the importance of the KRAS gene.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the emerging biochemical evidence that the epidermal growth factor receptor (EGFR) treatment mechanism (Cetuximab) was even more finely detailed than previously understood, the study authors of the 2007 RCT undertook a retrospective subgroup analysis using tumor tissue samples preserved from their initial study. Following laboratory analysis, all viable tissue samples were classified as having a wild-type (non-mutated) or a mutated KRAS gene. Instead of the previous two study arms (cetuximab plus best supportive care vs. best supportive care alone), there were 4 for this new analysis: each of the two original study arms was further divided by wild-type vs. mutated KRAS status. Laboratory evaluation determined that 40.9% and 42.3% of all patients in the RCT had a KRAS mutation in the cetuximab plus best supportive care group compared to the best supportive care group alone, respectively. The efficacy of cetuximab was found to be significantly correlated with KRAS status: in patients with wild-type (non-mutated). KRAS genes, cetuximab plus best supportive care compared to best supportive care alone improved overall survival (median 9.5 vs. 4.8 months, respectively; hazard ratio  for death=0.55; 95% CI, 0.41-0.74, P&amp;lt;0.001), and progression-free survival (median 3.7 vs. 1.9 months, respectively; hazard ratio for progression or death=0.40; 95% CI, 0.30-0.54, P&amp;lt;0.001). Meanwhile, in patients with mutated KRAS tumors, the authors found no significant difference in outcome between cetuximab plus best supportive care vs. best supportive care alone.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on these and similar results from other studies, the FDA narrowed its product labeling in July 2009 to indicate that cetuximab is not recommended for mCRC patients with mutated KRAS tumors. This distinction reduces the relevant population by approximately 40%. Similarly, the American society of Clinical oncology released a provisional clinical recommendation that all mCRC patients have their tumors tested for KRAS status before receiving anti-EGFR therapy. The benefits of targeted treatment are many. Patients who previously underwent cetuximab therapy without knowing their genetic predisposition would no longer have to be exposed to the drug’s toxic effects if unnecessary, as the efficacy of cetuximab is markedly higher in the genetically defined appropriate patients. In a less-uncertain environment, clinicians can be more confident in advocating a course of action in their care of patients. And finally, knowledge that targeted therapy is possible suggests the potential for further innovation in treatment options. In fact, research continues to demonstrate options for targeted cetuximab treatment of mCRC at an even finer scale than seen with KRAS; and similar genetic targeting is being investigated, and advocated, in other cancer types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are generally viewed as the gold standard, results of one or even a series of trials may not accurately reflect the benefits experienced by an individual patient.  This case-study suggests that cetuximab initially appeared to have rather modest clinical benefits. Albeit, new information that became available and subsequent genetic subgroup assessments led to very different conclusions. Clinicians should be aware that the current knowledge is likely to evolve and any decisions about patient care should be carefully considered with that sense of uncertainty in mind. As in this case study, subgroup analyses (e.g., genetic subtypes) need a theoretical rationale. Ideally, the analyses should be determined at the time of original RCT design and should not just occur as explorations of the subsequent data. When improperly employed, post hoc analyses may lead to incorrect patient care conclusions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RCTs Tips for the CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
o	RCTs can determine whether an intervention can provide benefit in a very controlled environment.&lt;br /&gt;
&lt;br /&gt;
o	The controlled nature of an RCT may limit its generalizability to a broader population.&lt;br /&gt;
&lt;br /&gt;
o	No results are permanent; advances in scientific knowledge and understanding can influence how we view the effectiveness (or safety) of a therapeutic intervention.&lt;br /&gt;
&lt;br /&gt;
o	Targeted therapy illuminated by carefully thought out subgroup analyses can improve the efficacious and safe use of an intervention.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 2: The Rosiglitazone Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-analysis&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Often the results for the same intervention differ across clinical trials and it may not be clear whether one therapy provides more benefit than another. As CER increases and more studies are conducted, clinicians and policymakers are more likely to encounter this scenario. In a systematic review, a researcher identifies similar studies and displays their results in a table, enabling qualitative comparisons across the studies. With a meta-analysis, the data from included studies are statistically combined into a single “result.” Merging the data from a number of studies increases the effective sample size of the investigation, providing a statistically stronger conclusion about the body of research. By so doing, investigators may detect low frequency events and demonstrate more subtle distinctions between therapeutic alternatives.&lt;br /&gt;
&lt;br /&gt;
When studies have been properly identified and combined, the meta-analysis produces a summary estimate of the findings and a confidence interval that can serve as a benchmark in medical opinion and practice. However, when done incorrectly, the quantitative and statistical analysis can create impressive “numbers” but biased results. The following are important criteria for properly conducted meta-analyses:&lt;br /&gt;
&lt;br /&gt;
1.	Carefully defining unbiased inclusion or exclusion criteria for study selection&lt;br /&gt;
&lt;br /&gt;
2.	Including only those studies that have similar design elements, such as patient population, drug regimen, outcomes being assessed, and time-frame&lt;br /&gt;
&lt;br /&gt;
3.	Applying correct statistical methods to combine and analyze the data&lt;br /&gt;
&lt;br /&gt;
Reporting this information is essential for the reader to determine whether the data were suitable to combine, and if the meta-analysis draws unbiased conclusions. Meta-analyses of randomized clinical trials are considered to be the highest level of medical evidence as they are based upon a synthesis of rigorously controlled trials that systematically reduce bias and confounding. This technique is useful in summarizing available evidence and will likely become more common in the era of publicly funded comparative effectiveness research. The following case study will examine several key principles that will be useful as the reader encounters these publications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Application&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Heart disease is the leading cause of mortality in the United States, resulting in approximately 20% of all deaths. Diabetics are particularly susceptible to heart disease, with more than 65% of deaths attributable to it. The nonfatal complications of diabetes are wide-ranging and include kidney failure, nerve damage, amputation, stroke and blindness, among other outcomes. In 2007, the total estimated cost of diabetes in the United States was $174B; $116B was derived from direct medical expenditures and the rest from the indirect cost of lost productivity due to the disease. With such serious health effects and heavy direct and indirect costs tied to diabetes, proper disease management is critical. Historically, diabetes treatment has focused on strict blood sugar control, assuming that this goal not only targets diabetes but also reduces other serious comorbidities of the disease.&lt;br /&gt;
&lt;br /&gt;
Anti-diabetic agents have long been associated with key questions as to their benefits/risks in the treatment of diabetes. The sulfonylurea tolbutamide, a first generation anti-diabetic drug, was found in a landmark study in the 1970s to significantly increase the CV mortality rate compared to patients not on this agent. Further analysis by external parties concluded that the methods employed in this trial were significantly flawed (e.g., use of an “arbitrary” definition of diabetes status, heterogeneous baseline characteristics of the populations studied, and incorrect statistical methods). Since these early studies, CV concerns continue to be an issue with selected oral hypoglycemic agents that have subsequently entered the marketplace.&lt;br /&gt;
&lt;br /&gt;
A class of drugs, thiazolidinedione (TZD), was approved in the late 1990s, as a solution to the problems associated with the older generation of sulfonylureas. Rosiglitazone, a member of the TZD class, was approved by the FDA in 1999 and was widely prescribed for the treatment of type-2 diabetes. A number of RCTs supported the benefit of rosiglitazone as an important new oral antidiabetic agent. However, safety concerns developed as the FDA received reports of adverse cardiac events potentially associated with rosiglitazone. It was in this setting that a meta-analysis by Nissen and Wolski was published in the New England Journal of Medicine in June 2007.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nissen and Wolski conducted a meta-analysis examining the impact of rosiglitazone on cardiac events and mortality compared to alternative therapeutic approaches. The study began with a broad search to locate potential studies for review. The authors screened published phase II, III, and IV trials; the FDA website; and the drug manufacturer’s clinical-trial registry for applicable data relating to rosiglitazone use. When the initial search was complete, the studies were further categorized by pre-stated inclusion criteria. Meta-analysis inclusion criteria were simple: studies had to include rosiglitazone and a randomized comparator group treated with either another drug or placebo, study arms had to show similar length of treatment, and all groups had to have received more than 24 weeks of exposure to the study drugs. The studies had to contain outcome data of interest including the rate of myocardial infarction (MI) or death from all CV causes. Out of 116 studies surveyed by the authors, 42 met their inclusion criteria and were included in the meta-analysis. Of the studies they included, 23 had durations of 26 weeks or less, and only five studies followed patients for more than a year. Until this point, the study’s authors were following a path similar to that of any reviewer interested in CV outcomes, examining the results of these 42 studies and comparing them qualitatively. Quantitatively combining the data, however, required the authors to make choices about the studies they could merge and the statistical methods they should apply for analysis. Those decisions greatly influenced the results that were reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the studies were combined, the meta-analysis contained data from 15,565 patients in the rosiglitazone group and 12,282 patients as comparators. Analyzing their data, the authors chose one particular statistical method (the Peto odds ratio method, a fixed-effect statistical approach), which calculates the odds of events occurring where the outcomes of interest are rare and small in number. In comparing rosiglitazone with a “control” group that included other drugs or placebo, the authors reported odds ratios of 1.43 (95% CI, 1.03-1.98; P=0.03) and 1.64 (95% CI,&lt;br /&gt;
0.98-2.74; P=0.06) for MI and death from CV causes, respectively. In other words, the odds of an MI or death from a CV cause are higher for rosiglitazone patients than for patients on other therapies or placebo. The authors reported that rosiglitazone was significantly associated with an increase in the risk of MI and had borderline significance in increasing the risk of death from all CV causes. These findings appeared online on the same day that the FDA issued a safety alert regarding rosiglitazone. Discussion of the meta-analysis was immediately featured prominently in the news media. By December 2007, prescription claims for the drug at retail pharmacies had fallen by more than 50%.&lt;br /&gt;
&lt;br /&gt;
As diabetic patients and their clinicians reacted to the news, a methodologic debate also ensued. This discussion included statistical issues pertaining to the conduct of the analysis, its implications for clinical care, and finally the FDA and drug manufacturer’s roles in overseeing and regulating rosiglitazone. The concern among patients with diabetes regarding treatment, continues in the medical community today.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should the studies have been combined? Commentators faulted the authors for including several studies that were not originally intended to investigate diabetes, and for combining both placebo and drug therapy data into one comparator arm. Some critics noted that despite the stated inclusion criteria, some data were derived from studies where the rosiglitazone arm was allowed a longer follow-up than the comparator arm. By failing to account for this longer follow-up period, commentators felt that the authors may have overestimated the effect of rosiglitazone on CV outcomes. Many reviewers were concerned that this meta-analysis excluded trials in which no patients suffered an MI or died from CV causes – the outcomes of greatest interest. Some reviewers also noted that the exclusion of zero-event trials from the pooled dataset not only gave an incomplete picture of the impact of rosiglitazone but could have increased the odds ratio estimate. In general, the pooled dataset was criticized by many for being a faulty microcosm of the information available regarding rosiglitazone.&lt;br /&gt;
&lt;br /&gt;
It is essential that a meta-analysis be based on similarity in the data sources. If studies differ in important areas such as the patient populations, interventions, or outcomes, combining their data may not be suitable. The researchers accepted studies and populations that were clinically heterogeneous, yet pooled them as if they were not. The study reported that the results were combined from a number of trials that were not initially intended to investigate CV outcomes. Furthermore, the available data did not allow for time-to-event analysis, an essential tool in comparing the impact of alternative treatment options. Reviewers considered the data to be insufficiently homogeneous, and the line of cause and effect to be murkier than the authors described.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Were the statistical methods optimal?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The statistical methods for this meta-analysis also came under significant criticism. The critiques focused on the authors’ use of the Peto method as being an incorrect choice because data were pooled from both small and very large studies, resulting in a potential overestimation of treatment effect. Others reviewers pointed that the Peto method should not have been used, as a number of the underlying studies did not have patients assigned equally to rosiglitazone and comparator groups. Finally, critics suggested that the heterogeneity of the included studies required an altogether different set of analytic techniques.&lt;br /&gt;
&lt;br /&gt;
Demonstrating the sensitivity of the authors’ initial analysis to the inclusion criteria and statistical tests used, a number of researchers reworked the data from this study. one researcher used the same studies but analyzed the data with a more commonly used statistical method (Mantel-Haenszel), and found no significant increase in the relative risk or common odds ratio with MI or CV death. When the pool of studies was expanded to include those originally eliminated because they had zero CV events, the odds ratios for MI and death from CV causes dropped from 1.43 to 1.26 (95% CI, 0.93-1.72) and from 1.64 to 1.14 (95% CI, 0.74-1.74), respectively. Neither of the recalculated odd ratios were significant for MI or CV death. Finally, several newer long-term studies have been published since the Nissen meta-analysis. Incorporating their results with the meta-analysis data showed that rosiglitazone is associated with an increased risk of MI but not of CV death. Thus, the findings from these meta-analyses varied with the methods employed, the studies included, and the addition of later trials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controversy surrounding the rosiglitazone meta-analysis authored by Nissen and Wolski forced an unplanned interim analysis of a long-term, randomized trial investigating the CV effects of rosiglitazone among patients with type 2 diabetes. The authors of the RECORD trial noted that even though the follow-up at 3.75 years was shorter than expected, rosiglitazone, when added to standard glucose-lowering therapy, was found to be associated with an increase in the risk of heart failure but was not associated with any increase in death from CV or other causes. Data at the time were found to be insufficient to determine the effect of rosiglitazone on an increase in the risk of MI. the final report of that trial, published in June 2009, confirmed the elevated risk of heart failure in people with type 2 diabetes treated with rosiglitazone in addition to glucose-lowering drugs, but continued to show inconclusive results about the effect of the drug therapy on the risk of MI. Further, the RECORD trial clarified that rosiglitazone does not result in an increased risk of CV morbidity or mortality compared to standard glucose-lowering drugs. Other trials conducted since the publishing of the meta-analysis have corroborated these results, casting further doubt on the findings of the meta-analysis published by Nissen and Wolski.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Now what?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some sources suggest that the original Nissen meta-analysis delivered more harm than benefit, and that a well-recognized medical journal may have erred in its process of peer review. Despite this criticism, it is important to note that subsequent publications support the risk of adverse CV events associated with rosiglitazone, although rosiglitazone use does not appear to increase deaths. These results and emerging data point to the need for further rigorous research to clarify the benefits and risks of rosiglitazone on a variety of outcomes, and the importance of directing the drug to the population that will maximally benefit from its use.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this Case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results from initial randomized trials that seem definitive at one time may not be conclusive, as further trials may emerge to clarify, redirect, or negate previously accepted results. A meta-analysis of those trials can lead to varying results based upon the timing of the analysis and the choices made in its performance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-Analysis: Tips for CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
o	The results of a meta-analysis are highly dependent on the studies included (and excluded). Are these criteria properly defined and relevant to the purposes of the meta-analysis? Were the combined studies sufficiently similar? Can results from this cohort be generalized to other populations of interest?&lt;br /&gt;
&lt;br /&gt;
o	The statistical methodology can impact study results. Have there been reviews critiquing the methods used in the meta-analysis?&lt;br /&gt;
&lt;br /&gt;
o	A variety of statistical tests should be considered, and perhaps reported, in the analysis of results. Do the authors mention their rationale in choosing a statistical method? Do they show the stability of their results across a spectrum of analytical methods?&lt;br /&gt;
&lt;br /&gt;
o	Nothing is permanent. Emerging data may change the playing field, and meta- analysis results are only as good as the data and statistics from which they are derived.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 3: The Nurses’ Health Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;An observational study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An observational study is a very common type of research design in which the effects of a treatment or condition are studied without formally randomizing patients in an experimental design. Such studies can be done prospectively, wherein data are collected about a group of patients going forward in time; or retrospectively, in which the researcher looks into the past, mining existing databases for data that have already been collected. Latter studies are frequently performed by using an electronic database that contains, for example, administrative, “billing,” or claims data. Less commonly, observational research uses electronic health records, which have greater clinical information that more closely resembles the data collected in an RCT. Observational studies often take place in “real- world” environments, which allow researchers to collect data for a wide array of outcomes. Patients are not randomized in these studies, but the findings can be used to generate hypotheses for investigation in a more constrained experimental setting. Perhaps the best known observational study is the “Framingham study,” which collected demographic and health data for a group of individuals over many years (and continues to do so) and has provided an understanding of the key risk factors for heart disease and stroke.&lt;br /&gt;
&lt;br /&gt;
Observational studies present many advantages to the comparative effectiveness researcher. the study design can provide a unique glimpse of the use of a health care intervention in the “real world,” an essential step in gauging the gap between efficacy (can a treatment work in a controlled setting?) and effectiveness (does the treatment work in a real-life situation?). Furthermore, observational studies can be conducted at low cost, particularly if they involve the secondary analysis of existing data sources. CER often uses administrative databases, which are based upon the billing data submitted by providers during routine care. These databases typically have limited clinical information, may have errors in them, and generally do not undergo auditing.&lt;br /&gt;
&lt;br /&gt;
The uncontrolled nature of observational studies allows them to be subject to bias and confounding. For example, doctors may prescribe a new medication only for the sickest patients. Comparing these outcomes (without careful statistical adjustment) with those from less ill patients receiving alternative treatment may lead to misleading results. Observational studies can identify important associations but cannot prove cause and effect. These studies can generate hypotheses that may require RCTs for fuller demonstration of those relationships. Secondary analysis can also be problematic if researchers overwork datasets by doing multiple exploratory analyses (e.g., data-dredging): the more we look, the more we find, even if those findings are merely statistical aberrations. Unfortunately, the growing need for CER and the wide availability of administrative databases may lead to selection of research of poor quality with inaccurate findings.&lt;br /&gt;
&lt;br /&gt;
In comparative effectiveness research, observational studies are typically considered to be less conclusive than RCTs and meta-analyses. Nonetheless, they can be useful, especially because they examine typical care. Due to lower cost and improvements in health information, observational studies will become increasingly common. Critical assessment of whether the described results are helpful or biased (based upon how the study was performed) are necessary. This case will illustrate several characteristics of the types of studies that will assist in evaluating newly published work. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Applications&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cardiovascular diseases (CVD) are the leading cause of death in women older than   the age of 50. Epidemiologic evidence suggests that estrogen is a key mediator in the development of CVD. Estrogen is an ovarian hormone whose production decreases as women approach menopause. The steep increase in CVD in women at menopause and older and in women who have had hysterectomies further supports a relationship between estrogen and CVD. Building on this evidence of biologic plausibility, epidemiological and observational studies suggested that estrogen replacement therapy (a form of &amp;lt;b&amp;gt;hormone replacement therapy&amp;lt;/b&amp;gt;, or HRT) had positive effects on the risk of CVD in postmenopausal women, (albeit with some negative effects in its potential to increase the risk for breast cancer and stroke). Based on these findings, in the 1980s and 1990s HRT was routinely employed to treat menopausal symptoms and serve as prophylaxis against CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Nurses’ Health Study (NHS) began collecting data in 1976. In the study, researchers intended to examine a broad range of health effects in women over a long period of time, and a key goal was to clarify the role of HRT in heart disease. The cohort (i.e., the group being followed) included married registered nurses aged 30-55 in 1976 who lived in the 11 most populous states. To collect data, the researchers mailed the study participants a survey every 2 years that asked questions about topics such as smoking, hormone use, menopausal status, and less frequently, diet. Data were collected for key end points that included MI, coronary-artery bypass grafting or angioplasty, stroke, total CVD mortality, and deaths from all causes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a 10-year follow-up point, the NHS had a study pool of 48,470 women. The researchers found that estrogen use (alone, without progestin) in postmenopausal women was associated with a reduction in the incidence of CVD as well as in CVD mortality compared to non-users. Later, estrogen-progestin combination therapy was shown to be even more cardioprotective than estrogen monotherapy, and lower doses of estrogen replacement therapy were found to deliver equal cardioprotection and lower the risk for adverse events. NHS researchers were alert to the potential for bias in observational studies. Adjustment for risk factors such as age (a typical practice to eliminate confounding) did not change the reported findings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NHS was not unique in reporting the benefits associated with HRT; other observational studies corroborated the NHS findings. A secondary retrospective data analysis of the UK primary care electronic medical record database, for example, also showed the protective effect associated with HRT use. Researchers were aware of the fundamental limitations of observational studies, particularly with regard to selection bias. They and practicing clinicians were also aware of the potential negative health effects of HRT, which had to be constantly weighed against the potential cardioprotective benefits in deciding a patient’s course of treatment. As a large section of the population could experience the health effects of HRT, researchers began planning RCTs to verify the promising observational study results. It was highly anticipated that those RCTs would corroborate the belief that estrogen replacement can reduce CVD risk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Randomized Controlled Trial: The Women’s Health Initiative&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Women’s health Initiative (WHI) was a major study established by the National Institutes of health in 1992 to assess a broad range of health effects in postmenopausal women. The trial was intended to follow these women for 8 years, at a cost of millions of dollars in federal funding. Among its many facets, it included an RCT to confirm the results from the observational studies discussed above. To fully investigate earlier findings, the WHI had two subgroups. One subgroup consisted of women with prior hysterectomies; they received estrogen monotherapy. The second group consisted of women who had not undergone hysterectomy; they received estrogen in combination with progestin. The WHI enrolled 27,347 women in their HRT investigation: 10,739 in the estrogen-alone arm and 16,608 in the estrogen plus progestin arm. Within each arm, women were randomly assigned to receive either HRT or placebo. All women in the trial were postmenopausal and aged 50-79 years; the mean age was 63.6 years (a fact that would be important in later analysis). Some participants had experienced previous CV events. The primary outcome of both subgroups was coronary heart disease (CHD), as described by nonfatal MI or death due to CHD.&lt;br /&gt;
&lt;br /&gt;
The estrogen-progestin arm of the WHI was halted after a mean follow-up of 5.2 years, 3 years earlier than expected, as the HRT users in this arm were found to be at increased risk for CHD compared to those who received placebo. The study also noted elevated rates of breast cancer and stroke, among other poor outcomes. The estrogen-alone arm continued for an average follow-up of 6.8 years before being similarly discontinued ahead of schedule. Although this part of the study did not find an increased risk of CHD, it also did not find any cardioprotective effect. Beyond failing to locate any clear CV benefits, the WHI also found real evidence of harm, including increased risk of blood clots, breast cancer and stroke. Initial WHI publications therefore recommended against HRT being prescribed for the secondary prevention of CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What Next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scientists and the clinicians who relied on their data for guidance in treating patients, were faced with conflicting data: epidemiological and observational studies suggested that HRT was cardioprotective while the higher-quality evidence from RCTs strongly suggested the opposite. Clinicians primarily followed the WHI results, so prescriptions for HRT in postmenopausal women quickly declined. Meanwhile, researchers began to analyze the studies for potential discrepancies, and found that the women being followed in the NHS and the WHI differed in several important characteristics.&lt;br /&gt;
&lt;br /&gt;
First, the WHI population was older than the NHS cohort, and many had entered menopause at least 10 years before they enrolled in the RCT. Thus, the WHI enrollees experienced a long duration from the onset of menopause to the commencement of HRT. At the same time, many in the NHS population were closer to the onset of menopause and were still displaying hormonal symptoms when they began HRT. Second, although the NHS researchers adjusted the data for various confounding effects, their results could still have been subject to bias. In general, the NHS cohort was more highly educated and of a higher socioeconomic status than the WHI participants, and therefore more likely to see a physician regularly. The NHS women were also leaner and generally healthier than their RCT counterparts, and had been selected for their evident lack of pre-existing CV conditions. This selection bias in the NHS enrollment may have led to a “healthy woman” effect that in turn led to an overestimation of the benefits of therapy in the observational study. Third, researchers noted that dosing differences between the two study types may have contributed to the divergent results. The NHS reported beneficial results following low-dose estrogen therapy. The WHL, meanwhile, used a higher estrogen dose, exposing women to a larger dosage of hormones and increasing their risk for adverse events. The increased risk profile of the WHI women (e.g., older, more comorbidities, higher estrogen dose) could have contributed to the evidence of harm seen in the WHI results.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
In addition to identifying the inherent differences between the two study populations, researchers began a secondary analysis of the NHS and WHI trials. NHS researchers reported that women who began HRT close to the onset of menopause had a significantly reduced risk of CHD. In the subgroups of women that were older and had a similar duration after menopause compared with the WHI women, they found no significant relationship between HRT and CHD. Also, the WHI study further stratified these results by age, and found that women who began HRT close to their onset of menopause experienced some cardioprotection, while women who were further from the onset of menopause had a slightly elevated risk for CHD.&lt;br /&gt;
&lt;br /&gt;
Secondary analysis of both studies was therefore necessary to show that age and a short duration from the onset of menopause are crucial to HRT success as a cardioprotective agent. Neither study type provided “truth” or rather, both studies provided “truth” if viewed carefully (e.g., both produced valid and important results). The differences seen in the studies were rooted in the timing of HRT and the populations being studied.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are given a higher evidence grade, observational studies provide important clinical insights. In this example, the study populations differed. For policymakers and clinicians, it is crucial to examine whether the CER was based upon patients similar to those being considered. Any study with a dissimilar population may provide non-relevant results. Thus, readers of CER need to carefully examine the generalizability of the findings being reported.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
General Classification and Regression Tree (CART) data analysis steps part of the R package &amp;lt;b&amp;gt;rpart.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Growing the Tree===&lt;br /&gt;
&lt;br /&gt;
 # To grow a tree, use&lt;br /&gt;
 rpart(formula, data=, method=,control=), where&lt;br /&gt;
 formula 	is in the format outcome ~ predictor1+predictor2+...&lt;br /&gt;
 data= 	specifies the data frame&lt;br /&gt;
 method= 	&amp;quot;class&amp;quot; for a classification tree, use &amp;quot;anova&amp;quot; for a regression tree&lt;br /&gt;
 control= 	optional parameters for controlling tree growth. For example, control=rpart.control(minsplit=30, cp=0.001) requires that the minimum number of observations in a node be 30 before attempting a split and that a split      must decrease the overall lack of fit by a factor of 0.001 (cost complexity factor) before being attempted.&lt;br /&gt;
&lt;br /&gt;
===Examining Results===&lt;br /&gt;
&lt;br /&gt;
 # These functions help with examining the results.&lt;br /&gt;
 printcp(fit) 	display complexity parameter (cp) table&lt;br /&gt;
 plotcp(fit) 	plot cross-validation results&lt;br /&gt;
 rsq.rpart(fit) 	plot approximate R-squared and relative error for different splits (2 plots). labels are only appropriate for the &amp;quot;anova&amp;quot; method.&lt;br /&gt;
 print(fit) 		print results&lt;br /&gt;
 summary(fit) 	detailed results including surrogate splits&lt;br /&gt;
 plot(fit) 		plot decision tree&lt;br /&gt;
 text(fit) 		label the decision tree plot&lt;br /&gt;
 post(fit, file=) 	create postscript plot of decision tree&lt;br /&gt;
 # In trees created by rpart(), move to the LEFT branch when the stated condition is true.&lt;br /&gt;
&lt;br /&gt;
===Pruning Trees===&lt;br /&gt;
&lt;br /&gt;
 #In general, trees should be pruned back to avoid overfitting the data. The tree size should minimize the cross-#validated error – xerror column printed by printcp(). Pruning the tree is accomplished by:&lt;br /&gt;
 prune(fit, cp= )&lt;br /&gt;
 # use printcp( ) to examine the cross-validation error results, select the complexity parameter (CP) associated with minimum error, and insert the CP it into the prune() function. This (automatically selecting the complexity  parameter associated with the smallest cross-validated error) can be done succinctly by:&lt;br /&gt;
 fit$\$$cptable[which.min(fit$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===Compete Dataset for N-of-1 Example===&lt;br /&gt;
[[SMHS_MethodsHeterogeneity_CER_Nof1|This N-of-1 Dataset]] includes an example.&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_CER}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16073</id>
		<title>SMHS MethodsHeterogeneity CER</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16073"/>
		<updated>2016-05-19T19:22:44Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Observational Studies: Tips for the CER Practitioners */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Comparative Effectiveness Research (CER) ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
==Observational Studies: Tips for the CER Practitioners==&lt;br /&gt;
&lt;br /&gt;
•	Different study types can offer different understandings; neither should be discounted without closer examination.&lt;br /&gt;
&lt;br /&gt;
•	RCTs provide an accurate understanding of the effect of a particular intervention in a well-defined patient group under “controlled” circumstances.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies provide an understanding of real-world care and its impact, but can be biased due to uncontrolled factors.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies differ in the types of databases used. These databases may lack clinical detail and contain incomplete or inaccurate data.&lt;br /&gt;
&lt;br /&gt;
•	Before accepting the findings from an observational study, consider whether confounding factors may have influenced the results.&lt;br /&gt;
&lt;br /&gt;
•	In this scenario, subgroup analysis was vital in clarifying both study designs; what is true for the many (e.g., overall, estrogen appeared to be detrimental) may not be true for the few (e.g., that for the younger post-menopausal woman, the benefits were greater and the harms less frequent).&lt;br /&gt;
&lt;br /&gt;
•	Carefully examine the generalizability of the study. Do the study’s patients and intervention match those under consideration?&lt;br /&gt;
&lt;br /&gt;
•	Observational studies can identify associations but cannot prove cause-and-effect relationships.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 1: The Cetuximab Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done and what was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cetuximab, an anti-epidermal growth factor receptor (EGFR) agent, has recently been added to the therapeutic armamentarium.  Two important CRTs examined its impact in patients with mCRC (metastatic-stage Colorectal cancer). In the first one, 56 centers in 11 European countries investigated the outcomes associated with cetuximab therapy in 329 mCRC patients who experienced disease progression either on irinotecan therapy or within 3 months thereafter. The study reported that the group on a combination of irinotecan and cetuximab had a significantly higher rate of overall response to treatment (primary endpoint) than the group on cetuximab alone: 22.9% (95% CI, 17.5-29.1%) vs. 10.8% (95% CI, 5.7-18.1%) (P=0.007), respectively. Similarly, the median time to progression was significantly longer in the combination therapy group (4.1 vs. 1.5 months, P&amp;lt;0.001). As these patients had already progressed on irinotecan prior to the study, any response was viewed as positive. Safety between the two treatment arms was similar: approximately 80% of patients in each arm experienced a rash. Grade 3 or 4 (the more severe) toxic effects on the skin were slightly more frequent in the combination-therapy group compared to cetuximab monotherapy, observed in 9.4% and 5.2% of participants, respectively. Other side effects, such as diarrhea and neutropenia observed in the combination-therapy arm, were considered to be in the range expected for irinotecan alone. Data from this study demonstrated the efficacy and safety of cetuximab and were instrumental in the FDA’s 2004 approval.&lt;br /&gt;
&lt;br /&gt;
A second CRT (2007) examined 572 patients and suggested efficacy of cetuximab in the treatment of mCRC. This study was a randomized, non-blinded, controlled trial that examined cetuximab monotherapy plus best supportive care compared to best supportive care alone in patients who had received and failed prior chemotherapy regimens. It reported that median overall survival (the primary endpoint) was significantly higher in patients receiving cetuximab plus best supportive care compared to best supportive care alone (6.1 vs. 4.6 months, respectively) (hazard ratio for death=0.77; 95% CI: 0.64- 0.92, P=0.005). This RCT described a greater incidence of adverse events in the cetuximab plus best supportive care group compared to best supportive care alone including (most significantly) rash, as well as edema, fatigue, nausea and vomiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These RCTs had fairly broad enrollment criteria and the cetuximab benefits were modest. Emerging scientific theories raised the possibility that genetically defined population subsets might experience a greater-than-average treatment benefit. One such area of inquiry entailed examining “biomarkers,” or genetic indicators of a patient’s greater response to therapy. Even as the above RCTs were being conducted, data emerged showing the importance of the KRAS gene.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the emerging biochemical evidence that the epidermal growth factor receptor (EGFR) treatment mechanism (Cetuximab) was even more finely detailed than previously understood, the study authors of the 2007 RCT undertook a retrospective subgroup analysis using tumor tissue samples preserved from their initial study. Following laboratory analysis, all viable tissue samples were classified as having a wild-type (non-mutated) or a mutated KRAS gene. Instead of the previous two study arms (cetuximab plus best supportive care vs. best supportive care alone), there were 4 for this new analysis: each of the two original study arms was further divided by wild-type vs. mutated KRAS status. Laboratory evaluation determined that 40.9% and 42.3% of all patients in the RCT had a KRAS mutation in the cetuximab plus best supportive care group compared to the best supportive care group alone, respectively. The efficacy of cetuximab was found to be significantly correlated with KRAS status: in patients with wild-type (non-mutated). KRAS genes, cetuximab plus best supportive care compared to best supportive care alone improved overall survival (median 9.5 vs. 4.8 months, respectively; hazard ratio  for death=0.55; 95% CI, 0.41-0.74, P&amp;lt;0.001), and progression-free survival (median 3.7 vs. 1.9 months, respectively; hazard ratio for progression or death=0.40; 95% CI, 0.30-0.54, P&amp;lt;0.001). Meanwhile, in patients with mutated KRAS tumors, the authors found no significant difference in outcome between cetuximab plus best supportive care vs. best supportive care alone.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on these and similar results from other studies, the FDA narrowed its product labeling in July 2009 to indicate that cetuximab is not recommended for mCRC patients with mutated KRAS tumors. This distinction reduces the relevant population by approximately 40%. Similarly, the American society of Clinical oncology released a provisional clinical recommendation that all mCRC patients have their tumors tested for KRAS status before receiving anti-EGFR therapy. The benefits of targeted treatment are many. Patients who previously underwent cetuximab therapy without knowing their genetic predisposition would no longer have to be exposed to the drug’s toxic effects if unnecessary, as the efficacy of cetuximab is markedly higher in the genetically defined appropriate patients. In a less-uncertain environment, clinicians can be more confident in advocating a course of action in their care of patients. And finally, knowledge that targeted therapy is possible suggests the potential for further innovation in treatment options. In fact, research continues to demonstrate options for targeted cetuximab treatment of mCRC at an even finer scale than seen with KRAS; and similar genetic targeting is being investigated, and advocated, in other cancer types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are generally viewed as the gold standard, results of one or even a series of trials may not accurately reflect the benefits experienced by an individual patient.  This case-study suggests that cetuximab initially appeared to have rather modest clinical benefits. Albeit, new information that became available and subsequent genetic subgroup assessments led to very different conclusions. Clinicians should be aware that the current knowledge is likely to evolve and any decisions about patient care should be carefully considered with that sense of uncertainty in mind. As in this case study, subgroup analyses (e.g., genetic subtypes) need a theoretical rationale. Ideally, the analyses should be determined at the time of original RCT design and should not just occur as explorations of the subsequent data. When improperly employed, post hoc analyses may lead to incorrect patient care conclusions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RCTs Tips for the CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
o	RCTs can determine whether an intervention can provide benefit in a very controlled environment.&lt;br /&gt;
&lt;br /&gt;
o	The controlled nature of an RCT may limit its generalizability to a broader population.&lt;br /&gt;
&lt;br /&gt;
o	No results are permanent; advances in scientific knowledge and understanding can influence how we view the effectiveness (or safety) of a therapeutic intervention.&lt;br /&gt;
&lt;br /&gt;
o	Targeted therapy illuminated by carefully thought out subgroup analyses can improve the efficacious and safe use of an intervention.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 2: The Rosiglitazone Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-analysis&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Often the results for the same intervention differ across clinical trials and it may not be clear whether one therapy provides more benefit than another. As CER increases and more studies are conducted, clinicians and policymakers are more likely to encounter this scenario. In a systematic review, a researcher identifies similar studies and displays their results in a table, enabling qualitative comparisons across the studies. With a meta-analysis, the data from included studies are statistically combined into a single “result.” Merging the data from a number of studies increases the effective sample size of the investigation, providing a statistically stronger conclusion about the body of research. By so doing, investigators may detect low frequency events and demonstrate more subtle distinctions between therapeutic alternatives.&lt;br /&gt;
&lt;br /&gt;
When studies have been properly identified and combined, the meta-analysis produces a summary estimate of the findings and a confidence interval that can serve as a benchmark in medical opinion and practice. However, when done incorrectly, the quantitative and statistical analysis can create impressive “numbers” but biased results. The following are important criteria for properly conducted meta-analyses:&lt;br /&gt;
&lt;br /&gt;
1.	Carefully defining unbiased inclusion or exclusion criteria for study selection&lt;br /&gt;
&lt;br /&gt;
2.	Including only those studies that have similar design elements, such as patient population, drug regimen, outcomes being assessed, and time-frame&lt;br /&gt;
&lt;br /&gt;
3.	Applying correct statistical methods to combine and analyze the data&lt;br /&gt;
&lt;br /&gt;
Reporting this information is essential for the reader to determine whether the data were suitable to combine, and if the meta-analysis draws unbiased conclusions. Meta-analyses of randomized clinical trials are considered to be the highest level of medical evidence as they are based upon a synthesis of rigorously controlled trials that systematically reduce bias and confounding. This technique is useful in summarizing available evidence and will likely become more common in the era of publicly funded comparative effectiveness research. The following case study will examine several key principles that will be useful as the reader encounters these publications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Application&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Heart disease is the leading cause of mortality in the United States, resulting in approximately 20% of all deaths. Diabetics are particularly susceptible to heart disease, with more than 65% of deaths attributable to it. The nonfatal complications of diabetes are wide-ranging and include kidney failure, nerve damage, amputation, stroke and blindness, among other outcomes. In 2007, the total estimated cost of diabetes in the United States was $174B; $116B was derived from direct medical expenditures and the rest from the indirect cost of lost productivity due to the disease. With such serious health effects and heavy direct and indirect costs tied to diabetes, proper disease management is critical. Historically, diabetes treatment has focused on strict blood sugar control, assuming that this goal not only targets diabetes but also reduces other serious comorbidities of the disease.&lt;br /&gt;
&lt;br /&gt;
Anti-diabetic agents have long been associated with key questions as to their benefits/risks in the treatment of diabetes. The sulfonylurea tolbutamide, a first generation anti-diabetic drug, was found in a landmark study in the 1970s to significantly increase the CV mortality rate compared to patients not on this agent. Further analysis by external parties concluded that the methods employed in this trial were significantly flawed (e.g., use of an “arbitrary” definition of diabetes status, heterogeneous baseline characteristics of the populations studied, and incorrect statistical methods). Since these early studies, CV concerns continue to be an issue with selected oral hypoglycemic agents that have subsequently entered the marketplace.&lt;br /&gt;
&lt;br /&gt;
A class of drugs, thiazolidinedione (TZD), was approved in the late 1990s, as a solution to the problems associated with the older generation of sulfonylureas. Rosiglitazone, a member of the TZD class, was approved by the FDA in 1999 and was widely prescribed for the treatment of type-2 diabetes. A number of RCTs supported the benefit of rosiglitazone as an important new oral antidiabetic agent. However, safety concerns developed as the FDA received reports of adverse cardiac events potentially associated with rosiglitazone. It was in this setting that a meta-analysis by Nissen and Wolski was published in the New England Journal of Medicine in June 2007.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nissen and Wolski conducted a meta-analysis examining the impact of rosiglitazone on cardiac events and mortality compared to alternative therapeutic approaches. The study began with a broad search to locate potential studies for review. The authors screened published phase II, III, and IV trials; the FDA website; and the drug manufacturer’s clinical-trial registry for applicable data relating to rosiglitazone use. When the initial search was complete, the studies were further categorized by pre-stated inclusion criteria. Meta-analysis inclusion criteria were simple: studies had to include rosiglitazone and a randomized comparator group treated with either another drug or placebo, study arms had to show similar length of treatment, and all groups had to have received more than 24 weeks of exposure to the study drugs. The studies had to contain outcome data of interest including the rate of myocardial infarction (MI) or death from all CV causes. Out of 116 studies surveyed by the authors, 42 met their inclusion criteria and were included in the meta-analysis. Of the studies they included, 23 had durations of 26 weeks or less, and only five studies followed patients for more than a year. Until this point, the study’s authors were following a path similar to that of any reviewer interested in CV outcomes, examining the results of these 42 studies and comparing them qualitatively. Quantitatively combining the data, however, required the authors to make choices about the studies they could merge and the statistical methods they should apply for analysis. Those decisions greatly influenced the results that were reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the studies were combined, the meta-analysis contained data from 15,565 patients in the rosiglitazone group and 12,282 patients as comparators. Analyzing their data, the authors chose one particular statistical method (the Peto odds ratio method, a fixed-effect statistical approach), which calculates the odds of events occurring where the outcomes of interest are rare and small in number. In comparing rosiglitazone with a “control” group that included other drugs or placebo, the authors reported odds ratios of 1.43 (95% CI, 1.03-1.98; P=0.03) and 1.64 (95% CI,&lt;br /&gt;
0.98-2.74; P=0.06) for MI and death from CV causes, respectively. In other words, the odds of an MI or death from a CV cause are higher for rosiglitazone patients than for patients on other therapies or placebo. The authors reported that rosiglitazone was significantly associated with an increase in the risk of MI and had borderline significance in increasing the risk of death from all CV causes. These findings appeared online on the same day that the FDA issued a safety alert regarding rosiglitazone. Discussion of the meta-analysis was immediately featured prominently in the news media. By December 2007, prescription claims for the drug at retail pharmacies had fallen by more than 50%.&lt;br /&gt;
&lt;br /&gt;
As diabetic patients and their clinicians reacted to the news, a methodologic debate also ensued. This discussion included statistical issues pertaining to the conduct of the analysis, its implications for clinical care, and finally the FDA and drug manufacturer’s roles in overseeing and regulating rosiglitazone. The concern among patients with diabetes regarding treatment, continues in the medical community today.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should the studies have been combined? Commentators faulted the authors for including several studies that were not originally intended to investigate diabetes, and for combining both placebo and drug therapy data into one comparator arm. Some critics noted that despite the stated inclusion criteria, some data were derived from studies where the rosiglitazone arm was allowed a longer follow-up than the comparator arm. By failing to account for this longer follow-up period, commentators felt that the authors may have overestimated the effect of rosiglitazone on CV outcomes. Many reviewers were concerned that this meta-analysis excluded trials in which no patients suffered an MI or died from CV causes – the outcomes of greatest interest. Some reviewers also noted that the exclusion of zero-event trials from the pooled dataset not only gave an incomplete picture of the impact of rosiglitazone but could have increased the odds ratio estimate. In general, the pooled dataset was criticized by many for being a faulty microcosm of the information available regarding rosiglitazone.&lt;br /&gt;
&lt;br /&gt;
It is essential that a meta-analysis be based on similarity in the data sources. If studies differ in important areas such as the patient populations, interventions, or outcomes, combining their data may not be suitable. The researchers accepted studies and populations that were clinically heterogeneous, yet pooled them as if they were not. The study reported that the results were combined from a number of trials that were not initially intended to investigate CV outcomes. Furthermore, the available data did not allow for time-to-event analysis, an essential tool in comparing the impact of alternative treatment options. Reviewers considered the data to be insufficiently homogeneous, and the line of cause and effect to be murkier than the authors described.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Were the statistical methods optimal?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The statistical methods for this meta-analysis also came under significant criticism. The critiques focused on the authors’ use of the Peto method as being an incorrect choice because data were pooled from both small and very large studies, resulting in a potential overestimation of treatment effect. Others reviewers pointed that the Peto method should not have been used, as a number of the underlying studies did not have patients assigned equally to rosiglitazone and comparator groups. Finally, critics suggested that the heterogeneity of the included studies required an altogether different set of analytic techniques.&lt;br /&gt;
&lt;br /&gt;
Demonstrating the sensitivity of the authors’ initial analysis to the inclusion criteria and statistical tests used, a number of researchers reworked the data from this study. one researcher used the same studies but analyzed the data with a more commonly used statistical method (Mantel-Haenszel), and found no significant increase in the relative risk or common odds ratio with MI or CV death. When the pool of studies was expanded to include those originally eliminated because they had zero CV events, the odds ratios for MI and death from CV causes dropped from 1.43 to 1.26 (95% CI, 0.93-1.72) and from 1.64 to 1.14 (95% CI, 0.74-1.74), respectively. Neither of the recalculated odd ratios were significant for MI or CV death. Finally, several newer long-term studies have been published since the Nissen meta-analysis. Incorporating their results with the meta-analysis data showed that rosiglitazone is associated with an increased risk of MI but not of CV death. Thus, the findings from these meta-analyses varied with the methods employed, the studies included, and the addition of later trials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controversy surrounding the rosiglitazone meta-analysis authored by Nissen and Wolski forced an unplanned interim analysis of a long-term, randomized trial investigating the CV effects of rosiglitazone among patients with type 2 diabetes. The authors of the RECORD trial noted that even though the follow-up at 3.75 years was shorter than expected, rosiglitazone, when added to standard glucose-lowering therapy, was found to be associated with an increase in the risk of heart failure but was not associated with any increase in death from CV or other causes. Data at the time were found to be insufficient to determine the effect of rosiglitazone on an increase in the risk of MI. the final report of that trial, published in June 2009, confirmed the elevated risk of heart failure in people with type 2 diabetes treated with rosiglitazone in addition to glucose-lowering drugs, but continued to show inconclusive results about the effect of the drug therapy on the risk of MI. Further, the RECORD trial clarified that rosiglitazone does not result in an increased risk of CV morbidity or mortality compared to standard glucose-lowering drugs. Other trials conducted since the publishing of the meta-analysis have corroborated these results, casting further doubt on the findings of the meta-analysis published by Nissen and Wolski.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Now what?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some sources suggest that the original Nissen meta-analysis delivered more harm than benefit, and that a well-recognized medical journal may have erred in its process of peer review. Despite this criticism, it is important to note that subsequent publications support the risk of adverse CV events associated with rosiglitazone, although rosiglitazone use does not appear to increase deaths. These results and emerging data point to the need for further rigorous research to clarify the benefits and risks of rosiglitazone on a variety of outcomes, and the importance of directing the drug to the population that will maximally benefit from its use.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this Case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results from initial randomized trials that seem definitive at one time may not be conclusive, as further trials may emerge to clarify, redirect, or negate previously accepted results. A meta-analysis of those trials can lead to varying results based upon the timing of the analysis and the choices made in its performance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-Analysis: Tips for CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
o	The results of a meta-analysis are highly dependent on the studies included (and excluded). Are these criteria properly defined and relevant to the purposes of the meta-analysis? Were the combined studies sufficiently similar? Can results from this cohort be generalized to other populations of interest?&lt;br /&gt;
&lt;br /&gt;
o	The statistical methodology can impact study results. Have there been reviews critiquing the methods used in the meta-analysis?&lt;br /&gt;
&lt;br /&gt;
o	A variety of statistical tests should be considered, and perhaps reported, in the analysis of results. Do the authors mention their rationale in choosing a statistical method? Do they show the stability of their results across a spectrum of analytical methods?&lt;br /&gt;
&lt;br /&gt;
o	Nothing is permanent. Emerging data may change the playing field, and meta- analysis results are only as good as the data and statistics from which they are derived.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 3: The Nurses’ Health Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;An observational study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An observational study is a very common type of research design in which the effects of a treatment or condition are studied without formally randomizing patients in an experimental design. Such studies can be done prospectively, wherein data are collected about a group of patients going forward in time; or retrospectively, in which the researcher looks into the past, mining existing databases for data that have already been collected. Latter studies are frequently performed by using an electronic database that contains, for example, administrative, “billing,” or claims data. Less commonly, observational research uses electronic health records, which have greater clinical information that more closely resembles the data collected in an RCT. Observational studies often take place in “real- world” environments, which allow researchers to collect data for a wide array of outcomes. Patients are not randomized in these studies, but the findings can be used to generate hypotheses for investigation in a more constrained experimental setting. Perhaps the best known observational study is the “Framingham study,” which collected demographic and health data for a group of individuals over many years (and continues to do so) and has provided an understanding of the key risk factors for heart disease and stroke.&lt;br /&gt;
&lt;br /&gt;
Observational studies present many advantages to the comparative effectiveness researcher. the study design can provide a unique glimpse of the use of a health care intervention in the “real world,” an essential step in gauging the gap between efficacy (can a treatment work in a controlled setting?) and effectiveness (does the treatment work in a real-life situation?). Furthermore, observational studies can be conducted at low cost, particularly if they involve the secondary analysis of existing data sources. CER often uses administrative databases, which are based upon the billing data submitted by providers during routine care. These databases typically have limited clinical information, may have errors in them, and generally do not undergo auditing.&lt;br /&gt;
&lt;br /&gt;
The uncontrolled nature of observational studies allows them to be subject to bias and confounding. For example, doctors may prescribe a new medication only for the sickest patients. Comparing these outcomes (without careful statistical adjustment) with those from less ill patients receiving alternative treatment may lead to misleading results. Observational studies can identify important associations but cannot prove cause and effect. These studies can generate hypotheses that may require RCTs for fuller demonstration of those relationships. Secondary analysis can also be problematic if researchers overwork datasets by doing multiple exploratory analyses (e.g., data-dredging): the more we look, the more we find, even if those findings are merely statistical aberrations. Unfortunately, the growing need for CER and the wide availability of administrative databases may lead to selection of research of poor quality with inaccurate findings.&lt;br /&gt;
&lt;br /&gt;
In comparative effectiveness research, observational studies are typically considered to be less conclusive than RCTs and meta-analyses. Nonetheless, they can be useful, especially because they examine typical care. Due to lower cost and improvements in health information, observational studies will become increasingly common. Critical assessment of whether the described results are helpful or biased (based upon how the study was performed) are necessary. This case will illustrate several characteristics of the types of studies that will assist in evaluating newly published work. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Applications&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cardiovascular diseases (CVD) are the leading cause of death in women older than   the age of 50. Epidemiologic evidence suggests that estrogen is a key mediator in the development of CVD. Estrogen is an ovarian hormone whose production decreases as women approach menopause. The steep increase in CVD in women at menopause and older and in women who have had hysterectomies further supports a relationship between estrogen and CVD. Building on this evidence of biologic plausibility, epidemiological and observational studies suggested that estrogen replacement therapy (a form of &amp;lt;b&amp;gt;hormone replacement therapy&amp;lt;/b&amp;gt;, or HRT) had positive effects on the risk of CVD in postmenopausal women, (albeit with some negative effects in its potential to increase the risk for breast cancer and stroke).65 Based on these findings, in the 1980s and 1990s HRT was routinely employed to treat menopausal symptoms and serve as prophylaxis against CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Nurses’ Health Study (NHS) began collecting data in 1976. In the study, researchers intended to examine a broad range of health effects in women over a long period of time, and a key goal was to clarify the role of HRT in heart disease. The cohort (i.e., the group being followed) included married registered nurses aged 30-55 in 1976 who lived in the 11 most populous states. To collect data, the researchers mailed the study participants a survey every 2 years that asked questions about topics such as smoking, hormone use, menopausal status, and less frequently, diet. Data were collected for key end points that included MI, coronary-artery bypass grafting or angioplasty, stroke, total CVD mortality, and deaths from all causes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a 10-year follow-up point, the NHS had a study pool of 48,470 women. The researchers found that estrogen use (alone, without progestin) in postmenopausal women was associated with a reduction in the incidence of CVD as well as in CVD mortality compared to non-users. Later, estrogen-progestin combination therapy was shown to be even more cardioprotective than estrogen monotherapy, and lower doses of estrogen replacement therapy were found to deliver equal cardioprotection and lower the risk for adverse events. NHS researchers were alert to the potential for bias in observational studies. Adjustment for risk factors such as age (a typical practice to eliminate confounding) did not change the reported findings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NHS was not unique in reporting the benefits associated with HRT; other observational studies corroborated the NHS findings. A secondary retrospective data analysis of the UK primary care electronic medical record database, for example, also showed the protective effect associated with HRT use. Researchers were aware of the fundamental limitations of observational studies, particularly with regard to selection bias. They and practicing clinicians were also aware of the potential negative health effects of HRT, which had to be constantly weighed against the potential cardioprotective benefits in deciding a patient’s course of treatment. As a large section of the population could experience the health effects of HRT, researchers began planning RCTs to verify the promising observational study results. It was highly anticipated that those RCTs would corroborate the belief that estrogen replacement can reduce CVD risk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Randomized Controlled Trial: The Women’s Health Initiative&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Women’s health Initiative (WHI) was a major study established by the National Institutes of health in 1992 to assess a broad range of health effects in postmenopausal women. The trial was intended to follow these women for 8 years, at a cost of millions of dollars in federal funding. Among its many facets, it included an RCT to confirm the results from the observational studies discussed above. To fully investigate earlier findings, the WHI had two subgroups. One subgroup consisted of women with prior hysterectomies; they received estrogen monotherapy. The second group consisted of women who had not undergone hysterectomy; they received estrogen in combination with progestin. The WHI enrolled 27,347 women in their HRT investigation: 10,739 in the estrogen-alone arm and 16,608 in the estrogen plus progestin arm. Within each arm, women were randomly assigned to receive either HRT or placebo. All women in the trial were postmenopausal and aged 50-79 years; the mean age was 63.6 years (a fact that would be important in later analysis). Some participants had experienced previous CV events. The primary outcome of both subgroups was coronary heart disease (CHD), as described by nonfatal MI or death due to CHD.&lt;br /&gt;
&lt;br /&gt;
The estrogen-progestin arm of the WHI was halted after a mean follow-up of 5.2 years, 3 years earlier than expected, as the HRT users in this arm were found to be at increased risk for CHD compared to those who received placebo. The study also noted elevated rates of breast cancer and stroke, among other poor outcomes. The estrogen-alone arm continued for an average follow-up of 6.8 years before being similarly discontinued ahead of schedule. Although this part of the study did not find an increased risk of CHD, it also did not find any cardioprotective effect. Beyond failing to locate any clear CV benefits, the WHI also found real evidence of harm, including increased risk of blood clots, breast cancer and stroke. Initial WHI publications therefore recommended against HRT being prescribed for the secondary prevention of CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What Next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scientists and the clinicians who relied on their data for guidance in treating patients, were faced with conflicting data: epidemiological and observational studies suggested that HRT was cardioprotective while the higher-quality evidence from RCTs strongly suggested the opposite. Clinicians primarily followed the WHI results, so prescriptions for HRT in postmenopausal women quickly declined. Meanwhile, researchers began to analyze the studies for potential discrepancies, and found that the women being followed in the NHS and the WHI differed in several important characteristics.&lt;br /&gt;
&lt;br /&gt;
First, the WHI population was older than the NHS cohort, and many had entered menopause at least 10 years before they enrolled in the RCT. Thus, the WHI enrollees experienced a long duration from the onset of menopause to the commencement of HRT. At the same time, many in the NHS population were closer to the onset of menopause and were still displaying hormonal symptoms when they began HRT. Second, although the NHS researchers adjusted the data for various confounding effects, their results could still have been subject to bias. In general, the NHS cohort was more highly educated and of a higher socioeconomic status than the WHI participants, and therefore more likely to see a physician regularly. The NHS women were also leaner and generally healthier than their RCT counterparts, and had been selected for their evident lack of pre-existing CV conditions. This selection bias in the NHS enrollment may have led to a “healthy woman” effect that in turn led to an overestimation of the benefits of therapy in the observational study. Third, researchers noted that dosing differences between the two study types may have contributed to the divergent results. The NHS reported beneficial results following low-dose estrogen therapy. The WHL, meanwhile, used a higher estrogen dose, exposing women to a larger dosage of hormones and increasing their risk for adverse events. The increased risk profile of the WHI women (e.g., older, more comorbidities, higher estrogen dose) could have contributed to the evidence of harm seen in the WHI results.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
In addition to identifying the inherent differences between the two study populations, researchers began a secondary analysis of the NHS and WHI trials. NHS researchers reported that women who began HRT close to the onset of menopause had a significantly reduced risk of CHD. In the subgroups of women that were older and had a similar duration after menopause compared with the WHI women, they found no significant relationship between HRT and CHD. Also, the WHI study further stratified these results by age, and found that women who began HRT close to their onset of menopause experienced some cardioprotection, while women who were further from the onset of menopause had a slightly elevated risk for CHD.&lt;br /&gt;
&lt;br /&gt;
Secondary analysis of both studies was therefore necessary to show that age and a short duration from the onset of menopause are crucial to HRT success as a cardioprotective agent. Neither study type provided “truth” or rather, both studies provided “truth” if viewed carefully (e.g., both produced valid and important results). The differences seen in the studies were rooted in the timing of HRT and the populations being studied.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are given a higher evidence grade, observational studies provide important clinical insights. In this example, the study populations differed. For policymakers and clinicians, it is crucial to examine whether the CER was based upon patients similar to those being considered. Any study with a dissimilar population may provide non-relevant results. Thus, readers of CER need to carefully examine the generalizability of the findings being reported.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
General Classification and Regression Tree (CART) data analysis steps part of the R package &amp;lt;b&amp;gt;rpart.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Growing the Tree===&lt;br /&gt;
&lt;br /&gt;
 # To grow a tree, use&lt;br /&gt;
 rpart(formula, data=, method=,control=), where&lt;br /&gt;
 formula 	is in the format outcome ~ predictor1+predictor2+...&lt;br /&gt;
 data= 	specifies the data frame&lt;br /&gt;
 method= 	&amp;quot;class&amp;quot; for a classification tree, use &amp;quot;anova&amp;quot; for a regression tree&lt;br /&gt;
 control= 	optional parameters for controlling tree growth. For example, control=rpart.control(minsplit=30, cp=0.001) requires that the minimum number of observations in a node be 30 before attempting a split and that a split      must decrease the overall lack of fit by a factor of 0.001 (cost complexity factor) before being attempted.&lt;br /&gt;
&lt;br /&gt;
===Examining Results===&lt;br /&gt;
&lt;br /&gt;
 # These functions help with examining the results.&lt;br /&gt;
 printcp(fit) 	display complexity parameter (cp) table&lt;br /&gt;
 plotcp(fit) 	plot cross-validation results&lt;br /&gt;
 rsq.rpart(fit) 	plot approximate R-squared and relative error for different splits (2 plots). labels are only appropriate for the &amp;quot;anova&amp;quot; method.&lt;br /&gt;
 print(fit) 		print results&lt;br /&gt;
 summary(fit) 	detailed results including surrogate splits&lt;br /&gt;
 plot(fit) 		plot decision tree&lt;br /&gt;
 text(fit) 		label the decision tree plot&lt;br /&gt;
 post(fit, file=) 	create postscript plot of decision tree&lt;br /&gt;
 # In trees created by rpart(), move to the LEFT branch when the stated condition is true.&lt;br /&gt;
&lt;br /&gt;
===Pruning Trees===&lt;br /&gt;
&lt;br /&gt;
 #In general, trees should be pruned back to avoid overfitting the data. The tree size should minimize the cross-#validated error – xerror column printed by printcp(). Pruning the tree is accomplished by:&lt;br /&gt;
 prune(fit, cp= )&lt;br /&gt;
 # use printcp( ) to examine the cross-validation error results, select the complexity parameter (CP) associated with minimum error, and insert the CP it into the prune() function. This (automatically selecting the complexity  parameter associated with the smallest cross-validated error) can be done succinctly by:&lt;br /&gt;
 fit$\$$cptable[which.min(fit$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===Compete Dataset for N-of-1 Example===&lt;br /&gt;
[[SMHS_MethodsHeterogeneity_CER_Nof1|This N-of-1 Dataset]] includes an example.&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_CER}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16067</id>
		<title>SMHS MethodsHeterogeneity CER</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_CER&amp;diff=16067"/>
		<updated>2016-05-19T19:00:40Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Case-Study 1: The Cetuximab Study */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Comparative Effectiveness Research (CER) ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
==Observational Studies: Tips for the CER Practitioners==&lt;br /&gt;
&lt;br /&gt;
•	Different study types can offer different understandings; neither should be discounted without closer examination.&lt;br /&gt;
&lt;br /&gt;
•	RCTs provide an accurate understanding of the effect of a particular intervention in a well-defined patient group under “controlled” circumstances.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies provide an understanding of real-world care and its impact, but can be biased due to uncontrolled factors.&lt;br /&gt;
&lt;br /&gt;
•	Observational studies differ in the types of databases used. These databases may lack clinical detail and contain incomplete or inaccurate data.&lt;br /&gt;
&lt;br /&gt;
•	Before accepting the findings from an observational study, consider whether confounding factors may have influenced the results.&lt;br /&gt;
&lt;br /&gt;
•	In this scenario, subgroup analysis was vital in clarifying both study designs; what is true for the many (e.g., overall, estrogen appeared to be detrimental) may not be true for the few (e.g., that for the younger post-menopausal woman, the benefits were greater and the harms less frequent).&lt;br /&gt;
&lt;br /&gt;
•	Carefully examine the generalizability of the study. Do the study’s patients and intervention match those under consideration?&lt;br /&gt;
&lt;br /&gt;
•	Observational studies can identify associations but cannot prove cause-and-effect relationships.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 1: The Cetuximab Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done and what was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cetuximab, an anti-epidermal growth factor receptor (EGFR) agent, has recently been added to the therapeutic armamentarium.  Two important CRTs examined its impact in patients with mCRC (metastatic-stage Colorectal cancer). In the first one, 56 centers in 11 European countries investigated the outcomes associated with cetuximab therapy in 329 mCRC patients who experienced disease progression either on irinotecan therapy or within 3 months thereafter. The study reported that the group on a combination of irinotecan and cetuximab had a significantly higher rate of overall response to treatment (primary endpoint) than the group on cetuximab alone: 22.9% (95% CI, 17.5-29.1%) vs. 10.8% (95% CI, 5.7-18.1%) (P=0.007), respectively. Similarly, the median time to progression was significantly longer in the combination therapy group (4.1 vs. 1.5 months, P&amp;lt;0.001). As these patients had already progressed on irinotecan prior to the study, any response was viewed as positive. Safety between the two treatment arms was similar: approximately 80% of patients in each arm experienced a rash. Grade 3 or 4 (the more severe) toxic effects on the skin were slightly more frequent in the combination-therapy group compared to cetuximab monotherapy, observed in 9.4% and 5.2% of participants, respectively. Other side effects, such as diarrhea and neutropenia observed in the combination-therapy arm, were considered to be in the range expected for irinotecan alone. Data from this study demonstrated the efficacy and safety of cetuximab and were instrumental in the FDA’s 2004 approval.&lt;br /&gt;
&lt;br /&gt;
A second CRT (2007) examined 572 patients and suggested efficacy of cetuximab in the treatment of mCRC. This study was a randomized, non-blinded, controlled trial that examined cetuximab monotherapy plus best supportive care compared to best supportive care alone in patients who had received and failed prior chemotherapy regimens. It reported that median overall survival (the primary endpoint) was significantly higher in patients receiving cetuximab plus best supportive care compared to best supportive care alone (6.1 vs. 4.6 months, respectively) (hazard ratio for death=0.77; 95% CI: 0.64- 0.92, P=0.005). This RCT described a greater incidence of adverse events in the cetuximab plus best supportive care group compared to best supportive care alone including (most significantly) rash, as well as edema, fatigue, nausea and vomiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These RCTs had fairly broad enrollment criteria and the cetuximab benefits were modest. Emerging scientific theories raised the possibility that genetically defined population subsets might experience a greater-than-average treatment benefit. One such area of inquiry entailed examining “biomarkers,” or genetic indicators of a patient’s greater response to therapy. Even as the above RCTs were being conducted, data emerged showing the importance of the KRAS gene.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the emerging biochemical evidence that the epidermal growth factor receptor (EGFR) treatment mechanism (Cetuximab,) was even more finely detailed than previously understood, the study authors of the 2007 RCT undertook a retrospective subgroup analysis using tumor tissue samples preserved from their initial study. Following laboratory analysis, all viable tissue samples were classified as having a wild-type (non-mutated) or a mutated KRAS gene. Instead of the previous two study arms (cetuximab plus best supportive care vs. best supportive care alone), there were 4 for this new analysis: each of the two original study arms was further divided by wild-type vs. mutated KRAS status. Laboratory evaluation determined that 40.9% and 42.3% of all patients in the RCT had a KRAS mutation in the cetuximab plus best supportive care group compared to the best supportive care group alone, respectively. The efficacy of cetuximab was found to be significantly correlated with KRAS status: in patients with wild-type (non-mutated). KRAS genes, cetuximab plus best supportive care compared to best supportive care alone improved overall survival (median 9.5 vs. 4.8 months, respectively; hazard ratio  for death=0.55; 95% CI, 0.41-0.74, P&amp;lt;0.001), and progression-free survival (median 3.7 vs. 1.9 months, respectively; hazard ratio for progression or death=0.40; 95% CI, 0.30-0.54, P&amp;lt;0.001). Meanwhile, in patients with mutated KRAS tumors, the authors found no significant difference in outcome between cetuximab plus best supportive care vs. best supportive care alone.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on these and similar results from other studies, the FDA narrowed its product labeling in July 2009 to indicate that cetuximab is not recommended for mCRC patients with mutated KRAS tumors. This distinction reduces the relevant population by approximately 40%. Similarly, the American society of Clinical oncology released a provisional clinical recommendation that all mCRC patients have their tumors tested for KRAS status before receiving anti-EGFR therapy. The benefits of targeted treatment are many. Patients who previously underwent cetuximab therapy without knowing their genetic predisposition would no longer have to be exposed to the drug’s toxic effects if unnecessary, as the efficacy of cetuximab is markedly higher in the genetically defined appropriate patients. In a less-uncertain environment, clinicians can be more confident in advocating a course of action in their care of patients. And finally, knowledge that targeted therapy is possible suggests the potential for further innovation in treatment options. In fact, research continues to demonstrate options for targeted cetuximab treatment of mCRC at an even finer scale than seen with KRAS; and similar genetic targeting is being investigated, and advocated, in other cancer types.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are generally viewed as the gold standard, results of one or even a series of trials may not accurately reflect the benefits experienced by an individual patient.  This case-study suggests that cetuximab initially appeared to have rather modest clinical benefits. Albeit, new information that became available and subsequent genetic subgroup assessments led to very different conclusions. Clinicians should be aware that the current knowledge is likely to evolve and any decisions about patient care should be carefully considered with that sense of uncertainty in mind. As in this case study, subgroup analyses (e.g., genetic subtypes) need a theoretical rationale. Ideally, the analyses should be determined at the time of original RCT design and should not just occur as explorations of the subsequent data. When improperly employed, post hoc analyses may lead to incorrect patient care conclusions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RCTs Tips for the CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
o	RCTs can determine whether an intervention can provide benefit in a very controlled environment.&lt;br /&gt;
&lt;br /&gt;
o	The controlled nature of an RCT may limit its generalizability to a broader population.&lt;br /&gt;
&lt;br /&gt;
o	No results are permanent; advances in scientific knowledge and understanding can influence how we view the effectiveness (or safety) of a therapeutic intervention.&lt;br /&gt;
&lt;br /&gt;
o	Targeted therapy illuminated by carefully thought out subgroup analyses can improve the efficacious and safe use of an intervention.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 2: The Rosiglitazone Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-analysis&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Often the results for the same intervention differ across clinical trials and it may not be clear whether one therapy provides more benefit than another. As CER increases and more studies are conducted, clinicians and policymakers are more likely to encounter this scenario. In a systematic review, a researcher identifies similar studies and displays their results in a table, enabling qualitative comparisons across the studies. With a meta-analysis, the data from included studies are statistically combined into a single “result.” Merging the data from a number of studies increases the effective sample size of the investigation, providing a statistically stronger conclusion about the body of research. By so doing, investigators may detect low frequency events and demonstrate more subtle distinctions between therapeutic alternatives.&lt;br /&gt;
&lt;br /&gt;
When studies have been properly identified and combined, the meta-analysis produces a summary estimate of the findings and a confidence interval that can serve as a benchmark in medical opinion and practice. However, when done incorrectly, the quantitative and statistical analysis can create impressive “numbers” but biased results. The following are important criteria for properly conducted meta-analyses:&lt;br /&gt;
&lt;br /&gt;
1.	Carefully defining unbiased inclusion or exclusion criteria for study selection&lt;br /&gt;
&lt;br /&gt;
2.	Including only those studies that have similar design elements, such as patient population, drug regimen, outcomes being assessed, and time-frame&lt;br /&gt;
&lt;br /&gt;
3.	Applying correct statistical methods to combine and analyze the data&lt;br /&gt;
&lt;br /&gt;
Reporting this information is essential for the reader to determine whether the data were suitable to combine, and if the meta-analysis draws unbiased conclusions. Meta-analyses of randomized clinical trials are considered to be the highest level of medical evidence as they are based upon a synthesis of rigorously controlled trials that systematically reduce bias and confounding. This technique is useful in summarizing available evidence and will likely become more common in the era of publicly funded comparative effectiveness research. The following case study will examine several key principles that will be useful as the reader encounters these publications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Application&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Heart disease is the leading cause of mortality in the United States, resulting in approximately 20% of all deaths. Diabetics are particularly susceptible to heart disease, with more than 65% of deaths attributable to it. The nonfatal complications of diabetes are wide-ranging and include kidney failure, nerve damage, amputation, stroke and blindness, among other outcomes. In 2007, the total estimated cost of diabetes in the United States was $174B; $116B was derived from direct medical expenditures and the rest from the indirect cost of lost productivity due to the disease. With such serious health effects and heavy direct and indirect costs tied to diabetes, proper disease management is critical. Historically, diabetes treatment has focused on strict blood sugar control, assuming that this goal not only targets diabetes but also reduces other serious comorbidities of the disease.&lt;br /&gt;
&lt;br /&gt;
Anti-diabetic agents have long been associated with key questions as to their benefits/risks in the treatment of diabetes. The sulfonylurea tolbutamide, a first generation anti-diabetic drug, was found in a landmark study in the 1970s to significantly increase the CV mortality rate compared to patients not on this agent. Further analysis by external parties concluded that the methods employed in this trial were significantly flawed (e.g., use of an “arbitrary” definition of diabetes status, heterogeneous baseline characteristics of the populations studied, and incorrect statistical methods). Since these early studies, CV concerns continue to be an issue with selected oral hypoglycemic agents that have subsequently entered the marketplace.&lt;br /&gt;
&lt;br /&gt;
A class of drugs, thiazolidinedione (TZD), was approved in the late 1990s, as a solution to the problems associated with the older generation of sulfonylureas. Rosiglitazone, a member of the TZD class, was approved by the FDA in 1999 and was widely prescribed for the treatment of type-2 diabetes. A number of RCTs supported the benefit of rosiglitazone as an important new oral antidiabetic agent. However, safety concerns developed as the FDA received reports of adverse cardiac events potentially associated with rosiglitazone. It was in this setting that a meta-analysis by Nissen and Wolski was published in the New England Journal of Medicine in June 2007.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nissen and Wolski conducted a meta-analysis examining the impact of rosiglitazone on cardiac events and mortality compared to alternative therapeutic approaches. The study began with a broad search to locate potential studies for review. The authors screened published phase II, III, and IV trials; the FDA website; and the drug manufacturer’s clinical-trial registry for applicable data relating to rosiglitazone use. When the initial search was complete, the studies were further categorized by pre-stated inclusion criteria. Meta-analysis inclusion criteria were simple: studies had to include rosiglitazone and a randomized comparator group treated with either another drug or placebo, study arms had to show similar length of treatment, and all groups had to have received more than 24 weeks of exposure to the study drugs. The studies had to contain outcome data of interest including the rate of myocardial infarction (MI) or death from all CV causes. Out of 116 studies surveyed by the authors, 42 met their inclusion criteria and were included in the meta-analysis. Of the studies they included, 23 had durations of 26 weeks or less, and only five studies followed patients for more than a year. Until this point, the study’s authors were following a path similar to that of any reviewer interested in CV outcomes, examining the results of these 42 studies and comparing them qualitatively. Quantitatively combining the data, however, required the authors to make choices about the studies they could merge and the statistical methods they should apply for analysis. Those decisions greatly influenced the results that were reported.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the studies were combined, the meta-analysis contained data from 15,565 patients in the rosiglitazone group and 12,282 patients as comparators. Analyzing their data, the authors chose one particular statistical method (the Peto odds ratio method, a fixed-effect statistical approach), which calculates the odds of events occurring where the outcomes of interest are rare and small in number. In comparing rosiglitazone with a “control” group that included other drugs or placebo, the authors reported odds ratios of 1.43 (95% CI, 1.03-1.98; P=0.03) and 1.64 (95% CI,&lt;br /&gt;
0.98-2.74; P=0.06) for MI and death from CV causes, respectively. In other words, the odds of an MI or death from a CV cause are higher for rosiglitazone patients than for patients on other therapies or placebo. The authors reported that rosiglitazone was significantly associated with an increase in the risk of MI and had borderline significance in increasing the risk of death from all CV causes. These findings appeared online on the same day that the FDA issued a safety alert regarding rosiglitazone. Discussion of the meta-analysis was immediately featured prominently in the news media. By December 2007, prescription claims for the drug at retail pharmacies had fallen by more than 50%.&lt;br /&gt;
&lt;br /&gt;
As diabetic patients and their clinicians reacted to the news, a methodologic debate also ensued. This discussion included statistical issues pertaining to the conduct of the analysis, its implications for clinical care, and finally the FDA and drug manufacturer’s roles in overseeing and regulating rosiglitazone. The concern among patients with diabetes regarding treatment, continues in the medical community today.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should the studies have been combined? Commentators faulted the authors for including several studies that were not originally intended to investigate diabetes, and for combining both placebo and drug therapy data into one comparator arm. Some critics noted that despite the stated inclusion criteria, some data were derived from studies where the rosiglitazone arm was allowed a longer follow-up than the comparator arm. By failing to account for this longer follow-up period, commentators felt that the authors may have overestimated the effect of rosiglitazone on CV outcomes. Many reviewers were concerned that this meta-analysis excluded trials in which no patients suffered an MI or died from CV causes – the outcomes of greatest interest. Some reviewers also noted that the exclusion of zero-event trials from the pooled dataset not only gave an incomplete picture of the impact of rosiglitazone but could have increased the odds ratio estimate. In general, the pooled dataset was criticized by many for being a faulty microcosm of the information available regarding rosiglitazone.&lt;br /&gt;
&lt;br /&gt;
It is essential that a meta-analysis be based on similarity in the data sources. If studies differ in important areas such as the patient populations, interventions, or outcomes, combining their data may not be suitable. The researchers accepted studies and populations that were clinically heterogeneous, yet pooled them as if they were not. The study reported that the results were combined from a number of trials that were not initially intended to investigate CV outcomes. Furthermore, the available data did not allow for time-to-event analysis, an essential tool in comparing the impact of alternative treatment options. Reviewers considered the data to be insufficiently homogeneous, and the line of cause and effect to be murkier than the authors described.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Were the statistical methods optimal?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The statistical methods for this meta-analysis also came under significant criticism. The critiques focused on the authors’ use of the Peto method as being an incorrect choice because data were pooled from both small and very large studies, resulting in a potential overestimation of treatment effect. Others reviewers pointed that the Peto method should not have been used, as a number of the underlying studies did not have patients assigned equally to rosiglitazone and comparator groups. Finally, critics suggested that the heterogeneity of the included studies required an altogether different set of analytic techniques.&lt;br /&gt;
&lt;br /&gt;
Demonstrating the sensitivity of the authors’ initial analysis to the inclusion criteria and statistical tests used, a number of researchers reworked the data from this study. one researcher used the same studies but analyzed the data with a more commonly used statistical method (Mantel-Haenszel), and found no significant increase in the relative risk or common odds ratio with MI or CV death. When the pool of studies was expanded to include those originally eliminated because they had zero CV events, the odds ratios for MI and death from CV causes dropped from 1.43 to 1.26 (95% CI, 0.93-1.72) and from 1.64 to 1.14 (95% CI, 0.74-1.74), respectively. Neither of the recalculated odd ratios were significant for MI or CV death. Finally, several newer long-term studies have been published since the Nissen meta-analysis. Incorporating their results with the meta-analysis data showed that rosiglitazone is associated with an increased risk of MI but not of CV death. Thus, the findings from these meta-analyses varied with the methods employed, the studies included, and the addition of later trials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controversy surrounding the rosiglitazone meta-analysis authored by Nissen and Wolski forced an unplanned interim analysis of a long-term, randomized trial investigating the CV effects of rosiglitazone among patients with type 2 diabetes. The authors of the RECORD trial noted that even though the follow-up at 3.75 years was shorter than expected, rosiglitazone, when added to standard glucose-lowering therapy, was found to be associated with an increase in the risk of heart failure but was not associated with any increase in death from CV or other causes. Data at the time were found to be insufficient to determine the effect of rosiglitazone on an increase in the risk of MI. the final report of that trial, published in June 2009, confirmed the elevated risk of heart failure in people with type 2 diabetes treated with rosiglitazone in addition to glucose-lowering drugs, but continued to show inconclusive results about the effect of the drug therapy on the risk of MI. Further, the RECORD trial clarified that rosiglitazone does not result in an increased risk of CV morbidity or mortality compared to standard glucose-lowering drugs. Other trials conducted since the publishing of the meta-analysis have corroborated these results, casting further doubt on the findings of the meta-analysis published by Nissen and Wolski.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Now what?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some sources suggest that the original Nissen meta-analysis delivered more harm than benefit, and that a well-recognized medical journal may have erred in its process of peer review. Despite this criticism, it is important to note that subsequent publications support the risk of adverse CV events associated with rosiglitazone, although rosiglitazone use does not appear to increase deaths. These results and emerging data point to the need for further rigorous research to clarify the benefits and risks of rosiglitazone on a variety of outcomes, and the importance of directing the drug to the population that will maximally benefit from its use.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this Case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results from initial randomized trials that seem definitive at one time may not be conclusive, as further trials may emerge to clarify, redirect, or negate previously accepted results. A meta-analysis of those trials can lead to varying results based upon the timing of the analysis and the choices made in its performance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Meta-Analysis: Tips for CER Practitioners&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
o	The results of a meta-analysis are highly dependent on the studies included (and excluded). Are these criteria properly defined and relevant to the purposes of the meta-analysis? Were the combined studies sufficiently similar? Can results from this cohort be generalized to other populations of interest?&lt;br /&gt;
&lt;br /&gt;
o	The statistical methodology can impact study results. Have there been reviews critiquing the methods used in the meta-analysis?&lt;br /&gt;
&lt;br /&gt;
o	A variety of statistical tests should be considered, and perhaps reported, in the analysis of results. Do the authors mention their rationale in choosing a statistical method? Do they show the stability of their results across a spectrum of analytical methods?&lt;br /&gt;
&lt;br /&gt;
o	Nothing is permanent. Emerging data may change the playing field, and meta- analysis results are only as good as the data and statistics from which they are derived.&lt;br /&gt;
&lt;br /&gt;
===Case-Study 3: The Nurses’ Health Study===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;An observational study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An observational study is a very common type of research design in which the effects of a treatment or condition are studied without formally randomizing patients in an experimental design. Such studies can be done prospectively, wherein data are collected about a group of patients going forward in time; or retrospectively, in which the researcher looks into the past, mining existing databases for data that have already been collected. Latter studies are frequently performed by using an electronic database that contains, for example, administrative, “billing,” or claims data. Less commonly, observational research uses electronic health records, which have greater clinical information that more closely resembles the data collected in an RCT. Observational studies often take place in “real- world” environments, which allow researchers to collect data for a wide array of outcomes. Patients are not randomized in these studies, but the findings can be used to generate hypotheses for investigation in a more constrained experimental setting. Perhaps the best known observational study is the “Framingham study,” which collected demographic and health data for a group of individuals over many years (and continues to do so) and has provided an understanding of the key risk factors for heart disease and stroke.&lt;br /&gt;
&lt;br /&gt;
Observational studies present many advantages to the comparative effectiveness researcher. the study design can provide a unique glimpse of the use of a health care intervention in the “real world,” an essential step in gauging the gap between efficacy (can a treatment work in a controlled setting?) and effectiveness (does the treatment work in a real-life situation?). Furthermore, observational studies can be conducted at low cost, particularly if they involve the secondary analysis of existing data sources. CER often uses administrative databases, which are based upon the billing data submitted by providers during routine care. These databases typically have limited clinical information, may have errors in them, and generally do not undergo auditing.&lt;br /&gt;
&lt;br /&gt;
The uncontrolled nature of observational studies allows them to be subject to bias and confounding. For example, doctors may prescribe a new medication only for the sickest patients. Comparing these outcomes (without careful statistical adjustment) with those from less ill patients receiving alternative treatment may lead to misleading results. Observational studies can identify important associations but cannot prove cause and effect. These studies can generate hypotheses that may require RCTs for fuller demonstration of those relationships. Secondary analysis can also be problematic if researchers overwork datasets by doing multiple exploratory analyses (e.g., data-dredging): the more we look, the more we find, even if those findings are merely statistical aberrations. Unfortunately, the growing need for CER and the wide availability of administrative databases may lead to selection of research of poor quality with inaccurate findings.&lt;br /&gt;
&lt;br /&gt;
In comparative effectiveness research, observational studies are typically considered to be less conclusive than RCTs and meta-analyses. Nonetheless, they can be useful, especially because they examine typical care. Due to lower cost and improvements in health information, observational studies will become increasingly common. Critical assessment of whether the described results are helpful or biased (based upon how the study was performed) are necessary. This case will illustrate several characteristics of the types of studies that will assist in evaluating newly published work. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Clinical Applications&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cardiovascular diseases (CVD) are the leading cause of death in women older than   the age of 50. Epidemiologic evidence suggests that estrogen is a key mediator in the development of CVD. Estrogen is an ovarian hormone whose production decreases as women approach menopause. The steep increase in CVD in women at menopause and older and in women who have had hysterectomies further supports a relationship between estrogen and CVD. Building on this evidence of biologic plausibility, epidemiological and observational studies suggested that estrogen replacement therapy (a form of &amp;lt;b&amp;gt;hormone replacement therapy&amp;lt;/b&amp;gt;, or HRT) had positive effects on the risk of CVD in postmenopausal women, (albeit with some negative effects in its potential to increase the risk for breast cancer and stroke).65 Based on these findings, in the 1980s and 1990s HRT was routinely employed to treat menopausal symptoms and serve as prophylaxis against CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was done?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Nurses’ Health Study (NHS) began collecting data in 1976. In the study, researchers intended to examine a broad range of health effects in women over a long period of time, and a key goal was to clarify the role of HRT in heart disease. The cohort (i.e., the group being followed) included married registered nurses aged 30-55 in 1976 who lived in the 11 most populous states. To collect data, the researchers mailed the study participants a survey every 2 years that asked questions about topics such as smoking, hormone use, menopausal status, and less frequently, diet. Data were collected for key end points that included MI, coronary-artery bypass grafting or angioplasty, stroke, total CVD mortality, and deaths from all causes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What was found?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a 10-year follow-up point, the NHS had a study pool of 48,470 women. The researchers found that estrogen use (alone, without progestin) in postmenopausal women was associated with a reduction in the incidence of CVD as well as in CVD mortality compared to non-users. Later, estrogen-progestin combination therapy was shown to be even more cardioprotective than estrogen monotherapy, and lower doses of estrogen replacement therapy were found to deliver equal cardioprotection and lower the risk for adverse events. NHS researchers were alert to the potential for bias in observational studies. Adjustment for risk factors such as age (a typical practice to eliminate confounding) did not change the reported findings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Was this the right answer?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NHS was not unique in reporting the benefits associated with HRT; other observational studies corroborated the NHS findings. A secondary retrospective data analysis of the UK primary care electronic medical record database, for example, also showed the protective effect associated with HRT use. Researchers were aware of the fundamental limitations of observational studies, particularly with regard to selection bias. They and practicing clinicians were also aware of the potential negative health effects of HRT, which had to be constantly weighed against the potential cardioprotective benefits in deciding a patient’s course of treatment. As a large section of the population could experience the health effects of HRT, researchers began planning RCTs to verify the promising observational study results. It was highly anticipated that those RCTs would corroborate the belief that estrogen replacement can reduce CVD risk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Randomized Controlled Trial: The Women’s Health Initiative&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Women’s health Initiative (WHI) was a major study established by the National Institutes of health in 1992 to assess a broad range of health effects in postmenopausal women. The trial was intended to follow these women for 8 years, at a cost of millions of dollars in federal funding. Among its many facets, it included an RCT to confirm the results from the observational studies discussed above. To fully investigate earlier findings, the WHI had two subgroups. One subgroup consisted of women with prior hysterectomies; they received estrogen monotherapy. The second group consisted of women who had not undergone hysterectomy; they received estrogen in combination with progestin. The WHI enrolled 27,347 women in their HRT investigation: 10,739 in the estrogen-alone arm and 16,608 in the estrogen plus progestin arm. Within each arm, women were randomly assigned to receive either HRT or placebo. All women in the trial were postmenopausal and aged 50-79 years; the mean age was 63.6 years (a fact that would be important in later analysis). Some participants had experienced previous CV events. The primary outcome of both subgroups was coronary heart disease (CHD), as described by nonfatal MI or death due to CHD.&lt;br /&gt;
&lt;br /&gt;
The estrogen-progestin arm of the WHI was halted after a mean follow-up of 5.2 years, 3 years earlier than expected, as the HRT users in this arm were found to be at increased risk for CHD compared to those who received placebo. The study also noted elevated rates of breast cancer and stroke, among other poor outcomes. The estrogen-alone arm continued for an average follow-up of 6.8 years before being similarly discontinued ahead of schedule. Although this part of the study did not find an increased risk of CHD, it also did not find any cardioprotective effect. Beyond failing to locate any clear CV benefits, the WHI also found real evidence of harm, including increased risk of blood clots, breast cancer and stroke. Initial WHI publications therefore recommended against HRT being prescribed for the secondary prevention of CVD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;What Next?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scientists and the clinicians who relied on their data for guidance in treating patients, were faced with conflicting data: epidemiological and observational studies suggested that HRT was cardioprotective while the higher-quality evidence from RCTs strongly suggested the opposite. Clinicians primarily followed the WHI results, so prescriptions for HRT in postmenopausal women quickly declined. Meanwhile, researchers began to analyze the studies for potential discrepancies, and found that the women being followed in the NHS and the WHI differed in several important characteristics.&lt;br /&gt;
&lt;br /&gt;
First, the WHI population was older than the NHS cohort, and many had entered menopause at least 10 years before they enrolled in the RCT. Thus, the WHI enrollees experienced a long duration from the onset of menopause to the commencement of HRT. At the same time, many in the NHS population were closer to the onset of menopause and were still displaying hormonal symptoms when they began HRT. Second, although the NHS researchers adjusted the data for various confounding effects, their results could still have been subject to bias. In general, the NHS cohort was more highly educated and of a higher socioeconomic status than the WHI participants, and therefore more likely to see a physician regularly. The NHS women were also leaner and generally healthier than their RCT counterparts, and had been selected for their evident lack of pre-existing CV conditions. This selection bias in the NHS enrollment may have led to a “healthy woman” effect that in turn led to an overestimation of the benefits of therapy in the observational study. Third, researchers noted that dosing differences between the two study types may have contributed to the divergent results. The NHS reported beneficial results following low-dose estrogen therapy. The WHL, meanwhile, used a higher estrogen dose, exposing women to a larger dosage of hormones and increasing their risk for adverse events. The increased risk profile of the WHI women (e.g., older, more comorbidities, higher estrogen dose) could have contributed to the evidence of harm seen in the WHI results.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Emerging Data&amp;lt;/b&amp;gt;&lt;br /&gt;
In addition to identifying the inherent differences between the two study populations, researchers began a secondary analysis of the NHS and WHI trials. NHS researchers reported that women who began HRT close to the onset of menopause had a significantly reduced risk of CHD. In the subgroups of women that were older and had a similar duration after menopause compared with the WHI women, they found no significant relationship between HRT and CHD. Also, the WHI study further stratified these results by age, and found that women who began HRT close to their onset of menopause experienced some cardioprotection, while women who were further from the onset of menopause had a slightly elevated risk for CHD.&lt;br /&gt;
&lt;br /&gt;
Secondary analysis of both studies was therefore necessary to show that age and a short duration from the onset of menopause are crucial to HRT success as a cardioprotective agent. Neither study type provided “truth” or rather, both studies provided “truth” if viewed carefully (e.g., both produced valid and important results). The differences seen in the studies were rooted in the timing of HRT and the populations being studied.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Lessons Learned From this case Study&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although RCTs are given a higher evidence grade, observational studies provide important clinical insights. In this example, the study populations differed. For policymakers and clinicians, it is crucial to examine whether the CER was based upon patients similar to those being considered. Any study with a dissimilar population may provide non-relevant results. Thus, readers of CER need to carefully examine the generalizability of the findings being reported.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
General Classification and Regression Tree (CART) data analysis steps part of the R package &amp;lt;b&amp;gt;rpart.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Growing the Tree===&lt;br /&gt;
&lt;br /&gt;
 # To grow a tree, use&lt;br /&gt;
 rpart(formula, data=, method=,control=), where&lt;br /&gt;
 formula 	is in the format outcome ~ predictor1+predictor2+...&lt;br /&gt;
 data= 	specifies the data frame&lt;br /&gt;
 method= 	&amp;quot;class&amp;quot; for a classification tree, use &amp;quot;anova&amp;quot; for a regression tree&lt;br /&gt;
 control= 	optional parameters for controlling tree growth. For example, control=rpart.control(minsplit=30, cp=0.001) requires that the minimum number of observations in a node be 30 before attempting a split and that a split      must decrease the overall lack of fit by a factor of 0.001 (cost complexity factor) before being attempted.&lt;br /&gt;
&lt;br /&gt;
===Examining Results===&lt;br /&gt;
&lt;br /&gt;
 # These functions help with examining the results.&lt;br /&gt;
 printcp(fit) 	display complexity parameter (cp) table&lt;br /&gt;
 plotcp(fit) 	plot cross-validation results&lt;br /&gt;
 rsq.rpart(fit) 	plot approximate R-squared and relative error for different splits (2 plots). labels are only appropriate for the &amp;quot;anova&amp;quot; method.&lt;br /&gt;
 print(fit) 		print results&lt;br /&gt;
 summary(fit) 	detailed results including surrogate splits&lt;br /&gt;
 plot(fit) 		plot decision tree&lt;br /&gt;
 text(fit) 		label the decision tree plot&lt;br /&gt;
 post(fit, file=) 	create postscript plot of decision tree&lt;br /&gt;
 # In trees created by rpart(), move to the LEFT branch when the stated condition is true.&lt;br /&gt;
&lt;br /&gt;
===Pruning Trees===&lt;br /&gt;
&lt;br /&gt;
 #In general, trees should be pruned back to avoid overfitting the data. The tree size should minimize the cross-#validated error – xerror column printed by printcp(). Pruning the tree is accomplished by:&lt;br /&gt;
 prune(fit, cp= )&lt;br /&gt;
 # use printcp( ) to examine the cross-validation error results, select the complexity parameter (CP) associated with minimum error, and insert the CP it into the prune() function. This (automatically selecting the complexity  parameter associated with the smallest cross-validated error) can be done succinctly by:&lt;br /&gt;
 fit$\$$cptable[which.min(fit$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===Compete Dataset for N-of-1 Example===&lt;br /&gt;
[[SMHS_MethodsHeterogeneity_CER_Nof1|This N-of-1 Dataset]] includes an example.&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_CER}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_MetaAnalysis&amp;diff=16036</id>
		<title>SMHS MethodsHeterogeneity MetaAnalysis</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_MetaAnalysis&amp;diff=16036"/>
		<updated>2016-05-19T15:57:39Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Series of “N of 1” trials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Meta-Analyses ==&lt;br /&gt;
&lt;br /&gt;
==Meta-analysis==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Meta-analysis is an approach to combine treatment effects across trials or studies into an aggregated treatment effect with higher statistical power than observed in each individual trials. It may detect HTE by testing for differences in treatment effects across similar RCTs. It requires that the individual treatment effects are similar to ensure pooling is meaningful. In the presence of large clinical or methodological differences between the trials, it may be to avoid meta-analyses. The presence of HTE across studies in a meta-analysis may be due to differences in the design or execution of the individual trials (e.g., randomization methods, patient selection criteria). &amp;lt;b&amp;gt;Cochran's Q is a methods for detection of heterogeneity, which is computed as the weighted sum of squared differences between each study's treatment effect and the pooled effects across the studies.&amp;lt;/b&amp;gt; It is a barometer of inter-trial differences impacting the observed study result.  A possible source of error in a meta-analysis is publication bias. Trial size may introduce publication bias since larger trials are more likely to be published. Language and accessibility represent other potential confounding factors. When the heterogeneity is not due to poor study design, it may be useful to optimize the treatment benefits for different cohorts of participants.	&lt;br /&gt;
&lt;br /&gt;
Cochran's Q statistics is the weighted sum of squares on a standardized scale. &amp;lt;b&amp;gt;The corresponding P value indicates the strength of the evidence of presence of heterogeneity.&amp;lt;/b&amp;gt; This test may have low power to detect heterogeneity sometimes and it is suggested to use a value of 0.10 as a cut-off for significance (Higgins et al., 2003). The Q statistics also may have too much power as a test of heterogeneity when the number of studies is large.&lt;br /&gt;
&lt;br /&gt;
===Simulation Example 1===&lt;br /&gt;
&lt;br /&gt;
 # Install and Load library&lt;br /&gt;
 install.packages(&amp;quot;meta&amp;quot;)&lt;br /&gt;
 library(meta)&lt;br /&gt;
 &lt;br /&gt;
 # Set number of studies&lt;br /&gt;
 n.studies = 15&lt;br /&gt;
 &lt;br /&gt;
 # number of treatments: case1, case2, control&lt;br /&gt;
 n.trt = 3&lt;br /&gt;
 &lt;br /&gt;
 # number of outcomes&lt;br /&gt;
 n.event = 2&lt;br /&gt;
 &lt;br /&gt;
 # simulate the (balanced) number of cases (case1 and case2) and controls in each study&lt;br /&gt;
 ctl.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
 case1.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
 case2.group = rbinom(n = n.studies, size = 200, prob = 0.3)&lt;br /&gt;
&lt;br /&gt;
 # Simulate the number of outcome events (e.g., deaths) and no events in the control group&lt;br /&gt;
 event.ctl.group = rbinom(n = n.studies, size = ctl.group, prob = rep(&amp;lt;mark&amp;gt;0.1&amp;lt;/mark&amp;gt;, length(ctl.group)))&lt;br /&gt;
 noevent.ctl.group = ctl.group - event.ctl.group&lt;br /&gt;
 &lt;br /&gt;
 # Simulate the number of events and no events in the case1 group&lt;br /&gt;
 event.case1.group = rbinom(n = n.studies, size = case1.group, prob = rep(&amp;lt;mark&amp;gt;0.5&amp;lt;/mark&amp;gt;, length(case1.group)))&lt;br /&gt;
 noevent.case1.group = case1.group - event.case1.group&lt;br /&gt;
&lt;br /&gt;
 # Simulate the number of events and no events in the case2 group&lt;br /&gt;
 event.case2.group = rbinom(n = n.studies, size = case2.group, prob = rep(&amp;lt;mark&amp;gt;0.6&amp;lt;/mark&amp;gt;, length(case2.group)))&lt;br /&gt;
 noevent.case2.group = case2.group - event.case2.group&lt;br /&gt;
&lt;br /&gt;
 # Run the univariate meta-analysis using &amp;lt;b&amp;gt;metabin()&amp;lt;/b&amp;gt;, Meta-analysis of binary outcome data – &lt;br /&gt;
 # Calculation of fixed and random effects estimates (risk ratio, odds ratio, risk difference or arcsine&lt;br /&gt;
 # difference) for meta-analyses with binary outcome data.   Mantel-Haenszel (MH), &lt;br /&gt;
 #  inverse variance and Peto method are available for pooling.&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;method&amp;lt;/b&amp;gt; = A character string indicating which method is to be used for pooling of studies. &lt;br /&gt;
 # one of &amp;quot;MH&amp;quot; , &amp;quot;Inverse&amp;quot; , or &amp;quot;Cochran&amp;quot;&lt;br /&gt;
 # sm = A character string indicating which summary measure (“OR”, &amp;quot;RR&amp;quot; &amp;quot;RD&amp;quot;=risk difference) is to be &lt;br /&gt;
 # used for pooling of studies&lt;br /&gt;
&lt;br /&gt;
 # Control vs. Case1, n.e and n.c are numbers in experimental and control groups&lt;br /&gt;
 meta.ctr_case1 &amp;lt;- metabin(event.e = &amp;lt;b&amp;gt;event.case1.group&amp;lt;/b&amp;gt;, n.e = case1.group, event.c = &amp;lt;b&amp;gt;event.ctl.group&amp;lt;/b&amp;gt;, &lt;br /&gt;
 n.c = ctl.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 # in this case we use Odds Ratio, of the odds of death in the experimental and control studies&lt;br /&gt;
 forest(meta.ctr_case1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Control vs. Case2&lt;br /&gt;
 meta.ctr_case2 &amp;lt;- metabin(event.e = event.case2.group, n.e = case2.group, event.c = event.ctl.group, &lt;br /&gt;
 n.c = ctl.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 forest(meta.ctr_case2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Case1 vs. Case2&lt;br /&gt;
 meta.case1_case2 &amp;lt;- metabin(event.e = event.case1.group, n.e = case1.group, event.c = event.case2.group, &lt;br /&gt;
 n.c = case2.group, method = &amp;quot;MH&amp;quot;, sm = &amp;quot;OR&amp;quot;)&lt;br /&gt;
 forest(meta.case1_case2)&lt;br /&gt;
 summary(meta.case1_case2)&lt;br /&gt;
&lt;br /&gt;
 Test of heterogeneity:&lt;br /&gt;
     Q 	d.f.  	p-value&lt;br /&gt;
 11.99   	14   	0.6071&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;forest plo&amp;lt;/b&amp;gt;t shows the I2 test indicates the evidence to reject the null hypothesis (no study heterogeneity and the fixed effects model should be used).&lt;br /&gt;
&lt;br /&gt;
==Series of “N of 1” trials==&lt;br /&gt;
&lt;br /&gt;
This technique combines (a “series of”) n-of-1 trial data to identify HTE. An n-of-1 trial is a repeated crossover trial for a single patient, which randomly assigns the patient to one treatment vs. another for a given time period, after which the patient is re-randomized to treatment for the next time period, usually repeated for 4-6 time periods. Such trials are most feasibly done in chronic conditions, where little or no washout period is needed between treatments and treatment effects are identifiable in the short-term, such as pain or reliable surrogate markers. Combining data from identical n-of-1 trials across a set of patients enables the statistical analysis controlling for patient fixed or random effects, covariates, centers, or sequence effects, see &amp;lt;b&amp;gt;Figure&amp;lt;/b&amp;gt; below. These combined trials are often analyzed within a Bayesian context using shrinkage estimators that combine individual and group mean treatment effects to create a “posterior” individual mean treatment effect estimate which is a form of inverse variance-weighted average of the individual and group effects. Such trials are typically more expensive than standard RCTs on a per-patient basis, however, they require much smaller sample sizes, often less than 100 patients (due to the efficient individual-as-own-control design), and create individual treatment effect estimates that are not possible in a non-crossover design  . For the individual patient, the treatment effect can be re-estimated after each time period, and the trial stopped at any point when the more effective treatment is identified with reasonable statistical certainty.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&lt;br /&gt;
A study involving 8 participants collected data across 30 days, in which 15 treatment days and 15 control days are randomly assigned within each participant. The treatment effect is represented as a binary variable (control day=0; treatment day=1). The outcome variable represents the response to the intervention within each of the 8 participants. Study employed a fixed-effects modeling. By creating N − 1 dummy-coded variables representing the N=8 participants, where the last (i=8) participant serves as the reference (i.e., as the model intercept). So, each dummy-coded variable represents the difference between each participant (i) and the 8th participant. Thus, all other patients' values will be relative to the values of the 8th (reference) subject. The overall differences across participants in fixed effects can be evaluated with multiple &amp;lt;b&amp;gt;degree-of-freedom F-tests.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|...||...||...||...||...||...||...||...||...||...&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt; Complete data is available in the &amp;lt;b&amp;gt;Appendix.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Data Summary&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||Constant&lt;br /&gt;
|-&lt;br /&gt;
|Physical Activity||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|Intervention||Tx&lt;br /&gt;
|-&lt;br /&gt;
|WP Social Support||WPSS&lt;br /&gt;
|-&lt;br /&gt;
|PM Social Support (1-3)||PMss3&lt;br /&gt;
|-&lt;br /&gt;
|Self Efficacy||SelfEff25&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rm(list=ls())&lt;br /&gt;
 Nof1 &amp;lt;-read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q&amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)    # 02_Nof1_Data.csv&lt;br /&gt;
 attach(Nof1)&lt;br /&gt;
 head(Nof1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 df.1 = data.frame(PhyAct, Tx, WPSS, PMss3, SelfEff25) &lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;lme4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 lm.1 = model.lmer &amp;lt;- lmer(PhyAct ~ Tx + SelfEff + Tx*SelfEff + (1|Day) + (1|ID) , data= df.1)&lt;br /&gt;
 summary(lm.1)&lt;br /&gt;
&lt;br /&gt;
 Linear mixed model fit by REML ['lmerMod']&lt;br /&gt;
 Formula: PhyAct ~ Tx + SelfEff + Tx * SelfEff + (1 | Day) + (1 | ID)&lt;br /&gt;
   Data: df.1&lt;br /&gt;
&lt;br /&gt;
 REML criterion at convergence: 8820&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Scaled Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Min||1Q||Median||3Q||Max&lt;br /&gt;
|-&lt;br /&gt;
|-2.7012||-0.6833||-0.0333||0.6542||3.9612&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Random Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Groups ||Name||Variance ||Std.Dev.&lt;br /&gt;
|-&lt;br /&gt;
| Day||(Intercept) ||0.0 || 0.00   &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|ID|| (Intercept)||601.5||24.53   &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 |Residual|| ||969.0 ||31.13  &lt;br /&gt;
|}&lt;br /&gt;
Number of obs: 900, groups:  Day, 30; ID, 30&lt;br /&gt;
 &amp;lt;/center&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Estimate||Std.||Error||t value&lt;br /&gt;
|-&lt;br /&gt;
|(Intercept)||38.3772||14.4738||2.651&lt;br /&gt;
|-&lt;br /&gt;
|Tx||4.0283||6.3745||0.632&lt;br /&gt;
|-&lt;br /&gt;
|SelfEff||0.5818||0.5942||0.979&lt;br /&gt;
|-&lt;br /&gt;
|Tx:SelfEff||0.9702||0.2617||3.708&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Correlation of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||(Intr)||Tx ||SlfEff&lt;br /&gt;
|-&lt;br /&gt;
| Tx|| -0.220|| ||               &lt;br /&gt;
|-&lt;br /&gt;
| SelfEff||-0.946 ||0.208 ||     &lt;br /&gt;
|-&lt;br /&gt;
| Tx:SelfEff ||0.208 ||-0.946 ||-0.220&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Model:  PhyAct = Tx + WPSS + PMss3 + Tx*WPSS + Tx*PMss3 + SelfEff25 + Tx*SelfEff25 + ε&lt;br /&gt;
 lm.2 = lm(PhyAct ~ Tx + WPSS + PMss3 + Tx*WPSS + Tx*PMss3 + SelfEff25 + Tx*SelfEff25, df.1) &lt;br /&gt;
 summary(lm.2)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = PhyAct ~ Tx + WPSS + PMss3 + Tx * WPSS + Tx * PMss3 + &lt;br /&gt;
    SelfEff25 + Tx * SelfEff25, data = df.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Residuals&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Min||1Q||Median||3Q||Max               &lt;br /&gt;
|-&lt;br /&gt;
| -102.39||-28.24||-1.47||25.16||122.41    &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate||Std. Error||t value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||52.0067||1.8080||28.764||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|Tx||27.7366||2.5569||10.848||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|WPSS||1.9631||2.4272||0.809||0.418853 &lt;br /&gt;
|-   &lt;br /&gt;
|PMss3||13.5110||2.7853||4.851||1.45e-06 ***&lt;br /&gt;
|-&lt;br /&gt;
|SelfEff25||0.6289||0.2205||2.852||0.004439 ** &lt;br /&gt;
|-&lt;br /&gt;
|Tx:WPSS||9.9114||3.4320||2.888||0.003971 ** &lt;br /&gt;
|-&lt;br /&gt;
|Tx:PMss3||8.8422||3.9390||2.245||0.025025 *  &lt;br /&gt;
|-&lt;br /&gt;
|Tx:SelfEff25||1.0460||0.3118||3.354||0.000829 ***&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[Using SAS (StudyI_Analyses.sas, StudyIIab_Analyses.sas)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Type 3 Tests of Fixed Effects&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Effect&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Num DF&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;Den DF&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;F Value&amp;lt;/b&amp;gt;||&amp;lt;b&amp;gt;$Pr&amp;gt;F$&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Tx&amp;lt;/b&amp;gt;||1||224||67.46||&amp;lt;.0001          &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;ID&amp;lt;/b&amp;gt;||7||224||25.95||&amp;lt;.0001&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Tx*ID&amp;lt;/b&amp;gt;||7||224||2.92||0.0060&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quantile Treatment Effect (QTE)==&lt;br /&gt;
&lt;br /&gt;
QTE employs quantile regression estimation (QRE) to examine the central tendency and statistical dispersion of the treatment effect in a population. These may not be revealed by the conventional mean estimation in RCTs. For instance, patients with different comorbidity scores may respond differently to a treatment. Quantile regression has the ability to reveal HTE according to the ranking of patients’ comorbidity scores or some other relevant covariate by which patients may be ranked. Therefore, in an attempt to inform patient-centered care, quantile regression provides more information on the distribution of the treatment effect than typical conditional mean treatment effect estimation. QTE characterizes the heterogeneous treatment effect on individuals and groups across various positions in the distributions of different outcomes of interest. This unique feature has given quantile regression analysis substantial attention and has been employed across a wide range of applications, particularly when evaluating the economic effects of welfare reform.&lt;br /&gt;
&lt;br /&gt;
One caveat of applying QRE in clinical trials for examining HTE is that the QTE doesn’t demonstrate the treatment effect for a given patient. Instead, it focuses on the treatment effect among subjects within the qth quantile, such as those who are exactly at the top 10th percent in terms of blood pressure or a depression score for some covariate of interest, for example, comorbidity score. It is not uncommon for the qth quantiles to be two different sets of patients before and after the treatment. For this reason, we have to assume that these two groups of patients are homogeneous if they were in the same quantiles.&lt;br /&gt;
&lt;br /&gt;
Income-Food Expenditure Example: Let’s examine the Engel data (N=235) on the relationship between food expenditure (foodexp) and household income (income). We can plot the data and then explore the superposition of the six fitted quantile regression lines. &lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;quantreg&amp;quot;)&lt;br /&gt;
 library(quantreg)&lt;br /&gt;
 data(engel)&lt;br /&gt;
 attach(engel)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(engel)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Income||Foodexp&lt;br /&gt;
|-   &lt;br /&gt;
|1||420.1577||255.8394&lt;br /&gt;
|-&lt;br /&gt;
|2||541.4117||310.9587&lt;br /&gt;
|-&lt;br /&gt;
|3||901.1575||485.6800&lt;br /&gt;
|-   &lt;br /&gt;
|4||639.0802||402.9974&lt;br /&gt;
|-&lt;br /&gt;
|5||750.8756||495.5608&lt;br /&gt;
|-&lt;br /&gt;
|6||945.7989||633.7978&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;summary(engel)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Income||Foodexp&lt;br /&gt;
|-   &lt;br /&gt;
|Min||377.1||242.3&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.||638.9||429.7&lt;br /&gt;
|-&lt;br /&gt;
|Median||884.0||582.5&lt;br /&gt;
|-   &lt;br /&gt;
|Mean||982.5||624.2&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.||1164.0||743.9&lt;br /&gt;
|-&lt;br /&gt;
|Max||4957.8||2032.7&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: If &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt; be a real valued random variable with cumulative distribution function F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(y)=P(Y≤ y), then the τ-quantile of &amp;lt;i&amp;gt;Y&amp;lt;/i&amp;gt; is given by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; Q&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(τ)=F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;-1&amp;lt;/sup&amp;gt;(τ)=inf{ y:F&amp;lt;sub&amp;gt;Y&amp;lt;/sub&amp;gt;(y)≥τ} &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where 0≤τ≤1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (1) Graphics&lt;br /&gt;
 plot(income, foodexp, cex=.25, type=&amp;quot;n&amp;quot;, xlab=&amp;quot;Household Income&amp;quot;, ylab=&amp;quot;Food Expenditure&amp;quot;)&lt;br /&gt;
 points(income, foodexp, cex=.5, col=&amp;quot;blue&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # tau - the quantile(s) to be estimated, in the range from 0 to 1. An object &amp;quot;rq.process&amp;quot; and an object &amp;quot;rqs&amp;quot; &lt;br /&gt;
 # are returned containing the matrix of coefficient estimates at the specified quantiles.&lt;br /&gt;
 abline( rq(foodexp ~ income, tau=.5), col=&amp;quot;blue&amp;quot;)  	# Quantile Regression Model&lt;br /&gt;
&lt;br /&gt;
 abline( lm(foodexp ~ income), lty=2, lwd=3, col=&amp;quot;red&amp;quot;) 	# linear model&lt;br /&gt;
 taus &amp;lt;- c(0.05, 0.1, 0.25, 0.75, 0.90, 0.95)&lt;br /&gt;
 colors &amp;lt;- rainbow(length(taus))&lt;br /&gt;
&lt;br /&gt;
 models &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = length(taus)) # define a vector of models to store QR for diff taus&lt;br /&gt;
 model.names &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = length(taus)) # define a vector model names&lt;br /&gt;
&lt;br /&gt;
 for( i in 1:length(taus)){&lt;br /&gt;
 models[[i]] &amp;lt;-  rq(foodexp ~ income, tau=taus[i]) &lt;br /&gt;
 var &amp;lt;- taus[i]&lt;br /&gt;
 model.names[[i]] &amp;lt;- paste(&amp;quot;Model [&amp;quot;, i , &amp;quot;]: tau=&amp;quot;, var)&lt;br /&gt;
 abline( models[[i]], lwd=2, col= colors[[i]])&lt;br /&gt;
 }&lt;br /&gt;
 legend(3000, 1100, model.names, col= colors, pch= taus, bty='n', cex=.75)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # (2) Inference about quantile regression coefficients.  As an alternative to the rank-inversion confidence intervals, we can obtain a table of coefficients, standard errors, t-statistics, and p-values using the summary function:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;summary(models[[3]], se = &amp;quot;nid&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Call: rq(formula = foodexp ~ income, tau = taus[i])&lt;br /&gt;
&lt;br /&gt;
 tau: [1] 0.25&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Value||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||95.48354||21.39237||4.46344||0.00001&lt;br /&gt;
|-&lt;br /&gt;
|Income||0.47410||0.02906||16.31729||0.00000&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use summary.rq to compute bootstrapped standard errors.&lt;br /&gt;
 summary.rq(models[[3]], se = &amp;quot;nid&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 Call: rq(formula = foodexp ~ income, tau = taus[i])&lt;br /&gt;
 tau: [1] 0.25&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|||Value||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||95.48354||21.39237||4.46344||0.00001&lt;br /&gt;
|-&lt;br /&gt;
|Income||0.47410||0.02906||16.31729||0.00000&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
==Nonparametric Regression Methods ==&lt;br /&gt;
&lt;br /&gt;
Nonparametric regression enables dealing with HTE in RCTs. Different nonparametric methods, such as kernel smoothing methods and series methods, can be used to generate test statistics for examining the presence of HTE. A kernel method is a weighting scheme based on a kernel function (e.g. uniform, Gaussian). When evaluating the treatment effect of a patient in RCTs, the kernel method assigns larger weights to those observations with similar covariates. This is done because it is assumed that patients with similar covariates provide more relevant data on predicted treatment response. Examining participants that have different backgrounds (e.g., demographic, clinical), kernel smoothing methods utilize information from highly divergent participants when estimating a particular subject’s treatment effect. Lower weights are assigned to very different subjects and the kernel methods require choosing a set of smoothing parameters to group patients according to their relative degree of similarities. A drawback is that the corresponding proposed test statistics may be sensitive to the chosen bandwidths, which inhibits the interpretation of the results. Series methods use approximating functions (splines or power series of the explanatory variables) to construct test statistics. Compared to kernel smoothing methods, series methods normally have the advantage of computational convenience; however, the precision of test statistics depends on the number of terms selected in the series. &lt;br /&gt;
&lt;br /&gt;
Canadian Wage Data Example: Nonparametric regression extends the classical parametric regression (e.g., lm, lmer) involving one continuous dependent variable, y, and (1 or more) continuous explanatory variable(s), x. Let’s start with a popular parametric model of a wage equation that we can extend to a fully nonparametric regression model. First, we will compare and contrast the parametric and nonparametric approach towards univariate regression and then proceed to multivariate regression.&lt;br /&gt;
&lt;br /&gt;
Let’s use the Canadian cross-section wage data (&amp;lt;b&amp;gt;cps71&amp;lt;/b&amp;gt;) consisting of a random sample taken from the 1971 Canadian Census for male individuals having common education (High-School). N=205 observations, 2 variables, the logarithm of the individual’s wage (logwage) and their age (age). The classical wage equation model includes a quadratic term of age.&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;np&amp;quot;)&lt;br /&gt;
 library(&amp;quot;np&amp;quot;)&lt;br /&gt;
 data(&amp;quot;cps71&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (1) Linear Model -&amp;gt; R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;  = 0.2308&lt;br /&gt;
 model.lin &amp;lt;- lm( logwage ~ age + I(age^2), data = cps71)&lt;br /&gt;
 summary(model.lin)&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 lm(formula = logwage ~ age + I(age^2), data = cps71)&lt;br /&gt;
&lt;br /&gt;
 Residuals:&lt;br /&gt;
 Min      1Q  Median      3Q     Max &lt;br /&gt;
 -2.4041 -0.1711  0.0884  0.3182  1.3940 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Coefficients&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Estimate||Std. Error||t Value||$Pr(&amp;gt;|t|)$&lt;br /&gt;
|-   &lt;br /&gt;
|(Intercept)||10.0419773||0.4559986||22.022||&amp;lt; 2e-16 ***&lt;br /&gt;
|-&lt;br /&gt;
|Age||0.1731310||0.0238317|| 7.265||7.96e-12 ***&lt;br /&gt;
|-&lt;br /&gt;
|I(age^2)||-0.0019771||0.0002898||-6.822||1.02e-10 ***&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1&lt;br /&gt;
&lt;br /&gt;
 Residual standard error: 0.5608 on 202 degrees of freedom&lt;br /&gt;
 Multiple R-squared:  0.2308,	Adjusted R-squared:  0.2232 &lt;br /&gt;
 F-statistic:  30.3 on 2 and 202 DF,  p-value: 3.103e-12&lt;br /&gt;
&lt;br /&gt;
 # (2) Next, we consider the local linear nonparametric method employing cross-validated &lt;br /&gt;
 # bandwidth selection and estimation in one step. Start with computing the least-squares&lt;br /&gt;
 #  cross-validated bandwidths for the local constant estimator (default).&lt;br /&gt;
 # Note that &amp;lt;b&amp;gt;R&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; = 0.3108675&amp;lt;/b&amp;gt;&lt;br /&gt;
 bandwidth &amp;lt;- npregbw(formula= logwage ~ age, data = cps71)&lt;br /&gt;
 model.np &amp;lt;- npreg(bandwidth,  regtype = &amp;quot;ll&amp;quot;,  bwmethod = &amp;quot;cv.aic&amp;quot;, gradients = TRUE, data = cps71)&lt;br /&gt;
 summary(model.np)&lt;br /&gt;
&lt;br /&gt;
 Regression Data: 205 training points, in 1 variable(s) age&lt;br /&gt;
 Bandwidth(s): 1.892157&lt;br /&gt;
 Kernel Regression Estimator: Local-Constant&lt;br /&gt;
 Bandwidth Type: Fixed&lt;br /&gt;
 Residual standard error: 0.5307943&lt;br /&gt;
 R-squared: &amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;0.3108675&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
 Continuous Kernel Type: Second-Order Gaussian&lt;br /&gt;
 No. Continuous Explanatory Vars.: 1&lt;br /&gt;
&lt;br /&gt;
 # NP model significance may be tested by&lt;br /&gt;
 npsigtest(model.np)&lt;br /&gt;
&lt;br /&gt;
 Kernel Regression Significance Test&lt;br /&gt;
 Type I Test with IID Bootstrap (399 replications, Pivot=TRUE, joint=FALSE)&lt;br /&gt;
 Explanatory variables tested for significance: age (1)&lt;br /&gt;
&lt;br /&gt;
               age&lt;br /&gt;
 Bandwidth(s): 1.892157&lt;br /&gt;
&lt;br /&gt;
 Individual Significance Tests&lt;br /&gt;
 P Value: &lt;br /&gt;
 age &amp;lt; 2.22e-16 ***&lt;br /&gt;
&lt;br /&gt;
 # So, as was the case for the linear parametric model, Age is significant in the local linear NP-model&lt;br /&gt;
&lt;br /&gt;
 # (3) Graphical comparison of parametric and nonparametric models. &lt;br /&gt;
 plot(cps71$\$$age, cps71$\$$logwage, xlab = &amp;quot;age&amp;quot;, ylab = &amp;quot;log(wage)&amp;quot;, cex=.1)&lt;br /&gt;
 lines(cps71$\$$age, fitted(model.lin), lty = 2, col = &amp;quot; red&amp;quot;)&lt;br /&gt;
 lines(cps71$\$$age, fitted(model.np), lty = 1, col = &amp;quot;blue&amp;quot;)&lt;br /&gt;
 legend(&amp;quot;topright&amp;quot;, c(&amp;quot;Data&amp;quot;, &amp;quot;Linear&amp;quot;, &amp;quot;Non-linear&amp;quot;), col=c(&amp;quot;Black&amp;quot;, &amp;quot;Red&amp;quot;, &amp;quot;Blue&amp;quot;), pch = c(1, 1, 1), bty='n', cex=.75)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # some additional plots resenting the parametric (quadratic, dashed line) and the nonparametric estimates &lt;br /&gt;
 # (solid line) of the regression function for the cps71 data. &lt;br /&gt;
 plot(model.np, plot.errors.method = &amp;quot;asymptotic&amp;quot;)&lt;br /&gt;
 plot(model.np, gradients = TRUE)&lt;br /&gt;
 lines(cps71$\$$age, coef(model.lin)[2]+2*cps71$\$$age*coef(model.lin)[3], lty = 2, col = &amp;quot;red&amp;quot;)&lt;br /&gt;
 plot(model.np, gradients = TRUE, plot.errors.method = &amp;quot;asymptotic&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # (4) using the Lin and NL models to generate predictions based on the obtained appropriate &lt;br /&gt;
 # bandwidths and estimated a nonparametric model. We need to create a set of explanatory&lt;br /&gt;
 # variables for which to generate predictions. These can be part of the original dataset or be&lt;br /&gt;
 # outside its scope. Typically, we don’t have the outcome for the evaluation data and need only &lt;br /&gt;
 # provide the explanatory variables for which predicted values are generated by the models.&lt;br /&gt;
 # Occasionally, splitting the dataset into two independent samples (training/testing), allows estimation&lt;br /&gt;
 # of a model on one sample, and evaluation of its performance on another.&lt;br /&gt;
&lt;br /&gt;
 cps.eval.data &amp;lt;- data.frame(age = seq(10,70, by=10)) # simulate some explanatory X values (ages)&lt;br /&gt;
 pred.lin &amp;lt;- predict(model.lin, newdata = cps.eval.data)		# Linear Prediction of log(Wage)&lt;br /&gt;
 pred.np &amp;lt;- predict(model.np, newdata = cps.eval.data)		# non-Linear Prediction of log(Wage)&lt;br /&gt;
 plot(pred.lin, pred.np)&lt;br /&gt;
 abline(lm(pred.np ~ pred.lin))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
==Predictive risk models ==&lt;br /&gt;
&lt;br /&gt;
Predictive risk models represent a class of methods for identifying potential for HTE when the individual patient risk for disease-related events at baseline depends on observed factors. For instance, common measures are disease staging criteria, such as those used in COPD or heart failure, Framingham risk scores for cardiovascular event risk, or genetic variations, e.g., HER2 for breast cancer. Initial predictive risk modeling, aka risk function estimation, is often performed without accounting for treatment effects. Least squares or Cox proportional hazards regression methods are appropriate in many cases and provide relatively more interpretable risk functions, but rely on linearity assumptions and may not provide optimal predictive metrics. Partial least squares is an extension of least squares methods that can reduce the dimensionality of the predictor space by interposing latent variables, predicted by linear combinations of observable characteristics, as the intermediate predictors of one or more outcomes. Recursive partitioning, such as random forests, support vector machines, and neural networks represent latter methods with better predictive power than linear methods. Risk function estimation can range from highly exploratory analyses to near meta-analytic model validation, and may be useful at any stage of product development.&lt;br /&gt;
&lt;br /&gt;
HIV Example: The &amp;lt;b&amp;gt;“hmohiv”&amp;lt;/b&amp;gt; dataset   represents a study of HIV positive patients examining whether there was a difference in survival times of HIV positive patients between a cohort using intravenous drugs (drug=1) and a cohort not using the IV drug (drug=0). The &amp;lt;b&amp;gt;hmohiv&amp;lt;/b&amp;gt; data includes the following variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID||Time||Age||Drug||Censor||Entdate||Enddate&lt;br /&gt;
|-   &lt;br /&gt;
|1||5||46||0||1||5/15/1990||10/14/1990&lt;br /&gt;
|-&lt;br /&gt;
|2||6||35||1||0||9/19/1989||3/20/1990&lt;br /&gt;
|-&lt;br /&gt;
|3||8||30||1||1||4/21/1991||12/20/1991&lt;br /&gt;
|-&lt;br /&gt;
|4||3||30||1||1||1/3/1991||4/4/1991&lt;br /&gt;
|-&lt;br /&gt;
|5||22||36||0||1||9/18/1989||7/19/1991&lt;br /&gt;
|-&lt;br /&gt;
|6||1||32||1||0||3/18/1991||4/17/1991&lt;br /&gt;
|-&lt;br /&gt;
|...||...||...||...||...||...||...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #cleaning up environment&lt;br /&gt;
 rm(list=ls())&lt;br /&gt;
&lt;br /&gt;
 # load survival library&lt;br /&gt;
 library(survival)&lt;br /&gt;
&lt;br /&gt;
 # load hmohiv data&lt;br /&gt;
 hmohiv&amp;lt;-read.table(&amp;quot;http://www.ats.ucla.edu/stat/r/examples/asa/hmohiv.csv&amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 attach(hmohiv)&lt;br /&gt;
&lt;br /&gt;
 # Fit Cox proportional hazards regression model&lt;br /&gt;
 cox.model &amp;lt;- coxph( Surv(time, censor) ~ drug, method=&amp;quot;breslow&amp;quot;)&lt;br /&gt;
 fit.1 &amp;lt;- survfit(cox.model, newdata=drug.new)&lt;br /&gt;
&lt;br /&gt;
 # construct a frame of the 2 cohorts IV_drug and no-IV-drug&lt;br /&gt;
 drug.new&amp;lt;-data.frame(drug=c(0,1))&lt;br /&gt;
&lt;br /&gt;
 # plot results&lt;br /&gt;
 plot(fit.1, xlab=&amp;quot;Survival Time (Months)&amp;quot;, ylab=&amp;quot;Survival Probability&amp;quot;)&lt;br /&gt;
 points(fit.1$\$$time, fit.1$\$$surv[,1], pch=1)&lt;br /&gt;
 points(fit.1$\$$time, fit.1$\$$surv[,2], pch=2)&lt;br /&gt;
 legend(40, .8, c(&amp;quot;Drug Absent&amp;quot;, &amp;quot;Drug Present&amp;quot;), pch=c(1,2))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to inslect the resulting Cox Proportional Hazard Model&lt;br /&gt;
 cox.model &lt;br /&gt;
 Call:&lt;br /&gt;
 coxph(formula = Surv(time, censor) ~ drug, method = &amp;quot;breslow&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      	    coef 	exp(coef) 	se(coef)   	z      	        p&lt;br /&gt;
 &amp;lt;b&amp;gt;drug&amp;lt;/b&amp;gt; 	0.779          2.18    		0.242 		3.22 	       &amp;lt;b&amp;gt;0.0013&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Likelihood ratio test=10.2  on 1 df, p=0.00141  n= 100, number of events= 80 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_CER|Next see: Comparative Effectiveness Research (CER)]]==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_MetaAnalysis}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16035</id>
		<title>SMHS MethodsHeterogeneity HTE</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16035"/>
		<updated>2016-05-19T14:57:55Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Latent growth and growth mixture modeling (LGM/GMM) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Methods and Approaches for HTE Analytics ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Recursive partitioning is a data mining technique for exploring structure and patterns in complex data. It facilitates the visualization of decision rules for predicting categorical (classification tree) or continuous (regression tree) outcome variables. The R &amp;lt;b&amp;gt;rpart&amp;lt;/b&amp;gt; package   provides the tools for Classification and Regression Tree (CART) modeling, conditional inference trees, and random forests. Additional resources include an Introduction to Recursive Partitioning Using the RPART Routines  . The &amp;lt;b&amp;gt;Appendix&amp;lt;/b&amp;gt; includes description of the main CART analysis steps.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;install.packages(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CART===&lt;br /&gt;
Classification and Regression Tree (CART) is a decision-tree based technique that considers how variation observed in a given response variable (continuous or categorical) can be understood through a systematic deconstruction of the overall study population into subgroups, using explanatory variables of interest. For HTE analysis, CART is best suited for early-stage, exploratory analyses. Its relative simplicity can be powerful in identifying basic relationships between variables of interest, and thus identify potential subgroups for more advanced analyses. The key to CART is its ‘systematic’ approach to the development of the subgroups, which are constructed sequentially through repeated, binary splits of the population of interest, one explanatory variable at a time. In other words, each ‘parent’ group is divided into two ‘child’ groups, with the objective of creating increasingly homogeneous subgroups. The process is repeated and the subgroups are then further split, until no additional variables are available for further subgroup development. The resulting tree structure is oftentimes overgrown, but additional techniques are used to ‘trim’ the tree to a point at which its predictive power is balanced against issues of over-fitting. Because the CART approach does not make assumptions regarding the distribution of the dependent variable, it can be used in situations where other multivariate modeling techniques often used for exploratory predictive risk modeling would not be appropriate – namely in situations where data are not normally distributed. &lt;br /&gt;
&lt;br /&gt;
CART analyses are useful in situations where there is some evidence to suggest that HTE exists, but the subgroups defining the heterogeneous response are not well understood. CART allows for an exploration of response in a myriad of complex subpopulations, and more recently developed ensemble methods (such as Bayesian Additive Regression Trees) allow for more robust analyses through the combination of multiple CART analyses.&lt;br /&gt;
&lt;br /&gt;
====Example Fifth Dutch growth study====&lt;br /&gt;
&lt;br /&gt;
 # Let’s use the Fifth Dutch growth study (2009) &amp;lt;b&amp;gt;fdgs&amp;lt;/b&amp;gt;  . Is it true that “the world’s tallest nation has stopped growing taller: the height of Dutch children from 1955 to 2009”?&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 library(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 ?fdgs&lt;br /&gt;
 head(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID ||Reg ||Age ||Sex ||HGT ||WGT ||HGT.Z ||WGT.Z&lt;br /&gt;
|-&lt;br /&gt;
|1 ||100001||West||13.09514||boy||175.5||75.0||1.751||2.410&lt;br /&gt;
|-&lt;br /&gt;
|2 ||100003||West||13.81793 ||boy||148.4||40.0||2.292||1.494&lt;br /&gt;
|-&lt;br /&gt;
|3 ||100004||West||13.97125||boy||159.9||46.5||0.743||0.783&lt;br /&gt;
|-&lt;br /&gt;
|4 ||100005||West||13.98220 ||girl||159.7||46.5 ||0.743 ||0.783&lt;br /&gt;
|-&lt;br /&gt;
|5||100006||West||13.52225||girl||160.3||47.8||0.414||0.355&lt;br /&gt;
|-&lt;br /&gt;
|6||100018||East||10.21492||boy||157.8||39.7||2.025||0.823&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(fdgs)        &lt;br /&gt;
 summary(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID ||Reg ||Age ||Sex ||HGT&lt;br /&gt;
|-&lt;br /&gt;
|Min.:100001||North:732||Min.:0.008214||boy:4829||Min.:46.0&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.:106353||East:2528||1st Qu.:1.618754||girl:5201||1st Qu.:83.8&lt;br /&gt;
|-&lt;br /&gt;
|Median:203855||South:2931||Median:8.084873|| ||Median:131.5&lt;br /&gt;
|-&lt;br /&gt;
|Mean:180091||West:2578||Mean:8.157936|| ||Mean:123.9&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.210591||City:1261||3rd Qu.:13.547570|| ||3rd Qu.:162.3&lt;br /&gt;
|-&lt;br /&gt;
|Max:401955|| ||Max.:21.993155|| ||Max.:208.0&lt;br /&gt;
|-&lt;br /&gt;
| || || || ||NA's: 23&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1) Classification Tree&lt;br /&gt;
&lt;br /&gt;
Let's use the data frame fdgs to predict Region, from Age, Height, and Weight.&lt;br /&gt;
 # grow tree &lt;br /&gt;
 fit.1 &amp;lt;- rpart(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, data= fdgs[,-1])&lt;br /&gt;
&lt;br /&gt;
 printcp(fit.1) 	# display the results &lt;br /&gt;
 plotcp(fit.1) 	# visualize cross-validation results &lt;br /&gt;
 summary(fit.1) 	# detailed summary of splits&lt;br /&gt;
&lt;br /&gt;
 # plot tree &lt;br /&gt;
 par(oma=c(0,0,2,0))&lt;br /&gt;
 plot(fit.1, uniform=TRUE,  margin=0.3, main=&amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # create a better plot of the classification tree &lt;br /&gt;
 post(fit.1, title = &amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;, file = &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(2) Pruning the tree &lt;br /&gt;
&lt;br /&gt;
 pruned.fit.1&amp;lt;- prune(fit.1, cp=   fit.1$\$$cptable[which.min(fit.1$\$$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
 # plot the pruned tree &lt;br /&gt;
 plot(pruned.fit.1, uniform=TRUE,  main=&amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(pruned.fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
 post(pruned.fit.1,  title = &amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Not much change, as the initial tree is not complex!&lt;br /&gt;
&lt;br /&gt;
===Random Forests ===&lt;br /&gt;
Random forests may improve predictive accuracy by generating a large number of bootstrapped trees (based on random samples of variables). It classifies cases using each tree in this new &amp;quot;forest&amp;quot;, and decides the final predicted outcome by combining the results across all of the trees (an average in regression, a majority vote in classification). See the &amp;lt;b&amp;gt;randomForest&amp;lt;/b&amp;gt; package. &lt;br /&gt;
&lt;br /&gt;
 library(randomForest)&lt;br /&gt;
 fit.2 &amp;lt;- randomForest(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, na.action = na.omit, data= fdgs[,-1])&lt;br /&gt;
 print(fit.2) 		# view results &lt;br /&gt;
 importance(fit.2) 	# importance of each predictor &lt;br /&gt;
&lt;br /&gt;
Note on missing values/incomplete data: If the data have missing values, we have 3 choices:&lt;br /&gt;
&lt;br /&gt;
1.	Use a different tool (rpart handles missing values well)&lt;br /&gt;
&lt;br /&gt;
2.	Impute the missing values&lt;br /&gt;
&lt;br /&gt;
3.	For a small number of missing cases, we can use na.action = na.omit&lt;br /&gt;
&lt;br /&gt;
===Latent growth and growth mixture modeling (LGM/GMM)===&lt;br /&gt;
&lt;br /&gt;
LGM and GMM represent structural equation modeling techniques that capture inter-individual differences in longitudinal change corresponding to a particular treatment. For instance, patients’ different timing patterns of the treatment effects may represent the underlying sources of HTE. LGM distinguish if (yes/no) and how (fast/slow, temporary/lasting) patients respond to treatment. The heterogeneous individual growth trajectories are estimated from intra-individual changes over time by examining common population parameters, i.e., slopes, intercepts, and error variances. Suppose each individual has unique initial status (intercept) and response rate (slope) during a specific time interval. Then the variances of the individuals’ baseline measures (intercepts) and changes (slopes) in health outcomes will represent the degree of HTE. The LGM-identified HTE of individual growth curves can be attributed to observed predictors, including both fixed and time varying covariates.&lt;br /&gt;
&lt;br /&gt;
LGM assumes that all individuals are from the same population (too restrictive in some cases). If the HTE is due to observed demographic variables, such as age, gender, and marital status, one may utilize multiple-group LGM. Despite its successful applications for modeling longitudinal change, there may be multiple subpopulations with unobserved heterogeneities. Growth mixture modeling (GMM) extends LGM to allow the identification and prediction of unobserved subpopulations in longitudinal data analysis. Each unobserved subpopulation may constitute its own latent class and behave differently than individuals in other latent classes. Within each latent class, there are also different trajectories across individuals; however, different latent classes don’t share common population parameters. Suppose we are interested in studying retirees’ psychological well-being change trajectory when multiple unknown subpopulations exist. We can add another layer (a latent class variable) on the LGM framework so that the unobserved latent classes can be inferred from the data. The covariates in GMM are designed to affect growth factors distinctly across different latent classes. Therefore, there are two types of HTE: 1) the latent class variable in GMM divides individuals into groups with different growth curves; and 2) coefficient estimates vary across latent classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Latent variables&amp;lt;/b&amp;gt; are not directly observed – they are inferred (via a model) from other actually observed and directly measured variables. Models that explain observed variables in terms of latent variables are called latent variable models. Then the latent (unobserved) variable is discrete, it’s referred to as &amp;lt;b&amp;gt;latent class variable.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Breast Cancer Example: Recall the LMER package, earlier review discussions, where Linear Mixed Model (LMM) are used for longitudinal data to examine change over time of outcomes according relative to predictive covariates. LMM assumptions include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(i)&amp;lt;/b&amp;gt; continuous longitudinal outcome&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(ii)&amp;lt;/b&amp;gt; Gaussian random-effects and errors&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iii)&amp;lt;/b&amp;gt; linearity of the relationships with the outcome&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iv)&amp;lt;/b&amp;gt; homogeneous population&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(v)&amp;lt;/b&amp;gt; missing at random data&lt;br /&gt;
&lt;br /&gt;
The objectives of LGM/GMM models (see &amp;lt;b&amp;gt;Latent Class Mixed Models, lcmm&amp;lt;/b&amp;gt; R package) are to extend the linear mixed model estimation to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(i)&amp;lt;/b&amp;gt;	heterogeneous populations (relax (iv) above). Use &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; for latent class linear mixed models&amp;lt;/mark&amp;gt; (i.e. Gaussian continuous outcome)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(ii)&amp;lt;/b&amp;gt;	other types of longitudinal outcomes : ordinal, (bounded) quantitative non-Gaussian outcomes (relax (i), (ii), (iii), (iv)). Use &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; for general latent class mixed models with outcomes of different nature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iii)&amp;lt;/b&amp;gt;	joint analysis of a time-to-event (relax (iv), (v)). Use &amp;lt;b&amp;gt;Jointlcmm&amp;lt;/b&amp;gt; for joint latent class models with a longitudinal outcome and a right-censored (left-truncated) time-to-event&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s use these data (http://www.ats.ucla.edu/stat/data/hdp.csv), representing cancer phenotypes and predictors (e.g., &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;) and outcome measures (e.g., remission) collected on patients, nested within doctors (DID) and within hospitals (HID).&lt;br /&gt;
&lt;br /&gt;
We can illustrate the latent class linear mixed models implemented in &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; through a study of the quadratic trajectories of the response (remission) with TumorSize, adjusting for CO2*Pain interaction and assuming correlated random-effects for the functions of SmokingHx and Sex. To estimate the corresponding standard linear mixed model using 1 latent class where CO2 interacts with Pain:&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
 library(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 hdp &amp;lt;- read.csv(&amp;quot;http://www.ats.ucla.edu/stat/data/hdp.csv&amp;quot;)&lt;br /&gt;
 hdp &amp;lt;- within(hdp, {&lt;br /&gt;
 Married &amp;lt;- factor(Married, levels = 0:1, labels = c(&amp;quot;no&amp;quot;, &amp;quot;yes&amp;quot;))&lt;br /&gt;
 DID &amp;lt;- factor(DID)&lt;br /&gt;
 HID &amp;lt;- factor(HID)&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
add a new subject ID column (last column in the data, “ID”), this is necessary for the hmle call&lt;br /&gt;
hdp$\$$ID &amp;lt;- seq.int(nrow(hdp))&lt;br /&gt;
&lt;br /&gt;
 model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 summary(model.hlme)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Heterogenous linear mixed model &lt;br /&gt;
 fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 hlme(fixed = remission ~ IL6 + CRP + LengthofStay + Experience + &lt;br /&gt;
 I(tumorsize^2) + co2 * pain + I(tumorsize^2) * pain, random = ~SmokingHx + &lt;br /&gt;
 Sex, subject = &amp;quot;ID&amp;quot;, ng = 1, data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
 Dataset: hdp &lt;br /&gt;
 Number of subjects: 8525 &lt;br /&gt;
 Number of observations: 8525 &lt;br /&gt;
 Number of latent classes: 1 &lt;br /&gt;
 Number of parameters: 21  &lt;br /&gt;
 &lt;br /&gt;
 Iteration process: 	&lt;br /&gt;
 Convergence criteria satisfied &lt;br /&gt;
 Number of iterations:  34 &lt;br /&gt;
 Convergence criteria: parameters= 1.2e-09 &lt;br /&gt;
 : likelihood= 8.3e-06 &lt;br /&gt;
 : second derivatives= 2.7e-05 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
 maximum log-likelihood: -5223.9  &lt;br /&gt;
 AIC: 10489.79  &lt;br /&gt;
 BIC: 10637.86&lt;br /&gt;
&lt;br /&gt;
Maximum Likelihood Estimates: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Fixed effects in the Longitudinal Model:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||coef||Se||Wald||p-value&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||0.28636||0.24314||1.178||0.23890&lt;br /&gt;
|-&lt;br /&gt;
|IL6||-0.01134||0.00183||-6.184||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|CRP||-0.00674||0.00167||-4.043||0.00005&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||-0.04834||0.00463||-10.436||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|Experience||0.01695||0.00119||14.263||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2)||0.00000||0.00001||-0.076||0.93953&lt;br /&gt;
|-&lt;br /&gt;
|co2||-0.03549||0.16204||-0.219||0.82663&lt;br /&gt;
|-&lt;br /&gt;
|pain||0.03930||0.04278||0.919||0.35832&lt;br /&gt;
|-&lt;br /&gt;
|co2:pain||-0.01489||0.02871||-0.519||0.60395&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2):pain||0.00000||0.00000||0.553||0.58045&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Variance-covariance matrix of the random-effects&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||intercept||SmokingHxformer||SmokingHxnever||Sexmale&lt;br /&gt;
|-&lt;br /&gt;
|intercept||0.19310943|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxformer||-0.10617988||0.209155186|| ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxnever||-0.12388534||0.068342049||2.262655e-01|| &lt;br /&gt;
|-&lt;br /&gt;
|Sexmale||-0.08130975||-0.007353491||-1.873934e-05||0.1730187&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
                          &lt;br /&gt;
Residual standard error:&lt;br /&gt;
&lt;br /&gt;
coef: 0.1299767&lt;br /&gt;
&lt;br /&gt;
se: 1.187426&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Results interpretation:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1)	The first part of the summary provides information about the dataset, the number of subjects, observations, observations deleted (since by default, missing observations are deleted), number of latent classes and number of parameters. &lt;br /&gt;
&lt;br /&gt;
(2)	Next, details about the algorithm convergence is provided along with the number of iterations, the convergence criteria, and the information indicating if the model converged correctly: &amp;quot;convergence criteria satisfied&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
(3)	The maximum log-likelihood, Akaike criterion (AIC) and Bayesian Information criterion (BIC) are reported. &lt;br /&gt;
&lt;br /&gt;
(4)	Estimates of parameters, the estimated standard error, the Wald Test statistics (with Normal approximation) and the corresponding p-values are reported below. &lt;br /&gt;
&lt;br /&gt;
(5)	For the random-effect distribution, the estimated matrix of covariance of the random-effects is displayed.&lt;br /&gt;
&lt;br /&gt;
(6)	The standard error of the residuals is given along with its estimated standard error.&lt;br /&gt;
&lt;br /&gt;
(7)	The effect of &amp;lt;b&amp;gt;TumorSize&amp;lt;/b&amp;gt; seems not associated with change over Pain of Remission. This may be formally assessed using a multivariate Wald test:&lt;br /&gt;
&lt;br /&gt;
 WaldMult(model.hlme, pos=c(6,8)) &lt;br /&gt;
 # pos - a vector containing the indices in model.hlme of the parameters to test&lt;br /&gt;
 Wald Test p_value&lt;br /&gt;
 I(tumorsize^2) = pain = 0   0.85562 0.65193&lt;br /&gt;
&lt;br /&gt;
We may consider the model with an adjustment for CRP only on the intercept. Below we estimate the corresponding &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;models for a varying number of latent classes&amp;lt;/b&amp;gt;&amp;lt;/mark&amp;gt; (from 1 to 3) using the default initial values:&lt;br /&gt;
&lt;br /&gt;
 # Initial Model: model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
&lt;br /&gt;
 model.hlme.1 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 model.hlme.2 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=2)&lt;br /&gt;
 model.hlme.3 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=3)&lt;br /&gt;
&lt;br /&gt;
The estimation process for a varying number of latent classes can be summarized with &amp;lt;b&amp;gt;summarytable,&amp;lt;/b&amp;gt; which gives the &amp;lt;b&amp;gt;log-likelihood&amp;lt;/b&amp;gt;, the number of parameters, the Bayesian Information Criterion, and the posterior proportion of each class:&lt;br /&gt;
&lt;br /&gt;
 summarytable(model.hlme.1, model.hlme.2, model.hlme.3)&lt;br /&gt;
             G    loglik npm      BIC    %class1    %class2  %class3&lt;br /&gt;
 model.hlme.1 1 -33301.82   5 66648.89 100.000000                    &lt;br /&gt;
 model.hlme.2 2 -31592.79  11 63285.15  99.214076  0.7859238         &lt;br /&gt;
 model.hlme.3 3 -31589.55  15 63314.86   6.357771 82.2991202 11.34311&lt;br /&gt;
&lt;br /&gt;
The program took 404.65 seconds&lt;br /&gt;
&lt;br /&gt;
In this example, the optimal number of latent classes according to the BIC is two (the smallest BIC).  The posterior classification is described with:&lt;br /&gt;
&lt;br /&gt;
 postprob(model.hlme.2)&lt;br /&gt;
&lt;br /&gt;
 Posterior classification: &lt;br /&gt;
   class1 class2&lt;br /&gt;
 N 8458.00  67.00&lt;br /&gt;
 %   99.21   0.79&lt;br /&gt;
 &lt;br /&gt;
 Posterior classification table: &lt;br /&gt;
     --&amp;gt; mean of posterior probabilities in each class &lt;br /&gt;
        prob1  prob2&lt;br /&gt;
 class1 0.8555 0.1445&lt;br /&gt;
 class2 0.4362 0.5638&lt;br /&gt;
 &lt;br /&gt;
 Posterior probabilities above a threshold (%): &lt;br /&gt;
         class1 class2&lt;br /&gt;
 prob&amp;gt;0.7  92.48   2.99&lt;br /&gt;
 prob&amp;gt;0.8  77.38   0.00&lt;br /&gt;
 prob&amp;gt;0.9  38.53   0.00&lt;br /&gt;
&lt;br /&gt;
In this example, the first class includes a posteriori 8458 subjects (99%) while class 2 includes 67 (0.79%) subjects. Subjects were classified in class 1 with a mean posterior probability of 0.8555 %. &lt;br /&gt;
&lt;br /&gt;
In class 1, 92.48% were classified with a posterior probability above 0.7 while 2.99% of the subjects were classified in class 2 with a posterior probability above 0.7. Goodness-of-fit of the model can be assessed by displaying the residuals as in figure and the mean predictions of the model as in figure, according to the time variable given in &amp;lt;b&amp;gt;var.time&amp;lt;/b&amp;gt;:  &lt;br /&gt;
&lt;br /&gt;
 plot(model.hlme.2)&lt;br /&gt;
 # Figure (left panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2) &lt;br /&gt;
 # Figure (right panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2, marg=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The latent process mixed models implemented in &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; are illustrated through the study of the linear trajectory of &amp;lt;b&amp;gt;ntumors&amp;lt;/b&amp;gt; with Age adjusted for Sex and assuming correlated random-effects for the intercept and Age. Lines estimate the corresponding latent process mixed model with different link functions:&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', data=hdp)&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta')&lt;br /&gt;
 model.hlme.spl &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='splines')&lt;br /&gt;
 model.hlme.spl5q &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='5-quant-splines')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;link function&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;: An optional family of link functions. By default, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;linear&amp;quot; option specifies a linear link function leading to a standard linear mixed model (homogeneous or heterogeneous as estimated in hlme). &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;beta&amp;quot; for estimating a link function from the family of Beta cumulative distribution functions, &amp;quot;thresholds&amp;quot; for using a threshold model to describe the correspondence between each level of an ordinal outcome and the underlying latent process, and&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;Splines&amp;quot; for approximating the link function by I-splines. For this latter case, the number of nodes and the nodes location should be also specified. The number of nodes is first entered followed by,&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; -, then the location is specified with &amp;quot;equi&amp;quot;, &amp;quot;quant&amp;quot; or &amp;quot;manual&amp;quot; for respectively equidistant nodes, nodes at quantiles of the marker distribution or interior nodes entered manually in argument&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;intnodes. It is followed by - and finally &amp;quot;splines&amp;quot; is indicated. For example, &amp;quot;7-equi-splines&amp;quot; means I-splines with 7 equidistant nodes, &amp;quot;6-quant-splines&amp;quot; means I-splines with 6 nodes located at the quantiles of the marker distribution and &amp;quot;9-manual-splines&amp;quot; means I-splines with 9 nodes, the vector of 7 interior nodes being entered in the argument intnodes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary (model.hlme.lin)&lt;br /&gt;
&lt;br /&gt;
 General latent class mixed model fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 lcmm(fixed = ntumors ~ Age * Sex, random = ~Age, subject = &amp;quot;ID&amp;quot;,data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
     Dataset: hdp &lt;br /&gt;
     Number of subjects: 8525 &lt;br /&gt;
     Number of observations: 8525 &lt;br /&gt;
     Number of latent classes: 1 &lt;br /&gt;
     Number of parameters: 8  &lt;br /&gt;
     Link function: linear  &lt;br /&gt;
 &lt;br /&gt;
Iteration process: &lt;br /&gt;
     Maximum number of iteration reached without convergence &lt;br /&gt;
     Number of iterations:  100 &lt;br /&gt;
     Convergence criteria: parameters= 5.4e-10 &lt;br /&gt;
                         : likelihood= 5.5e-10 &lt;br /&gt;
                         : second derivatives= 1 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
     maximum log-likelihood: -19915.24  &lt;br /&gt;
     AIC: 39846.49  &lt;br /&gt;
     BIC: 39902.89  &lt;br /&gt;
 &lt;br /&gt;
     Discrete posterior log-likelihood: 0  &lt;br /&gt;
     Discrete AIC: 16  &lt;br /&gt;
 &lt;br /&gt;
     Mean discrete AIC per subject: 9e-04  &lt;br /&gt;
     Mean UACV per subject: 0  &lt;br /&gt;
     Mean discrete LL per subject: 0  &lt;br /&gt;
 &lt;br /&gt;
 Maximum Likelihood Estimates: &lt;br /&gt;
 &lt;br /&gt;
 Fixed effects in the longitudinal model:&lt;br /&gt;
&lt;br /&gt;
                              coef Se Wald p-value&lt;br /&gt;
 intercept (not estimated)  0.00000                &lt;br /&gt;
 Age                        0.09491                &lt;br /&gt;
 Sexmale                   -0.66303                &lt;br /&gt;
 Age:Sexmale                0.01132                &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Variance-covariance matrix of the random-effects:&lt;br /&gt;
           intercept         Age&lt;br /&gt;
 intercept 20.5013715            &lt;br /&gt;
 Age       -0.2889814 0.007696382&lt;br /&gt;
&lt;br /&gt;
 Residual standard error (not estimated) = 1&lt;br /&gt;
&lt;br /&gt;
 Parameters of the link function:&lt;br /&gt;
&lt;br /&gt;
                         coef Se Wald p-value&lt;br /&gt;
 Linear 1 (intercept) -0.36768                &lt;br /&gt;
 Linear 2 (std err)    0.71432           &lt;br /&gt;
&lt;br /&gt;
Objects &amp;lt;b&amp;gt;mlin, mbeta, mspl and mspl3eq&amp;lt;/b&amp;gt; are latent process mixed models that assume the exact same trajectory for the underlying latent process but respectively a linear, BetaCDF, I-splines with 5 equidistant knots (default with link=’splines’) and I-splines with 5 knots at percentiles. &amp;lt;b&amp;gt;mlin&amp;lt;/b&amp;gt; reduces to a standard linear mixed model (link=’linear’ by default). The only difference with a &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; object is the parameterization for the intercept and the residual standard error that are considered as rescaling parameters.&lt;br /&gt;
&lt;br /&gt;
 col &amp;lt;- rainbow(4)&lt;br /&gt;
 plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(model.hlme.beta, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[2], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[3], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl5q, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[4], lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;topleft&amp;quot;,legend=c(&amp;quot;linear&amp;quot;, &amp;quot;beta&amp;quot;,&amp;quot;splines (5equidistant)&amp;quot;, &amp;quot;splines (5 at quantiles)&amp;quot;), lty=1,col=col,bty=&amp;quot;n&amp;quot;,lwd=2)&lt;br /&gt;
&lt;br /&gt;
 # to obtain confidence bands use function predictlink &lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;Error in predictlink.lcmm(model.hlme.spl, ndraws = 2000):&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;No confidence intervals can be produced since the program did not converge properly&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;model.hlme.lin$\$$conv &amp;lt;mark&amp;gt;# double-check the convergence of the algorithm[1] 2&amp;lt;/mark&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# status of convergence:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =1 if the convergence criteria were satisfied,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =2 if the maximum number of iterations was reached,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =4 or 5 if a problem occured during optimisation&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', epsY = 0.5, convB = 1e-01, convL = 1e-01, &amp;lt;mark&amp;gt;convG = 1e-01&amp;lt;/mark&amp;gt;, maxiter=200, data=hdp); model.hlme.lin$conv&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;mark&amp;gt;# Now that we have convergence, we can obtain CI’s!!!&amp;lt;/mark&amp;gt;&lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 # plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(link.lin, add=TRUE, col=col[1], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for linear fit&amp;quot;), lty=c(2,NA), col=c(col[1],NA), bty=&amp;quot;n&amp;quot;, lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;Repeat using the other link functions … model.hlme.beta, model.hlme.spl, …&amp;lt;/mark&amp;gt;&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta', &lt;br /&gt;
 &amp;lt;mark&amp;gt;convB = 1e-01&amp;lt;/mark&amp;gt;, convL = 1e-01, convG = 1e-01, maxiter=200); model.hlme.beta$\$$conv&lt;br /&gt;
 link.beta &amp;lt;- predictlink(model.hlme.beta, ndraws=2000)&lt;br /&gt;
 plot(link.beta, add=TRUE, col=col[2], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for BETA fit&amp;quot;), lty=c(3,NA), col=c(col[2],NA), bty=&amp;quot;n&amp;quot;, lwd=1)&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity_MetaAnalysis|Next see: Meta-Analysis]]===&lt;br /&gt;
* [[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_HTE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16032</id>
		<title>SMHS MethodsHeterogeneity HTE</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16032"/>
		<updated>2016-05-19T14:44:41Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Latent growth and growth mixture modeling (LGM/GMM) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Methods and Approaches for HTE Analytics ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Recursive partitioning is a data mining technique for exploring structure and patterns in complex data. It facilitates the visualization of decision rules for predicting categorical (classification tree) or continuous (regression tree) outcome variables. The R &amp;lt;b&amp;gt;rpart&amp;lt;/b&amp;gt; package   provides the tools for Classification and Regression Tree (CART) modeling, conditional inference trees, and random forests. Additional resources include an Introduction to Recursive Partitioning Using the RPART Routines  . The &amp;lt;b&amp;gt;Appendix&amp;lt;/b&amp;gt; includes description of the main CART analysis steps.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;install.packages(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CART===&lt;br /&gt;
Classification and Regression Tree (CART) is a decision-tree based technique that considers how variation observed in a given response variable (continuous or categorical) can be understood through a systematic deconstruction of the overall study population into subgroups, using explanatory variables of interest. For HTE analysis, CART is best suited for early-stage, exploratory analyses. Its relative simplicity can be powerful in identifying basic relationships between variables of interest, and thus identify potential subgroups for more advanced analyses. The key to CART is its ‘systematic’ approach to the development of the subgroups, which are constructed sequentially through repeated, binary splits of the population of interest, one explanatory variable at a time. In other words, each ‘parent’ group is divided into two ‘child’ groups, with the objective of creating increasingly homogeneous subgroups. The process is repeated and the subgroups are then further split, until no additional variables are available for further subgroup development. The resulting tree structure is oftentimes overgrown, but additional techniques are used to ‘trim’ the tree to a point at which its predictive power is balanced against issues of over-fitting. Because the CART approach does not make assumptions regarding the distribution of the dependent variable, it can be used in situations where other multivariate modeling techniques often used for exploratory predictive risk modeling would not be appropriate – namely in situations where data are not normally distributed. &lt;br /&gt;
&lt;br /&gt;
CART analyses are useful in situations where there is some evidence to suggest that HTE exists, but the subgroups defining the heterogeneous response are not well understood. CART allows for an exploration of response in a myriad of complex subpopulations, and more recently developed ensemble methods (such as Bayesian Additive Regression Trees) allow for more robust analyses through the combination of multiple CART analyses.&lt;br /&gt;
&lt;br /&gt;
====Example Fifth Dutch growth study====&lt;br /&gt;
&lt;br /&gt;
 # Let’s use the Fifth Dutch growth study (2009) &amp;lt;b&amp;gt;fdgs&amp;lt;/b&amp;gt;  . Is it true that “the world’s tallest nation has stopped growing taller: the height of Dutch children from 1955 to 2009”?&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 library(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 ?fdgs&lt;br /&gt;
 head(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID ||Reg ||Age ||Sex ||HGT ||WGT ||HGT.Z ||WGT.Z&lt;br /&gt;
|-&lt;br /&gt;
|1 ||100001||West||13.09514||boy||175.5||75.0||1.751||2.410&lt;br /&gt;
|-&lt;br /&gt;
|2 ||100003||West||13.81793 ||boy||148.4||40.0||2.292||1.494&lt;br /&gt;
|-&lt;br /&gt;
|3 ||100004||West||13.97125||boy||159.9||46.5||0.743||0.783&lt;br /&gt;
|-&lt;br /&gt;
|4 ||100005||West||13.98220 ||girl||159.7||46.5 ||0.743 ||0.783&lt;br /&gt;
|-&lt;br /&gt;
|5||100006||West||13.52225||girl||160.3||47.8||0.414||0.355&lt;br /&gt;
|-&lt;br /&gt;
|6||100018||East||10.21492||boy||157.8||39.7||2.025||0.823&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(fdgs)        &lt;br /&gt;
 summary(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID ||Reg ||Age ||Sex ||HGT&lt;br /&gt;
|-&lt;br /&gt;
|Min.:100001||North:732||Min.:0.008214||boy:4829||Min.:46.0&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.:106353||East:2528||1st Qu.:1.618754||girl:5201||1st Qu.:83.8&lt;br /&gt;
|-&lt;br /&gt;
|Median:203855||South:2931||Median:8.084873|| ||Median:131.5&lt;br /&gt;
|-&lt;br /&gt;
|Mean:180091||West:2578||Mean:8.157936|| ||Mean:123.9&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.210591||City:1261||3rd Qu.:13.547570|| ||3rd Qu.:162.3&lt;br /&gt;
|-&lt;br /&gt;
|Max:401955|| ||Max.:21.993155|| ||Max.:208.0&lt;br /&gt;
|-&lt;br /&gt;
| || || || ||NA's: 23&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1) Classification Tree&lt;br /&gt;
&lt;br /&gt;
Let's use the data frame fdgs to predict Region, from Age, Height, and Weight.&lt;br /&gt;
 # grow tree &lt;br /&gt;
 fit.1 &amp;lt;- rpart(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, data= fdgs[,-1])&lt;br /&gt;
&lt;br /&gt;
 printcp(fit.1) 	# display the results &lt;br /&gt;
 plotcp(fit.1) 	# visualize cross-validation results &lt;br /&gt;
 summary(fit.1) 	# detailed summary of splits&lt;br /&gt;
&lt;br /&gt;
 # plot tree &lt;br /&gt;
 par(oma=c(0,0,2,0))&lt;br /&gt;
 plot(fit.1, uniform=TRUE,  margin=0.3, main=&amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # create a better plot of the classification tree &lt;br /&gt;
 post(fit.1, title = &amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;, file = &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(2) Pruning the tree &lt;br /&gt;
&lt;br /&gt;
 pruned.fit.1&amp;lt;- prune(fit.1, cp=   fit.1$\$$cptable[which.min(fit.1$\$$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
 # plot the pruned tree &lt;br /&gt;
 plot(pruned.fit.1, uniform=TRUE,  main=&amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(pruned.fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
 post(pruned.fit.1,  title = &amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Not much change, as the initial tree is not complex!&lt;br /&gt;
&lt;br /&gt;
===Random Forests ===&lt;br /&gt;
Random forests may improve predictive accuracy by generating a large number of bootstrapped trees (based on random samples of variables). It classifies cases using each tree in this new &amp;quot;forest&amp;quot;, and decides the final predicted outcome by combining the results across all of the trees (an average in regression, a majority vote in classification). See the &amp;lt;b&amp;gt;randomForest&amp;lt;/b&amp;gt; package. &lt;br /&gt;
&lt;br /&gt;
 library(randomForest)&lt;br /&gt;
 fit.2 &amp;lt;- randomForest(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, na.action = na.omit, data= fdgs[,-1])&lt;br /&gt;
 print(fit.2) 		# view results &lt;br /&gt;
 importance(fit.2) 	# importance of each predictor &lt;br /&gt;
&lt;br /&gt;
Note on missing values/incomplete data: If the data have missing values, we have 3 choices:&lt;br /&gt;
&lt;br /&gt;
1.	Use a different tool (rpart handles missing values well)&lt;br /&gt;
&lt;br /&gt;
2.	Impute the missing values&lt;br /&gt;
&lt;br /&gt;
3.	For a small number of missing cases, we can use na.action = na.omit&lt;br /&gt;
&lt;br /&gt;
===Latent growth and growth mixture modeling (LGM/GMM)===&lt;br /&gt;
&lt;br /&gt;
LGM and GMM represent structural equation modeling techniques that capture inter-individual differences in longitudinal change corresponding to a particular treatment. For instance, patients’ different timing patterns of the treatment effects may represent the underlying sources of HTE. LGM distinguish if (yes/no) and how (fast/slow, temporary/lasting) patients respond to treatment. The heterogeneous individual growth trajectories are estimated from intra-individual changes over time by examining common population parameters, i.e., slopes, intercepts, and error variances. Suppose each individual has unique initial status (intercept) and response rate (slope) during a specific time interval. Then the variances of the individuals’ baseline measures (intercepts) and changes (slopes) in health outcomes will represent the degree of HTE. The LGM-identified HTE of individual growth curves can be attributed to observed predictors, including both fixed and time varying covariates.&lt;br /&gt;
&lt;br /&gt;
LGM assumes that all individuals are from the same population (too restrictive in some cases). If the HTE is due to observed demographic variables, such as age, gender, and marital status, one may utilize multiple-group LGM. Despite its successful applications for modeling longitudinal change, there may be multiple subpopulations with unobserved heterogeneities. Growth mixture modeling (GMM) extends LGM to allow the identification and prediction of unobserved subpopulations in longitudinal data analysis. Each unobserved subpopulation may constitute its own latent class and behave differently than individuals in other latent classes. Within each latent class, there are also different trajectories across individuals; however, different latent classes don’t share common population parameters. Suppose we are interested in studying retirees’ psychological well-being change trajectory when multiple unknown subpopulations exist. We can add another layer (a latent class variable) on the LGM framework so that the unobserved latent classes can be inferred from the data. The covariates in GMM are designed to affect growth factors distinctly across different latent classes. Therefore, there are two types of HTE: 1) the latent class variable in GMM divides individuals into groups with different growth curves; and 2) coefficient estimates vary across latent classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Latent variables&amp;lt;/b&amp;gt; are not directly observed – they are inferred (via a model) from other actually observed and directly measured variables. Models that explain observed variables in terms of latent variables are called latent variable models. Then the latent (unobserved) variable is discrete, it’s referred to as &amp;lt;b&amp;gt;latent class variable.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Breast Cancer Example: Recall the LMER package, earlier review discussions, where Linear Mixed Model (LMM) are used for longitudinal data to examine change over time of outcomes according relative to predictive covariates. LMM assumptions include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(i)&amp;lt;/b&amp;gt; continuous longitudinal outcome&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(ii)&amp;lt;/b&amp;gt; Gaussian random-effects and errors&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iii)&amp;lt;/b&amp;gt; linearity of the relationships with the outcome&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iv)&amp;lt;/b&amp;gt; homogeneous population&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(v)&amp;lt;/b&amp;gt; missing at random data&lt;br /&gt;
&lt;br /&gt;
The objectives of LGM/GMM models (see &amp;lt;b&amp;gt;Latent Class Mixed Models, lcmm&amp;lt;/b&amp;gt; R package) are to extend the linear mixed model estimation to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(i)&amp;lt;/b&amp;gt;	heterogeneous populations (relax (iv) above). Use &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; for latent class linear mixed models&amp;lt;/mark&amp;gt; (i.e. Gaussian continuous outcome)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(ii)&amp;lt;/b&amp;gt;	other types of longitudinal outcomes : ordinal, (bounded) quantitative non-Gaussian outcomes (relax (i), (ii), (iii), (iv)). Use &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; for general latent class mixed models with outcomes of different nature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;(iii)&amp;lt;/b&amp;gt;	joint analysis of a time-to-event (relax (iv), (v)). Use &amp;lt;b&amp;gt;Jointlcmm&amp;lt;/b&amp;gt; for joint latent class models with a longitudinal outcome and a right-censored (left-truncated) time-to-event&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s use these data (http://www.ats.ucla.edu/stat/data/hdp.csv), representing cancer phenotypes and predictors (e.g., &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;) and outcome measures (e.g., remission) collected on patients, nested within doctors (DID) and within hospitals (HID).&lt;br /&gt;
&lt;br /&gt;
We can illustrate the latent class linear mixed models implemented in &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; through a study of the quadratic trajectories of the response (remission) with TumorSize, adjusting for CO2*Pain interaction and assuming correlated random-effects for the functions of SmokingHx and Sex. To estimate the corresponding standard linear mixed model using 1 latent class where CO2 interacts with Pain:&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
 library(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 hdp &amp;lt;- read.csv(&amp;quot;http://www.ats.ucla.edu/stat/data/hdp.csv&amp;quot;)&lt;br /&gt;
 hdp &amp;lt;- within(hdp, {&lt;br /&gt;
 Married &amp;lt;- factor(Married, levels = 0:1, labels = c(&amp;quot;no&amp;quot;, &amp;quot;yes&amp;quot;))&lt;br /&gt;
 DID &amp;lt;- factor(DID)&lt;br /&gt;
 HID &amp;lt;- factor(HID)&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
add a new subject ID column (last column in the data, “ID”), this is necessary for the hmle call&lt;br /&gt;
hdp$\$$ID &amp;lt;- seq.int(nrow(hdp))&lt;br /&gt;
&lt;br /&gt;
 model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 summary(model.hlme)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Heterogenous linear mixed model &lt;br /&gt;
 fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 hlme(fixed = remission ~ IL6 + CRP + LengthofStay + Experience + &lt;br /&gt;
 I(tumorsize^2) + co2 * pain + I(tumorsize^2) * pain, random = ~SmokingHx + &lt;br /&gt;
 Sex, subject = &amp;quot;ID&amp;quot;, ng = 1, data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
 Dataset: hdp &lt;br /&gt;
 Number of subjects: 8525 &lt;br /&gt;
 Number of observations: 8525 &lt;br /&gt;
 Number of latent classes: 1 &lt;br /&gt;
 Number of parameters: 21  &lt;br /&gt;
 &lt;br /&gt;
 Iteration process: 	&lt;br /&gt;
 Convergence criteria satisfied &lt;br /&gt;
 Number of iterations:  34 &lt;br /&gt;
 Convergence criteria: parameters= 1.2e-09 &lt;br /&gt;
 : likelihood= 8.3e-06 &lt;br /&gt;
 : second derivatives= 2.7e-05 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
 maximum log-likelihood: -5223.9  &lt;br /&gt;
 AIC: 10489.79  &lt;br /&gt;
 BIC: 10637.86&lt;br /&gt;
&lt;br /&gt;
Maximum Likelihood Estimates: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Fixed effects in the Longitudinal Model:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||coef||Se||Wald||p-value&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||0.28636||0.24314||1.178||0.23890&lt;br /&gt;
|-&lt;br /&gt;
|IL6||-0.01134||0.00183||-6.184||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|CRP||-0.00674||0.00167||-4.043||0.00005&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||-0.04834||0.00463||-10.436||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|Experience||0.01695||0.00119||14.263||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2)||0.00000||0.00001||-0.076||0.93953&lt;br /&gt;
|-&lt;br /&gt;
|co2||-0.03549||0.16204||-0.219||0.82663&lt;br /&gt;
|-&lt;br /&gt;
|pain||0.03930||0.04278||0.919||0.35832&lt;br /&gt;
|-&lt;br /&gt;
|co2:pain||-0.01489||0.02871||-0.519||0.60395&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2):pain||0.00000||0.00000||0.553||0.58045&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Variance-covariance matrix of the random-effects&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||intercept||SmokingHxformer||SmokingHxnever||Sexmale&lt;br /&gt;
|-&lt;br /&gt;
|intercept||0.19310943|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxformer||-0.10617988||0.209155186|| ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxnever||-0.12388534||0.068342049||2.262655e-01|| &lt;br /&gt;
|-&lt;br /&gt;
|Sexmale||-0.08130975||-0.007353491||-1.873934e-05||0.1730187&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
                          &lt;br /&gt;
Residual standard error:&lt;br /&gt;
&lt;br /&gt;
coef: 0.1299767&lt;br /&gt;
&lt;br /&gt;
se: 1.187426&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Results interpretation:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1)	The first part of the summary provides information about the dataset, the number of subjects, observations, observations deleted (since by default, missing observations are deleted), number of latent classes and number of parameters. &lt;br /&gt;
&lt;br /&gt;
(2)	Next, details about the algorithm convergence is provided along with the number of iterations, the convergence criteria, and the information indicating if the model converged correctly: &amp;quot;convergence criteria satisfied&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
(3)	The maximum log-likelihood, Akaike criterion (AIC) and Bayesian Information criterion (BIC) are reported. &lt;br /&gt;
&lt;br /&gt;
(4)	Estimates of parameters, the estimated standard error, the Wald Test statistics (with Normal approximation) and the corresponding p-values are reported below. &lt;br /&gt;
&lt;br /&gt;
(5)	For the random-effect distribution, the estimated matrix of covariance of the random-effects is displayed.&lt;br /&gt;
&lt;br /&gt;
(6)	The standard error of the residuals is given along with its estimated standard error.&lt;br /&gt;
&lt;br /&gt;
(7)	The effect of &amp;lt;b&amp;gt;TumorSize&amp;lt;/b&amp;gt; seems not associated with change over Pain of Remission. This may be formally assessed using a multivariate Wald test:&lt;br /&gt;
&lt;br /&gt;
 WaldMult(model.hlme, pos=c(6,8)) &lt;br /&gt;
 # pos - a vector containing the indices in model.hlme of the parameters to test&lt;br /&gt;
 Wald Test p_value&lt;br /&gt;
 I(tumorsize^2) = pain = 0   0.85562 0.65193&lt;br /&gt;
&lt;br /&gt;
We may consider the model with an adjustment for CRP only on the intercept. Below we estimate the corresponding &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;models for a varying number of latent classes&amp;lt;/b&amp;gt;&amp;lt;/mark&amp;gt; (from 1 to 3) using the default initial values:&lt;br /&gt;
&lt;br /&gt;
 # Initial Model: model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
&lt;br /&gt;
 model.hlme.1 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 model.hlme.2 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=2)&lt;br /&gt;
 model.hlme.3 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=3)&lt;br /&gt;
&lt;br /&gt;
The estimation process for a varying number of latent classes can be summarized with &amp;lt;b&amp;gt;summarytable,&amp;lt;/b&amp;gt; which gives the &amp;lt;b&amp;gt;log-likelihood&amp;lt;/b&amp;gt;, the number of parameters, the Bayesian Information Criterion, and the posterior proportion of each class:&lt;br /&gt;
&lt;br /&gt;
 summarytable(model.hlme.1, model.hlme.2, model.hlme.3)&lt;br /&gt;
             G    loglik npm      BIC    %class1    %class2  %class3&lt;br /&gt;
 model.hlme.1 1 -33301.82   5 66648.89 100.000000                    &lt;br /&gt;
 model.hlme.2 2 -31592.79  11 63285.15  99.214076  0.7859238         &lt;br /&gt;
 model.hlme.3 3 -31589.55  15 63314.86   6.357771 82.2991202 11.34311&lt;br /&gt;
&lt;br /&gt;
The program took 404.65 seconds)&lt;br /&gt;
&lt;br /&gt;
In this example, the optimal number of latent classes according to the BIC is two (the smallest BIC).  The posterior classification is described with:&lt;br /&gt;
&lt;br /&gt;
 postprob(model.hlme.2)&lt;br /&gt;
&lt;br /&gt;
 Posterior classification: &lt;br /&gt;
   class1 class2&lt;br /&gt;
 N 8458.00  67.00&lt;br /&gt;
 %   99.21   0.79&lt;br /&gt;
 &lt;br /&gt;
 Posterior classification table: &lt;br /&gt;
     --&amp;gt; mean of posterior probabilities in each class &lt;br /&gt;
        prob1  prob2&lt;br /&gt;
 class1 0.8555 0.1445&lt;br /&gt;
 class2 0.4362 0.5638&lt;br /&gt;
 &lt;br /&gt;
 Posterior probabilities above a threshold (%): &lt;br /&gt;
         class1 class2&lt;br /&gt;
 prob&amp;gt;0.7  92.48   2.99&lt;br /&gt;
 prob&amp;gt;0.8  77.38   0.00&lt;br /&gt;
 prob&amp;gt;0.9  38.53   0.00&lt;br /&gt;
&lt;br /&gt;
In this example, the first class includes a posteriori 8458 subjects (99%) while class 2 includes 67 (0.79%) subjects. Subjects were classified in class 1 with a mean posterior probability of 0.8555 %. &lt;br /&gt;
&lt;br /&gt;
In class 1, 92.48% were classified with a posterior probability above 0.7 while 2.99% of the subjects were classified in class 2 with a posterior probability above 0.7. Goodness-of-fit of the model can be assessed by displaying the residuals as in figure and the mean predictions of the model as in figure, according to the time variable given in &amp;lt;b&amp;gt;var.time&amp;lt;/b&amp;gt;:  &lt;br /&gt;
&lt;br /&gt;
 plot(model.hlme.2)&lt;br /&gt;
 # Figure (left panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2) &lt;br /&gt;
 # Figure (right panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2, marg=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The latent process mixed models implemented in &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; are illustrated through the study of the linear trajectory of &amp;lt;b&amp;gt;ntumors&amp;lt;/b&amp;gt; with Age adjusted for Sex and assuming correlated random-effects for the intercept and Age. Lines estimate the corresponding latent process mixed model with different link functions:&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', data=hdp)&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta')&lt;br /&gt;
 model.hlme.spl &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='splines')&lt;br /&gt;
 model.hlme.spl5q &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='5-quant-splines')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;link function&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;: An optional family of link functions. By default, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;linear&amp;quot; option specifies a linear link function leading to a standard linear mixed model (homogeneous or heterogeneous as estimated in hlme). &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;beta&amp;quot; for estimating a link function from the family of Beta cumulative distribution functions, &amp;quot;thresholds&amp;quot; for using a threshold model to describe the correspondence between each level of an ordinal outcome and the underlying latent process, and&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;Splines&amp;quot; for approximating the link function by I-splines. For this latter case, the number of nodes and the nodes location should be also specified. The number of nodes is first entered followed by,&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; -, then the location is specified with &amp;quot;equi&amp;quot;, &amp;quot;quant&amp;quot; or &amp;quot;manual&amp;quot; for respectively equidistant nodes, nodes at quantiles of the marker distribution or interior nodes entered manually in argument&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;intnodes. It is followed by - and finally &amp;quot;splines&amp;quot; is indicated. For example, &amp;quot;7-equi-splines&amp;quot; means I-splines with 7 equidistant nodes, &amp;quot;6-quant-splines&amp;quot; means I-splines with 6 nodes located at the quantiles of the marker distribution and &amp;quot;9-manual-splines&amp;quot; means I-splines with 9 nodes, the vector of 7 interior nodes being entered in the argument intnodes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary (model.hlme.lin)&lt;br /&gt;
&lt;br /&gt;
 General latent class mixed model fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 lcmm(fixed = ntumors ~ Age * Sex, random = ~Age, subject = &amp;quot;ID&amp;quot;,data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
     Dataset: hdp &lt;br /&gt;
     Number of subjects: 8525 &lt;br /&gt;
     Number of observations: 8525 &lt;br /&gt;
     Number of latent classes: 1 &lt;br /&gt;
     Number of parameters: 8  &lt;br /&gt;
     Link function: linear  &lt;br /&gt;
 &lt;br /&gt;
Iteration process: &lt;br /&gt;
     Maximum number of iteration reached without convergence &lt;br /&gt;
     Number of iterations:  100 &lt;br /&gt;
     Convergence criteria: parameters= 5.4e-10 &lt;br /&gt;
                         : likelihood= 5.5e-10 &lt;br /&gt;
                         : second derivatives= 1 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
     maximum log-likelihood: -19915.24  &lt;br /&gt;
     AIC: 39846.49  &lt;br /&gt;
     BIC: 39902.89  &lt;br /&gt;
 &lt;br /&gt;
     Discrete posterior log-likelihood: 0  &lt;br /&gt;
     Discrete AIC: 16  &lt;br /&gt;
 &lt;br /&gt;
     Mean discrete AIC per subject: 9e-04  &lt;br /&gt;
     Mean UACV per subject: 0  &lt;br /&gt;
     Mean discrete LL per subject: 0  &lt;br /&gt;
 &lt;br /&gt;
 Maximum Likelihood Estimates: &lt;br /&gt;
 &lt;br /&gt;
 Fixed effects in the longitudinal model:&lt;br /&gt;
&lt;br /&gt;
                              coef Se Wald p-value&lt;br /&gt;
 intercept (not estimated)  0.00000                &lt;br /&gt;
 Age                        0.09491                &lt;br /&gt;
 Sexmale                   -0.66303                &lt;br /&gt;
 Age:Sexmale                0.01132                &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Variance-covariance matrix of the random-effects:&lt;br /&gt;
           intercept         Age&lt;br /&gt;
 intercept 20.5013715            &lt;br /&gt;
 Age       -0.2889814 0.007696382&lt;br /&gt;
&lt;br /&gt;
 Residual standard error (not estimated) = 1&lt;br /&gt;
&lt;br /&gt;
 Parameters of the link function:&lt;br /&gt;
&lt;br /&gt;
                         coef Se Wald p-value&lt;br /&gt;
 Linear 1 (intercept) -0.36768                &lt;br /&gt;
 Linear 2 (std err)    0.71432           &lt;br /&gt;
&lt;br /&gt;
Objects &amp;lt;b&amp;gt;mlin, mbeta, mspl and mspl3eq&amp;lt;/b&amp;gt; are latent process mixed models that assume the exact same trajectory for the underlying latent process but respectively a linear, BetaCDF, I-splines with 5 equidistant knots (default with link=’splines’) and I-splines with 5 knots at percentiles. &amp;lt;b&amp;gt;mlin&amp;lt;/b&amp;gt; reduces to a standard linear mixed model (link=’linear’ by default). The only difference with a &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; object is the parameterization for the intercept and the residual standard error that are considered as rescaling parameters.&lt;br /&gt;
&lt;br /&gt;
 col &amp;lt;- rainbow(4)&lt;br /&gt;
 plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(model.hlme.beta, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[2], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[3], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl5q, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[4], lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;topleft&amp;quot;,legend=c(&amp;quot;linear&amp;quot;, &amp;quot;beta&amp;quot;,&amp;quot;splines (5equidistant)&amp;quot;, &amp;quot;splines (5 at quantiles)&amp;quot;), lty=1,col=col,bty=&amp;quot;n&amp;quot;,lwd=2)&lt;br /&gt;
&lt;br /&gt;
 # to obtain confidence bands use function predictlink &lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;Error in predictlink.lcmm(model.hlme.spl, ndraws = 2000):&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;No confidence intervals can be produced since the program did not converge properly&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;model.hlme.lin$\$$conv &amp;lt;mark&amp;gt;# double-check the convergence of the algorithm[1] 2&amp;lt;/mark&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# status of convergence:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =1 if the convergence criteria were satisfied,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =2 if the maximum number of iterations was reached,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =4 or 5 if a problem occured during optimisation&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', epsY = 0.5, convB = 1e-01, convL = 1e-01, &amp;lt;mark&amp;gt;convG = 1e-01&amp;lt;/mark&amp;gt;, maxiter=200, data=hdp); model.hlme.lin$conv&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;mark&amp;gt;# Now that we have convergence, we can obtain CI’s!!!&amp;lt;/mark&amp;gt;&lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 # plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(link.lin, add=TRUE, col=col[1], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for linear fit&amp;quot;), lty=c(2,NA), col=c(col[1],NA), bty=&amp;quot;n&amp;quot;, lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;Repeat using the other link functions … model.hlme.beta, model.hlme.spl, …&amp;lt;/mark&amp;gt;&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta', &lt;br /&gt;
 &amp;lt;mark&amp;gt;convB = 1e-01&amp;lt;/mark&amp;gt;, convL = 1e-01, convG = 1e-01, maxiter=200); model.hlme.beta$\$$conv&lt;br /&gt;
 link.beta &amp;lt;- predictlink(model.hlme.beta, ndraws=2000)&lt;br /&gt;
 plot(link.beta, add=TRUE, col=col[2], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for BETA fit&amp;quot;), lty=c(3,NA), col=c(col[2],NA), bty=&amp;quot;n&amp;quot;, lwd=1)&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity_MetaAnalysis|Next see: Meta-Analysis]]===&lt;br /&gt;
* [[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_HTE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16031</id>
		<title>SMHS MethodsHeterogeneity HTE</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity_HTE&amp;diff=16031"/>
		<updated>2016-05-19T14:42:38Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Latent growth and growth mixture modeling (LGM/GMM) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_MethodsHeterogeneity| Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research]] - Methods and Approaches for HTE Analytics ==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
&lt;br /&gt;
Recursive partitioning is a data mining technique for exploring structure and patterns in complex data. It facilitates the visualization of decision rules for predicting categorical (classification tree) or continuous (regression tree) outcome variables. The R &amp;lt;b&amp;gt;rpart&amp;lt;/b&amp;gt; package   provides the tools for Classification and Regression Tree (CART) modeling, conditional inference trees, and random forests. Additional resources include an Introduction to Recursive Partitioning Using the RPART Routines  . The &amp;lt;b&amp;gt;Appendix&amp;lt;/b&amp;gt; includes description of the main CART analysis steps.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;install.packages(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
 &amp;lt;b&amp;gt;library(&amp;quot;rpart&amp;quot;)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CART===&lt;br /&gt;
Classification and Regression Tree (CART) is a decision-tree based technique that considers how variation observed in a given response variable (continuous or categorical) can be understood through a systematic deconstruction of the overall study population into subgroups, using explanatory variables of interest. For HTE analysis, CART is best suited for early-stage, exploratory analyses. Its relative simplicity can be powerful in identifying basic relationships between variables of interest, and thus identify potential subgroups for more advanced analyses. The key to CART is its ‘systematic’ approach to the development of the subgroups, which are constructed sequentially through repeated, binary splits of the population of interest, one explanatory variable at a time. In other words, each ‘parent’ group is divided into two ‘child’ groups, with the objective of creating increasingly homogeneous subgroups. The process is repeated and the subgroups are then further split, until no additional variables are available for further subgroup development. The resulting tree structure is oftentimes overgrown, but additional techniques are used to ‘trim’ the tree to a point at which its predictive power is balanced against issues of over-fitting. Because the CART approach does not make assumptions regarding the distribution of the dependent variable, it can be used in situations where other multivariate modeling techniques often used for exploratory predictive risk modeling would not be appropriate – namely in situations where data are not normally distributed. &lt;br /&gt;
&lt;br /&gt;
CART analyses are useful in situations where there is some evidence to suggest that HTE exists, but the subgroups defining the heterogeneous response are not well understood. CART allows for an exploration of response in a myriad of complex subpopulations, and more recently developed ensemble methods (such as Bayesian Additive Regression Trees) allow for more robust analyses through the combination of multiple CART analyses.&lt;br /&gt;
&lt;br /&gt;
====Example Fifth Dutch growth study====&lt;br /&gt;
&lt;br /&gt;
 # Let’s use the Fifth Dutch growth study (2009) &amp;lt;b&amp;gt;fdgs&amp;lt;/b&amp;gt;  . Is it true that “the world’s tallest nation has stopped growing taller: the height of Dutch children from 1955 to 2009”?&lt;br /&gt;
&lt;br /&gt;
 #install.packages(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 library(&amp;quot;mice&amp;quot;)&lt;br /&gt;
 ?fdgs&lt;br /&gt;
 head(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||ID ||Reg ||Age ||Sex ||HGT ||WGT ||HGT.Z ||WGT.Z&lt;br /&gt;
|-&lt;br /&gt;
|1 ||100001||West||13.09514||boy||175.5||75.0||1.751||2.410&lt;br /&gt;
|-&lt;br /&gt;
|2 ||100003||West||13.81793 ||boy||148.4||40.0||2.292||1.494&lt;br /&gt;
|-&lt;br /&gt;
|3 ||100004||West||13.97125||boy||159.9||46.5||0.743||0.783&lt;br /&gt;
|-&lt;br /&gt;
|4 ||100005||West||13.98220 ||girl||159.7||46.5 ||0.743 ||0.783&lt;br /&gt;
|-&lt;br /&gt;
|5||100006||West||13.52225||girl||160.3||47.8||0.414||0.355&lt;br /&gt;
|-&lt;br /&gt;
|6||100018||East||10.21492||boy||157.8||39.7||2.025||0.823&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary(fdgs)        &lt;br /&gt;
 summary(fdgs)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ID ||Reg ||Age ||Sex ||HGT&lt;br /&gt;
|-&lt;br /&gt;
|Min.:100001||North:732||Min.:0.008214||boy:4829||Min.:46.0&lt;br /&gt;
|-&lt;br /&gt;
|1st Qu.:106353||East:2528||1st Qu.:1.618754||girl:5201||1st Qu.:83.8&lt;br /&gt;
|-&lt;br /&gt;
|Median:203855||South:2931||Median:8.084873|| ||Median:131.5&lt;br /&gt;
|-&lt;br /&gt;
|Mean:180091||West:2578||Mean:8.157936|| ||Mean:123.9&lt;br /&gt;
|-&lt;br /&gt;
|3rd Qu.210591||City:1261||3rd Qu.:13.547570|| ||3rd Qu.:162.3&lt;br /&gt;
|-&lt;br /&gt;
|Max:401955|| ||Max.:21.993155|| ||Max.:208.0&lt;br /&gt;
|-&lt;br /&gt;
| || || || ||NA's: 23&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1) Classification Tree&lt;br /&gt;
&lt;br /&gt;
Let's use the data frame fdgs to predict Region, from Age, Height, and Weight.&lt;br /&gt;
 # grow tree &lt;br /&gt;
 fit.1 &amp;lt;- rpart(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, data= fdgs[,-1])&lt;br /&gt;
&lt;br /&gt;
 printcp(fit.1) 	# display the results &lt;br /&gt;
 plotcp(fit.1) 	# visualize cross-validation results &lt;br /&gt;
 summary(fit.1) 	# detailed summary of splits&lt;br /&gt;
&lt;br /&gt;
 # plot tree &lt;br /&gt;
 par(oma=c(0,0,2,0))&lt;br /&gt;
 plot(fit.1, uniform=TRUE,  margin=0.3, main=&amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # create a better plot of the classification tree &lt;br /&gt;
 post(fit.1, title = &amp;quot;Classification Tree for Region (FDGS Data)&amp;quot;, file = &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(2) Pruning the tree &lt;br /&gt;
&lt;br /&gt;
 pruned.fit.1&amp;lt;- prune(fit.1, cp=   fit.1$\$$cptable[which.min(fit.1$\$$\$$cptable[,&amp;quot;xerror&amp;quot;]),&amp;quot;CP&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
 # plot the pruned tree &lt;br /&gt;
 plot(pruned.fit.1, uniform=TRUE,  main=&amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
 text(pruned.fit.1, use.n=TRUE, all=TRUE, cex=1.0)&lt;br /&gt;
 post(pruned.fit.1,  title = &amp;quot;Pruned Classification Tree for Region (FDGS Data)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Not much change, as the initial tree is not complex!&lt;br /&gt;
&lt;br /&gt;
===Random Forests ===&lt;br /&gt;
Random forests may improve predictive accuracy by generating a large number of bootstrapped trees (based on random samples of variables). It classifies cases using each tree in this new &amp;quot;forest&amp;quot;, and decides the final predicted outcome by combining the results across all of the trees (an average in regression, a majority vote in classification). See the &amp;lt;b&amp;gt;randomForest&amp;lt;/b&amp;gt; package. &lt;br /&gt;
&lt;br /&gt;
 library(randomForest)&lt;br /&gt;
 fit.2 &amp;lt;- randomForest(reg ~ age + hgt + wgt,   method=&amp;quot;class&amp;quot;, na.action = na.omit, data= fdgs[,-1])&lt;br /&gt;
 print(fit.2) 		# view results &lt;br /&gt;
 importance(fit.2) 	# importance of each predictor &lt;br /&gt;
&lt;br /&gt;
Note on missing values/incomplete data: If the data have missing values, we have 3 choices:&lt;br /&gt;
&lt;br /&gt;
1.	Use a different tool (rpart handles missing values well)&lt;br /&gt;
&lt;br /&gt;
2.	Impute the missing values&lt;br /&gt;
&lt;br /&gt;
3.	For a small number of missing cases, we can use na.action = na.omit&lt;br /&gt;
&lt;br /&gt;
===Latent growth and growth mixture modeling (LGM/GMM)===&lt;br /&gt;
&lt;br /&gt;
LGM and GMM represent structural equation modeling techniques that capture inter-individual differences in longitudinal change corresponding to a particular treatment. For instance, patients’ different timing patterns of the treatment effects may represent the underlying sources of HTE. LGM distinguish if (yes/no) and how (fast/slow, temporary/lasting) patients respond to treatment. The heterogeneous individual growth trajectories are estimated from intra-individual changes over time by examining common population parameters, i.e., slopes, intercepts, and error variances. Suppose each individual has unique initial status (intercept) and response rate (slope) during a specific time interval. Then the variances of the individuals’ baseline measures (intercepts) and changes (slopes) in health outcomes will represent the degree of HTE. The LGM-identified HTE of individual growth curves can be attributed to observed predictors, including both fixed and time varying covariates.&lt;br /&gt;
&lt;br /&gt;
LGM assumes that all individuals are from the same population (too restrictive in some cases). If the HTE is due to observed demographic variables, such as age, gender, and marital status, one may utilize multiple-group LGM. Despite its successful applications for modeling longitudinal change, there may be multiple subpopulations with unobserved heterogeneities. Growth mixture modeling (GMM) extends LGM to allow the identification and prediction of unobserved subpopulations in longitudinal data analysis. Each unobserved subpopulation may constitute its own latent class and behave differently than individuals in other latent classes. Within each latent class, there are also different trajectories across individuals; however, different latent classes don’t share common population parameters. Suppose we are interested in studying retirees’ psychological well-being change trajectory when multiple unknown subpopulations exist. We can add another layer (a latent class variable) on the LGM framework so that the unobserved latent classes can be inferred from the data. The covariates in GMM are designed to affect growth factors distinctly across different latent classes. Therefore, there are two types of HTE: 1) the latent class variable in GMM divides individuals into groups with different growth curves; and 2) coefficient estimates vary across latent classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Latent variables&amp;lt;/b&amp;gt; are not directly observed – they are inferred (via a model) from other actually observed and directly measured variables. Models that explain observed variables in terms of latent variables are called latent variable models. Then the latent (unobserved) variable is discrete, it’s referred to as &amp;lt;b&amp;gt;latent class variable.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Breast Cancer Example: Recall the LMER package, earlier review discussions, where Linear Mixed Model (LMM) are used for longitudinal data to examine change over time of outcomes according relative to predictive covariates. LMM assumptions include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(i) continuous longitudinal outcome&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(ii) Gaussian random-effects and errors&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(iii) linearity of the relationships with the outcome&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(iv) homogeneous population&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(v) missing at random data&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The objectives of LGM/GMM models (see &amp;lt;b&amp;gt;Latent Class Mixed Models, lcmm&amp;lt;/b&amp;gt; R package) are to extend the linear mixed model estimation to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(i)	heterogeneous populations (relax (iv) above). Use &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; for latent class linear mixed models&amp;lt;/mark&amp;gt; (i.e. Gaussian continuous outcome)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(ii)	other types of longitudinal outcomes : ordinal, (bounded) quantitative non-Gaussian outcomes (relax (i), (ii), (iii), (iv)). Use &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; for general latent class mixed models with outcomes of different nature&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;(iii)	joint analysis of a time-to-event (relax (iv), (v)). Use &amp;lt;b&amp;gt;Jointlcmm&amp;lt;/b&amp;gt; for joint latent class models with a longitudinal outcome and a right-censored (left-truncated) time-to-event&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s use these data (http://www.ats.ucla.edu/stat/data/hdp.csv), representing cancer phenotypes and predictors (e.g., &amp;quot;IL6&amp;quot;, &amp;quot;CRP&amp;quot;, &amp;quot;LengthofStay&amp;quot;, &amp;quot;Experience&amp;quot;) and outcome measures (e.g., remission) collected on patients, nested within doctors (DID) and within hospitals (HID).&lt;br /&gt;
&lt;br /&gt;
We can illustrate the latent class linear mixed models implemented in &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; through a study of the quadratic trajectories of the response (remission) with TumorSize, adjusting for CO2*Pain interaction and assuming correlated random-effects for the functions of SmokingHx and Sex. To estimate the corresponding standard linear mixed model using 1 latent class where CO2 interacts with Pain:&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
 library(&amp;quot;lcmm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 hdp &amp;lt;- read.csv(&amp;quot;http://www.ats.ucla.edu/stat/data/hdp.csv&amp;quot;)&lt;br /&gt;
 hdp &amp;lt;- within(hdp, {&lt;br /&gt;
 Married &amp;lt;- factor(Married, levels = 0:1, labels = c(&amp;quot;no&amp;quot;, &amp;quot;yes&amp;quot;))&lt;br /&gt;
 DID &amp;lt;- factor(DID)&lt;br /&gt;
 HID &amp;lt;- factor(HID)&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
add a new subject ID column (last column in the data, “ID”), this is necessary for the hmle call&lt;br /&gt;
hdp$\$$ID &amp;lt;- seq.int(nrow(hdp))&lt;br /&gt;
&lt;br /&gt;
 model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 summary(model.hlme)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Heterogenous linear mixed model &lt;br /&gt;
 fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 hlme(fixed = remission ~ IL6 + CRP + LengthofStay + Experience + &lt;br /&gt;
 I(tumorsize^2) + co2 * pain + I(tumorsize^2) * pain, random = ~SmokingHx + &lt;br /&gt;
 Sex, subject = &amp;quot;ID&amp;quot;, ng = 1, data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
 Dataset: hdp &lt;br /&gt;
 Number of subjects: 8525 &lt;br /&gt;
 Number of observations: 8525 &lt;br /&gt;
 Number of latent classes: 1 &lt;br /&gt;
 Number of parameters: 21  &lt;br /&gt;
 &lt;br /&gt;
 Iteration process: 	&lt;br /&gt;
 Convergence criteria satisfied &lt;br /&gt;
 Number of iterations:  34 &lt;br /&gt;
 Convergence criteria: parameters= 1.2e-09 &lt;br /&gt;
 : likelihood= 8.3e-06 &lt;br /&gt;
 : second derivatives= 2.7e-05 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
 maximum log-likelihood: -5223.9  &lt;br /&gt;
 AIC: 10489.79  &lt;br /&gt;
 BIC: 10637.86&lt;br /&gt;
&lt;br /&gt;
Maximum Likelihood Estimates: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Fixed effects in the Longitudinal Model:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||coef||Se||Wald||p-value&lt;br /&gt;
|-&lt;br /&gt;
|Intercept||0.28636||0.24314||1.178||0.23890&lt;br /&gt;
|-&lt;br /&gt;
|IL6||-0.01134||0.00183||-6.184||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|CRP||-0.00674||0.00167||-4.043||0.00005&lt;br /&gt;
|-&lt;br /&gt;
|LengthofStay||-0.04834||0.00463||-10.436||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|Experience||0.01695||0.00119||14.263||0.00000&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2)||0.00000||0.00001||-0.076||0.93953&lt;br /&gt;
|-&lt;br /&gt;
|co2||-0.03549||0.16204||-0.219||0.82663&lt;br /&gt;
|-&lt;br /&gt;
|pain||0.03930||0.04278||0.919||0.35832&lt;br /&gt;
|-&lt;br /&gt;
|co2:pain||-0.01489||0.02871||-0.519||0.60395&lt;br /&gt;
|-&lt;br /&gt;
|I(tumorsize^2):pain||0.00000||0.00000||0.553||0.58045&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Variance-covariance matrix of the random-effects&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||intercept||SmokingHxformer||SmokingHxnever||Sexmale&lt;br /&gt;
|-&lt;br /&gt;
|intercept||0.19310943|| || ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxformer||-0.10617988||0.209155186|| ||&lt;br /&gt;
|-&lt;br /&gt;
|SmokingHxnever||-0.12388534||0.068342049||2.262655e-01|| &lt;br /&gt;
|-&lt;br /&gt;
|Sexmale||-0.08130975||-0.007353491||-1.873934e-05||0.1730187&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
                          &lt;br /&gt;
Residual standard error:&lt;br /&gt;
&lt;br /&gt;
coef: 0.1299767&lt;br /&gt;
&lt;br /&gt;
se: 1.187426&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Results interpretation:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(1)	The first part of the summary provides information about the dataset, the number of subjects, observations, observations deleted (since by default, missing observations are deleted), number of latent classes and number of parameters. &lt;br /&gt;
&lt;br /&gt;
(2)	Next, details about the algorithm convergence is provided along with the number of iterations, the convergence criteria, and the information indicating if the model converged correctly: &amp;quot;convergence criteria satisfied&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
(3)	The maximum log-likelihood, Akaike criterion (AIC) and Bayesian Information criterion (BIC) are reported. &lt;br /&gt;
&lt;br /&gt;
(4)	Estimates of parameters, the estimated standard error, the Wald Test statistics (with Normal approximation) and the corresponding p-values are reported below. &lt;br /&gt;
&lt;br /&gt;
(5)	For the random-effect distribution, the estimated matrix of covariance of the random-effects is displayed.&lt;br /&gt;
&lt;br /&gt;
(6)	The standard error of the residuals is given along with its estimated standard error.&lt;br /&gt;
&lt;br /&gt;
(7)	The effect of &amp;lt;b&amp;gt;TumorSize&amp;lt;/b&amp;gt; seems not associated with change over Pain of Remission. This may be formally assessed using a multivariate Wald test:&lt;br /&gt;
&lt;br /&gt;
 WaldMult(model.hlme, pos=c(6,8)) &lt;br /&gt;
 # pos - a vector containing the indices in model.hlme of the parameters to test&lt;br /&gt;
 Wald Test p_value&lt;br /&gt;
 I(tumorsize^2) = pain = 0   0.85562 0.65193&lt;br /&gt;
&lt;br /&gt;
We may consider the model with an adjustment for CRP only on the intercept. Below we estimate the corresponding &amp;lt;mark&amp;gt;&amp;lt;b&amp;gt;models for a varying number of latent classes&amp;lt;/b&amp;gt;&amp;lt;/mark&amp;gt; (from 1 to 3) using the default initial values:&lt;br /&gt;
&lt;br /&gt;
 # Initial Model: model.hlme &amp;lt;- hlme(remission ~ IL6 + CRP + LengthofStay + Experience + I(tumorsize^2) + co2*pain + I(tumorsize^2)*pain, random=~ SmokingHx + Sex, subject='ID', data=hdp, ng=1)&lt;br /&gt;
&lt;br /&gt;
 model.hlme.1 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay, subject='ID', data=hdp, ng=1)&lt;br /&gt;
 model.hlme.2 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=2)&lt;br /&gt;
 model.hlme.3 &amp;lt;- hlme(tumorsize ~ IL6 + CRP + LengthofStay + SmokingHx, mixture=~ SmokingHx, subject='ID', data=hdp, ng=3)&lt;br /&gt;
&lt;br /&gt;
The estimation process for a varying number of latent classes can be summarized with &amp;lt;b&amp;gt;summarytable,&amp;lt;/b&amp;gt; which gives the &amp;lt;b&amp;gt;log-likelihood&amp;lt;/b&amp;gt;, the number of parameters, the Bayesian Information Criterion, and the posterior proportion of each class:&lt;br /&gt;
&lt;br /&gt;
 summarytable(model.hlme.1, model.hlme.2, model.hlme.3)&lt;br /&gt;
             G    loglik npm      BIC    %class1    %class2  %class3&lt;br /&gt;
 model.hlme.1 1 -33301.82   5 66648.89 100.000000                    &lt;br /&gt;
 model.hlme.2 2 -31592.79  11 63285.15  99.214076  0.7859238         &lt;br /&gt;
 model.hlme.3 3 -31589.55  15 63314.86   6.357771 82.2991202 11.34311&lt;br /&gt;
&lt;br /&gt;
The program took 404.65 seconds)&lt;br /&gt;
&lt;br /&gt;
In this example, the optimal number of latent classes according to the BIC is two (the smallest BIC).  The posterior classification is described with:&lt;br /&gt;
&lt;br /&gt;
 postprob(model.hlme.2)&lt;br /&gt;
&lt;br /&gt;
 Posterior classification: &lt;br /&gt;
   class1 class2&lt;br /&gt;
 N 8458.00  67.00&lt;br /&gt;
 %   99.21   0.79&lt;br /&gt;
 &lt;br /&gt;
 Posterior classification table: &lt;br /&gt;
     --&amp;gt; mean of posterior probabilities in each class &lt;br /&gt;
        prob1  prob2&lt;br /&gt;
 class1 0.8555 0.1445&lt;br /&gt;
 class2 0.4362 0.5638&lt;br /&gt;
 &lt;br /&gt;
 Posterior probabilities above a threshold (%): &lt;br /&gt;
         class1 class2&lt;br /&gt;
 prob&amp;gt;0.7  92.48   2.99&lt;br /&gt;
 prob&amp;gt;0.8  77.38   0.00&lt;br /&gt;
 prob&amp;gt;0.9  38.53   0.00&lt;br /&gt;
&lt;br /&gt;
In this example, the first class includes a posteriori 8458 subjects (99%) while class 2 includes 67 (0.79%) subjects. Subjects were classified in class 1 with a mean posterior probability of 0.8555 %. &lt;br /&gt;
&lt;br /&gt;
In class 1, 92.48% were classified with a posterior probability above 0.7 while 2.99% of the subjects were classified in class 2 with a posterior probability above 0.7. Goodness-of-fit of the model can be assessed by displaying the residuals as in figure and the mean predictions of the model as in figure, according to the time variable given in &amp;lt;b&amp;gt;var.time&amp;lt;/b&amp;gt;:  &lt;br /&gt;
&lt;br /&gt;
 plot(model.hlme.2)&lt;br /&gt;
 # Figure (left panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2) &lt;br /&gt;
 # Figure (right panel)&lt;br /&gt;
 plot(model.hlme.2, which=&amp;quot;fit&amp;quot;, var.time=&amp;quot;Age&amp;quot;, bty=&amp;quot;l&amp;quot;, ylab=&amp;quot; Remission &amp;quot;, xlab=&amp;quot;Age&amp;quot;, lwd=2, marg=FALSE)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The latent process mixed models implemented in &amp;lt;b&amp;gt;lcmm&amp;lt;/b&amp;gt; are illustrated through the study of the linear trajectory of &amp;lt;b&amp;gt;ntumors&amp;lt;/b&amp;gt; with Age adjusted for Sex and assuming correlated random-effects for the intercept and Age. Lines estimate the corresponding latent process mixed model with different link functions:&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', data=hdp)&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta')&lt;br /&gt;
 model.hlme.spl &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='splines')&lt;br /&gt;
 model.hlme.spl5q &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='5-quant-splines')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;link function&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;: An optional family of link functions. By default, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;linear&amp;quot; option specifies a linear link function leading to a standard linear mixed model (homogeneous or heterogeneous as estimated in hlme). &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;beta&amp;quot; for estimating a link function from the family of Beta cumulative distribution functions, &amp;quot;thresholds&amp;quot; for using a threshold model to describe the correspondence between each level of an ordinal outcome and the underlying latent process, and&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;Splines&amp;quot; for approximating the link function by I-splines. For this latter case, the number of nodes and the nodes location should be also specified. The number of nodes is first entered followed by,&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; -, then the location is specified with &amp;quot;equi&amp;quot;, &amp;quot;quant&amp;quot; or &amp;quot;manual&amp;quot; for respectively equidistant nodes, nodes at quantiles of the marker distribution or interior nodes entered manually in argument&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;intnodes. It is followed by - and finally &amp;quot;splines&amp;quot; is indicated. For example, &amp;quot;7-equi-splines&amp;quot; means I-splines with 7 equidistant nodes, &amp;quot;6-quant-splines&amp;quot; means I-splines with 6 nodes located at the quantiles of the marker distribution and &amp;quot;9-manual-splines&amp;quot; means I-splines with 9 nodes, the vector of 7 interior nodes being entered in the argument intnodes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 summary (model.hlme.lin)&lt;br /&gt;
&lt;br /&gt;
 General latent class mixed model fitted by maximum likelihood method &lt;br /&gt;
 &lt;br /&gt;
 lcmm(fixed = ntumors ~ Age * Sex, random = ~Age, subject = &amp;quot;ID&amp;quot;,data = hdp)&lt;br /&gt;
 &lt;br /&gt;
 Statistical Model: &lt;br /&gt;
     Dataset: hdp &lt;br /&gt;
     Number of subjects: 8525 &lt;br /&gt;
     Number of observations: 8525 &lt;br /&gt;
     Number of latent classes: 1 &lt;br /&gt;
     Number of parameters: 8  &lt;br /&gt;
     Link function: linear  &lt;br /&gt;
 &lt;br /&gt;
Iteration process: &lt;br /&gt;
     Maximum number of iteration reached without convergence &lt;br /&gt;
     Number of iterations:  100 &lt;br /&gt;
     Convergence criteria: parameters= 5.4e-10 &lt;br /&gt;
                         : likelihood= 5.5e-10 &lt;br /&gt;
                         : second derivatives= 1 &lt;br /&gt;
 &lt;br /&gt;
 Goodness-of-fit statistics: &lt;br /&gt;
     maximum log-likelihood: -19915.24  &lt;br /&gt;
     AIC: 39846.49  &lt;br /&gt;
     BIC: 39902.89  &lt;br /&gt;
 &lt;br /&gt;
     Discrete posterior log-likelihood: 0  &lt;br /&gt;
     Discrete AIC: 16  &lt;br /&gt;
 &lt;br /&gt;
     Mean discrete AIC per subject: 9e-04  &lt;br /&gt;
     Mean UACV per subject: 0  &lt;br /&gt;
     Mean discrete LL per subject: 0  &lt;br /&gt;
 &lt;br /&gt;
 Maximum Likelihood Estimates: &lt;br /&gt;
 &lt;br /&gt;
 Fixed effects in the longitudinal model:&lt;br /&gt;
&lt;br /&gt;
                              coef Se Wald p-value&lt;br /&gt;
 intercept (not estimated)  0.00000                &lt;br /&gt;
 Age                        0.09491                &lt;br /&gt;
 Sexmale                   -0.66303                &lt;br /&gt;
 Age:Sexmale                0.01132                &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Variance-covariance matrix of the random-effects:&lt;br /&gt;
           intercept         Age&lt;br /&gt;
 intercept 20.5013715            &lt;br /&gt;
 Age       -0.2889814 0.007696382&lt;br /&gt;
&lt;br /&gt;
 Residual standard error (not estimated) = 1&lt;br /&gt;
&lt;br /&gt;
 Parameters of the link function:&lt;br /&gt;
&lt;br /&gt;
                         coef Se Wald p-value&lt;br /&gt;
 Linear 1 (intercept) -0.36768                &lt;br /&gt;
 Linear 2 (std err)    0.71432           &lt;br /&gt;
&lt;br /&gt;
Objects &amp;lt;b&amp;gt;mlin, mbeta, mspl and mspl3eq&amp;lt;/b&amp;gt; are latent process mixed models that assume the exact same trajectory for the underlying latent process but respectively a linear, BetaCDF, I-splines with 5 equidistant knots (default with link=’splines’) and I-splines with 5 knots at percentiles. &amp;lt;b&amp;gt;mlin&amp;lt;/b&amp;gt; reduces to a standard linear mixed model (link=’linear’ by default). The only difference with a &amp;lt;b&amp;gt;hlme&amp;lt;/b&amp;gt; object is the parameterization for the intercept and the residual standard error that are considered as rescaling parameters.&lt;br /&gt;
&lt;br /&gt;
 col &amp;lt;- rainbow(4)&lt;br /&gt;
 plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(model.hlme.beta, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[2], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[3], lwd=2)&lt;br /&gt;
 plot(model.hlme.spl5q, which=&amp;quot;linkfunction&amp;quot;, add=T, col=col[4], lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;topleft&amp;quot;,legend=c(&amp;quot;linear&amp;quot;, &amp;quot;beta&amp;quot;,&amp;quot;splines (5equidistant)&amp;quot;, &amp;quot;splines (5 at quantiles)&amp;quot;), lty=1,col=col,bty=&amp;quot;n&amp;quot;,lwd=2)&lt;br /&gt;
&lt;br /&gt;
 # to obtain confidence bands use function predictlink &lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;Error in predictlink.lcmm(model.hlme.spl, ndraws = 2000):&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;No confidence intervals can be produced since the program did not converge properly&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;model.hlme.lin$\$$conv &amp;lt;mark&amp;gt;# double-check the convergence of the algorithm[1] 2&amp;lt;/mark&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# status of convergence:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =1 if the convergence criteria were satisfied,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =2 if the maximum number of iterations was reached,&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;# =4 or 5 if a problem occured during optimisation&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 model.hlme.lin &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age ,subject='ID', epsY = 0.5, convB = 1e-01, convL = 1e-01, &amp;lt;mark&amp;gt;convG = 1e-01&amp;lt;/mark&amp;gt;, maxiter=200, data=hdp); model.hlme.lin$conv&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;mark&amp;gt;# Now that we have convergence, we can obtain CI’s!!!&amp;lt;/mark&amp;gt;&lt;br /&gt;
 link.lin &amp;lt;- predictlink(model.hlme.lin, ndraws=2000)&lt;br /&gt;
&lt;br /&gt;
 # plot(model.hlme.lin, which=&amp;quot;linkfunction&amp;quot;, bty='l', ylab=&amp;quot;Number-of-Tumors&amp;quot;, col=col[1], lwd=2, xlab=&amp;quot;underlying latent process&amp;quot;)&lt;br /&gt;
 plot(link.lin, add=TRUE, col=col[1], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for linear fit&amp;quot;), lty=c(2,NA), col=c(col[1],NA), bty=&amp;quot;n&amp;quot;, lwd=2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_Methods7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;Repeat using the other link functions … model.hlme.beta, model.hlme.spl, …&amp;lt;/mark&amp;gt;&lt;br /&gt;
 model.hlme.beta &amp;lt;- lcmm(ntumors ~ Age*Sex, random=~ Age, subject='ID', data=hdp, link='beta', &lt;br /&gt;
 &amp;lt;mark&amp;gt;convB = 1e-01&amp;lt;/mark&amp;gt;, convL = 1e-01, convG = 1e-01, maxiter=200); model.hlme.beta$\$$conv&lt;br /&gt;
 link.beta &amp;lt;- predictlink(model.hlme.beta, ndraws=2000)&lt;br /&gt;
 plot(link.beta, add=TRUE, col=col[2], lty=2, lwd=2)&lt;br /&gt;
 legend(x=&amp;quot;left&amp;quot;, legend=c(&amp;quot;95% confidence bands&amp;quot;, &amp;quot;for BETA fit&amp;quot;), lty=c(3,NA), col=c(col[2],NA), bty=&amp;quot;n&amp;quot;, lwd=1)&lt;br /&gt;
&lt;br /&gt;
===[[SMHS_MethodsHeterogeneity_MetaAnalysis|Next see: Meta-Analysis]]===&lt;br /&gt;
* [[SMHS_MethodsHeterogeneity|Back to the Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research section]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_HTE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity&amp;diff=16030</id>
		<title>SMHS MethodsHeterogeneity</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_MethodsHeterogeneity&amp;diff=16030"/>
		<updated>2016-05-19T14:40:58Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS| Scientific Methods for Health Sciences]] - Methods for Studying Heterogeneity of Treatment Effects, Case-Studies of Comparative Effectiveness Research ==&lt;br /&gt;
&lt;br /&gt;
==Methods and Approaches for HTE Analytics==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;8&amp;quot; |Methods and Approaches for HTE Analytics ****&lt;br /&gt;
|-&lt;br /&gt;
|||Meta-analysis||CART*||N of 1 trials||LGM/GMM**||QTE***||Nonparametric||Predictive risk models&lt;br /&gt;
|-&lt;br /&gt;
|Intent of the Analysis||Exploratory and confirmatory||Exploratory||Exploratory and initial testing||&amp;quot;Exploratory, initial testing, and confirmatory&amp;quot;||&amp;quot;Exploratory, initial testing, &amp;amp; confirmatory&amp;quot;||Exploratory and confirmatory||Initial testing and confirmatory&lt;br /&gt;
|-&lt;br /&gt;
|Data Structure ||&amp;quot;Trial summary results, possibly with subgroup results&amp;quot;||Panel or cross-section||Repeated measures for a single patient: time series||Time series and panel||Panel and cross-sectional||&amp;quot;Panel, time series, and cross-sectional&amp;quot;||Panel or cross-sectional&lt;br /&gt;
|-&lt;br /&gt;
|Data Size Consideration ||Advantage of combining small sample sizes||Large sample sizes||Small sample sizes||LGM: small to large sample sizes; GMM: Large sample sizes ||Moderate to large sample sizes||Large sample sizes||Sample sizes depends on specific risk function&lt;br /&gt;
|-&lt;br /&gt;
|Key Strength(s)||Increase statistical power by pooling of results||Does not require assumptions around normality of distribution Can utilize different types of response variables; Possible to identify HTE across trials Possibility to measure and explain covariate's effect on treatment effect ||Patient is own control; Estimates patient-specific effects ||Accounting for unobserved characteristics Heterogeneous response across time||Robust to outcome outliers Heterogeneous response across quantiles||No functional form assumptions Flexible regressions||Multivariate approach to identifying risk factors or HTE&lt;br /&gt;
Estimates patient-specific effects&lt;br /&gt;
|-&lt;br /&gt;
|Key Limitation(s)||Included studies need to be similar enough to be meaningful Assumed distribution; Selection bias||Fairly sensitive to changes in underlying data May not fully identify additive impacts of multiple variables||Requires de novo study Not applicable to all conditions or treatments||Criteria for optimization solutions not clear||&amp;quot;Treatment effect designed for a quantile, not a specific patient&amp;quot;||Computationally demanding Smoothing parameters required for kernel methods||May be more or less interpretable or useful clinically&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; *CART: Classification and regression tree (CART) analysis&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; LGM/GMM: Latent growth modeling/Growth mixture modeling.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; QTE: Quantile Treatment Effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Standard meta-analysis like fixed and random effect models, and tests of heterogeneity, together with various plots and summaries, can be found in the [http://cran.r-project.org/web/packages/rmeta R-package rmeta]. Non-parametric R approaches are included in the [http://cran.r-project.org/web/packages/np/vignettes/np.pdf np package]. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additional details are provided in a paper entitled [http://dx.doi.org/10.1186/1471-2288-12-185 From concepts, theory, and evidence of heterogeneity of treatment effects to methodological approaches: a primer].&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_HTE |HTE Analytics, Latent growth and growth mixture modeling (LGM/GMM)]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_MetaAnalysis |Meta-analysis]]==&lt;br /&gt;
&lt;br /&gt;
==[[SMHS_MethodsHeterogeneity_CER| Comparative Effectiveness Research (CER)]]==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php/SMHS_MethodsHeterogeneity_HTE}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_NetworkViz&amp;diff=16029</id>
		<title>SMHS SciVisualization NetworkViz</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_NetworkViz&amp;diff=16029"/>
		<updated>2016-05-19T14:30:22Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* See Next */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - Complex Network Visualization ==&lt;br /&gt;
&lt;br /&gt;
===Background===&lt;br /&gt;
[[SMHS_SciVisualization_SOCR_Excel_R_Charts|First see the SOCR, Excel and R charts section]].&lt;br /&gt;
&lt;br /&gt;
 # Install package&lt;br /&gt;
 # install.packages(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
 library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # build a simple graph&lt;br /&gt;
 g &amp;lt;- graph( c(1,2, 1,3, 2,3, 3,4), n=10)&lt;br /&gt;
 plot(g)&lt;br /&gt;
&lt;br /&gt;
 summary(g); g; is.igraph(g); is.directed(g); vcount(g); ecount(g)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization38.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization39.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(g, layout=layout.circle)&lt;br /&gt;
&lt;br /&gt;
 plot(g, layout=layout.fruchterman.reingold)&lt;br /&gt;
 plot(g, layout=layout.graphopt)&lt;br /&gt;
 plot(g, layout=layout.kamada.kawai, vertex.color=&amp;quot;cyan&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Interactive&lt;br /&gt;
 tkplot(g, layout=layout.kamada.kawai)&lt;br /&gt;
 # 3D plot&lt;br /&gt;
 rglplot(g, layout=layout.kamada.kawai(g))&lt;br /&gt;
&lt;br /&gt;
Dataset 1: Coappearance network in the novel “les miserablese”. &lt;br /&gt;
&lt;br /&gt;
D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).&lt;br /&gt;
&lt;br /&gt;
The data contains the weighted network of coappearances of characters in Victor Hugo's novel &amp;quot;Les Miserables&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
Nodes represent characters as indicated by the labels and edges connect any pair of characters that appear in the same chapter of the book.  The values on the edges are the number of such coappearances.&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use a directed, weighted network representing the neural network of the nematode &lt;br /&gt;
&lt;br /&gt;
C. Elegans. D. Watts and S. Strogatz, Nature 393, 440-442 (1998). &lt;br /&gt;
&lt;br /&gt;
The file celegansneural.gml describes a weighted, directed network where the nodes have been renumbered to be consecutive.&lt;br /&gt;
&lt;br /&gt;
Edge weights are the weights given by Watts.&lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;rgl&amp;quot;)&lt;br /&gt;
 library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 g&amp;lt;-read.graph(&amp;quot;C:\\Users\\Dinov\\Desktop\\celegansneural.gml&amp;quot;,format=c(&amp;quot;gml&amp;quot;))&lt;br /&gt;
 g&lt;br /&gt;
 plot(g, layout=layout.graphopt)&lt;br /&gt;
&lt;br /&gt;
 data_g &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330389/download?download_frd=1&amp;amp;verifier=u1jqCGS8AAU0MsO5ffLCyvVFYXXAflpdLtg8RXhk&amp;quot;, sep=&amp;quot; &amp;quot;, header = FALSE)&lt;br /&gt;
&lt;br /&gt;
 data_g_mat &amp;lt;- as.matrix(data_g, byrow=TRUE, nc=2)&lt;br /&gt;
 g_miserab &amp;lt;- graph.edgelist(data_g_mat, dir=FALSE)&lt;br /&gt;
 summary(g_miserab)&lt;br /&gt;
 plot(g_miserab, layout=layout.graphopt)&lt;br /&gt;
 # rglplot(g_miserab, layout=layout.kamada.kawai(g_miserab))&lt;br /&gt;
&lt;br /&gt;
 # to name the vertices and and plot the graph  of the first 10 vertices&lt;br /&gt;
 V(g_miserab)$\$$name&lt;br /&gt;
 g_miserab.1 &amp;lt;- graph.ring(10)&lt;br /&gt;
 V(g_miserab.1)$\$$name &amp;lt;- sample(letters, vcount(g_miserab.1))&lt;br /&gt;
 plot(g_miserab.1, layout=layout.graphopt)&lt;br /&gt;
&lt;br /&gt;
 # compute the node adjacency matrix&lt;br /&gt;
 g &amp;lt;- g_miserab; as_adjacency_matrix(g)&lt;br /&gt;
 E(g)$\$$weight &amp;lt;- runif(ecount(g))&lt;br /&gt;
 W &amp;lt;- get.adjacency(g, attr=&amp;quot;weight&amp;quot;)&lt;br /&gt;
 W&lt;br /&gt;
&lt;br /&gt;
===Social Network Analysis Example===&lt;br /&gt;
&lt;br /&gt;
 # free memory&lt;br /&gt;
 # rm(list = ls())&lt;br /&gt;
 # gc()&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 # load termDocMatrix dataset&lt;br /&gt;
 # These data include Twitter text data of @RDataMining representing a general social network analysis&lt;br /&gt;
 # example. The terms represent people and the tweets represent LinkedIn groups.&lt;br /&gt;
 # The term-document matrix can be viewed as the group membership of people. &lt;br /&gt;
 # We may want to build a network of terms based on their co-occurrence in the same tweets,&lt;br /&gt;
 # similarly to a network of people based on their group membership.&lt;br /&gt;
 # https://umich.instructure.com/files/541336/download?download_frd=1 &lt;br /&gt;
&lt;br /&gt;
load(&amp;quot;E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\03_GraphNetwork_TermDocMatrix.rdata&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Labeled graph [[Image:SMHS_SciVisualization40.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Adjacency matrix [[Image:SMHS_SciVisualization41.png|300px]] Coordinates are 1-6.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # inspect part of the matrix&lt;br /&gt;
 termDocMatrix [5:10,1:20]&lt;br /&gt;
 # change it to a Boolean matrix == incidence matrix&lt;br /&gt;
 termDocMatrix [termDocMatrix &amp;gt;=1] &amp;lt;- 1&lt;br /&gt;
&lt;br /&gt;
 # transform into a term-term adjacency matrix (n×n), where (i,j)th entries correspond to the number of edges &lt;br /&gt;
 # node from xi to node xj.&lt;br /&gt;
 # Matrix Multiplication in R: http://www.statmethods.net/advstats/matrix.html, dim(t(termDocMatrix))&lt;br /&gt;
 termMatrix &amp;lt;- termDocMatrix %*% t(termDocMatrix)&lt;br /&gt;
&lt;br /&gt;
 # A graph has no loops, when all entries of the adjacency matrix on the main diagonal of are zeroes&lt;br /&gt;
 # http://mathonline.wikidot.com/adjacency-matrices &lt;br /&gt;
 diag(termMatrix)&lt;br /&gt;
&lt;br /&gt;
 # The matrix product of incidence matrix (B) and it’s transpose B×B^T represents the degrees of all nodes!&lt;br /&gt;
 # inspect terms numbered 5 to 10&lt;br /&gt;
 termMatrix[5:10,5:10]&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
 # build a graph from the adjacency matrix&lt;br /&gt;
 g &amp;lt;- graph.adjacency(termMatrix, weighted=T, mode=&amp;quot;undirected&amp;quot;)&lt;br /&gt;
 plot(g)&lt;br /&gt;
&lt;br /&gt;
 # remove loops &lt;br /&gt;
 g &amp;lt;- simplify(g); plot(g)&lt;br /&gt;
&lt;br /&gt;
 # set labels and degrees of  V(g)&lt;br /&gt;
 V(g)$\$$label &amp;lt;- V(g)$\$$name&lt;br /&gt;
 V(g)$\$$degree &amp;lt;- degree(g)&lt;br /&gt;
&lt;br /&gt;
 # set seed to make the layout reproducible&lt;br /&gt;
 set.seed(1953)&lt;br /&gt;
 layout1 &amp;lt;- layout.fruchterman.reingold(g)   # Fruchterman-Reingold layout&lt;br /&gt;
 plot(g, layout=layout1)&lt;br /&gt;
&lt;br /&gt;
 # plot(g, layout=layout.kamada.kawai)&lt;br /&gt;
 # tkplot(g, layout=layout.kamada.kawai)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization42.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Finesse the graph appearance – vertices and edges&lt;br /&gt;
 V(g)$\$$label.cex &amp;lt;- 2.2 * V(g)$\$$degree / max(V(g)$\$$degree)+ .2&lt;br /&gt;
 V(g)$\$$label.color &amp;lt;- rgb(0, 0, .2, .8)&lt;br /&gt;
 V(g)$\$$frame.color &amp;lt;- rgb(0,0,1)&lt;br /&gt;
 egam &amp;lt;- (log(E(g)$\$$weight)+.4) / max(log(E(g)$\$$weight)+.4)&lt;br /&gt;
 E(g)$\$$color &amp;lt;- rgb(.5, .5, 0, egam)		# Graph Edges, E(g)&lt;br /&gt;
 E(g)$\$$width &amp;lt;- egam&lt;br /&gt;
 # plot the graph in layout1&lt;br /&gt;
 plot(g, layout=layout1)&lt;br /&gt;
&lt;br /&gt;
 V(g)$\$$label &amp;lt;- V(g)$\$$name&lt;br /&gt;
 V(g)$\$$label.color &amp;lt;- rgb(0, 0, 0, 0.5)&lt;br /&gt;
 V(g)$\$$label.dist &amp;lt;- 1.0	# relative distance of labels from node center&lt;br /&gt;
 V(g)$\$$label.angle&amp;lt;- 3/8   #in radians&lt;br /&gt;
 V(g)$\$$label.cex &amp;lt;- 1.4*V(g)$\$$degree/max(V(g)$\$$degree) + 1&lt;br /&gt;
 V(g)$\$$color &amp;lt;- rgb(1, 0, 0, .4)&lt;br /&gt;
 V(g)$\$$size &amp;lt;- 22 * V(g)$\$$degree / max(V(g)$\$$degree)+ 2&lt;br /&gt;
 V(g)$\$$shape &amp;lt;- &amp;quot;rectangle&amp;quot;&lt;br /&gt;
 # V(g)$\$$.size=10*(strwidth(V(g)$\$$label) + strwidth(&amp;quot;oo&amp;quot;)) * 10&lt;br /&gt;
 # V(g)$\$$.size2=strheight(&amp;quot;I&amp;quot;) * 10&lt;br /&gt;
 V(g)$\$$frame.color &amp;lt;- NA&lt;br /&gt;
 # set vertex labels and their colors and sizes&lt;br /&gt;
 # set edge width and color&lt;br /&gt;
 E(g)$\$$width &amp;lt;- .3	&lt;br /&gt;
 E(g)$\$$color &amp;lt;- rgb(.5, .5, 0, .3) &lt;br /&gt;
&lt;br /&gt;
 set.seed(1234)&lt;br /&gt;
 plot(g, layout=layout.fruchterman.reingold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization43.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on activity (oncological primary doctor and a second-opinion)===&lt;br /&gt;
&lt;br /&gt;
We use some of the Stanford Real Graph Data (http://snap.stanford.edu/data/) or this graph data on cancer patients seen by a primary doctor and a second-opinion doctor, stage of the disease, and diagnostic agreement between primary and secondary oncologist: &amp;lt;b&amp;gt;Primary&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;Secondary&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;Stage&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;DxAgreement&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # 03_GraphData_Health.txt&lt;br /&gt;
 healthGraphTable &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/554234/download?download_frd=1&amp;quot;, sep='\t', dec=',', header=T)&lt;br /&gt;
 #specify the path, separator(tab, comma, ...), decimal point symbol, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(healthGraphTable)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Primary||Secondary||Stage||DxAgreement&lt;br /&gt;
|-&lt;br /&gt;
|1||AA||DD||3||Y&lt;br /&gt;
|-&lt;br /&gt;
|2||AB||DD||3||R&lt;br /&gt;
|-&lt;br /&gt;
|3||AF||BA||3||Q&lt;br /&gt;
|-&lt;br /&gt;
|4||DD||DA||3||Q&lt;br /&gt;
|-&lt;br /&gt;
|5||CD||EC||3||X&lt;br /&gt;
|-&lt;br /&gt;
|6||DD||CE||3||Y&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Transform the table into the required graph format:&lt;br /&gt;
 healthGraph.network&amp;lt;-graph.data.frame(healthGraphTable, directed=F) &lt;br /&gt;
 # the 'directed' attribute specifies whether the edges are directed&lt;br /&gt;
 # or equivalent irrespective of the position (1st vs 2nd column). For directed graphs use 'directed=T'&lt;br /&gt;
&lt;br /&gt;
 # Inspect the data:&lt;br /&gt;
 V(healthGraph.network) &amp;lt;blockquote&amp;gt;# prints the list of vertices (physicians/oncologists)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 E(healthGraph.network) &amp;lt;blockquote&amp;gt;# prints the list of edges (primary-secondary relationships)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 degree(healthGraph.network) &amp;lt;blockquote&amp;gt;# print the number of edges (relationships) per node (physician)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # first plot of graph&lt;br /&gt;
 plot(healthGraph.network)&lt;br /&gt;
&lt;br /&gt;
 #Subset the data. If we want to exclude only physicians who are mostly outside of the network &lt;br /&gt;
 # i.e., participate only tangentially (with 1 or 2 relationships only)&lt;br /&gt;
 # we can exclude nodes by subsetting the graph on the basis of the node/physician’s 'degree':&lt;br /&gt;
 healthGraph.out.network &amp;lt;- V(healthGraph.network)[degree(healthGraph.network)&amp;lt;=2] &lt;br /&gt;
 #identify those vertices part of less than or equal to 2 connections (edges)&lt;br /&gt;
 healthGraph.in.network &amp;lt;- delete.vertices(healthGraph.network, healthGraph.out.network) &lt;br /&gt;
 #exclude them from the graph&lt;br /&gt;
&lt;br /&gt;
 # Plot the data by specifying certain details about the graph, e.g., separate some nodes (people) by color:&lt;br /&gt;
 V(healthGraph.in.network)$\$$color &amp;lt;- ifelse(V(healthGraph.in.network)$\$$name=='CA', 'blue', 'red') &lt;br /&gt;
 #useful for highlighting certain people. Works by matching the name attribute of the vertex to the one specified in the 'ifelse' expression&lt;br /&gt;
 # We can also color the connecting edges differently depending on the 'Stage': &lt;br /&gt;
 E(healthGraph.in.network)$\$$color&amp;lt;-ifelse(E(healthGraph.in.network)$\$$Stage&amp;gt;3, &amp;quot;red&amp;quot;, &amp;quot;grey&amp;quot;)&lt;br /&gt;
 # or depending on the different diagnostic agreement labels ('DxAgreement'):&lt;br /&gt;
 E(healthGraph.in.network)$\$$color&amp;lt;-ifelse(E(healthGraph.in.network)$\$$DxAgreement =='X', &amp;quot;red&amp;quot;, ifelse(E(healthGraph.in.network)$\$$DxAgreement=='Y', &amp;quot;blue&amp;quot;, &amp;quot;grey&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Note: the example uses nested ifelse expressions which can be improved&lt;br /&gt;
 # Additional attributes like size can be further specified in an analogous manner:&lt;br /&gt;
 V(healthGraph.in.network)$\$$size&amp;lt;-degree(healthGraph.in.network)/10	&lt;br /&gt;
 #here the size of the vertices is specified by the degree of the vertex, so that people supervising more have get proportionally bigger dots. Getting the right scale gets some playing around with the parameters of the scale function    (from the 'base' package)&lt;br /&gt;
&lt;br /&gt;
 # Note that if the same attribute is specified beforehand and inside the function, the former will be overridden.&lt;br /&gt;
 # And finally the plot itself:&lt;br /&gt;
 par(mai=c(0,0,1,0)) 		&lt;br /&gt;
 #this specifies the size of the margins, default settings leave too much free space on all sides&lt;br /&gt;
 plot(healthGraph.in.network,		#the graph to be plotted&lt;br /&gt;
 layout=layout.fruchterman.reingold,	# the layout method. see the igraph documentation for details&lt;br /&gt;
 main='Onco Physician Network Example',	#specifies the title&lt;br /&gt;
 vertex.label.dist=0.5,			#puts the name labels slightly off the dots&lt;br /&gt;
 vertex.frame.color='blue', 		#the color of the border of the dots &lt;br /&gt;
 vertex.label.color='black',		#the color of the name labels&lt;br /&gt;
 vertex.label.font=2,			#the font of the name labels&lt;br /&gt;
 vertex.label=V(healthGraph.in.network)$\$$name,   #specifies the labels of the vertices&lt;br /&gt;
 vertex.label.cex=1			#specifies the size of the font of the labels&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # Save or export the plot as a metafile to the clipboard, a pdf or png (and other formats).&lt;br /&gt;
 png(filename=&amp;quot;org_network.png&amp;quot;, height=1900, width=1200) #call the png writer&lt;br /&gt;
 # alternatively print to high-res PDF file # pdf(file=&amp;quot;org_network.pdf&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 #run the plot&lt;br /&gt;
&lt;br /&gt;
 dev.off() #don’t forget to close the device&lt;br /&gt;
&lt;br /&gt;
==Pathway analysis==&lt;br /&gt;
&lt;br /&gt;
Pathway analysis   is a technique that reduces complexity and increased explanatory power in studies examining underlying biological structure of differentially expressed genes and proteins.&lt;br /&gt;
&lt;br /&gt;
 # install package &lt;br /&gt;
 # install.packages(&amp;quot;dendsort&amp;quot;) – contains the “” dataset&lt;br /&gt;
 # Data: Sample data matrix from the integrated pathway analysis of gastric cancer from the &lt;br /&gt;
 # Cancer Genome Atlas (TCGA) study. A multivariate table obtained from the integrated pathway analysis &lt;br /&gt;
 # of gastric cancer from the Cancer Genome Atlas (TCGA) study. Each column represents a pathway&lt;br /&gt;
 # &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;consisting of a set of genes and each row represents a cohort of samples based on specific clinical &lt;br /&gt;
 # or genetic features.&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; For each pair of a pathway and a feature, a continuous value of between &lt;br /&gt;
 # 1 and -1 is assigned to score positive or negative association, respectively.&lt;br /&gt;
 # A data frame with &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;215&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; rows and &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;117 variables&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 library(&amp;quot;dendsort&amp;quot;)&lt;br /&gt;
 data(sample_tcga)&lt;br /&gt;
 dataTable &amp;lt;- t(sample_tcga)&lt;br /&gt;
 head(dataTable)&lt;br /&gt;
 write.csv(dataTable, &amp;quot;E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\03_TCGA_Data_117x215.csv&amp;quot;)&lt;br /&gt;
 # data.new &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330393/download?download_frd=1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # install SPIA package: http://bioconductor.org/packages/2.6/bioc/html/SPIA.html &lt;br /&gt;
 # source(&amp;quot;http://bioconductor.org/biocLite.R&amp;quot;)&lt;br /&gt;
 # biocLite(&amp;quot;SPIA&amp;quot;)&lt;br /&gt;
 library(&amp;quot;SPIA&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # “top” Colorectal cancer dataset provided by SPIA package.&lt;br /&gt;
 data(Vessels)&lt;br /&gt;
 head(top)&lt;br /&gt;
 # pathway analysis based on combined evidence; &lt;br /&gt;
 # use nB=2000 or more for more accurate results&lt;br /&gt;
 res&amp;lt;-spia(de=DE_Vessels,all=ALL_Vessels,organism=&amp;quot;hsa&amp;quot;,nB=500,plots=FALSE,beta=NULL,verbose=FALSE)&lt;br /&gt;
 #make the output fit this screen&lt;br /&gt;
 res$\$$Name=substr(res$\$$Name,1,10)&lt;br /&gt;
 #show first 15 pathways, omitting KEGG links&lt;br /&gt;
 res[1:15,-12]&lt;br /&gt;
&lt;br /&gt;
==GIS/Distortion mapping==&lt;br /&gt;
&lt;br /&gt;
 # install the R GISTools package&lt;br /&gt;
 # install.packages(&amp;quot;GISTools&amp;quot;)&lt;br /&gt;
 library(&amp;quot;GISTools&amp;quot;)&lt;br /&gt;
 data(georgia)&lt;br /&gt;
 …&lt;br /&gt;
&lt;br /&gt;
Java Applet: http://www.socr.ucla.edu/htmls/SOCR_Cartograhy.html&lt;br /&gt;
Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_Cartography_Project &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Circos Connectogram/Table visualization==&lt;br /&gt;
&lt;br /&gt;
Circular chord/ribbon diagrams present a mechanism to visualize numeric tables containing information of directional relations. This type of chart visualizes tables in a circular way. Sectors of the plot is union(rownames(mat), colnames(mat)). When there is no rowname or colname, the chart assigns names for it (rows could be auto-named as &amp;quot;R1&amp;quot;, &amp;quot;R2&amp;quot;, ... and columns may be named as &amp;quot;C1&amp;quot;, &amp;quot;C2&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
•	Circos: http://circos.ca &lt;br /&gt;
&lt;br /&gt;
•	R circlize: http://cran.r-project.org/web/packages/circlize/circlize.pdf&lt;br /&gt;
&lt;br /&gt;
===Example Early-Onset Alzheimer’s Disease===&lt;br /&gt;
&lt;br /&gt;
Recent studies examined the Interactions between imaging (Structural Brain Change) and genetics (SNP) biomarkers in Early-Onset Alzheimer's Disease Subjects. Circular representation of the significant SNP-Neuroimaging interactions. The left and right parts of the graph contain the 15-ROI imaging markers and the 20-SNP genotypes, respectively. The strength of the connection between each SNP-ROI pair is presented as a ribbon, whose size, color and location are proportional to -log (p). Clearly, there are a lot of spurious effects (skinny red lines on background) and several significantly strong associations (thicker purple ribbons on foreground), e.g., purple association between SNP_5 (rs7718456) and ROI_10 (L_hippocampus, Volume). SNP: single nucleotide polymorphism, ROI: region of interest. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization44.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|SNPROI||ROI_1||ROI_2||ROI_3||ROI_4||ROI_5||ROI_6||ROI_7||ROI_8||ROI_9||ROI_10||ROI_11||ROI_12||ROI_13||ROI_14||ROI_15&lt;br /&gt;
|-&lt;br /&gt;
|rs17029131||10||10||10||10||10||10||10||10||10||10||188||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1822144||10||10||10||10||10||200||10||10||10||10||188||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs6446443||10||10||10||126||113||10||10||113||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12506164||10||10||10||10||10||167||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs7718456||10||202||144||206||10||10||10||169||225||321||10||10||290||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs9377090||10||145||10||10||10||10||10||153||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2776932||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs4933672||10||10||113||10||10||10||10||10||10||10||10||232||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193270||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193272||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193274||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12218153||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1338956||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1338025||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12101936||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs16964473||10||10||10||10||10||10||10||10||10||10||112||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12972537||10||10||10||10||10||10||125||10||10||10||126||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2212356||10||10||10||10||10||10||10||10||10||10||10||129||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2831165||10||10||10||10||10||10||10||10||10||10||10||10||10||10||169&lt;br /&gt;
|-&lt;br /&gt;
|rs1266320||10||120||10||10||10||10||10||10||10||145||10||10||10||10||129&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;circlize&amp;quot;)&lt;br /&gt;
 library(&amp;quot;circlize&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;03_CircularTable_EOAD_Data.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 EOAD_data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330388/download?download_frd=1&amp;quot;, sep=&amp;quot;,&amp;quot;,  row.names=1, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 rownames(EOAD_data) &lt;br /&gt;
 colnames(EOAD_data) &lt;br /&gt;
 EOAD_matrix &amp;lt;- as.matrix(EOAD_data)&lt;br /&gt;
&lt;br /&gt;
 ### graphics settings&lt;br /&gt;
 # par(mfrow = c(3, 2))&lt;br /&gt;
 # par(mar = c(1, 1, 1, 1))&lt;br /&gt;
 chordDiagram(EOAD_matrix)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 circos.par(gap.degree = c(rep(2, nrow(EOAD_matrix)-1), 10, rep(2, ncol(EOAD_matrix)-1), 10))&lt;br /&gt;
 chordDiagram(EOAD_matrix)	&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 circos.par(start.degree = 90)&lt;br /&gt;
 chordDiagram(EOAD_matrix)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 # chordDiagram(EOAD_matrix, order = c(&amp;quot;ROI_1&amp;quot;, &amp;quot;ROI_2&amp;quot;, &amp;quot;ROI_3&amp;quot;, &amp;quot;ROI_4&amp;quot;, &amp;quot;ROI_5&amp;quot;, &amp;quot;ROI_6&amp;quot;, &amp;quot;ROI_7&amp;quot;, &amp;quot;ROI_8&amp;quot;, &amp;quot;ROI_9&amp;quot;, &amp;quot;ROI_10&amp;quot;, &amp;quot;ROI_11&amp;quot;, &amp;quot;ROI_12&amp;quot;, &amp;quot;ROI_13&amp;quot;, &amp;quot;ROI_14&amp;quot;, &amp;quot;ROI_15&amp;quot;))&lt;br /&gt;
 chordDiagram(EOAD_matrix, directional = TRUE)&lt;br /&gt;
 chordDiagram(EOAD_matrix, directional = TRUE, diffHeight = 0.06)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
&lt;br /&gt;
 ### colors settings&lt;br /&gt;
 rand_color = function(n, alpha = 1) {&lt;br /&gt;
 return(rgb(runif(n), runif(n), runif(n), alpha = alpha))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 par(mfrow = c(2, 2))&lt;br /&gt;
 par(mar = c(1, 1, 1, 1))&lt;br /&gt;
 grid.col = NULL&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;random&amp;lt;/mark&amp;gt; grid/sector and ribbon/chord colors&lt;br /&gt;
 col_mat = rand_color(length(EOAD_matrix), alpha = 0.5)&lt;br /&gt;
 grid_col = rand_color(length(rownames(EOAD_matrix)) + length(colnames(EOAD_matrix)), alpha = 0.5)&lt;br /&gt;
 dim(col_mat) = dim(EOAD_matrix)&lt;br /&gt;
 chordDiagram(EOAD_matrix, grid.col = grid_col, col = col_mat)&lt;br /&gt;
&lt;br /&gt;
 # grid/sector and ribbon/chord colors according to cell values&lt;br /&gt;
 # Generate quantile values for the color mapping relative to table cell-values&lt;br /&gt;
 seqs &amp;lt;- seq(0.92, 1, 0.008)&lt;br /&gt;
&lt;br /&gt;
 chordDiagram(EOAD_matrix, grid.col = grid_col, col = colorRamp2(quantile(EOAD_matrix, seqs), rev(heat.colors(11))), transparency = 0.5)&lt;br /&gt;
 circos.clear()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization46.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Practice===&lt;br /&gt;
&lt;br /&gt;
Repeat these charts using the 03_NIPS_Baby_VitK_Shot_DataSummaryAnalysis_March2012_Short.csv dataset (Appendix), https://umich.instructure.com/files/330392/download?download_frd=1 &lt;br /&gt;
&lt;br /&gt;
==Graphical Workflow Protocol Visualization==&lt;br /&gt;
&lt;br /&gt;
(1)	Brain Imaging &amp;amp; Genetics Data:&lt;br /&gt;
&lt;br /&gt;
a.	ADNI: http://adni.loni.usc.edu/&lt;br /&gt;
&lt;br /&gt;
b.	PPMI: http://ppmi-info.org/&lt;br /&gt;
&lt;br /&gt;
c.	XNAT Central: https://central.xnat.org/&lt;br /&gt;
&lt;br /&gt;
d.	Pipeline Data (see client library)&lt;br /&gt;
&lt;br /&gt;
e.	Cloud Services (AWS/Box/Drive)&lt;br /&gt;
&lt;br /&gt;
(2)	Pipeline Environment&lt;br /&gt;
&lt;br /&gt;
a.	http://pipeline.loni.usc.edu/&lt;br /&gt;
&lt;br /&gt;
b.	Web-Java Client: http://pipeline.loni.usc.edu/products-services/pws/ &lt;br /&gt;
&lt;br /&gt;
c.	Videos: http://pipeline.loni.usc.edu/learn/basic-videos/ &lt;br /&gt;
&lt;br /&gt;
d.	Publications: http://pipeline.loni.usc.edu/get-started/acknowledgmentscredits/ &lt;br /&gt;
&lt;br /&gt;
(3)	End-to-end Computational workflows&lt;br /&gt;
&lt;br /&gt;
a.	Navigator: http://pipeline.loni.usc.edu/explore/library-navigator/&lt;br /&gt;
&lt;br /&gt;
b.	Detailed Descriptions: http://wiki.loni.usc.edu/twiki/bin/view/CCB/PipelineWorkflows &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization47.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization48.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Neonate Infant Pain Score (NIPS) Data (Vitamin K shots) Dataset===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;A short version of the Neonate Infant Pain Score (NIPS) Data (Vitamin K shots) dataset, http://wiki.socr.umich.edu/index.php/SOCR_Data_NIPS_InfantVitK_ShotData&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|Index||Immediate||30_Sec||60_Sec||120_Sec||TotalCryTime&lt;br /&gt;
|-&lt;br /&gt;
|1||6||7||6||2||63&lt;br /&gt;
|-&lt;br /&gt;
|2||5||1||2||0||0&lt;br /&gt;
|-&lt;br /&gt;
|3||7||6||6||7||54&lt;br /&gt;
|-&lt;br /&gt;
|4||3||7||3||0||27&lt;br /&gt;
|-&lt;br /&gt;
|5||7||5||6||0||19&lt;br /&gt;
|-&lt;br /&gt;
|6||6||6||6||2||2&lt;br /&gt;
|-&lt;br /&gt;
|7||7||7||6||0||46&lt;br /&gt;
|-&lt;br /&gt;
|8||6||7||0||0||33&lt;br /&gt;
|-&lt;br /&gt;
|9||5||0||4||0||56&lt;br /&gt;
|-&lt;br /&gt;
|10||7||7||7||6||63&lt;br /&gt;
|-&lt;br /&gt;
|105||6||0||0||0||11&lt;br /&gt;
|-&lt;br /&gt;
|106||7||6||0||0||59&lt;br /&gt;
|-&lt;br /&gt;
|107||7||4||4||0||28&lt;br /&gt;
|-&lt;br /&gt;
|108||7||7||7||1||64&lt;br /&gt;
|-&lt;br /&gt;
|109||7||0||0||0||8&lt;br /&gt;
|-&lt;br /&gt;
|110||5||0||1||3||64&lt;br /&gt;
|-&lt;br /&gt;
|111||7||5||7||7||72&lt;br /&gt;
|-&lt;br /&gt;
|112||4||2||0||2||50&lt;br /&gt;
|-&lt;br /&gt;
|113||7||6||7||0||44&lt;br /&gt;
|-&lt;br /&gt;
|114||7||1||0||0||11&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
* [[SMHS_SciVisualization| Back to the Scientific Visualization section]]&lt;br /&gt;
* [[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_NetworkViz&amp;diff=16028</id>
		<title>SMHS SciVisualization NetworkViz</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_NetworkViz&amp;diff=16028"/>
		<updated>2016-05-19T14:08:38Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - Complex Network Visualization ==&lt;br /&gt;
&lt;br /&gt;
===Background===&lt;br /&gt;
[[SMHS_SciVisualization_SOCR_Excel_R_Charts|First see the SOCR, Excel and R charts section]].&lt;br /&gt;
&lt;br /&gt;
 # Install package&lt;br /&gt;
 # install.packages(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
 library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # build a simple graph&lt;br /&gt;
 g &amp;lt;- graph( c(1,2, 1,3, 2,3, 3,4), n=10)&lt;br /&gt;
 plot(g)&lt;br /&gt;
&lt;br /&gt;
 summary(g); g; is.igraph(g); is.directed(g); vcount(g); ecount(g)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization38.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization39.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(g, layout=layout.circle)&lt;br /&gt;
&lt;br /&gt;
 plot(g, layout=layout.fruchterman.reingold)&lt;br /&gt;
 plot(g, layout=layout.graphopt)&lt;br /&gt;
 plot(g, layout=layout.kamada.kawai, vertex.color=&amp;quot;cyan&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # Interactive&lt;br /&gt;
 tkplot(g, layout=layout.kamada.kawai)&lt;br /&gt;
 # 3D plot&lt;br /&gt;
 rglplot(g, layout=layout.kamada.kawai(g))&lt;br /&gt;
&lt;br /&gt;
Dataset 1: Coappearance network in the novel “les miserablese”. &lt;br /&gt;
&lt;br /&gt;
D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).&lt;br /&gt;
&lt;br /&gt;
The data contains the weighted network of coappearances of characters in Victor Hugo's novel &amp;quot;Les Miserables&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
Nodes represent characters as indicated by the labels and edges connect any pair of characters that appear in the same chapter of the book.  The values on the edges are the number of such coappearances.&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use a directed, weighted network representing the neural network of the nematode &lt;br /&gt;
&lt;br /&gt;
C. Elegans. D. Watts and S. Strogatz, Nature 393, 440-442 (1998). &lt;br /&gt;
&lt;br /&gt;
The file celegansneural.gml describes a weighted, directed network where the nodes have been renumbered to be consecutive.&lt;br /&gt;
&lt;br /&gt;
Edge weights are the weights given by Watts.&lt;br /&gt;
&lt;br /&gt;
 install.packages(&amp;quot;rgl&amp;quot;)&lt;br /&gt;
 library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 g&amp;lt;-read.graph(&amp;quot;C:\\Users\\Dinov\\Desktop\\celegansneural.gml&amp;quot;,format=c(&amp;quot;gml&amp;quot;))&lt;br /&gt;
 g&lt;br /&gt;
 plot(g, layout=layout.graphopt)&lt;br /&gt;
&lt;br /&gt;
 data_g &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330389/download?download_frd=1&amp;amp;verifier=u1jqCGS8AAU0MsO5ffLCyvVFYXXAflpdLtg8RXhk&amp;quot;, sep=&amp;quot; &amp;quot;, header = FALSE)&lt;br /&gt;
&lt;br /&gt;
 data_g_mat &amp;lt;- as.matrix(data_g, byrow=TRUE, nc=2)&lt;br /&gt;
 g_miserab &amp;lt;- graph.edgelist(data_g_mat, dir=FALSE)&lt;br /&gt;
 summary(g_miserab)&lt;br /&gt;
 plot(g_miserab, layout=layout.graphopt)&lt;br /&gt;
 # rglplot(g_miserab, layout=layout.kamada.kawai(g_miserab))&lt;br /&gt;
&lt;br /&gt;
 # to name the vertices and and plot the graph  of the first 10 vertices&lt;br /&gt;
 V(g_miserab)$\$$name&lt;br /&gt;
 g_miserab.1 &amp;lt;- graph.ring(10)&lt;br /&gt;
 V(g_miserab.1)$\$$name &amp;lt;- sample(letters, vcount(g_miserab.1))&lt;br /&gt;
 plot(g_miserab.1, layout=layout.graphopt)&lt;br /&gt;
&lt;br /&gt;
 # compute the node adjacency matrix&lt;br /&gt;
 g &amp;lt;- g_miserab; as_adjacency_matrix(g)&lt;br /&gt;
 E(g)$\$$weight &amp;lt;- runif(ecount(g))&lt;br /&gt;
 W &amp;lt;- get.adjacency(g, attr=&amp;quot;weight&amp;quot;)&lt;br /&gt;
 W&lt;br /&gt;
&lt;br /&gt;
===Social Network Analysis Example===&lt;br /&gt;
&lt;br /&gt;
 # free memory&lt;br /&gt;
 # rm(list = ls())&lt;br /&gt;
 # gc()&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 # load termDocMatrix dataset&lt;br /&gt;
 # These data include Twitter text data of @RDataMining representing a general social network analysis&lt;br /&gt;
 # example. The terms represent people and the tweets represent LinkedIn groups.&lt;br /&gt;
 # The term-document matrix can be viewed as the group membership of people. &lt;br /&gt;
 # We may want to build a network of terms based on their co-occurrence in the same tweets,&lt;br /&gt;
 # similarly to a network of people based on their group membership.&lt;br /&gt;
 # https://umich.instructure.com/files/541336/download?download_frd=1 &lt;br /&gt;
&lt;br /&gt;
load(&amp;quot;E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\03_GraphNetwork_TermDocMatrix.rdata&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Labeled graph [[Image:SMHS_SciVisualization40.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;Adjacency matrix [[Image:SMHS_SciVisualization41.png|300px]] Coordinates are 1-6.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # inspect part of the matrix&lt;br /&gt;
 termDocMatrix [5:10,1:20]&lt;br /&gt;
 # change it to a Boolean matrix == incidence matrix&lt;br /&gt;
 termDocMatrix [termDocMatrix &amp;gt;=1] &amp;lt;- 1&lt;br /&gt;
&lt;br /&gt;
 # transform into a term-term adjacency matrix (n×n), where (i,j)th entries correspond to the number of edges &lt;br /&gt;
 # node from xi to node xj.&lt;br /&gt;
 # Matrix Multiplication in R: http://www.statmethods.net/advstats/matrix.html, dim(t(termDocMatrix))&lt;br /&gt;
 termMatrix &amp;lt;- termDocMatrix %*% t(termDocMatrix)&lt;br /&gt;
&lt;br /&gt;
 # A graph has no loops, when all entries of the adjacency matrix on the main diagonal of are zeroes&lt;br /&gt;
 # http://mathonline.wikidot.com/adjacency-matrices &lt;br /&gt;
 diag(termMatrix)&lt;br /&gt;
&lt;br /&gt;
 # The matrix product of incidence matrix (B) and it’s transpose B×B^T represents the degrees of all nodes!&lt;br /&gt;
 # inspect terms numbered 5 to 10&lt;br /&gt;
 termMatrix[5:10,5:10]&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;igraph&amp;quot;)&lt;br /&gt;
 # build a graph from the adjacency matrix&lt;br /&gt;
 g &amp;lt;- graph.adjacency(termMatrix, weighted=T, mode=&amp;quot;undirected&amp;quot;)&lt;br /&gt;
 plot(g)&lt;br /&gt;
&lt;br /&gt;
 # remove loops &lt;br /&gt;
 g &amp;lt;- simplify(g); plot(g)&lt;br /&gt;
&lt;br /&gt;
 # set labels and degrees of  V(g)&lt;br /&gt;
 V(g)$\$$label &amp;lt;- V(g)$\$$name&lt;br /&gt;
 V(g)$\$$degree &amp;lt;- degree(g)&lt;br /&gt;
&lt;br /&gt;
 # set seed to make the layout reproducible&lt;br /&gt;
 set.seed(1953)&lt;br /&gt;
 layout1 &amp;lt;- layout.fruchterman.reingold(g)   # Fruchterman-Reingold layout&lt;br /&gt;
 plot(g, layout=layout1)&lt;br /&gt;
&lt;br /&gt;
 # plot(g, layout=layout.kamada.kawai)&lt;br /&gt;
 # tkplot(g, layout=layout.kamada.kawai)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization42.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Finesse the graph appearance – vertices and edges&lt;br /&gt;
 V(g)$\$$label.cex &amp;lt;- 2.2 * V(g)$\$$degree / max(V(g)$\$$degree)+ .2&lt;br /&gt;
 V(g)$\$$label.color &amp;lt;- rgb(0, 0, .2, .8)&lt;br /&gt;
 V(g)$\$$frame.color &amp;lt;- rgb(0,0,1)&lt;br /&gt;
 egam &amp;lt;- (log(E(g)$\$$weight)+.4) / max(log(E(g)$\$$weight)+.4)&lt;br /&gt;
 E(g)$\$$color &amp;lt;- rgb(.5, .5, 0, egam)		# Graph Edges, E(g)&lt;br /&gt;
 E(g)$\$$width &amp;lt;- egam&lt;br /&gt;
 # plot the graph in layout1&lt;br /&gt;
 plot(g, layout=layout1)&lt;br /&gt;
&lt;br /&gt;
 V(g)$\$$label &amp;lt;- V(g)$\$$name&lt;br /&gt;
 V(g)$\$$label.color &amp;lt;- rgb(0, 0, 0, 0.5)&lt;br /&gt;
 V(g)$\$$label.dist &amp;lt;- 1.0	# relative distance of labels from node center&lt;br /&gt;
 V(g)$\$$label.angle&amp;lt;- 3/8   #in radians&lt;br /&gt;
 V(g)$\$$label.cex &amp;lt;- 1.4*V(g)$\$$degree/max(V(g)$\$$degree) + 1&lt;br /&gt;
 V(g)$\$$color &amp;lt;- rgb(1, 0, 0, .4)&lt;br /&gt;
 V(g)$\$$size &amp;lt;- 22 * V(g)$\$$degree / max(V(g)$\$$degree)+ 2&lt;br /&gt;
 V(g)$\$$shape &amp;lt;- &amp;quot;rectangle&amp;quot;&lt;br /&gt;
 # V(g)$\$$.size=10*(strwidth(V(g)$\$$label) + strwidth(&amp;quot;oo&amp;quot;)) * 10&lt;br /&gt;
 # V(g)$\$$.size2=strheight(&amp;quot;I&amp;quot;) * 10&lt;br /&gt;
 V(g)$\$$frame.color &amp;lt;- NA&lt;br /&gt;
 # set vertex labels and their colors and sizes&lt;br /&gt;
 # set edge width and color&lt;br /&gt;
 E(g)$\$$width &amp;lt;- .3	&lt;br /&gt;
 E(g)$\$$color &amp;lt;- rgb(.5, .5, 0, .3) &lt;br /&gt;
&lt;br /&gt;
 set.seed(1234)&lt;br /&gt;
 plot(g, layout=layout.fruchterman.reingold)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization43.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on activity (oncological primary doctor and a second-opinion)===&lt;br /&gt;
&lt;br /&gt;
We use some of the Stanford Real Graph Data (http://snap.stanford.edu/data/) or this graph data on cancer patients seen by a primary doctor and a second-opinion doctor, stage of the disease, and diagnostic agreement between primary and secondary oncologist: &amp;lt;b&amp;gt;Primary&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;Secondary&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;Stage&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;DxAgreement&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # 03_GraphData_Health.txt&lt;br /&gt;
 healthGraphTable &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/554234/download?download_frd=1&amp;quot;, sep='\t', dec=',', header=T)&lt;br /&gt;
 #specify the path, separator(tab, comma, ...), decimal point symbol, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;head(healthGraphTable)&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Primary||Secondary||Stage||DxAgreement&lt;br /&gt;
|-&lt;br /&gt;
|1||AA||DD||3||Y&lt;br /&gt;
|-&lt;br /&gt;
|2||AB||DD||3||R&lt;br /&gt;
|-&lt;br /&gt;
|3||AF||BA||3||Q&lt;br /&gt;
|-&lt;br /&gt;
|4||DD||DA||3||Q&lt;br /&gt;
|-&lt;br /&gt;
|5||CD||EC||3||X&lt;br /&gt;
|-&lt;br /&gt;
|6||DD||CE||3||Y&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Transform the table into the required graph format:&lt;br /&gt;
 healthGraph.network&amp;lt;-graph.data.frame(healthGraphTable, directed=F) &lt;br /&gt;
 # the 'directed' attribute specifies whether the edges are directed&lt;br /&gt;
 # or equivalent irrespective of the position (1st vs 2nd column). For directed graphs use 'directed=T'&lt;br /&gt;
&lt;br /&gt;
 # Inspect the data:&lt;br /&gt;
 V(healthGraph.network) &amp;lt;blockquote&amp;gt;# prints the list of vertices (physicians/oncologists)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 E(healthGraph.network) &amp;lt;blockquote&amp;gt;# prints the list of edges (primary-secondary relationships)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 degree(healthGraph.network) &amp;lt;blockquote&amp;gt;# print the number of edges (relationships) per node (physician)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # first plot of graph&lt;br /&gt;
 plot(healthGraph.network)&lt;br /&gt;
&lt;br /&gt;
 #Subset the data. If we want to exclude only physicians who are mostly outside of the network &lt;br /&gt;
 # i.e., participate only tangentially (with 1 or 2 relationships only)&lt;br /&gt;
 # we can exclude nodes by subsetting the graph on the basis of the node/physician’s 'degree':&lt;br /&gt;
 healthGraph.out.network &amp;lt;- V(healthGraph.network)[degree(healthGraph.network)&amp;lt;=2] &lt;br /&gt;
 #identify those vertices part of less than or equal to 2 connections (edges)&lt;br /&gt;
 healthGraph.in.network &amp;lt;- delete.vertices(healthGraph.network, healthGraph.out.network) &lt;br /&gt;
 #exclude them from the graph&lt;br /&gt;
&lt;br /&gt;
 # Plot the data by specifying certain details about the graph, e.g., separate some nodes (people) by color:&lt;br /&gt;
 V(healthGraph.in.network)$\$$color &amp;lt;- ifelse(V(healthGraph.in.network)$\$$name=='CA', 'blue', 'red') &lt;br /&gt;
 #useful for highlighting certain people. Works by matching the name attribute of the vertex to the one specified in the 'ifelse' expression&lt;br /&gt;
 # We can also color the connecting edges differently depending on the 'Stage': &lt;br /&gt;
 E(healthGraph.in.network)$\$$color&amp;lt;-ifelse(E(healthGraph.in.network)$\$$Stage&amp;gt;3, &amp;quot;red&amp;quot;, &amp;quot;grey&amp;quot;)&lt;br /&gt;
 # or depending on the different diagnostic agreement labels ('DxAgreement'):&lt;br /&gt;
 E(healthGraph.in.network)$\$$color&amp;lt;-ifelse(E(healthGraph.in.network)$\$$DxAgreement =='X', &amp;quot;red&amp;quot;, ifelse(E(healthGraph.in.network)$\$$DxAgreement=='Y', &amp;quot;blue&amp;quot;, &amp;quot;grey&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Note: the example uses nested ifelse expressions which can be improved&lt;br /&gt;
 # Additional attributes like size can be further specified in an analogous manner:&lt;br /&gt;
 V(healthGraph.in.network)$\$$size&amp;lt;-degree(healthGraph.in.network)/10	&lt;br /&gt;
 #here the size of the vertices is specified by the degree of the vertex, so that people supervising more have get proportionally bigger dots. Getting the right scale gets some playing around with the parameters of the scale function    (from the 'base' package)&lt;br /&gt;
&lt;br /&gt;
 # Note that if the same attribute is specified beforehand and inside the function, the former will be overridden.&lt;br /&gt;
 # And finally the plot itself:&lt;br /&gt;
 par(mai=c(0,0,1,0)) 		&lt;br /&gt;
 #this specifies the size of the margins, default settings leave too much free space on all sides&lt;br /&gt;
 plot(healthGraph.in.network,		#the graph to be plotted&lt;br /&gt;
 layout=layout.fruchterman.reingold,	# the layout method. see the igraph documentation for details&lt;br /&gt;
 main='Onco Physician Network Example',	#specifies the title&lt;br /&gt;
 vertex.label.dist=0.5,			#puts the name labels slightly off the dots&lt;br /&gt;
 vertex.frame.color='blue', 		#the color of the border of the dots &lt;br /&gt;
 vertex.label.color='black',		#the color of the name labels&lt;br /&gt;
 vertex.label.font=2,			#the font of the name labels&lt;br /&gt;
 vertex.label=V(healthGraph.in.network)$\$$name,   #specifies the labels of the vertices&lt;br /&gt;
 vertex.label.cex=1			#specifies the size of the font of the labels&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # Save or export the plot as a metafile to the clipboard, a pdf or png (and other formats).&lt;br /&gt;
 png(filename=&amp;quot;org_network.png&amp;quot;, height=1900, width=1200) #call the png writer&lt;br /&gt;
 # alternatively print to high-res PDF file # pdf(file=&amp;quot;org_network.pdf&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 #run the plot&lt;br /&gt;
&lt;br /&gt;
 dev.off() #don’t forget to close the device&lt;br /&gt;
&lt;br /&gt;
==Pathway analysis==&lt;br /&gt;
&lt;br /&gt;
Pathway analysis   is a technique that reduces complexity and increased explanatory power in studies examining underlying biological structure of differentially expressed genes and proteins.&lt;br /&gt;
&lt;br /&gt;
 # install package &lt;br /&gt;
 # install.packages(&amp;quot;dendsort&amp;quot;) – contains the “” dataset&lt;br /&gt;
 # Data: Sample data matrix from the integrated pathway analysis of gastric cancer from the &lt;br /&gt;
 # Cancer Genome Atlas (TCGA) study. A multivariate table obtained from the integrated pathway analysis &lt;br /&gt;
 # of gastric cancer from the Cancer Genome Atlas (TCGA) study. Each column represents a pathway&lt;br /&gt;
 # &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;consisting of a set of genes and each row represents a cohort of samples based on specific clinical &lt;br /&gt;
 # or genetic features.&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; For each pair of a pathway and a feature, a continuous value of between &lt;br /&gt;
 # 1 and -1 is assigned to score positive or negative association, respectively.&lt;br /&gt;
 # A data frame with &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;215&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; rows and &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;117 variables&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 library(&amp;quot;dendsort&amp;quot;)&lt;br /&gt;
 data(sample_tcga)&lt;br /&gt;
 dataTable &amp;lt;- t(sample_tcga)&lt;br /&gt;
 head(dataTable)&lt;br /&gt;
 write.csv(dataTable, &amp;quot;E:\\Ivo.dir\\Research\\UMichigan\\Education_Teaching_Curricula\\2015_2016\\HS_853_Fall_2015\\Modules_docx\\data\\03_TCGA_Data_117x215.csv&amp;quot;)&lt;br /&gt;
 # data.new &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330393/download?download_frd=1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # install SPIA package: http://bioconductor.org/packages/2.6/bioc/html/SPIA.html &lt;br /&gt;
 # source(&amp;quot;http://bioconductor.org/biocLite.R&amp;quot;)&lt;br /&gt;
 # biocLite(&amp;quot;SPIA&amp;quot;)&lt;br /&gt;
 library(&amp;quot;SPIA&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # “top” Colorectal cancer dataset provided by SPIA package.&lt;br /&gt;
 data(Vessels)&lt;br /&gt;
 head(top)&lt;br /&gt;
 # pathway analysis based on combined evidence; &lt;br /&gt;
 # use nB=2000 or more for more accurate results&lt;br /&gt;
 res&amp;lt;-spia(de=DE_Vessels,all=ALL_Vessels,organism=&amp;quot;hsa&amp;quot;,nB=500,plots=FALSE,beta=NULL,verbose=FALSE)&lt;br /&gt;
 #make the output fit this screen&lt;br /&gt;
 res$\$$Name=substr(res$\$$Name,1,10)&lt;br /&gt;
 #show first 15 pathways, omitting KEGG links&lt;br /&gt;
 res[1:15,-12]&lt;br /&gt;
&lt;br /&gt;
==GIS/Distortion mapping==&lt;br /&gt;
&lt;br /&gt;
 # install the R GISTools package&lt;br /&gt;
 # install.packages(&amp;quot;GISTools&amp;quot;)&lt;br /&gt;
 library(&amp;quot;GISTools&amp;quot;)&lt;br /&gt;
 data(georgia)&lt;br /&gt;
 …&lt;br /&gt;
&lt;br /&gt;
Java Applet: http://www.socr.ucla.edu/htmls/SOCR_Cartograhy.html&lt;br /&gt;
Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_Cartography_Project &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Circos Connectogram/Table visualization==&lt;br /&gt;
&lt;br /&gt;
Circular chord/ribbon diagrams present a mechanism to visualize numeric tables containing information of directional relations. This type of chart visualizes tables in a circular way. Sectors of the plot is union(rownames(mat), colnames(mat)). When there is no rowname or colname, the chart assigns names for it (rows could be auto-named as &amp;quot;R1&amp;quot;, &amp;quot;R2&amp;quot;, ... and columns may be named as &amp;quot;C1&amp;quot;, &amp;quot;C2&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
•	Circos: http://circos.ca &lt;br /&gt;
&lt;br /&gt;
•	R circlize: http://cran.r-project.org/web/packages/circlize/circlize.pdf&lt;br /&gt;
&lt;br /&gt;
===Example Early-Onset Alzheimer’s Disease===&lt;br /&gt;
&lt;br /&gt;
Recent studies examined the Interactions between imaging (Structural Brain Change) and genetics (SNP) biomarkers in Early-Onset Alzheimer's Disease Subjects. Circular representation of the significant SNP-Neuroimaging interactions. The left and right parts of the graph contain the 15-ROI imaging markers and the 20-SNP genotypes, respectively. The strength of the connection between each SNP-ROI pair is presented as a ribbon, whose size, color and location are proportional to -log (p). Clearly, there are a lot of spurious effects (skinny red lines on background) and several significantly strong associations (thicker purple ribbons on foreground), e.g., purple association between SNP_5 (rs7718456) and ROI_10 (L_hippocampus, Volume). SNP: single nucleotide polymorphism, ROI: region of interest. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization44.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|SNPROI||ROI_1||ROI_2||ROI_3||ROI_4||ROI_5||ROI_6||ROI_7||ROI_8||ROI_9||ROI_10||ROI_11||ROI_12||ROI_13||ROI_14||ROI_15&lt;br /&gt;
|-&lt;br /&gt;
|rs17029131||10||10||10||10||10||10||10||10||10||10||188||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1822144||10||10||10||10||10||200||10||10||10||10||188||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs6446443||10||10||10||126||113||10||10||113||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12506164||10||10||10||10||10||167||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs7718456||10||202||144||206||10||10||10||169||225||321||10||10||290||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs9377090||10||145||10||10||10||10||10||153||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2776932||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs4933672||10||10||113||10||10||10||10||10||10||10||10||232||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193270||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193272||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs11193274||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12218153||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1338956||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs1338025||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12101936||10||10||10||10||10||10||10||10||10||10||10||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs16964473||10||10||10||10||10||10||10||10||10||10||112||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs12972537||10||10||10||10||10||10||125||10||10||10||126||10||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2212356||10||10||10||10||10||10||10||10||10||10||10||129||10||10||10&lt;br /&gt;
|-&lt;br /&gt;
|rs2831165||10||10||10||10||10||10||10||10||10||10||10||10||10||10||169&lt;br /&gt;
|-&lt;br /&gt;
|rs1266320||10||120||10||10||10||10||10||10||10||145||10||10||10||10||129&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # install.packages(&amp;quot;circlize&amp;quot;)&lt;br /&gt;
 library(&amp;quot;circlize&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;b&amp;gt;03_CircularTable_EOAD_Data.csv&amp;lt;/b&amp;gt;&lt;br /&gt;
 EOAD_data &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/330388/download?download_frd=1&amp;quot;, sep=&amp;quot;,&amp;quot;,  row.names=1, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 rownames(EOAD_data) &lt;br /&gt;
 colnames(EOAD_data) &lt;br /&gt;
 EOAD_matrix &amp;lt;- as.matrix(EOAD_data)&lt;br /&gt;
&lt;br /&gt;
 ### graphics settings&lt;br /&gt;
 # par(mfrow = c(3, 2))&lt;br /&gt;
 # par(mar = c(1, 1, 1, 1))&lt;br /&gt;
 chordDiagram(EOAD_matrix)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 circos.par(gap.degree = c(rep(2, nrow(EOAD_matrix)-1), 10, rep(2, ncol(EOAD_matrix)-1), 10))&lt;br /&gt;
 chordDiagram(EOAD_matrix)	&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 circos.par(start.degree = 90)&lt;br /&gt;
 chordDiagram(EOAD_matrix)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
 # chordDiagram(EOAD_matrix, order = c(&amp;quot;ROI_1&amp;quot;, &amp;quot;ROI_2&amp;quot;, &amp;quot;ROI_3&amp;quot;, &amp;quot;ROI_4&amp;quot;, &amp;quot;ROI_5&amp;quot;, &amp;quot;ROI_6&amp;quot;, &amp;quot;ROI_7&amp;quot;, &amp;quot;ROI_8&amp;quot;, &amp;quot;ROI_9&amp;quot;, &amp;quot;ROI_10&amp;quot;, &amp;quot;ROI_11&amp;quot;, &amp;quot;ROI_12&amp;quot;, &amp;quot;ROI_13&amp;quot;, &amp;quot;ROI_14&amp;quot;, &amp;quot;ROI_15&amp;quot;))&lt;br /&gt;
 chordDiagram(EOAD_matrix, directional = TRUE)&lt;br /&gt;
 chordDiagram(EOAD_matrix, directional = TRUE, diffHeight = 0.06)&lt;br /&gt;
&lt;br /&gt;
 circos.clear()&lt;br /&gt;
&lt;br /&gt;
 ### colors settings&lt;br /&gt;
 rand_color = function(n, alpha = 1) {&lt;br /&gt;
 return(rgb(runif(n), runif(n), runif(n), alpha = alpha))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 par(mfrow = c(2, 2))&lt;br /&gt;
 par(mar = c(1, 1, 1, 1))&lt;br /&gt;
 grid.col = NULL&lt;br /&gt;
&lt;br /&gt;
 # &amp;lt;mark&amp;gt;random&amp;lt;/mark&amp;gt; grid/sector and ribbon/chord colors&lt;br /&gt;
 col_mat = rand_color(length(EOAD_matrix), alpha = 0.5)&lt;br /&gt;
 grid_col = rand_color(length(rownames(EOAD_matrix)) + length(colnames(EOAD_matrix)), alpha = 0.5)&lt;br /&gt;
 dim(col_mat) = dim(EOAD_matrix)&lt;br /&gt;
 chordDiagram(EOAD_matrix, grid.col = grid_col, col = col_mat)&lt;br /&gt;
&lt;br /&gt;
 # grid/sector and ribbon/chord colors according to cell values&lt;br /&gt;
 # Generate quantile values for the color mapping relative to table cell-values&lt;br /&gt;
 seqs &amp;lt;- seq(0.92, 1, 0.008)&lt;br /&gt;
&lt;br /&gt;
 chordDiagram(EOAD_matrix, grid.col = grid_col, col = colorRamp2(quantile(EOAD_matrix, seqs), rev(heat.colors(11))), transparency = 0.5)&lt;br /&gt;
 circos.clear()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization46.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Practice===&lt;br /&gt;
&lt;br /&gt;
Repeat these charts using the 03_NIPS_Baby_VitK_Shot_DataSummaryAnalysis_March2012_Short.csv dataset (Appendix), https://umich.instructure.com/files/330392/download?download_frd=1 &lt;br /&gt;
&lt;br /&gt;
==Graphical Workflow Protocol Visualization==&lt;br /&gt;
&lt;br /&gt;
(1)	Brain Imaging &amp;amp; Genetics Data:&lt;br /&gt;
&lt;br /&gt;
a.	ADNI: http://adni.loni.usc.edu/&lt;br /&gt;
&lt;br /&gt;
b.	PPMI: http://ppmi-info.org/&lt;br /&gt;
&lt;br /&gt;
c.	XNAT Central: https://central.xnat.org/&lt;br /&gt;
&lt;br /&gt;
d.	Pipeline Data (see client library)&lt;br /&gt;
&lt;br /&gt;
e.	Cloud Services (AWS/Box/Drive)&lt;br /&gt;
&lt;br /&gt;
(2)	Pipeline Environment&lt;br /&gt;
&lt;br /&gt;
a.	http://pipeline.loni.usc.edu/&lt;br /&gt;
&lt;br /&gt;
b.	Web-Java Client: http://pipeline.loni.usc.edu/products-services/pws/ &lt;br /&gt;
&lt;br /&gt;
c.	Videos: http://pipeline.loni.usc.edu/learn/basic-videos/ &lt;br /&gt;
&lt;br /&gt;
d.	Publications: http://pipeline.loni.usc.edu/get-started/acknowledgmentscredits/ &lt;br /&gt;
&lt;br /&gt;
(3)	End-to-end Computational workflows&lt;br /&gt;
&lt;br /&gt;
a.	Navigator: http://pipeline.loni.usc.edu/explore/library-navigator/&lt;br /&gt;
&lt;br /&gt;
b.	Detailed Descriptions: http://wiki.loni.usc.edu/twiki/bin/view/CCB/PipelineWorkflows &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization47.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization48.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Neonate Infant Pain Score (NIPS) Data (Vitamin K shots) Dataset===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;A short version of the Neonate Infant Pain Score (NIPS) Data (Vitamin K shots) dataset, http://wiki.socr.umich.edu/index.php/SOCR_Data_NIPS_InfantVitK_ShotData&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|Index||Immediate||30_Sec||60_Sec||120_Sec||TotalCryTime&lt;br /&gt;
|-&lt;br /&gt;
|1||6||7||6||2||63&lt;br /&gt;
|-&lt;br /&gt;
|2||5||1||2||0||0&lt;br /&gt;
|-&lt;br /&gt;
|3||7||6||6||7||54&lt;br /&gt;
|-&lt;br /&gt;
|4||3||7||3||0||27&lt;br /&gt;
|-&lt;br /&gt;
|5||7||5||6||0||19&lt;br /&gt;
|-&lt;br /&gt;
|6||6||6||6||2||2&lt;br /&gt;
|-&lt;br /&gt;
|7||7||7||6||0||46&lt;br /&gt;
|-&lt;br /&gt;
|8||6||7||0||0||33&lt;br /&gt;
|-&lt;br /&gt;
|9||5||0||4||0||56&lt;br /&gt;
|-&lt;br /&gt;
|10||7||7||7||6||63&lt;br /&gt;
|-&lt;br /&gt;
|105||6||0||0||0||11&lt;br /&gt;
|-&lt;br /&gt;
|106||7||6||0||0||59&lt;br /&gt;
|-&lt;br /&gt;
|107||7||4||4||0||28&lt;br /&gt;
|-&lt;br /&gt;
|108||7||7||7||1||64&lt;br /&gt;
|-&lt;br /&gt;
|109||7||0||0||0||8&lt;br /&gt;
|-&lt;br /&gt;
|110||5||0||1||3||64&lt;br /&gt;
|-&lt;br /&gt;
|111||7||5||7||7||72&lt;br /&gt;
|-&lt;br /&gt;
|112||4||2||0||2||50&lt;br /&gt;
|-&lt;br /&gt;
|113||7||6||7||0||44&lt;br /&gt;
|-&lt;br /&gt;
|114||7||1||0||0||11&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===See Next===&lt;br /&gt;
* [[SMHS_SciVisualization| Back to the Scientific Visualization section]]&lt;br /&gt;
* [[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16027</id>
		<title>SMHS SciVisualization SOCR Excel R Charts</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16027"/>
		<updated>2016-05-19T13:59:42Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Trees and Graphs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - SOCR, Excel and R charts ==&lt;br /&gt;
&lt;br /&gt;
==SOCR Charts==&lt;br /&gt;
&lt;br /&gt;
•	URL: http://socr.umich.edu/html/cha/ (Java applet)&lt;br /&gt;
&lt;br /&gt;
•	About/List: http://wiki.stat.ucla.edu/socr/index.php/About_pages_for_SOCR_Chart_List &lt;br /&gt;
&lt;br /&gt;
•	Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_ChartsActivities&lt;br /&gt;
&lt;br /&gt;
•	Data: http://wiki.socr.umich.edu/index.php/SOCR_Data &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Excel Charts==&lt;br /&gt;
&lt;br /&gt;
MS Excel provides a large number of charts that can be used to quickly and effectively render complex multivariate data. For instance, the table below contains the principal component analysis (PCA) of 50 derived neuroimaging biomarkers (region of interest (ROI) by shape morphometry metric). The loadings of these 50 variables on the top 5 (most significant) principal component directions are shown in the table. Experiment with effective visualizations of these data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Hemi||ROI||measure||ROI_Measure||Dim.1||Dim.2||Dim.3||Dim.4||Dim.5&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||AvgMeanCurvature||L_insular_cortex_AvgMeanCurvature||0.72||0||0.06||0.06||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ComputeArea||L_insular_cortex_ComputeArea||0.77||0.06||0.04||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Volume||L_insular_cortex_Volume||0.72||0.09||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ShapeIndex||L_insular_cortex_ShapeIndex||0.46||0.06||0.01||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Curvedness||L_insular_cortex_Curvedness||0.78||0||0.05||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||AvgMeanCurvature||R_insular_cortex_AvgMeanCurvature||0.79||0||0.03||0.08||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ComputeArea||R_insular_cortex_ComputeArea||0.79||0.09||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Volume||R_insular_cortex_Volume||0.73||0.11||0.03||0.03||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ShapeIndex||R_insular_cortex_ShapeIndex||0.27||0.17||0||0.07||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Curvedness||R_insular_cortex_Curvedness||0.84||0.02||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||AvgMeanCurvature||L_cingulate_gyrus_AvgMeanCurvature||0.72||0||0.05||0.02||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ComputeArea||L_cingulate_gyrus_ComputeArea||0.74||0.05||0.06||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Volume||L_cingulate_gyrus_Volume||0.69||0.08||0.05||0.05||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ShapeIndex||L_cingulate_gyrus_ShapeIndex||0.53||0||0.05||0||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Curvedness||L_cingulate_gyrus_Curvedness||0.7||0.01||0.05||0.04||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||AvgMeanCurvature||R_cingulate_gyrus_AvgMeanCurvature||0.6||0||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ComputeArea||R_cingulate_gyrus_ComputeArea||0.73||0.06||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Volume||R_cingulate_gyrus_Volume||0.68||0.09||0.04||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ShapeIndex||R_cingulate_gyrus_ShapeIndex||0.56||0.01||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Curvedness||R_cingulate_gyrus_Curvedness||0.25||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||AvgMeanCurvature||L_caudate_AvgMeanCurvature||0.52||0||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ComputeArea||L_caudate_ComputeArea||0.51||0.09||0.03||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Volume||L_caudate_Volume||0.44||0.09||0.03||0.06||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ShapeIndex||L_caudate_ShapeIndex||0.2||0.03||0.04||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Curvedness||L_caudate_Curvedness||0.51||0.12||0.02||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||AvgMeanCurvature||R_caudate_AvgMeanCurvature||0.68||0.04||0.04||0.02||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ComputeArea||R_caudate_ComputeArea||0.67||0.17||0.03||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Volume||R_caudate_Volume||0.61||0.16||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ShapeIndex||R_caudate_ShapeIndex||0.18||0.02||0.03||0.11||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Curvedness||R_caudate_Curvedness||0.65||0.19||0.01||0||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||AvgMeanCurvature||L_putamen_AvgMeanCurvature||0.62||0||0.04||0.03||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ComputeArea||L_putamen_ComputeArea||0.56||0.05||0.04||0.03||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Volume||L_putamen_Volume||0.52||0.07||0.04||0.05||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ShapeIndex||L_putamen_ShapeIndex||0.06||0.13||0||0.15||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Curvedness||L_putamen_Curvedness||0.64||0.11||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||AvgMeanCurvature||R_putamen_AvgMeanCurvature||0.62||0||0.07||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ComputeArea||R_putamen_ComputeArea||0.66||0.08||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Volume||R_putamen_Volume||0.64||0.12||0.03||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ShapeIndex||R_putamen_ShapeIndex||0.15||0.24||0||0.08||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Curvedness||R_putamen_Curvedness||0.65||0.05||0.05||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||AvgMeanCurvature||L_hippocampus_AvgMeanCurvature||0.78||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ComputeArea||L_hippocampus_ComputeArea||0.75||0.07||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Volume||L_hippocampus_Volume||0.72||0.09||0.01||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ShapeIndex||L_hippocampus_ShapeIndex||0.45||0.17||0||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Curvedness||L_hippocampus_Curvedness||0.79||0.03||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||AvgMeanCurvature||R_hippocampus_AvgMeanCurvature||0.72||0||0||0.1||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ComputeArea||R_hippocampus_ComputeArea||0.71||0.09||0||0||0.05&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Volume||R_hippocampus_Volume||0.68||0.1||0||0||0.04&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ShapeIndex||R_hippocampus_ShapeIndex||0.37||0.18||0||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Curvedness||R_hippocampus_Curvedness||0.77||0.03||0||0.02||0.04&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==R-Charts==&lt;br /&gt;
&lt;br /&gt;
There are 100’s of packages and 1,000 of different charts, plots and graphs that can be generated using R. Such interactive visualizations enable deeper exploration of data, models and results. JavaScript libraries, e.g., D3, provide advantages for data visualization as these involve HTML5 and are easily shareable online. The R community is developing R interfaces to some popular JavaScript libraries to allow users to create interactive visualizations without detailed knowledge of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Examples of powerful R interactive visualization packages===&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;ggplot2&amp;lt;/b&amp;gt; – http://ggplot2.org&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;ggvis&amp;lt;/b&amp;gt; – interactive plots extending the static ggplot2 charts, http://ggvis.rstudio.com&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;rCharts&amp;lt;/b&amp;gt; – R interface to multiple JavaScript charting libraries, http://rcharts.io&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;plotly&amp;lt;/b&amp;gt; – transforming ggplot2 charts into interactive plots, https://plot.ly/r &lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;googleVis&amp;lt;/b&amp;gt; – Google Charts using R, http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;HTMLWidgets&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;leaflet&amp;lt;/b&amp;gt; – library for creating dynamic maps, supports panning and zooming, annotations, markers, polygons, etc. http://www.htmlwidgets.org/showcase_leaflet.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;dygraphs&amp;lt;/b&amp;gt; – provides mechanism for charting time-series data, supports interactive navigation features including series/point highlighting, zooming, and panning, http://www.htmlwidgets.org/showcase_dygraphs.html&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;networkD3&amp;lt;/b&amp;gt; – library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks, http://www.htmlwidgets.org/showcase_networkD3.html&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;DataTables&amp;lt;/b&amp;gt; – displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting, http://www.htmlwidgets.org/showcase_datatables.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;Rthreejs&amp;lt;/b&amp;gt; – features 3D scatterplots and globes based on WebGL, http://www.htmlwidgets.org/showcase_threejs.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	Other R graphic examples&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	To write out plots out to file use:&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 # pdf() command all graphs are redirected to test.pdf.  Also works with other common formats:  jpeg, png, ps, tiff.&lt;br /&gt;
 pdf(&amp;quot;C:\\Users\\Dinov\\Desktop\\test.pdf&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
 # Generates Scalable Vector Graphics (SVG) that can be edited by vector graphics software&lt;br /&gt;
 svg(&amp;quot;test.svg&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
&lt;br /&gt;
===Paired ScatterPlots===&lt;br /&gt;
&lt;br /&gt;
 set.seed(100)&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 describe(x)    # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 plot(x[,1], x[,2], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 text(x[,1]+0.03, x[,2], rownames(x))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pairs(x)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another way to generate scatterplots is by using &amp;lt;b&amp;gt;ggplot:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 x &amp;lt;- sample(1:20, 20); y &amp;lt;- sample(1:20, 20); cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), 5)  &lt;br /&gt;
 #vs. cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), each=5)&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 #  Case_03_MentalHealthServicesSurvey&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399128/download?download_frd=1&amp;amp;verifier=AG2e9QUKUm1jvDBpkX7D9jbEjKNc4irA0ECk0f7p', header=T)	&lt;br /&gt;
 head(data1)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 describe(data1)&lt;br /&gt;
&lt;br /&gt;
 plot(data1[,3], data1[,4], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 # text(data1 [,3]+0.03, data1 [,4], rownames(data1))&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # redo plots using majorfundtype FacilityType Ownership Focus&lt;br /&gt;
 # pairs(data1, na.action=na.omit)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Scatterplot with regression line. Use the “diamonds” dataset, which is a data frame with&lt;br /&gt;
 # 53,940 rows and 10 variables ()&lt;br /&gt;
 # describe(diamonds)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 # CaseStudy01_Divorce_YoungAdults&lt;br /&gt;
 # data1 &amp;lt;- read.csv('https://umich.instructure.com/files/399118/download?download_frd=1&amp;amp;verifier=ESACv31KcyiHbkPZPuT8Oo4V7XzPtgTTbs6PQLTv', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # plot variables: DIVYEAR momint dadint momclose depression livewithmom gethitched&lt;br /&gt;
&lt;br /&gt;
 set.seed(110)&lt;br /&gt;
 # par(mfrow=c(1,2))&lt;br /&gt;
 data.2 &amp;lt;- diamonds[sample(nrow(diamonds), 500), ]&lt;br /&gt;
 plot.2 &amp;lt;- qplot(price, depth, data = data.2, geom = c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), method = &amp;quot;lm&amp;quot;)&lt;br /&gt;
 plot.3 &amp;lt;- qplot(carat, price, data=data.2, geom=c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), span=0.4)&lt;br /&gt;
 print(plot.2); print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Barplots===&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 barplot(x[1:4,], ylim=c(0, max(x[1:4,])+0.3), beside=TRUE, legend.text = letters[1:4],&lt;br /&gt;
        args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:4,])),2), x=seq(1.5, 21, by=1) + sort(rep(c(0,1,2,3,4), 4)), y=as.vector(as.matrix(x[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to put error bars on barplot:&lt;br /&gt;
&lt;br /&gt;
 # 10 rows (a, b, c, …):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- rowMeans(x) * 10, ylim=c(0, 10))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Case_04_ChildTrauma&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399129/download?download_frd=1&amp;amp;verifier=Hmv0YW2Kie5ZTV9CKBUNArSHR66f3GWSmVzZDBxc', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 head(x)&lt;br /&gt;
 head(data1)&lt;br /&gt;
 # plot data&lt;br /&gt;
 data2 &amp;lt;- data1[,-5]   # remove the 5th columns text&lt;br /&gt;
 data1 &amp;lt;- data2[,-5]   # remove the 6th columns text&lt;br /&gt;
 # or data1 &amp;lt;- data1[,c(-5,-6)]&lt;br /&gt;
&lt;br /&gt;
 data2 &amp;lt;- as.data.frame(data1)&lt;br /&gt;
 Blacks &amp;lt;- data2[which(data2$\$$race==&amp;quot;black&amp;quot;),]&lt;br /&gt;
 Other &amp;lt;- data2[which(data2$\$$race==&amp;quot;other&amp;quot;),]&lt;br /&gt;
 Hispanic &amp;lt;- data2[which(data2$\$$race==&amp;quot;hispanic&amp;quot;),]&lt;br /&gt;
 White &amp;lt;- data2[which(data2$\$$race==&amp;quot;white&amp;quot;),]&lt;br /&gt;
&lt;br /&gt;
 A &amp;lt;- c(mean(Blacks$\$$age), mean(Blacks$\$$service))&lt;br /&gt;
 #colnames(A) &amp;lt;- c(&amp;quot;age &amp;quot;,&amp;quot; service &amp;quot;)  &lt;br /&gt;
 B &amp;lt;- c(mean(Other$\$$age), mean(Other$\$$service))&lt;br /&gt;
 C &amp;lt;- c(mean(Hispanic$\$$age), mean(Hispanic$\$$service))&lt;br /&gt;
 D &amp;lt;- c(mean(White$\$$age), mean(White$\$$service))&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- cbind(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
 bar &amp;lt;- barplot(x[1:2,], ylim=c(0, max(x[1:2,])+2.0), beside=TRUE, &lt;br /&gt;
 legend.text = c(&amp;quot;age&amp;quot;,&amp;quot;service&amp;quot;) ,  args.legend = list(x = &amp;quot;right&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:2,])),2), x=seq(1.4, 21, by=1.5), #y=as.vector(as.matrix(x[1:2,]))+0.3)&lt;br /&gt;
	y=11.5)&lt;br /&gt;
&lt;br /&gt;
 m &amp;lt;- x; stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 barplot(as.matrix(data1[1:4,]), ylim=c(0, max(data1[1:4,])+0.3), beside=TRUE, legend.text = data1[1:4,1], args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(data1[1:4,])),2), x=seq(1.5, 21, by=1), y=as.vector(as.matrix(data1[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Columns (A, B, C, D, E):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- colMeans(x) * 5, ylim=c(0, 5))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Histograms and Density Plots===&lt;br /&gt;
&lt;br /&gt;
 hist(x, freq=TRUE, breaks=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(density(x), lwd = 10, col=&amp;quot;green&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pie Chart===&lt;br /&gt;
&lt;br /&gt;
 # first , “A”, and second, “B”, columns&lt;br /&gt;
 par (mfrow=c(1,2))&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,2], col=rainbow(length(x[,2]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
 legend(&amp;quot;topleft&amp;quot;, legend=row.names(x), cex=1.3, bty=&amp;quot;n&amp;quot;, pch=15, pt.cex=1.8, col=rainbow(length(x[,2]), start=0.1, end=0.8), ncol=1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 You can export the data: &lt;br /&gt;
 write.table(x, &amp;quot; &amp;quot;, &amp;quot;data.txt&amp;quot;)&lt;br /&gt;
 # copy-paste it in SOCR Pie chart to generate another Pie view of data&lt;br /&gt;
&lt;br /&gt;
===Line Plots Using ggplot===&lt;br /&gt;
&lt;br /&gt;
 head(diamonds)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Carat||Cut||Color||Clarity||Depth||Table||Price||X||Y||Z&lt;br /&gt;
|-&lt;br /&gt;
|1||0.23||Ideal||E||SI2||61.5||55||326||3.95||3.98||2.43&lt;br /&gt;
|-&lt;br /&gt;
|2||0.21||Premium||E||SI1||59.8||61||326||3.89||3.84||2.31&lt;br /&gt;
|-&lt;br /&gt;
|3||0.23||Good||E||VS1||56.9||65||237||4.05||4.07||2.31&lt;br /&gt;
|-&lt;br /&gt;
|4||0.29||Premium||I||VS2||62.4||58||334||4.2||4.23||2.63&lt;br /&gt;
|-&lt;br /&gt;
|5||0.31||Good||J||SI2||63.3||58||335||4.34||4.35||4.75&lt;br /&gt;
|-&lt;br /&gt;
|6||0.24||VeryGood||J||VVS2||62.8||57||336||3.94||3.96||2.48&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(diamonds, aes(carat, price, group=cut, color=cut)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization17.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(data1, aes(age, service, group=race, color=race)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Faceting plot (geometrically, faceting (or facetting) is the process of removing parts of a polygon, polyhedron or polytope, without creating any new vertices)&lt;br /&gt;
 plot.3 &amp;lt;- ggplot(diamonds, aes(carat, price)) + geom_line(aes(color=cut), size=1) + &lt;br /&gt;
 facet_wrap(~cut, ncol=1)&lt;br /&gt;
 print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization18.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Barplots with ggplot===&lt;br /&gt;
&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization19.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 New_var &amp;lt;- service+rnorm(1000, 0,1)&lt;br /&gt;
 data1$\$$New_var &amp;lt;- int(New_var)&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(data1, aes(race, fill= traumatype)) + geom_bar() + facet_grid(. ~ New_var)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 plot.4a &amp;lt;- ggplot(diamonds, aes(color, price/carat, fill=color)) + geom_boxplot()&lt;br /&gt;
 print(plot.4a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization20.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Jitter plot===&lt;br /&gt;
&lt;br /&gt;
 plot.5 &amp;lt;- ggplot(diamonds, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))&lt;br /&gt;
 print(plot.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization21.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Density Plots===&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(color = cut))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization22.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(data1, aes(age, size=2)) + geom_density(aes(color = traumatype))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
 plot.7 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(fill = color))&lt;br /&gt;
 print(plot.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization23.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8 &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), binwidth=0.2) + geom_density()&lt;br /&gt;
 print(plot.8)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization24.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8a &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), stat=&amp;quot;identity&amp;quot;) + geom_density()&lt;br /&gt;
 print(plot.8a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization25.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heatmaps===&lt;br /&gt;
&lt;br /&gt;
 # Generating Dendogram Association Heatmap Plot (Genotype vs. Imaging phenotype)&lt;br /&gt;
 # http://stat.ethz.ch/R-manual/R-patched/library/stats/html/heatmap.html&lt;br /&gt;
 # http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4005931/ &lt;br /&gt;
	   &lt;br /&gt;
 AD_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330387/download?download_frd=1&amp;amp;verifier=gLk2ADgrLhXGeknI6mqIeJugi2ODr8RARsQlBUMe&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
&lt;br /&gt;
 MCI_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330390/download?download_frd=1&amp;amp;verifier=FczlJD6ISRPZhu69xvHuoZHx2c7gXX9YEvvPCTBG&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 require(grDevices)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
&lt;br /&gt;
 AD_Data &amp;lt;- AD_Associations_Data &lt;br /&gt;
 MCI_Data &amp;lt;- MCI_Associations_Data &lt;br /&gt;
 NC_Data &amp;lt;- NC_Associations_Data &lt;br /&gt;
&lt;br /&gt;
 AD_mat  &amp;lt;- as.matrix(AD_Data); class(AD_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 MCI_mat  &amp;lt;- as.matrix(MCI_Data); class(MCI_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 NC_mat  &amp;lt;- as.matrix(NC_Data); class(NC_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # set up the rol (rc) and column (cc) colors for each cohort&lt;br /&gt;
 rcAD &amp;lt;- rainbow(nrow(AD_mat), start = 0, end = 1.0); ccAD&amp;lt;-rainbow(ncol(AD_mat), start = 0, end = 1.0)&lt;br /&gt;
 rcMCI &amp;lt;- rainbow(nrow(MCI_mat), start = 0, end=1.0); ccMCI&amp;lt;-rainbow(ncol(MCI_mat),start=0,end=1.0)&lt;br /&gt;
 rcNC &amp;lt;- rainbow(nrow(NC_mat), start = 0, end = 1.0); ccNC&amp;lt;-rainbow(ncol(NC_mat), start = 0, end = 1.0)&lt;br /&gt;
&lt;br /&gt;
 # set up 1x3 graph display - par (mfrow=c(1,3)) – does not work with ‘heatmap’&lt;br /&gt;
 hvAD &amp;lt;- heatmap(AD_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcAD, ColSideColors = ccAD, margins = c(2,2), main=&amp;quot;AD Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvMCI &amp;lt;- heatmap(MCI_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcMCI, ColSideColors = ccMCI, margins = c(2,2), main=&amp;quot;MCI Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvNC &amp;lt;- heatmap(NC_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcNC, ColSideColors = ccNC, margins = c(2,2), main=&amp;quot;NC Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization26.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use the R package gplots&lt;br /&gt;
 install.packages(&amp;quot;gplots&amp;quot;)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
 ## col dendrogram plotted and col reordering done. &lt;br /&gt;
 # heatmap.2(AD_mat, keysize=2) &lt;br /&gt;
 ## A more decorative heatmap, with z-score scaling along columns &lt;br /&gt;
 heatmap.2(AD_mat, col=cm.colors(255), scale=&amp;quot;column&amp;quot;, RowSideColors=rcAD, ColSideColors=ccAD, margin=c(8, 7), xlab=&amp;quot;Imaging Biomarkers (ROI volume)&amp;quot;, ylab= &amp;quot;Genetics Biomarkers (SNPs)&amp;quot;, main=&amp;quot;AD Associations Heatmap (SNP-Imaging)&amp;quot;,     tracecol=&amp;quot;green&amp;quot;, density=&amp;quot;density&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization27.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Correlation Plots===&lt;br /&gt;
&lt;br /&gt;
 The &amp;lt;b&amp;gt;corrplot&amp;lt;/b&amp;gt; package is a graphical display of a correlation matrix and confidence intervals, with some tools for matrix reordering. There are seven visualization methods (parameter method) in corrplot package, named   &amp;quot;circle&amp;quot;, &amp;quot;square&amp;quot;, &amp;quot;ellipse&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;shade&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;pie&amp;quot;.&lt;br /&gt;
 # install.packages(&amp;quot;corrplot&amp;quot;)&lt;br /&gt;
 library(corrplot)&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
 M &amp;lt;- cor(NC_Associations_Data)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization28.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hyperbolic Visualization===&lt;br /&gt;
&lt;br /&gt;
•	URL: http://socr.umich.edu/html/Navigators.html  &lt;br /&gt;
&lt;br /&gt;
•	Tools:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	Java/Jar applet: http://socr.umich.edu/html/navigators/HW/jars/SOCR_HW_Viewer.jar&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	JavaScript: http://socr.umich.edu/html/navigators/D3/SOCR_D3_Viewer.html (JSON)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	Data Format&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	XML data: http://socr.umich.edu/html/navigators/HW/SOCR_HyperTree.xml&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	JSON data: http://socr.umich.edu/html/navigators/D3/xml/SOCR_HyperTree.json&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
•	D3 Visualization&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	E:\Ivo.dir\Research\UMichigan\Education_Teaching_Curricula\2015_2016\HS_853_Fall_2015\Modules_docx\Tools\TreeViewer_JS&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	treeJS.json&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	flareD3.json&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization29.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization30.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	URL: https://github.com/mbostock/d3/wiki/Gallery&lt;br /&gt;
&lt;br /&gt;
•	Source code: https://github.com/mbostock/d3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization31.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Motion Charts===&lt;br /&gt;
&lt;br /&gt;
•	Video: http://www.socr.ucla.edu/SOCR_MotionCharts/SOCR_HTML5_MotionChart_Video2.gif&lt;br /&gt;
&lt;br /&gt;
•	Java: http://www.socr.ucla.edu/SOCR_MotionCharts/ &lt;br /&gt;
&lt;br /&gt;
•	HTML5: http://socr.umich.edu/HTML5/MotionChart/ &lt;br /&gt;
&lt;br /&gt;
•	Activities: http://wiki.socr.umich.edu/index.php/SOCR_MotionCharts &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization32.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1D/2D/3D signal/area/volume/surface/model/atlas visualization===&lt;br /&gt;
&lt;br /&gt;
• 1D: (See R/SOCR Visualization tools above)&lt;br /&gt;
&lt;br /&gt;
• 2D: http://imagej.nih.gov/ij/ &lt;br /&gt;
&lt;br /&gt;
• 3D: http://socr.umich.edu/HTML5/BrainViewer/ &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;Supported File Formats:&amp;lt;/b&amp;gt;&lt;br /&gt;
 Volumes (.nii / .nii.gz / .img&amp;amp;.hdr / .mgh / .mgz / .nrrd)&lt;br /&gt;
 Shapes (.dx / .vtk / .stl / FreeSurfer)&lt;br /&gt;
 Fibers (.trk)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization33.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trees and Graphs===&lt;br /&gt;
&lt;br /&gt;
• Trees/Hierarchies and general Graphs&lt;br /&gt;
&lt;br /&gt;
 # Install and load the APE package, needed for the phylogenetic tree rendering (as.phylo)&lt;br /&gt;
 # install.packages(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Load data &lt;br /&gt;
&lt;br /&gt;
 # Data: 02_Nof1_Data.csv&lt;br /&gt;
 data.1 &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clustering&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.1), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;,&amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA),&amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization34.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 (x &amp;lt;- identify(hc)) ##  Terminate with 2nd mouse button !!&lt;br /&gt;
 identify(hc, &amp;lt;mark&amp;gt;function(k)&amp;lt;/mark&amp;gt; print(table(data.1[k,5])))&lt;br /&gt;
&lt;br /&gt;
You can now cut the tree into branches. You can split the tree into 2 groups, by setting the number of cuts with the k=2 parameter, or by specifying height to cut the tree at (?cutree):&lt;br /&gt;
&lt;br /&gt;
k- an integer scalar or vector with the desired number of groups&lt;br /&gt;
&lt;br /&gt;
h- numeric scalar or vector with heights where the tree should be cut&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the clustering method &lt;br /&gt;
 # for the particular agglomeration.&lt;br /&gt;
 cutree(hc, h= 50) # cut at h=50&lt;br /&gt;
 table(cutree(hc, h= 50)) # cluster distribution&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=5; &lt;br /&gt;
 myClusters = sapply(2:10,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:10, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 groups.10 &amp;lt;- cutree(hc, k = 10)	&lt;br /&gt;
 sapply(unique(groups.10),function(g)data.1$\$$ID[groups.10 == g])&lt;br /&gt;
 #To see which Treatments (Tx) are in which clusters:&lt;br /&gt;
 groups.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.2),function(g)data.1$\$$Tx[groups.2 == g])&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.2, data.1$\$$Tx)&lt;br /&gt;
 # For a small number of observations, we can often interpret the cluster solution directly by looking &lt;br /&gt;
 # at the labels of the observations that are in each cluster. &lt;br /&gt;
 # This is hard for larger data sets. To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;aggregate&amp;lt;/b&amp;gt; function will compute stats (e.g., median) on many variables simultaneously. &lt;br /&gt;
&lt;br /&gt;
To look at the median values for the variables we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
&lt;br /&gt;
 aggregate(data.1, list(groups.10),median) # may have to &amp;lt;b&amp;gt;shrink data.1&amp;lt;/b&amp;gt; prior to clustering! &lt;br /&gt;
 # data.2 &amp;lt;- data.1[,-c(1,3)]  # Remove ID and Tx variables?&lt;br /&gt;
 aggregate(data.2, list(groups.2),median) # for only 2 clusters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Group||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 table(groups.2, data.1$\$$&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 describe(data.1$\$$PhyAct)&lt;br /&gt;
&lt;br /&gt;
 # It’s useful to add the numbers of observations in each group (aggregate returns a data frame, &lt;br /&gt;
 # that can be manipulated)&lt;br /&gt;
&lt;br /&gt;
 df.2 &amp;lt;- aggregate(data.1, list(groups.2),median)&lt;br /&gt;
&lt;br /&gt;
 data.frame(Cluster= df.2[,1], Freq=as.vector(table(groups.2)), df.2[,-1])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Cluster||&amp;lt;mark&amp;gt;Freq&amp;lt;/mark&amp;gt;||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||&amp;lt;mark&amp;gt;570&amp;lt;/mark&amp;gt;||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||&amp;lt;mark&amp;gt;330&amp;lt;/mark&amp;gt;||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
•	This paper examines nasal and bronchial tissue cultures as appropriate in vitro models for the assessment of smoking-induced adverse effects in the respiratory system (doi: 10.1177/1091581814551647), using “hclust” package. No data.&lt;br /&gt;
&lt;br /&gt;
•	This paper classified subtypes of gastric cancer based on epidemiologic and histologic and gene expression data. These new classifications of gastric cancer have implications for improving our understanding of disease biology and identification of unique molecular drivers for each gastric cancer subtype (doi: 10.1158/1078-0432.CCR-10-2203).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Repeat the clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # using centroids and squared Euclidean distance&lt;br /&gt;
 # cut the tree into 10 clusters and reconstruct the upper part of the tree from the cluster centers.&lt;br /&gt;
 hc &amp;lt;- hclust(dist(data.1), &amp;quot;cen&amp;quot;)&lt;br /&gt;
 mem &amp;lt;- cutree(hc, k = 10)&lt;br /&gt;
 cent &amp;lt;- NULL&lt;br /&gt;
 for(k in 1:10){&lt;br /&gt;
  		cent &amp;lt;- rbind(cent, colMeans(data.1[mem == k, , drop = FALSE]))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 hc1 &amp;lt;- hclust(dist(cent), method = &amp;quot;cen&amp;quot;, members = table(mem))&lt;br /&gt;
&lt;br /&gt;
 opar &amp;lt;- par(mfrow = c(1, 2))&lt;br /&gt;
 plot(hc,  labels = FALSE, hang = -1, main = &amp;quot;Original Tree&amp;quot;)&lt;br /&gt;
 plot(hc1, hang = -1, main = &amp;quot;Re-start from 10 clusters&amp;quot;)&lt;br /&gt;
 par(opar)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization35.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Identify subjects within each of the 10 classes&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rect.hclust(hc, h=10) &lt;br /&gt;
&lt;br /&gt;
 # To save the cluster numbers to a new variable in the dataset, use the cutree function.&lt;br /&gt;
 # data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct||&amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;CluserID&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53||1&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73||1&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23||2&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36||2&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21||2&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0||2&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Phylogenetic tree diagram&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc1), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;, tip.color = hsv(runif(15, 0.65, 0.95), 1, 1, 0.7), label.offset = 1, cex = log(data.1$\$$ID, 10), col = &amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization36.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization37.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity (Health Behavior Risks)===&lt;br /&gt;
&lt;br /&gt;
 # load data CaseStudy09_HealthBehaviorRisks_Data&lt;br /&gt;
 data.2 &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/399182/download?download_frd=1 &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # Classify the cases using these variables:  &amp;quot;AGE_G&amp;quot;    &amp;quot;SEX&amp;quot;      &amp;quot;RACEGR3&amp;quot;  &amp;quot;IMPEDUC&amp;quot;  &amp;quot;IMPMRTL&amp;quot;  &lt;br /&gt;
 #	&amp;quot;EMPLOY1&amp;quot;  &amp;quot;INCOMG&amp;quot;  &amp;quot;CVDINFR4&amp;quot; &amp;quot;CVDCRHD4&amp;quot; &amp;quot;CVDSTRK3&amp;quot; &amp;quot;DIABETE3&amp;quot; &amp;quot;RFSMOK3&amp;quot;  &lt;br /&gt;
 #	&amp;quot;FRTLT1&amp;quot;   &amp;quot;VEGLT1&amp;quot; &lt;br /&gt;
 data.raw &amp;lt;- data.2[,-c(1,14,17)]&lt;br /&gt;
&lt;br /&gt;
 # Does the classification match either of these: &lt;br /&gt;
 #	TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t know/Refused/Missing)&lt;br /&gt;
 #	RFDRHV4 (Heavy alcohol consumption, 1=No, 2=Yes, 9=Don’t know/Refused/Missing)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.raw), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;, &amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA), &amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
 &lt;br /&gt;
 summary(data.2$\$$TOTINDA); summary(data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the &lt;br /&gt;
 # clustering method for the particular agglomeration -- cutree(hc, h= 10)&lt;br /&gt;
&lt;br /&gt;
 table(cutree(hc, h= 10)) # cluster distribution&lt;br /&gt;
&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to sapply -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=4; &lt;br /&gt;
 myClusters = sapply(2:5,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:5, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 table(cutree(hc, k=2)) &lt;br /&gt;
 groups.k.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.k.2),function(g)data.2$\$$ID[groups.k.2 == g])&lt;br /&gt;
&lt;br /&gt;
 #To see which TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t &lt;br /&gt;
 # 	know/Refused/Missing) &amp;amp; whch RFDRHV4 are in which clusters:&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4[groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Perhaps there are intrinsically 3 groups here e.g., 1, 2 and 9 …&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4 [groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Note that there is quite a dependence between the outcome variables …&lt;br /&gt;
 plot(data.2$\$$RFDRHV4, data.2$\$$TOTINDA)&lt;br /&gt;
&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.k.3, data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 # To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. The aggregate function will compute stats&lt;br /&gt;
 # (e.g., median) on many variables simultaneously. To look at the median values for the variables &lt;br /&gt;
 # we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
 aggregate(data.2, list(groups.k.3),median) &lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS_SciVisualization_NetworkViz|Next See the Complex Network Visualization section]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]/&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16026</id>
		<title>SMHS SciVisualization SOCR Excel R Charts</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16026"/>
		<updated>2016-05-19T13:58:53Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Hyperbolic Visualization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - SOCR, Excel and R charts ==&lt;br /&gt;
&lt;br /&gt;
==SOCR Charts==&lt;br /&gt;
&lt;br /&gt;
•	URL: http://socr.umich.edu/html/cha/ (Java applet)&lt;br /&gt;
&lt;br /&gt;
•	About/List: http://wiki.stat.ucla.edu/socr/index.php/About_pages_for_SOCR_Chart_List &lt;br /&gt;
&lt;br /&gt;
•	Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_ChartsActivities&lt;br /&gt;
&lt;br /&gt;
•	Data: http://wiki.socr.umich.edu/index.php/SOCR_Data &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Excel Charts==&lt;br /&gt;
&lt;br /&gt;
MS Excel provides a large number of charts that can be used to quickly and effectively render complex multivariate data. For instance, the table below contains the principal component analysis (PCA) of 50 derived neuroimaging biomarkers (region of interest (ROI) by shape morphometry metric). The loadings of these 50 variables on the top 5 (most significant) principal component directions are shown in the table. Experiment with effective visualizations of these data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Hemi||ROI||measure||ROI_Measure||Dim.1||Dim.2||Dim.3||Dim.4||Dim.5&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||AvgMeanCurvature||L_insular_cortex_AvgMeanCurvature||0.72||0||0.06||0.06||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ComputeArea||L_insular_cortex_ComputeArea||0.77||0.06||0.04||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Volume||L_insular_cortex_Volume||0.72||0.09||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ShapeIndex||L_insular_cortex_ShapeIndex||0.46||0.06||0.01||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Curvedness||L_insular_cortex_Curvedness||0.78||0||0.05||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||AvgMeanCurvature||R_insular_cortex_AvgMeanCurvature||0.79||0||0.03||0.08||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ComputeArea||R_insular_cortex_ComputeArea||0.79||0.09||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Volume||R_insular_cortex_Volume||0.73||0.11||0.03||0.03||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ShapeIndex||R_insular_cortex_ShapeIndex||0.27||0.17||0||0.07||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Curvedness||R_insular_cortex_Curvedness||0.84||0.02||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||AvgMeanCurvature||L_cingulate_gyrus_AvgMeanCurvature||0.72||0||0.05||0.02||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ComputeArea||L_cingulate_gyrus_ComputeArea||0.74||0.05||0.06||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Volume||L_cingulate_gyrus_Volume||0.69||0.08||0.05||0.05||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ShapeIndex||L_cingulate_gyrus_ShapeIndex||0.53||0||0.05||0||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Curvedness||L_cingulate_gyrus_Curvedness||0.7||0.01||0.05||0.04||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||AvgMeanCurvature||R_cingulate_gyrus_AvgMeanCurvature||0.6||0||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ComputeArea||R_cingulate_gyrus_ComputeArea||0.73||0.06||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Volume||R_cingulate_gyrus_Volume||0.68||0.09||0.04||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ShapeIndex||R_cingulate_gyrus_ShapeIndex||0.56||0.01||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Curvedness||R_cingulate_gyrus_Curvedness||0.25||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||AvgMeanCurvature||L_caudate_AvgMeanCurvature||0.52||0||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ComputeArea||L_caudate_ComputeArea||0.51||0.09||0.03||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Volume||L_caudate_Volume||0.44||0.09||0.03||0.06||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ShapeIndex||L_caudate_ShapeIndex||0.2||0.03||0.04||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Curvedness||L_caudate_Curvedness||0.51||0.12||0.02||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||AvgMeanCurvature||R_caudate_AvgMeanCurvature||0.68||0.04||0.04||0.02||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ComputeArea||R_caudate_ComputeArea||0.67||0.17||0.03||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Volume||R_caudate_Volume||0.61||0.16||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ShapeIndex||R_caudate_ShapeIndex||0.18||0.02||0.03||0.11||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Curvedness||R_caudate_Curvedness||0.65||0.19||0.01||0||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||AvgMeanCurvature||L_putamen_AvgMeanCurvature||0.62||0||0.04||0.03||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ComputeArea||L_putamen_ComputeArea||0.56||0.05||0.04||0.03||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Volume||L_putamen_Volume||0.52||0.07||0.04||0.05||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ShapeIndex||L_putamen_ShapeIndex||0.06||0.13||0||0.15||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Curvedness||L_putamen_Curvedness||0.64||0.11||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||AvgMeanCurvature||R_putamen_AvgMeanCurvature||0.62||0||0.07||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ComputeArea||R_putamen_ComputeArea||0.66||0.08||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Volume||R_putamen_Volume||0.64||0.12||0.03||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ShapeIndex||R_putamen_ShapeIndex||0.15||0.24||0||0.08||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Curvedness||R_putamen_Curvedness||0.65||0.05||0.05||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||AvgMeanCurvature||L_hippocampus_AvgMeanCurvature||0.78||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ComputeArea||L_hippocampus_ComputeArea||0.75||0.07||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Volume||L_hippocampus_Volume||0.72||0.09||0.01||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ShapeIndex||L_hippocampus_ShapeIndex||0.45||0.17||0||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Curvedness||L_hippocampus_Curvedness||0.79||0.03||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||AvgMeanCurvature||R_hippocampus_AvgMeanCurvature||0.72||0||0||0.1||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ComputeArea||R_hippocampus_ComputeArea||0.71||0.09||0||0||0.05&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Volume||R_hippocampus_Volume||0.68||0.1||0||0||0.04&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ShapeIndex||R_hippocampus_ShapeIndex||0.37||0.18||0||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Curvedness||R_hippocampus_Curvedness||0.77||0.03||0||0.02||0.04&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==R-Charts==&lt;br /&gt;
&lt;br /&gt;
There are 100’s of packages and 1,000 of different charts, plots and graphs that can be generated using R. Such interactive visualizations enable deeper exploration of data, models and results. JavaScript libraries, e.g., D3, provide advantages for data visualization as these involve HTML5 and are easily shareable online. The R community is developing R interfaces to some popular JavaScript libraries to allow users to create interactive visualizations without detailed knowledge of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Examples of powerful R interactive visualization packages===&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;ggplot2&amp;lt;/b&amp;gt; – http://ggplot2.org&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;ggvis&amp;lt;/b&amp;gt; – interactive plots extending the static ggplot2 charts, http://ggvis.rstudio.com&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;rCharts&amp;lt;/b&amp;gt; – R interface to multiple JavaScript charting libraries, http://rcharts.io&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;plotly&amp;lt;/b&amp;gt; – transforming ggplot2 charts into interactive plots, https://plot.ly/r &lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;googleVis&amp;lt;/b&amp;gt; – Google Charts using R, http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;HTMLWidgets&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;leaflet&amp;lt;/b&amp;gt; – library for creating dynamic maps, supports panning and zooming, annotations, markers, polygons, etc. http://www.htmlwidgets.org/showcase_leaflet.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;dygraphs&amp;lt;/b&amp;gt; – provides mechanism for charting time-series data, supports interactive navigation features including series/point highlighting, zooming, and panning, http://www.htmlwidgets.org/showcase_dygraphs.html&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;networkD3&amp;lt;/b&amp;gt; – library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks, http://www.htmlwidgets.org/showcase_networkD3.html&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;DataTables&amp;lt;/b&amp;gt; – displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting, http://www.htmlwidgets.org/showcase_datatables.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;Rthreejs&amp;lt;/b&amp;gt; – features 3D scatterplots and globes based on WebGL, http://www.htmlwidgets.org/showcase_threejs.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	Other R graphic examples&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	To write out plots out to file use:&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 # pdf() command all graphs are redirected to test.pdf.  Also works with other common formats:  jpeg, png, ps, tiff.&lt;br /&gt;
 pdf(&amp;quot;C:\\Users\\Dinov\\Desktop\\test.pdf&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
 # Generates Scalable Vector Graphics (SVG) that can be edited by vector graphics software&lt;br /&gt;
 svg(&amp;quot;test.svg&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
&lt;br /&gt;
===Paired ScatterPlots===&lt;br /&gt;
&lt;br /&gt;
 set.seed(100)&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 describe(x)    # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 plot(x[,1], x[,2], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 text(x[,1]+0.03, x[,2], rownames(x))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pairs(x)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another way to generate scatterplots is by using &amp;lt;b&amp;gt;ggplot:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 x &amp;lt;- sample(1:20, 20); y &amp;lt;- sample(1:20, 20); cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), 5)  &lt;br /&gt;
 #vs. cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), each=5)&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 #  Case_03_MentalHealthServicesSurvey&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399128/download?download_frd=1&amp;amp;verifier=AG2e9QUKUm1jvDBpkX7D9jbEjKNc4irA0ECk0f7p', header=T)	&lt;br /&gt;
 head(data1)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 describe(data1)&lt;br /&gt;
&lt;br /&gt;
 plot(data1[,3], data1[,4], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 # text(data1 [,3]+0.03, data1 [,4], rownames(data1))&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # redo plots using majorfundtype FacilityType Ownership Focus&lt;br /&gt;
 # pairs(data1, na.action=na.omit)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Scatterplot with regression line. Use the “diamonds” dataset, which is a data frame with&lt;br /&gt;
 # 53,940 rows and 10 variables ()&lt;br /&gt;
 # describe(diamonds)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 # CaseStudy01_Divorce_YoungAdults&lt;br /&gt;
 # data1 &amp;lt;- read.csv('https://umich.instructure.com/files/399118/download?download_frd=1&amp;amp;verifier=ESACv31KcyiHbkPZPuT8Oo4V7XzPtgTTbs6PQLTv', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # plot variables: DIVYEAR momint dadint momclose depression livewithmom gethitched&lt;br /&gt;
&lt;br /&gt;
 set.seed(110)&lt;br /&gt;
 # par(mfrow=c(1,2))&lt;br /&gt;
 data.2 &amp;lt;- diamonds[sample(nrow(diamonds), 500), ]&lt;br /&gt;
 plot.2 &amp;lt;- qplot(price, depth, data = data.2, geom = c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), method = &amp;quot;lm&amp;quot;)&lt;br /&gt;
 plot.3 &amp;lt;- qplot(carat, price, data=data.2, geom=c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), span=0.4)&lt;br /&gt;
 print(plot.2); print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Barplots===&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 barplot(x[1:4,], ylim=c(0, max(x[1:4,])+0.3), beside=TRUE, legend.text = letters[1:4],&lt;br /&gt;
        args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:4,])),2), x=seq(1.5, 21, by=1) + sort(rep(c(0,1,2,3,4), 4)), y=as.vector(as.matrix(x[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to put error bars on barplot:&lt;br /&gt;
&lt;br /&gt;
 # 10 rows (a, b, c, …):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- rowMeans(x) * 10, ylim=c(0, 10))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Case_04_ChildTrauma&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399129/download?download_frd=1&amp;amp;verifier=Hmv0YW2Kie5ZTV9CKBUNArSHR66f3GWSmVzZDBxc', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 head(x)&lt;br /&gt;
 head(data1)&lt;br /&gt;
 # plot data&lt;br /&gt;
 data2 &amp;lt;- data1[,-5]   # remove the 5th columns text&lt;br /&gt;
 data1 &amp;lt;- data2[,-5]   # remove the 6th columns text&lt;br /&gt;
 # or data1 &amp;lt;- data1[,c(-5,-6)]&lt;br /&gt;
&lt;br /&gt;
 data2 &amp;lt;- as.data.frame(data1)&lt;br /&gt;
 Blacks &amp;lt;- data2[which(data2$\$$race==&amp;quot;black&amp;quot;),]&lt;br /&gt;
 Other &amp;lt;- data2[which(data2$\$$race==&amp;quot;other&amp;quot;),]&lt;br /&gt;
 Hispanic &amp;lt;- data2[which(data2$\$$race==&amp;quot;hispanic&amp;quot;),]&lt;br /&gt;
 White &amp;lt;- data2[which(data2$\$$race==&amp;quot;white&amp;quot;),]&lt;br /&gt;
&lt;br /&gt;
 A &amp;lt;- c(mean(Blacks$\$$age), mean(Blacks$\$$service))&lt;br /&gt;
 #colnames(A) &amp;lt;- c(&amp;quot;age &amp;quot;,&amp;quot; service &amp;quot;)  &lt;br /&gt;
 B &amp;lt;- c(mean(Other$\$$age), mean(Other$\$$service))&lt;br /&gt;
 C &amp;lt;- c(mean(Hispanic$\$$age), mean(Hispanic$\$$service))&lt;br /&gt;
 D &amp;lt;- c(mean(White$\$$age), mean(White$\$$service))&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- cbind(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
 bar &amp;lt;- barplot(x[1:2,], ylim=c(0, max(x[1:2,])+2.0), beside=TRUE, &lt;br /&gt;
 legend.text = c(&amp;quot;age&amp;quot;,&amp;quot;service&amp;quot;) ,  args.legend = list(x = &amp;quot;right&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:2,])),2), x=seq(1.4, 21, by=1.5), #y=as.vector(as.matrix(x[1:2,]))+0.3)&lt;br /&gt;
	y=11.5)&lt;br /&gt;
&lt;br /&gt;
 m &amp;lt;- x; stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 barplot(as.matrix(data1[1:4,]), ylim=c(0, max(data1[1:4,])+0.3), beside=TRUE, legend.text = data1[1:4,1], args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(data1[1:4,])),2), x=seq(1.5, 21, by=1), y=as.vector(as.matrix(data1[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Columns (A, B, C, D, E):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- colMeans(x) * 5, ylim=c(0, 5))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Histograms and Density Plots===&lt;br /&gt;
&lt;br /&gt;
 hist(x, freq=TRUE, breaks=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(density(x), lwd = 10, col=&amp;quot;green&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pie Chart===&lt;br /&gt;
&lt;br /&gt;
 # first , “A”, and second, “B”, columns&lt;br /&gt;
 par (mfrow=c(1,2))&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,2], col=rainbow(length(x[,2]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
 legend(&amp;quot;topleft&amp;quot;, legend=row.names(x), cex=1.3, bty=&amp;quot;n&amp;quot;, pch=15, pt.cex=1.8, col=rainbow(length(x[,2]), start=0.1, end=0.8), ncol=1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 You can export the data: &lt;br /&gt;
 write.table(x, &amp;quot; &amp;quot;, &amp;quot;data.txt&amp;quot;)&lt;br /&gt;
 # copy-paste it in SOCR Pie chart to generate another Pie view of data&lt;br /&gt;
&lt;br /&gt;
===Line Plots Using ggplot===&lt;br /&gt;
&lt;br /&gt;
 head(diamonds)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Carat||Cut||Color||Clarity||Depth||Table||Price||X||Y||Z&lt;br /&gt;
|-&lt;br /&gt;
|1||0.23||Ideal||E||SI2||61.5||55||326||3.95||3.98||2.43&lt;br /&gt;
|-&lt;br /&gt;
|2||0.21||Premium||E||SI1||59.8||61||326||3.89||3.84||2.31&lt;br /&gt;
|-&lt;br /&gt;
|3||0.23||Good||E||VS1||56.9||65||237||4.05||4.07||2.31&lt;br /&gt;
|-&lt;br /&gt;
|4||0.29||Premium||I||VS2||62.4||58||334||4.2||4.23||2.63&lt;br /&gt;
|-&lt;br /&gt;
|5||0.31||Good||J||SI2||63.3||58||335||4.34||4.35||4.75&lt;br /&gt;
|-&lt;br /&gt;
|6||0.24||VeryGood||J||VVS2||62.8||57||336||3.94||3.96||2.48&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(diamonds, aes(carat, price, group=cut, color=cut)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization17.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(data1, aes(age, service, group=race, color=race)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Faceting plot (geometrically, faceting (or facetting) is the process of removing parts of a polygon, polyhedron or polytope, without creating any new vertices)&lt;br /&gt;
 plot.3 &amp;lt;- ggplot(diamonds, aes(carat, price)) + geom_line(aes(color=cut), size=1) + &lt;br /&gt;
 facet_wrap(~cut, ncol=1)&lt;br /&gt;
 print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization18.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Barplots with ggplot===&lt;br /&gt;
&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization19.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 New_var &amp;lt;- service+rnorm(1000, 0,1)&lt;br /&gt;
 data1$\$$New_var &amp;lt;- int(New_var)&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(data1, aes(race, fill= traumatype)) + geom_bar() + facet_grid(. ~ New_var)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 plot.4a &amp;lt;- ggplot(diamonds, aes(color, price/carat, fill=color)) + geom_boxplot()&lt;br /&gt;
 print(plot.4a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization20.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Jitter plot===&lt;br /&gt;
&lt;br /&gt;
 plot.5 &amp;lt;- ggplot(diamonds, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))&lt;br /&gt;
 print(plot.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization21.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Density Plots===&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(color = cut))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization22.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(data1, aes(age, size=2)) + geom_density(aes(color = traumatype))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
 plot.7 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(fill = color))&lt;br /&gt;
 print(plot.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization23.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8 &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), binwidth=0.2) + geom_density()&lt;br /&gt;
 print(plot.8)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization24.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8a &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), stat=&amp;quot;identity&amp;quot;) + geom_density()&lt;br /&gt;
 print(plot.8a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization25.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heatmaps===&lt;br /&gt;
&lt;br /&gt;
 # Generating Dendogram Association Heatmap Plot (Genotype vs. Imaging phenotype)&lt;br /&gt;
 # http://stat.ethz.ch/R-manual/R-patched/library/stats/html/heatmap.html&lt;br /&gt;
 # http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4005931/ &lt;br /&gt;
	   &lt;br /&gt;
 AD_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330387/download?download_frd=1&amp;amp;verifier=gLk2ADgrLhXGeknI6mqIeJugi2ODr8RARsQlBUMe&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
&lt;br /&gt;
 MCI_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330390/download?download_frd=1&amp;amp;verifier=FczlJD6ISRPZhu69xvHuoZHx2c7gXX9YEvvPCTBG&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 require(grDevices)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
&lt;br /&gt;
 AD_Data &amp;lt;- AD_Associations_Data &lt;br /&gt;
 MCI_Data &amp;lt;- MCI_Associations_Data &lt;br /&gt;
 NC_Data &amp;lt;- NC_Associations_Data &lt;br /&gt;
&lt;br /&gt;
 AD_mat  &amp;lt;- as.matrix(AD_Data); class(AD_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 MCI_mat  &amp;lt;- as.matrix(MCI_Data); class(MCI_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 NC_mat  &amp;lt;- as.matrix(NC_Data); class(NC_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # set up the rol (rc) and column (cc) colors for each cohort&lt;br /&gt;
 rcAD &amp;lt;- rainbow(nrow(AD_mat), start = 0, end = 1.0); ccAD&amp;lt;-rainbow(ncol(AD_mat), start = 0, end = 1.0)&lt;br /&gt;
 rcMCI &amp;lt;- rainbow(nrow(MCI_mat), start = 0, end=1.0); ccMCI&amp;lt;-rainbow(ncol(MCI_mat),start=0,end=1.0)&lt;br /&gt;
 rcNC &amp;lt;- rainbow(nrow(NC_mat), start = 0, end = 1.0); ccNC&amp;lt;-rainbow(ncol(NC_mat), start = 0, end = 1.0)&lt;br /&gt;
&lt;br /&gt;
 # set up 1x3 graph display - par (mfrow=c(1,3)) – does not work with ‘heatmap’&lt;br /&gt;
 hvAD &amp;lt;- heatmap(AD_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcAD, ColSideColors = ccAD, margins = c(2,2), main=&amp;quot;AD Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvMCI &amp;lt;- heatmap(MCI_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcMCI, ColSideColors = ccMCI, margins = c(2,2), main=&amp;quot;MCI Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvNC &amp;lt;- heatmap(NC_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcNC, ColSideColors = ccNC, margins = c(2,2), main=&amp;quot;NC Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization26.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use the R package gplots&lt;br /&gt;
 install.packages(&amp;quot;gplots&amp;quot;)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
 ## col dendrogram plotted and col reordering done. &lt;br /&gt;
 # heatmap.2(AD_mat, keysize=2) &lt;br /&gt;
 ## A more decorative heatmap, with z-score scaling along columns &lt;br /&gt;
 heatmap.2(AD_mat, col=cm.colors(255), scale=&amp;quot;column&amp;quot;, RowSideColors=rcAD, ColSideColors=ccAD, margin=c(8, 7), xlab=&amp;quot;Imaging Biomarkers (ROI volume)&amp;quot;, ylab= &amp;quot;Genetics Biomarkers (SNPs)&amp;quot;, main=&amp;quot;AD Associations Heatmap (SNP-Imaging)&amp;quot;,     tracecol=&amp;quot;green&amp;quot;, density=&amp;quot;density&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization27.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Correlation Plots===&lt;br /&gt;
&lt;br /&gt;
 The &amp;lt;b&amp;gt;corrplot&amp;lt;/b&amp;gt; package is a graphical display of a correlation matrix and confidence intervals, with some tools for matrix reordering. There are seven visualization methods (parameter method) in corrplot package, named   &amp;quot;circle&amp;quot;, &amp;quot;square&amp;quot;, &amp;quot;ellipse&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;shade&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;pie&amp;quot;.&lt;br /&gt;
 # install.packages(&amp;quot;corrplot&amp;quot;)&lt;br /&gt;
 library(corrplot)&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
 M &amp;lt;- cor(NC_Associations_Data)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization28.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hyperbolic Visualization===&lt;br /&gt;
&lt;br /&gt;
•	URL: http://socr.umich.edu/html/Navigators.html  &lt;br /&gt;
&lt;br /&gt;
•	Tools:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	Java/Jar applet: http://socr.umich.edu/html/navigators/HW/jars/SOCR_HW_Viewer.jar&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	JavaScript: http://socr.umich.edu/html/navigators/D3/SOCR_D3_Viewer.html (JSON)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	Data Format&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	XML data: http://socr.umich.edu/html/navigators/HW/SOCR_HyperTree.xml&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	JSON data: http://socr.umich.edu/html/navigators/D3/xml/SOCR_HyperTree.json&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
•	D3 Visualization&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	E:\Ivo.dir\Research\UMichigan\Education_Teaching_Curricula\2015_2016\HS_853_Fall_2015\Modules_docx\Tools\TreeViewer_JS&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	treeJS.json&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	flareD3.json&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization29.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization30.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	URL: https://github.com/mbostock/d3/wiki/Gallery&lt;br /&gt;
&lt;br /&gt;
•	Source code: https://github.com/mbostock/d3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization31.png|400px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Motion Charts===&lt;br /&gt;
&lt;br /&gt;
•	Video: http://www.socr.ucla.edu/SOCR_MotionCharts/SOCR_HTML5_MotionChart_Video2.gif&lt;br /&gt;
&lt;br /&gt;
•	Java: http://www.socr.ucla.edu/SOCR_MotionCharts/ &lt;br /&gt;
&lt;br /&gt;
•	HTML5: http://socr.umich.edu/HTML5/MotionChart/ &lt;br /&gt;
&lt;br /&gt;
•	Activities: http://wiki.socr.umich.edu/index.php/SOCR_MotionCharts &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization32.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1D/2D/3D signal/area/volume/surface/model/atlas visualization===&lt;br /&gt;
&lt;br /&gt;
• 1D: (See R/SOCR Visualization tools above)&lt;br /&gt;
&lt;br /&gt;
• 2D: http://imagej.nih.gov/ij/ &lt;br /&gt;
&lt;br /&gt;
• 3D: http://socr.umich.edu/HTML5/BrainViewer/ &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;Supported File Formats:&amp;lt;/b&amp;gt;&lt;br /&gt;
 Volumes (.nii / .nii.gz / .img&amp;amp;.hdr / .mgh / .mgz / .nrrd)&lt;br /&gt;
 Shapes (.dx / .vtk / .stl / FreeSurfer)&lt;br /&gt;
 Fibers (.trk)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization33.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trees and Graphs===&lt;br /&gt;
&lt;br /&gt;
• Trees/Hierarchies and general Graphs&lt;br /&gt;
&lt;br /&gt;
 # Install and load the APE package, needed for the phylogenetic tree rendering (as.phylo)&lt;br /&gt;
 # install.packages(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Load data &lt;br /&gt;
&lt;br /&gt;
 # Data: 02_Nof1_Data.csv&lt;br /&gt;
 data.1 &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clustering&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.1), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;,&amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA),&amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization34.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 (x &amp;lt;- identify(hc)) ##  Terminate with 2nd mouse button !!&lt;br /&gt;
 identify(hc, &amp;lt;mark&amp;gt;function(k)&amp;lt;/mark&amp;gt; print(table(data.1[k,5])))&lt;br /&gt;
&lt;br /&gt;
You can now cut the tree into branches. You can split the tree into 2 groups, by setting the number of cuts with the k=2 parameter, or by specifying height to cut the tree at (?cutree):&lt;br /&gt;
&lt;br /&gt;
 k	an integer scalar or vector with the desired number of groups&lt;br /&gt;
 h	numeric scalar or vector with heights where the tree should be cut&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the clustering method &lt;br /&gt;
 # for the particular agglomeration.&lt;br /&gt;
 cutree(hc, h= 50) # cut at h=50&lt;br /&gt;
 table(cutree(hc, h= 50)) # cluster distribution&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=5; &lt;br /&gt;
 myClusters = sapply(2:10,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:10, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 groups.10 &amp;lt;- cutree(hc, k = 10)	&lt;br /&gt;
 sapply(unique(groups.10),function(g)data.1$\$$ID[groups.10 == g])&lt;br /&gt;
 #To see which Treatments (Tx) are in which clusters:&lt;br /&gt;
 groups.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.2),function(g)data.1$\$$Tx[groups.2 == g])&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.2, data.1$\$$Tx)&lt;br /&gt;
 # For a small number of observations, we can often interpret the cluster solution directly by looking &lt;br /&gt;
 # at the labels of the observations that are in each cluster. &lt;br /&gt;
 # This is hard for larger data sets. To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;aggregate&amp;lt;/b&amp;gt; function will compute stats (e.g., median) on many variables simultaneously. &lt;br /&gt;
&lt;br /&gt;
To look at the median values for the variables we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
&lt;br /&gt;
 aggregate(data.1, list(groups.10),median) # may have to &amp;lt;b&amp;gt;shrink data.1&amp;lt;/b&amp;gt; prior to clustering! &lt;br /&gt;
 # data.2 &amp;lt;- data.1[,-c(1,3)]  # Remove ID and Tx variables?&lt;br /&gt;
 aggregate(data.2, list(groups.2),median) # for only 2 clusters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Group||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 table(groups.2, data.1$\$$&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 describe(data.1$\$$PhyAct)&lt;br /&gt;
&lt;br /&gt;
 # It’s useful to add the numbers of observations in each group (aggregate returns a data frame, &lt;br /&gt;
 # that can be manipulated)&lt;br /&gt;
&lt;br /&gt;
 df.2 &amp;lt;- aggregate(data.1, list(groups.2),median)&lt;br /&gt;
&lt;br /&gt;
 data.frame(Cluster= df.2[,1], Freq=as.vector(table(groups.2)), df.2[,-1])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Cluster||&amp;lt;mark&amp;gt;Freq&amp;lt;/mark&amp;gt;||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||&amp;lt;mark&amp;gt;570&amp;lt;/mark&amp;gt;||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||&amp;lt;mark&amp;gt;330&amp;lt;/mark&amp;gt;||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
•	This paper examines nasal and bronchial tissue cultures as appropriate in vitro models for the assessment of smoking-induced adverse effects in the respiratory system (doi: 10.1177/1091581814551647), using “hclust” package. No data.&lt;br /&gt;
&lt;br /&gt;
•	This paper classified subtypes of gastric cancer based on epidemiologic and histologic and gene expression data. These new classifications of gastric cancer have implications for improving our understanding of disease biology and identification of unique molecular drivers for each gastric cancer subtype (doi: 10.1158/1078-0432.CCR-10-2203).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Repeat the clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # using centroids and squared Euclidean distance&lt;br /&gt;
 # cut the tree into 10 clusters and reconstruct the upper part of the tree from the cluster centers.&lt;br /&gt;
 hc &amp;lt;- hclust(dist(data.1), &amp;quot;cen&amp;quot;)&lt;br /&gt;
 mem &amp;lt;- cutree(hc, k = 10)&lt;br /&gt;
 cent &amp;lt;- NULL&lt;br /&gt;
 for(k in 1:10){&lt;br /&gt;
  		cent &amp;lt;- rbind(cent, colMeans(data.1[mem == k, , drop = FALSE]))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 hc1 &amp;lt;- hclust(dist(cent), method = &amp;quot;cen&amp;quot;, members = table(mem))&lt;br /&gt;
&lt;br /&gt;
 opar &amp;lt;- par(mfrow = c(1, 2))&lt;br /&gt;
 plot(hc,  labels = FALSE, hang = -1, main = &amp;quot;Original Tree&amp;quot;)&lt;br /&gt;
 plot(hc1, hang = -1, main = &amp;quot;Re-start from 10 clusters&amp;quot;)&lt;br /&gt;
 par(opar)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization35.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Identify subjects within each of the 10 classes&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rect.hclust(hc, h=10) &lt;br /&gt;
&lt;br /&gt;
 # To save the cluster numbers to a new variable in the dataset, use the cutree function.&lt;br /&gt;
 # data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct||&amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;CluserID&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53||1&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73||1&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23||2&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36||2&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21||2&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0||2&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Phylogenetic tree diagram&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc1), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;, tip.color = hsv(runif(15, 0.65, 0.95), 1, 1, 0.7), label.offset = 1, cex = log(data.1$\$$ID, 10), col = &amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization36.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization37.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity (Health Behavior Risks)===&lt;br /&gt;
&lt;br /&gt;
 # load data CaseStudy09_HealthBehaviorRisks_Data&lt;br /&gt;
 data.2 &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/399182/download?download_frd=1 &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # Classify the cases using these variables:  &amp;quot;AGE_G&amp;quot;    &amp;quot;SEX&amp;quot;      &amp;quot;RACEGR3&amp;quot;  &amp;quot;IMPEDUC&amp;quot;  &amp;quot;IMPMRTL&amp;quot;  &lt;br /&gt;
 #	&amp;quot;EMPLOY1&amp;quot;  &amp;quot;INCOMG&amp;quot;  &amp;quot;CVDINFR4&amp;quot; &amp;quot;CVDCRHD4&amp;quot; &amp;quot;CVDSTRK3&amp;quot; &amp;quot;DIABETE3&amp;quot; &amp;quot;RFSMOK3&amp;quot;  &lt;br /&gt;
 #	&amp;quot;FRTLT1&amp;quot;   &amp;quot;VEGLT1&amp;quot; &lt;br /&gt;
 data.raw &amp;lt;- data.2[,-c(1,14,17)]&lt;br /&gt;
&lt;br /&gt;
 # Does the classification match either of these: &lt;br /&gt;
 #	TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t know/Refused/Missing)&lt;br /&gt;
 #	RFDRHV4 (Heavy alcohol consumption, 1=No, 2=Yes, 9=Don’t know/Refused/Missing)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.raw), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;, &amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA), &amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
 &lt;br /&gt;
 summary(data.2$\$$TOTINDA); summary(data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the &lt;br /&gt;
 # clustering method for the particular agglomeration -- cutree(hc, h= 10)&lt;br /&gt;
&lt;br /&gt;
 table(cutree(hc, h= 10)) # cluster distribution&lt;br /&gt;
&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to sapply -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=4; &lt;br /&gt;
 myClusters = sapply(2:5,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:5, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 table(cutree(hc, k=2)) &lt;br /&gt;
 groups.k.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.k.2),function(g)data.2$\$$ID[groups.k.2 == g])&lt;br /&gt;
&lt;br /&gt;
 #To see which TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t &lt;br /&gt;
 # 	know/Refused/Missing) &amp;amp; whch RFDRHV4 are in which clusters:&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4[groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Perhaps there are intrinsically 3 groups here e.g., 1, 2 and 9 …&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4 [groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Note that there is quite a dependence between the outcome variables …&lt;br /&gt;
 plot(data.2$\$$RFDRHV4, data.2$\$$TOTINDA)&lt;br /&gt;
&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.k.3, data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 # To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. The aggregate function will compute stats&lt;br /&gt;
 # (e.g., median) on many variables simultaneously. To look at the median values for the variables &lt;br /&gt;
 # we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
 aggregate(data.2, list(groups.k.3),median) &lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS_SciVisualization_NetworkViz|Next See the Complex Network Visualization section]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]/&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16025</id>
		<title>SMHS SciVisualization SOCR Excel R Charts</title>
		<link rel="alternate" type="text/html" href="https://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts&amp;diff=16025"/>
		<updated>2016-05-19T13:58:33Z</updated>

		<summary type="html">&lt;p&gt;Imoubara: /* Hyperbolic Visualization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==[[SMHS_SciVisualization| SMHS Scientific Visualization]] - SOCR, Excel and R charts ==&lt;br /&gt;
&lt;br /&gt;
==SOCR Charts==&lt;br /&gt;
&lt;br /&gt;
•	URL: http://socr.umich.edu/html/cha/ (Java applet)&lt;br /&gt;
&lt;br /&gt;
•	About/List: http://wiki.stat.ucla.edu/socr/index.php/About_pages_for_SOCR_Chart_List &lt;br /&gt;
&lt;br /&gt;
•	Activities: http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_ChartsActivities&lt;br /&gt;
&lt;br /&gt;
•	Data: http://wiki.socr.umich.edu/index.php/SOCR_Data &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization2.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Excel Charts==&lt;br /&gt;
&lt;br /&gt;
MS Excel provides a large number of charts that can be used to quickly and effectively render complex multivariate data. For instance, the table below contains the principal component analysis (PCA) of 50 derived neuroimaging biomarkers (region of interest (ROI) by shape morphometry metric). The loadings of these 50 variables on the top 5 (most significant) principal component directions are shown in the table. Experiment with effective visualizations of these data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:99%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Hemi||ROI||measure||ROI_Measure||Dim.1||Dim.2||Dim.3||Dim.4||Dim.5&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||AvgMeanCurvature||L_insular_cortex_AvgMeanCurvature||0.72||0||0.06||0.06||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ComputeArea||L_insular_cortex_ComputeArea||0.77||0.06||0.04||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Volume||L_insular_cortex_Volume||0.72||0.09||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||ShapeIndex||L_insular_cortex_ShapeIndex||0.46||0.06||0.01||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||insular||Curvedness||L_insular_cortex_Curvedness||0.78||0||0.05||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||AvgMeanCurvature||R_insular_cortex_AvgMeanCurvature||0.79||0||0.03||0.08||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ComputeArea||R_insular_cortex_ComputeArea||0.79||0.09||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Volume||R_insular_cortex_Volume||0.73||0.11||0.03||0.03||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||ShapeIndex||R_insular_cortex_ShapeIndex||0.27||0.17||0||0.07||0&lt;br /&gt;
|-&lt;br /&gt;
|R||insular||Curvedness||R_insular_cortex_Curvedness||0.84||0.02||0.03||0.01||0&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||AvgMeanCurvature||L_cingulate_gyrus_AvgMeanCurvature||0.72||0||0.05||0.02||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ComputeArea||L_cingulate_gyrus_ComputeArea||0.74||0.05||0.06||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Volume||L_cingulate_gyrus_Volume||0.69||0.08||0.05||0.05||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||ShapeIndex||L_cingulate_gyrus_ShapeIndex||0.53||0||0.05||0||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||cingulate||Curvedness||L_cingulate_gyrus_Curvedness||0.7||0.01||0.05||0.04||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||AvgMeanCurvature||R_cingulate_gyrus_AvgMeanCurvature||0.6||0||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ComputeArea||R_cingulate_gyrus_ComputeArea||0.73||0.06||0.04||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Volume||R_cingulate_gyrus_Volume||0.68||0.09||0.04||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||ShapeIndex||R_cingulate_gyrus_ShapeIndex||0.56||0.01||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||cingulate||Curvedness||R_cingulate_gyrus_Curvedness||0.25||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||AvgMeanCurvature||L_caudate_AvgMeanCurvature||0.52||0||0.05||0||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ComputeArea||L_caudate_ComputeArea||0.51||0.09||0.03||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Volume||L_caudate_Volume||0.44||0.09||0.03||0.06||0.03&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||ShapeIndex||L_caudate_ShapeIndex||0.2||0.03||0.04||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||caudate||Curvedness||L_caudate_Curvedness||0.51||0.12||0.02||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||AvgMeanCurvature||R_caudate_AvgMeanCurvature||0.68||0.04||0.04||0.02||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ComputeArea||R_caudate_ComputeArea||0.67||0.17||0.03||0.02||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Volume||R_caudate_Volume||0.61||0.16||0.02||0.03||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||ShapeIndex||R_caudate_ShapeIndex||0.18||0.02||0.03||0.11||0&lt;br /&gt;
|-&lt;br /&gt;
|R||caudate||Curvedness||R_caudate_Curvedness||0.65||0.19||0.01||0||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||AvgMeanCurvature||L_putamen_AvgMeanCurvature||0.62||0||0.04||0.03||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ComputeArea||L_putamen_ComputeArea||0.56||0.05||0.04||0.03||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Volume||L_putamen_Volume||0.52||0.07||0.04||0.05||0.05&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||ShapeIndex||L_putamen_ShapeIndex||0.06||0.13||0||0.15||0&lt;br /&gt;
|-&lt;br /&gt;
|L||putamen||Curvedness||L_putamen_Curvedness||0.64||0.11||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||AvgMeanCurvature||R_putamen_AvgMeanCurvature||0.62||0||0.07||0.04||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ComputeArea||R_putamen_ComputeArea||0.66||0.08||0.03||0.01||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Volume||R_putamen_Volume||0.64||0.12||0.03||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||ShapeIndex||R_putamen_ShapeIndex||0.15||0.24||0||0.08||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||putamen||Curvedness||R_putamen_Curvedness||0.65||0.05||0.05||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||AvgMeanCurvature||L_hippocampus_AvgMeanCurvature||0.78||0||0.01||0.04||0&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ComputeArea||L_hippocampus_ComputeArea||0.75||0.07||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Volume||L_hippocampus_Volume||0.72||0.09||0.01||0.01||0.01&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||ShapeIndex||L_hippocampus_ShapeIndex||0.45||0.17||0||0.04||0.02&lt;br /&gt;
|-&lt;br /&gt;
|L||hippocampus||Curvedness||L_hippocampus_Curvedness||0.79||0.03||0.01||0||0.02&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||AvgMeanCurvature||R_hippocampus_AvgMeanCurvature||0.72||0||0||0.1||0.01&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ComputeArea||R_hippocampus_ComputeArea||0.71||0.09||0||0||0.05&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Volume||R_hippocampus_Volume||0.68||0.1||0||0||0.04&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||ShapeIndex||R_hippocampus_ShapeIndex||0.37||0.18||0||0.02||0.03&lt;br /&gt;
|-&lt;br /&gt;
|R||hippocampus||Curvedness||R_hippocampus_Curvedness||0.77||0.03||0||0.02||0.04&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization3.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization4.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization5.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==R-Charts==&lt;br /&gt;
&lt;br /&gt;
There are 100’s of packages and 1,000 of different charts, plots and graphs that can be generated using R. Such interactive visualizations enable deeper exploration of data, models and results. JavaScript libraries, e.g., D3, provide advantages for data visualization as these involve HTML5 and are easily shareable online. The R community is developing R interfaces to some popular JavaScript libraries to allow users to create interactive visualizations without detailed knowledge of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Examples of powerful R interactive visualization packages===&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;ggplot2&amp;lt;/b&amp;gt; – http://ggplot2.org&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;ggvis&amp;lt;/b&amp;gt; – interactive plots extending the static ggplot2 charts, http://ggvis.rstudio.com&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;rCharts&amp;lt;/b&amp;gt; – R interface to multiple JavaScript charting libraries, http://rcharts.io&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;plotly&amp;lt;/b&amp;gt; – transforming ggplot2 charts into interactive plots, https://plot.ly/r &lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;googleVis&amp;lt;/b&amp;gt; – Google Charts using R, http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html&lt;br /&gt;
&lt;br /&gt;
•	&amp;lt;b&amp;gt;HTMLWidgets&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;leaflet&amp;lt;/b&amp;gt; – library for creating dynamic maps, supports panning and zooming, annotations, markers, polygons, etc. http://www.htmlwidgets.org/showcase_leaflet.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;dygraphs&amp;lt;/b&amp;gt; – provides mechanism for charting time-series data, supports interactive navigation features including series/point highlighting, zooming, and panning, http://www.htmlwidgets.org/showcase_dygraphs.html&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;networkD3&amp;lt;/b&amp;gt; – library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks, http://www.htmlwidgets.org/showcase_networkD3.html&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;DataTables&amp;lt;/b&amp;gt; – displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting, http://www.htmlwidgets.org/showcase_datatables.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	&amp;lt;b&amp;gt;Rthreejs&amp;lt;/b&amp;gt; – features 3D scatterplots and globes based on WebGL, http://www.htmlwidgets.org/showcase_threejs.html&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	Other R graphic examples&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	To write out plots out to file use:&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
 # pdf() command all graphs are redirected to test.pdf.  Also works with other common formats:  jpeg, png, ps, tiff.&lt;br /&gt;
 pdf(&amp;quot;C:\\Users\\Dinov\\Desktop\\test.pdf&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
 # Generates Scalable Vector Graphics (SVG) that can be edited by vector graphics software&lt;br /&gt;
 svg(&amp;quot;test.svg&amp;quot;); plot(1:100, 1:100); dev.off()&lt;br /&gt;
&lt;br /&gt;
===Paired ScatterPlots===&lt;br /&gt;
&lt;br /&gt;
 set.seed(100)&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 describe(x)    # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 plot(x[,1], x[,2], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 text(x[,1]+0.03, x[,2], rownames(x))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization6.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pairs(x)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization7.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another way to generate scatterplots is by using &amp;lt;b&amp;gt;ggplot:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(ggplot2)&lt;br /&gt;
 x &amp;lt;- sample(1:20, 20); y &amp;lt;- sample(1:20, 20); cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), 5)  &lt;br /&gt;
 #vs. cat &amp;lt;- rep(c(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;), each=5)&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 #  Case_03_MentalHealthServicesSurvey&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399128/download?download_frd=1&amp;amp;verifier=AG2e9QUKUm1jvDBpkX7D9jbEjKNc4irA0ECk0f7p', header=T)	&lt;br /&gt;
 head(data1)&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
 describe(data1)&lt;br /&gt;
&lt;br /&gt;
 plot(data1[,3], data1[,4], pch=20, col=&amp;quot;red&amp;quot;, main=&amp;quot;Symbols and Labels&amp;quot;)&lt;br /&gt;
 # text(data1 [,3]+0.03, data1 [,4], rownames(data1))&lt;br /&gt;
 plot.1 &amp;lt;- qplot(x, y, geom=&amp;quot;point&amp;quot;, size=5*x, color=cat, main=&amp;quot;GGplot with Relative Dot Size and Color&amp;quot;) + theme(legend.position = &amp;quot;topleft&amp;quot;)&lt;br /&gt;
 print(plot.1)&lt;br /&gt;
&lt;br /&gt;
 # redo plots using majorfundtype FacilityType Ownership Focus&lt;br /&gt;
 # pairs(data1, na.action=na.omit)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization8.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Scatterplot with regression line. Use the “diamonds” dataset, which is a data frame with&lt;br /&gt;
 # 53,940 rows and 10 variables ()&lt;br /&gt;
 # describe(diamonds)&lt;br /&gt;
&lt;br /&gt;
 # Use Case-Studies: https://umich.instructure.com/courses/38100/files/folder/Case_Studies&lt;br /&gt;
 # CaseStudy01_Divorce_YoungAdults&lt;br /&gt;
 # data1 &amp;lt;- read.csv('https://umich.instructure.com/files/399118/download?download_frd=1&amp;amp;verifier=ESACv31KcyiHbkPZPuT8Oo4V7XzPtgTTbs6PQLTv', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 # plot variables: DIVYEAR momint dadint momclose depression livewithmom gethitched&lt;br /&gt;
&lt;br /&gt;
 set.seed(110)&lt;br /&gt;
 # par(mfrow=c(1,2))&lt;br /&gt;
 data.2 &amp;lt;- diamonds[sample(nrow(diamonds), 500), ]&lt;br /&gt;
 plot.2 &amp;lt;- qplot(price, depth, data = data.2, geom = c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), method = &amp;quot;lm&amp;quot;)&lt;br /&gt;
 plot.3 &amp;lt;- qplot(carat, price, data=data.2, geom=c(&amp;quot;point&amp;quot;, &amp;quot;smooth&amp;quot;), span=0.4)&lt;br /&gt;
 print(plot.2); print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization9.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization10.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Barplots===&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- matrix(runif(50), ncol=5, dimnames=list(letters[1:10], LETTERS[1:5]))&lt;br /&gt;
 barplot(x[1:4,], ylim=c(0, max(x[1:4,])+0.3), beside=TRUE, legend.text = letters[1:4],&lt;br /&gt;
        args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:4,])),2), x=seq(1.5, 21, by=1) + sort(rep(c(0,1,2,3,4), 4)), y=as.vector(as.matrix(x[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization11.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # to put error bars on barplot:&lt;br /&gt;
&lt;br /&gt;
 # 10 rows (a, b, c, …):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- rowMeans(x) * 10, ylim=c(0, 10))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Case_04_ChildTrauma&lt;br /&gt;
 # data1 &amp;lt;- read.table('https://umich.instructure.com/files/399129/download?download_frd=1&amp;amp;verifier=Hmv0YW2Kie5ZTV9CKBUNArSHR66f3GWSmVzZDBxc', header=T)	&lt;br /&gt;
 attach(data1)&lt;br /&gt;
 head(x)&lt;br /&gt;
 head(data1)&lt;br /&gt;
 # plot data&lt;br /&gt;
 data2 &amp;lt;- data1[,-5]   # remove the 5th columns text&lt;br /&gt;
 data1 &amp;lt;- data2[,-5]   # remove the 6th columns text&lt;br /&gt;
 # or data1 &amp;lt;- data1[,c(-5,-6)]&lt;br /&gt;
&lt;br /&gt;
 data2 &amp;lt;- as.data.frame(data1)&lt;br /&gt;
 Blacks &amp;lt;- data2[which(data2$\$$race==&amp;quot;black&amp;quot;),]&lt;br /&gt;
 Other &amp;lt;- data2[which(data2$\$$race==&amp;quot;other&amp;quot;),]&lt;br /&gt;
 Hispanic &amp;lt;- data2[which(data2$\$$race==&amp;quot;hispanic&amp;quot;),]&lt;br /&gt;
 White &amp;lt;- data2[which(data2$\$$race==&amp;quot;white&amp;quot;),]&lt;br /&gt;
&lt;br /&gt;
 A &amp;lt;- c(mean(Blacks$\$$age), mean(Blacks$\$$service))&lt;br /&gt;
 #colnames(A) &amp;lt;- c(&amp;quot;age &amp;quot;,&amp;quot; service &amp;quot;)  &lt;br /&gt;
 B &amp;lt;- c(mean(Other$\$$age), mean(Other$\$$service))&lt;br /&gt;
 C &amp;lt;- c(mean(Hispanic$\$$age), mean(Hispanic$\$$service))&lt;br /&gt;
 D &amp;lt;- c(mean(White$\$$age), mean(White$\$$service))&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- cbind(A, B, C, D)&lt;br /&gt;
&lt;br /&gt;
 bar &amp;lt;- barplot(x[1:2,], ylim=c(0, max(x[1:2,])+2.0), beside=TRUE, &lt;br /&gt;
 legend.text = c(&amp;quot;age&amp;quot;,&amp;quot;service&amp;quot;) ,  args.legend = list(x = &amp;quot;right&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(x[1:2,])),2), x=seq(1.4, 21, by=1.5), #y=as.vector(as.matrix(x[1:2,]))+0.3)&lt;br /&gt;
	y=11.5)&lt;br /&gt;
&lt;br /&gt;
 m &amp;lt;- x; stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 barplot(as.matrix(data1[1:4,]), ylim=c(0, max(data1[1:4,])+0.3), beside=TRUE, legend.text = data1[1:4,1], args.legend = list(x = &amp;quot;topleft&amp;quot;))&lt;br /&gt;
 text(labels=round(as.vector(as.matrix(data1[1:4,])),2), x=seq(1.5, 21, by=1), y=as.vector(as.matrix(data1[1:4,]))+0.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization12.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Columns (A, B, C, D, E):&lt;br /&gt;
 bar &amp;lt;- barplot(m &amp;lt;- colMeans(x) * 5, ylim=c(0, 5))&lt;br /&gt;
 stdev &amp;lt;- sd(t(x))&lt;br /&gt;
 arrows(bar, m, bar, m + stdev, length=0.15, angle = 90)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization13.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Histograms and Density Plots===&lt;br /&gt;
&lt;br /&gt;
 hist(x, freq=TRUE, breaks=10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization14.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot(density(x), lwd = 10, col=&amp;quot;green&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization15.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pie Chart===&lt;br /&gt;
&lt;br /&gt;
 # first , “A”, and second, “B”, columns&lt;br /&gt;
 par (mfrow=c(1,2))&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,1], col=rainbow(length(x[,1]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
&lt;br /&gt;
 pie(x[,2], col=rainbow(length(x[,2]), start=0.1, end=0.8), clockwise=TRUE)&lt;br /&gt;
 legend(&amp;quot;topleft&amp;quot;, legend=row.names(x), cex=1.3, bty=&amp;quot;n&amp;quot;, pch=15, pt.cex=1.8, col=rainbow(length(x[,2]), start=0.1, end=0.8), ncol=1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization16.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 You can export the data: &lt;br /&gt;
 write.table(x, &amp;quot; &amp;quot;, &amp;quot;data.txt&amp;quot;)&lt;br /&gt;
 # copy-paste it in SOCR Pie chart to generate another Pie view of data&lt;br /&gt;
&lt;br /&gt;
===Line Plots Using ggplot===&lt;br /&gt;
&lt;br /&gt;
 head(diamonds)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; &amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ||Carat||Cut||Color||Clarity||Depth||Table||Price||X||Y||Z&lt;br /&gt;
|-&lt;br /&gt;
|1||0.23||Ideal||E||SI2||61.5||55||326||3.95||3.98||2.43&lt;br /&gt;
|-&lt;br /&gt;
|2||0.21||Premium||E||SI1||59.8||61||326||3.89||3.84||2.31&lt;br /&gt;
|-&lt;br /&gt;
|3||0.23||Good||E||VS1||56.9||65||237||4.05||4.07||2.31&lt;br /&gt;
|-&lt;br /&gt;
|4||0.29||Premium||I||VS2||62.4||58||334||4.2||4.23||2.63&lt;br /&gt;
|-&lt;br /&gt;
|5||0.31||Good||J||SI2||63.3||58||335||4.34||4.35||4.75&lt;br /&gt;
|-&lt;br /&gt;
|6||0.24||VeryGood||J||VVS2||62.8||57||336||3.94||3.96||2.48&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(diamonds, aes(carat, price, group=cut, color=cut)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization17.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.2 &amp;lt;- ggplot(data1, aes(age, service, group=race, color=race)) + geom_line()&lt;br /&gt;
 print(plot.2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Faceting plot (geometrically, faceting (or facetting) is the process of removing parts of a polygon, polyhedron or polytope, without creating any new vertices)&lt;br /&gt;
 plot.3 &amp;lt;- ggplot(diamonds, aes(carat, price)) + geom_line(aes(color=cut), size=1) + &lt;br /&gt;
 facet_wrap(~cut, ncol=1)&lt;br /&gt;
 print(plot.3)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization18.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Barplots with ggplot===&lt;br /&gt;
&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization19.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 New_var &amp;lt;- service+rnorm(1000, 0,1)&lt;br /&gt;
 data1$\$$New_var &amp;lt;- int(New_var)&lt;br /&gt;
 plot.4 &amp;lt;- ggplot(data1, aes(race, fill= traumatype)) + geom_bar() + facet_grid(. ~ New_var)&lt;br /&gt;
 print(plot.4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 plot.4a &amp;lt;- ggplot(diamonds, aes(color, price/carat, fill=color)) + geom_boxplot()&lt;br /&gt;
 print(plot.4a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization20.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Jitter plot===&lt;br /&gt;
&lt;br /&gt;
 plot.5 &amp;lt;- ggplot(diamonds, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))&lt;br /&gt;
 print(plot.5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization21.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Density Plots===&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(color = cut))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization22.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.6 &amp;lt;- ggplot(data1, aes(age, size=2)) + geom_density(aes(color = traumatype))&lt;br /&gt;
 print(plot.6)&lt;br /&gt;
&lt;br /&gt;
 plot.7 &amp;lt;- ggplot(diamonds, aes(carat, size=2)) + geom_density(aes(fill = color))&lt;br /&gt;
 print(plot.7)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization23.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8 &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), binwidth=0.2) + geom_density()&lt;br /&gt;
 print(plot.8)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization24.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 plot.8a &amp;lt;- ggplot(diamonds, aes(x=carat, size=1)) + geom_histogram(aes(y = price), stat=&amp;quot;identity&amp;quot;) + geom_density()&lt;br /&gt;
 print(plot.8a)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization25.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heatmaps===&lt;br /&gt;
&lt;br /&gt;
 # Generating Dendogram Association Heatmap Plot (Genotype vs. Imaging phenotype)&lt;br /&gt;
 # http://stat.ethz.ch/R-manual/R-patched/library/stats/html/heatmap.html&lt;br /&gt;
 # http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4005931/ &lt;br /&gt;
	   &lt;br /&gt;
 AD_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330387/download?download_frd=1&amp;amp;verifier=gLk2ADgrLhXGeknI6mqIeJugi2ODr8RARsQlBUMe&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
&lt;br /&gt;
 MCI_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330390/download?download_frd=1&amp;amp;verifier=FczlJD6ISRPZhu69xvHuoZHx2c7gXX9YEvvPCTBG&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   	   &lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 require(grDevices)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
&lt;br /&gt;
 AD_Data &amp;lt;- AD_Associations_Data &lt;br /&gt;
 MCI_Data &amp;lt;- MCI_Associations_Data &lt;br /&gt;
 NC_Data &amp;lt;- NC_Associations_Data &lt;br /&gt;
&lt;br /&gt;
 AD_mat  &amp;lt;- as.matrix(AD_Data); class(AD_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 MCI_mat  &amp;lt;- as.matrix(MCI_Data); class(MCI_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
 NC_mat  &amp;lt;- as.matrix(NC_Data); class(NC_mat) &amp;lt;- &amp;quot;numeric&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # set up the rol (rc) and column (cc) colors for each cohort&lt;br /&gt;
 rcAD &amp;lt;- rainbow(nrow(AD_mat), start = 0, end = 1.0); ccAD&amp;lt;-rainbow(ncol(AD_mat), start = 0, end = 1.0)&lt;br /&gt;
 rcMCI &amp;lt;- rainbow(nrow(MCI_mat), start = 0, end=1.0); ccMCI&amp;lt;-rainbow(ncol(MCI_mat),start=0,end=1.0)&lt;br /&gt;
 rcNC &amp;lt;- rainbow(nrow(NC_mat), start = 0, end = 1.0); ccNC&amp;lt;-rainbow(ncol(NC_mat), start = 0, end = 1.0)&lt;br /&gt;
&lt;br /&gt;
 # set up 1x3 graph display - par (mfrow=c(1,3)) – does not work with ‘heatmap’&lt;br /&gt;
 hvAD &amp;lt;- heatmap(AD_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcAD, ColSideColors = ccAD, margins = c(2,2), main=&amp;quot;AD Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvMCI &amp;lt;- heatmap(MCI_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcMCI, ColSideColors = ccMCI, margins = c(2,2), main=&amp;quot;MCI Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
 hvNC &amp;lt;- heatmap(NC_mat, col = cm.colors(256), scale = &amp;quot;column&amp;quot;, RowSideColors = rcNC, ColSideColors = ccNC, margins = c(2,2), main=&amp;quot;NC Cohort SNP-ROI_volume Association (p_values)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization26.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # Alternatively, we can use the R package gplots&lt;br /&gt;
 install.packages(&amp;quot;gplots&amp;quot;)&lt;br /&gt;
 library(gplots)&lt;br /&gt;
 ## col dendrogram plotted and col reordering done. &lt;br /&gt;
 # heatmap.2(AD_mat, keysize=2) &lt;br /&gt;
 ## A more decorative heatmap, with z-score scaling along columns &lt;br /&gt;
 heatmap.2(AD_mat, col=cm.colors(255), scale=&amp;quot;column&amp;quot;, RowSideColors=rcAD, ColSideColors=ccAD, margin=c(8, 7), xlab=&amp;quot;Imaging Biomarkers (ROI volume)&amp;quot;, ylab= &amp;quot;Genetics Biomarkers (SNPs)&amp;quot;, main=&amp;quot;AD Associations Heatmap (SNP-Imaging)&amp;quot;,     tracecol=&amp;quot;green&amp;quot;, density=&amp;quot;density&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization27.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Correlation Plots===&lt;br /&gt;
&lt;br /&gt;
 The &amp;lt;b&amp;gt;corrplot&amp;lt;/b&amp;gt; package is a graphical display of a correlation matrix and confidence intervals, with some tools for matrix reordering. There are seven visualization methods (parameter method) in corrplot package, named   &amp;quot;circle&amp;quot;, &amp;quot;square&amp;quot;, &amp;quot;ellipse&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;shade&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;pie&amp;quot;.&lt;br /&gt;
 # install.packages(&amp;quot;corrplot&amp;quot;)&lt;br /&gt;
 library(corrplot)&lt;br /&gt;
 NC_Associations_Data &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330391/download?download_frd=1&amp;amp;verifier=i2BEtSpmpbrzQUPoA2ST06IzzcaenyVEHRepHSF3&amp;quot;, header=TRUE, row.names=1,  sep=&amp;quot;,&amp;quot;, dec=&amp;quot;.&amp;quot;)	   &lt;br /&gt;
 M &amp;lt;- cor(NC_Associations_Data)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization28.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hyperbolic Visualization===&lt;br /&gt;
&lt;br /&gt;
•	URL: http://socr.umich.edu/html/Navigators.html  &lt;br /&gt;
&lt;br /&gt;
•	Tools:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	Java/Jar applet: http://socr.umich.edu/html/navigators/HW/jars/SOCR_HW_Viewer.jar&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	JavaScript: http://socr.umich.edu/html/navigators/D3/SOCR_D3_Viewer.html (JSON)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	Data Format&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	XML data: http://socr.umich.edu/html/navigators/HW/SOCR_HyperTree.xml&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	JSON data: http://socr.umich.edu/html/navigators/D3/xml/SOCR_HyperTree.json&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
•	D3 Visualization&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	E:\Ivo.dir\Research\UMichigan\Education_Teaching_Curricula\2015_2016\HS_853_Fall_2015\Modules_docx\Tools\TreeViewer_JS&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	treeJS.json&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;o	flareD3.json&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization29.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization30.png|300px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	URL: https://github.com/mbostock/d3/wiki/Gallery&lt;br /&gt;
&lt;br /&gt;
•	Source code: https://github.com/mbostock/d3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization31.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Motion Charts===&lt;br /&gt;
&lt;br /&gt;
•	Video: http://www.socr.ucla.edu/SOCR_MotionCharts/SOCR_HTML5_MotionChart_Video2.gif&lt;br /&gt;
&lt;br /&gt;
•	Java: http://www.socr.ucla.edu/SOCR_MotionCharts/ &lt;br /&gt;
&lt;br /&gt;
•	HTML5: http://socr.umich.edu/HTML5/MotionChart/ &lt;br /&gt;
&lt;br /&gt;
•	Activities: http://wiki.socr.umich.edu/index.php/SOCR_MotionCharts &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization32.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===1D/2D/3D signal/area/volume/surface/model/atlas visualization===&lt;br /&gt;
&lt;br /&gt;
• 1D: (See R/SOCR Visualization tools above)&lt;br /&gt;
&lt;br /&gt;
• 2D: http://imagej.nih.gov/ij/ &lt;br /&gt;
&lt;br /&gt;
• 3D: http://socr.umich.edu/HTML5/BrainViewer/ &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;b&amp;gt;Supported File Formats:&amp;lt;/b&amp;gt;&lt;br /&gt;
 Volumes (.nii / .nii.gz / .img&amp;amp;.hdr / .mgh / .mgz / .nrrd)&lt;br /&gt;
 Shapes (.dx / .vtk / .stl / FreeSurfer)&lt;br /&gt;
 Fibers (.trk)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization33.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trees and Graphs===&lt;br /&gt;
&lt;br /&gt;
• Trees/Hierarchies and general Graphs&lt;br /&gt;
&lt;br /&gt;
 # Install and load the APE package, needed for the phylogenetic tree rendering (as.phylo)&lt;br /&gt;
 # install.packages(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Load data &lt;br /&gt;
&lt;br /&gt;
 # Data: 02_Nof1_Data.csv&lt;br /&gt;
 data.1 &amp;lt;- read.table(&amp;quot;https://umich.instructure.com/files/330385/download?download_frd=1&amp;amp;verifier=DwJUGSd6t24dvK7uYmzA2aDyzlmsohyaK6P7jK0Q &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
mydata1&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clustering&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.1), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;,&amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA),&amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization34.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 require(graphics)&lt;br /&gt;
 (x &amp;lt;- identify(hc)) ##  Terminate with 2nd mouse button !!&lt;br /&gt;
 identify(hc, &amp;lt;mark&amp;gt;function(k)&amp;lt;/mark&amp;gt; print(table(data.1[k,5])))&lt;br /&gt;
&lt;br /&gt;
You can now cut the tree into branches. You can split the tree into 2 groups, by setting the number of cuts with the k=2 parameter, or by specifying height to cut the tree at (?cutree):&lt;br /&gt;
&lt;br /&gt;
 k	an integer scalar or vector with the desired number of groups&lt;br /&gt;
 h	numeric scalar or vector with heights where the tree should be cut&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the clustering method &lt;br /&gt;
 # for the particular agglomeration.&lt;br /&gt;
 cutree(hc, h= 50) # cut at h=50&lt;br /&gt;
 table(cutree(hc, h= 50)) # cluster distribution&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to &amp;lt;b&amp;gt;sapply&amp;lt;/b&amp;gt; -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=5; &lt;br /&gt;
 myClusters = sapply(2:10,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:10, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 groups.10 &amp;lt;- cutree(hc, k = 10)	&lt;br /&gt;
 sapply(unique(groups.10),function(g)data.1$\$$ID[groups.10 == g])&lt;br /&gt;
 #To see which Treatments (Tx) are in which clusters:&lt;br /&gt;
 groups.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.2),function(g)data.1$\$$Tx[groups.2 == g])&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.2, data.1$\$$Tx)&lt;br /&gt;
 # For a small number of observations, we can often interpret the cluster solution directly by looking &lt;br /&gt;
 # at the labels of the observations that are in each cluster. &lt;br /&gt;
 # This is hard for larger data sets. To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;b&amp;gt;aggregate&amp;lt;/b&amp;gt; function will compute stats (e.g., median) on many variables simultaneously. &lt;br /&gt;
&lt;br /&gt;
To look at the median values for the variables we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
&lt;br /&gt;
 aggregate(data.1, list(groups.10),median) # may have to &amp;lt;b&amp;gt;shrink data.1&amp;lt;/b&amp;gt; prior to clustering! &lt;br /&gt;
 # data.2 &amp;lt;- data.1[,-c(1,3)]  # Remove ID and Tx variables?&lt;br /&gt;
 aggregate(data.2, list(groups.2),median) # for only 2 clusters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Group||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 table(groups.2, data.1$\$$&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;PhyAct&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;Hmisc&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 describe(data.1$\$$PhyAct)&lt;br /&gt;
&lt;br /&gt;
 # It’s useful to add the numbers of observations in each group (aggregate returns a data frame, &lt;br /&gt;
 # that can be manipulated)&lt;br /&gt;
&lt;br /&gt;
 df.2 &amp;lt;- aggregate(data.1, list(groups.2),median)&lt;br /&gt;
&lt;br /&gt;
 data.frame(Cluster= df.2[,1], Freq=as.vector(table(groups.2)), df.2[,-1])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||Cluster||&amp;lt;mark&amp;gt;Freq&amp;lt;/mark&amp;gt;||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct&lt;br /&gt;
|-&lt;br /&gt;
|1||1||&amp;lt;mark&amp;gt;570&amp;lt;/mark&amp;gt;||14||16||0||20||-5||-0.040||2.995||3.275||0.275||&amp;lt;mark&amp;gt;41&amp;lt;/mark&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|2||2||&amp;lt;mark&amp;gt;330&amp;lt;/mark&amp;gt;||16||15||1||25||0||0.025||3.280||3.360||0.360||&amp;lt;mark&amp;gt;104&amp;lt;/mark&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
•	This paper examines nasal and bronchial tissue cultures as appropriate in vitro models for the assessment of smoking-induced adverse effects in the respiratory system (doi: 10.1177/1091581814551647), using “hclust” package. No data.&lt;br /&gt;
&lt;br /&gt;
•	This paper classified subtypes of gastric cancer based on epidemiologic and histologic and gene expression data. These new classifications of gastric cancer have implications for improving our understanding of disease biology and identification of unique molecular drivers for each gastric cancer subtype (doi: 10.1158/1078-0432.CCR-10-2203).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Repeat the clustering&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # using centroids and squared Euclidean distance&lt;br /&gt;
 # cut the tree into 10 clusters and reconstruct the upper part of the tree from the cluster centers.&lt;br /&gt;
 hc &amp;lt;- hclust(dist(data.1), &amp;quot;cen&amp;quot;)&lt;br /&gt;
 mem &amp;lt;- cutree(hc, k = 10)&lt;br /&gt;
 cent &amp;lt;- NULL&lt;br /&gt;
 for(k in 1:10){&lt;br /&gt;
  		cent &amp;lt;- rbind(cent, colMeans(data.1[mem == k, , drop = FALSE]))&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 hc1 &amp;lt;- hclust(dist(cent), method = &amp;quot;cen&amp;quot;, members = table(mem))&lt;br /&gt;
&lt;br /&gt;
 opar &amp;lt;- par(mfrow = c(1, 2))&lt;br /&gt;
 plot(hc,  labels = FALSE, hang = -1, main = &amp;quot;Original Tree&amp;quot;)&lt;br /&gt;
 plot(hc1, hang = -1, main = &amp;quot;Re-start from 10 clusters&amp;quot;)&lt;br /&gt;
 par(opar)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization35.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Identify subjects within each of the 10 classes&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 rect.hclust(hc, h=10) &lt;br /&gt;
&lt;br /&gt;
 # To save the cluster numbers to a new variable in the dataset, use the cutree function.&lt;br /&gt;
 # data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 data.1$\$$clusterID &amp;lt;- cutree(hc, 10)&lt;br /&gt;
 head(data.1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center; width:35%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-		&lt;br /&gt;
|||ID||Day||Tx||SelfEff||SelfEff25||WPSS||SocSuppt||PMss||PMss3||PhyAct||&amp;lt;b&amp;gt;&amp;lt;mark&amp;gt;CluserID&amp;lt;/mark&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||1||33||8||0.97||5.00||4.03||1.03||53||1&lt;br /&gt;
|-&lt;br /&gt;
|2||1||2||1||33||8||-0.17||3.87||4.03||1.03||73||1&lt;br /&gt;
|-&lt;br /&gt;
|3||1||3||0||33||8||0.81||4.84||4.03||1.03||23||2&lt;br /&gt;
|-&lt;br /&gt;
|4||1||4||0||33||8||-0.41||3.62||4.03||1.03||36||2&lt;br /&gt;
|-&lt;br /&gt;
|5||1||5||1||33||8||0.59||4.62||4.03||1.03||21||2&lt;br /&gt;
|-&lt;br /&gt;
|6||1||6||1||33||8||-1.16||2.87||4.03||1.03||0||2&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Phylogenetic tree diagram&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # library(&amp;quot;ape&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc1), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;)&lt;br /&gt;
 plot(as.phylo(hc), use.edge.length = TRUE, type = &amp;quot;fan&amp;quot;, tip.color = hsv(runif(15, 0.65, 0.95), 1, 1, 0.7), label.offset = 1, cex = log(data.1$\$$ID, 10), col = &amp;quot;red&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization36.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:SMHS_SciVisualization37.png|500px]] &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hands-on Activity (Health Behavior Risks)===&lt;br /&gt;
&lt;br /&gt;
 # load data CaseStudy09_HealthBehaviorRisks_Data&lt;br /&gt;
 data.2 &amp;lt;- read.csv(&amp;quot;https://umich.instructure.com/files/399182/download?download_frd=1 &amp;quot;, sep=&amp;quot;,&amp;quot;, header = TRUE)&lt;br /&gt;
&lt;br /&gt;
 # Classify the cases using these variables:  &amp;quot;AGE_G&amp;quot;    &amp;quot;SEX&amp;quot;      &amp;quot;RACEGR3&amp;quot;  &amp;quot;IMPEDUC&amp;quot;  &amp;quot;IMPMRTL&amp;quot;  &lt;br /&gt;
 #	&amp;quot;EMPLOY1&amp;quot;  &amp;quot;INCOMG&amp;quot;  &amp;quot;CVDINFR4&amp;quot; &amp;quot;CVDCRHD4&amp;quot; &amp;quot;CVDSTRK3&amp;quot; &amp;quot;DIABETE3&amp;quot; &amp;quot;RFSMOK3&amp;quot;  &lt;br /&gt;
 #	&amp;quot;FRTLT1&amp;quot;   &amp;quot;VEGLT1&amp;quot; &lt;br /&gt;
 data.raw &amp;lt;- data.2[,-c(1,14,17)]&lt;br /&gt;
&lt;br /&gt;
 # Does the classification match either of these: &lt;br /&gt;
 #	TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t know/Refused/Missing)&lt;br /&gt;
 #	RFDRHV4 (Heavy alcohol consumption, 1=No, 2=Yes, 9=Don’t know/Refused/Missing)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 hc = hclust(dist(data.raw), 'ave') &lt;br /&gt;
 # the agglomeration method can be specified &amp;quot;ward.D&amp;quot;, &amp;quot;ward.D2&amp;quot;, &amp;quot;single&amp;quot;, &amp;quot;complete&amp;quot;, &amp;quot;average&amp;quot; (= UPGMA), &amp;quot;mcquitty&amp;quot; (= WPGMA), &amp;quot;median&amp;quot; (= WPGMC) or &amp;quot;centroid&amp;quot; (= UPGMC)&lt;br /&gt;
&lt;br /&gt;
 # (3) Plot clustering diagram&lt;br /&gt;
 par (mfrow=c(1,1))&lt;br /&gt;
 # very simple dendrogram&lt;br /&gt;
 plot(hc)&lt;br /&gt;
 &lt;br /&gt;
 summary(data.2$\$$TOTINDA); summary(data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 cutree(hc, k = 2)&lt;br /&gt;
 # alternatively specify the height, which is, the value of the criterion associated with the &lt;br /&gt;
 # clustering method for the particular agglomeration -- cutree(hc, h= 10)&lt;br /&gt;
&lt;br /&gt;
 table(cutree(hc, h= 10)) # cluster distribution&lt;br /&gt;
&lt;br /&gt;
 # To identify the number of cases for varying number of clusters we can combine calls to cutree and table &lt;br /&gt;
 # in a call to sapply -- to see the sizes of the clusters for 2≤ k≤10 cluster-solutions:&lt;br /&gt;
 # numbClusters=4; &lt;br /&gt;
 myClusters = sapply(2:5,function(numbClusters)table(cutree(hc, numbClusters)))&lt;br /&gt;
 names(myClusters) &amp;lt;- paste(&amp;quot;Number of Clusters=&amp;quot;, 2:5, sep = &amp;quot;&amp;quot;)&lt;br /&gt;
 myClusters&lt;br /&gt;
&lt;br /&gt;
 #To see which SubjectIDs are in which clusters:&lt;br /&gt;
 table(cutree(hc, k=2)) &lt;br /&gt;
 groups.k.2 &amp;lt;- cutree(hc, k = 2)&lt;br /&gt;
 sapply(unique(groups.k.2),function(g)data.2$\$$ID[groups.k.2 == g])&lt;br /&gt;
&lt;br /&gt;
 #To see which TOTINDA (Leisure time physical activities per month, 1=Yes, 2=No, 9=Don’t &lt;br /&gt;
 # 	know/Refused/Missing) &amp;amp; whch RFDRHV4 are in which clusters:&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4[groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Perhaps there are intrinsically 3 groups here e.g., 1, 2 and 9 …&lt;br /&gt;
 groups.k.3 &amp;lt;- cutree(hc, k = 3)&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$TOTINDA [groups.k.3 == g])&lt;br /&gt;
 sapply(unique(groups.k.3),function(g)data.2$\$$RFDRHV4 [groups.k.3 == g])&lt;br /&gt;
&lt;br /&gt;
 # Note that there is quite a dependence between the outcome variables …&lt;br /&gt;
 plot(data.2$\$$RFDRHV4, data.2$\$$TOTINDA)&lt;br /&gt;
&lt;br /&gt;
 # drill down deeper&lt;br /&gt;
 table(groups.k.3, data.2$\$$RFDRHV4)&lt;br /&gt;
&lt;br /&gt;
 # To characterize clusters we can look at cluster summary statistics, &lt;br /&gt;
 # like the median, of the variables that were used to perform the cluster analysis broken down &lt;br /&gt;
 # by the groups that the cluster analysis identified. The aggregate function will compute stats&lt;br /&gt;
 # (e.g., median) on many variables simultaneously. To look at the median values for the variables &lt;br /&gt;
 # we've used in the cluster analysis, broken up by the cluster groups:&lt;br /&gt;
 aggregate(data.2, list(groups.k.3),median) &lt;br /&gt;
&lt;br /&gt;
==See Next==&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS_SciVisualization_NetworkViz|Next See the Complex Network Visualization section]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; [[SMHS| Back to the Scientific Methods for Health Sciences EBook ToC]]/&amp;lt;li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
* SOCR Home page: http://www.socr.umich.edu&lt;br /&gt;
{{translate|pageName=http://wiki.socr.umich.edu/index.php?title=SMHS_SciVisualization_SOCR_Excel_R_Charts}}&lt;/div&gt;</summary>
		<author><name>Imoubara</name></author>
		
	</entry>
</feed>