[R] AIC in MuMIn

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Aug 18 09:51:02 CEST 2010


On Wed, 2010-08-18 at 05:42 +0800, elaine kuo wrote:
> Thank you.
> Most of the answers solved the puzzles.
> 
> 
> Q2 
> 
>         
>         > I tried to display sub-model with only temp_ran using the
>         code below but
>         > failed.
>         > Please kindly suggest the potential failure cause.
>         >
>         > code
>         >
>         > library(MuMIn)
>         > datam
>         <-read.csv("c:/migration/Mig_ratio_20100817.csv",header=T,
>         > row.names=1)
>         
>         
>         
>         mig.stds <-lm(SummerM_ratio ~ temp_max + evi_mean + topo_var +
>                      topo_mean + coast + Iso_index_0808,
>                      ## now tell R were to find the variables in
>         formula
>                      data = datum.std)
>         ## If you are fitting a Gaussian GLM it is better fitted with
>         lm()
> 
> 
>  => Please explain why fitted lm is better for GLM.

Seriously? A GLM specified as glm(...., family = gaussian) is the linear
model that you'd get with lm(). lm() fits the model far more efficiently
than glm(). The code you showed specifically used 'family = gaussian',
hence my comment.

>         But temp_ran is not in your model...
>         
>         > error in eval(expr, envir, enclos), 'temp_ran' not found
>         
>         
>         When used properly (none of this datam.std$ business), subset
>         will do
>         what you want:
>         
>         > dd2 <- dredge(lm1, subset = X1)
>         > dd2
>         Global model: lm(formula = y ~ ., data = Cement)
>         ---
>         Model selection table
>            (Int)        X     X1     X2      X3      X4 k   R.sq
>         Adj.R.sq     RSS
>         3   52.58          1.4680 0.6623                 4 0.9787
>         0.9744   57.90
>         
>         
> => Please suggest how to define subset in my case

How would I know? I still haven't seen your data. You seem to be
mistaken on what is and is not included in your model and you fitted it.
What hope do we have...? However, given the model 'mig.stds' from above
in this email:

> mig.stds <-lm(SummerM_ratio ~ temp_max + evi_mean + topo_var +
>              topo_mean + coast + Iso_index_0808,
>              ## now tell R were to find the variables in formula
>              data = datum.std)
> ## If you are fitting a Gaussian GLM it is better fitted with lm()

If you want to consider dredged models containing temp_max, then you
would do

dredge(mig.stds, subset = temp_max)

If you want models that contain temp_max and coast, then you'd do

dredge(mig.stds, subset = temp_max & coast)

or

dredge(mig.stds, fixed = ~ temp_max + coast)

The bits you include in subset or fixed are the names of your variables
that you want in or out of the models. In your case, the names of the
variables as input into the model formula. With 'subset' you need to use
logical operators (and [&], or [|]) whilst with 'fixed' you can specify
a formula of variables that should be included or excluded in the same
way you'd write any R formula.

But, now having been told this, please note that this is *all* discussed
on the ?dredge help page if you bother to read it. I've never used this
package, and, OK, I have used R for going on for 11 or 12 years now so
am used to reading help pages and understand the language a bit more you
perhaps do, but you do seem to be asking questions or running into
problems that are all covered by the help pages.

> Finally, it would be highly appreciated to recommend any references of
> R for a beginner like me.

Read the An Introduction to R manual that comes with R or that can be
downloaded from the R website/CRAN. Also look at the contributed
documentation section on the R website which contains numerous free
introductory guides.

> Elaine

HTH

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list