[R-sig-ME] Subset data problems with mm

CL Pressland Kate.Pressland at bristol.ac.uk
Mon Apr 27 13:12:19 CEST 2009


AHA! That solved it. Crikey, I do feel a little stupid now for doing 
everything EXCEPT remove the additional brackets. Thanks for the help, 
seems to be working fine now.

Kate

--On 27 April 2009 12:54 +0200 Andrew Dolman <andydolman at gmail.com> wrote:

> Dear Kate,
>
> Try removing the brackets from around "(Week > 15)"
>
> e.g.
>
>
> model1<-lme(Lep~MAN, random=~1|Site, data=new.ALL, subset=Week > 15)
>
>
> Andy.
>
> andydolman at gmail.com
>
>
>
> 2009/4/27 CL Pressland <Kate.Pressland at bristol.ac.uk>
>
> Dear all,
>
> Thank for your previous comments and help on my queries regarding mixed
> models.
>
> I now have a problem regarding subsetting my data. For previous
> explanations on how my data is structured please see post "model
> definition with repeat measures". Briefly, my data is on lepidoptera
> surveyed over weeks and years on various sites that are all under
> different management. I am interested in whether management and leps are
> correlated in some way. I would like to subset the data frame but I am
> having problems and I think this may be down to my variable definitions.
>
> An example model I tried:
>
>         model1<-lme(Lep~MAN, random=~1|Site, data=new.ALL, subset =
> (Week > 15))
>
> I get this error message:
>
>         Error in sprintf(gettext(fmt, domain = domain), ...) :
>                 object "Call" not found
>
> I have created the variable Week by using this code:
>         Week<-ordered(Weeks_rec)
>
> Is this the cause of my problem? I think it's important that my variables
> are labelled (e.g. MAN<-factor(management)) but does this then interfere
> with subsetting code? As I have labeled Week as ordered(Weeks_rec), would
> I have to write individually != 1 & 1= 2...& != 15? This seem quite
> laborious!
>
> My data is unbalanced so I also have included the command:
>         new.ALL<-na.exclude(ALL)
>         names(new.ALL)
>         attach(new.ALL)
>
> I have tried creating a new 'dataset':
>         new.All1<-subset(new.ALL, Week > 15)
>
> and writing that into the model instead
>         model1<-lme(Lep~MAN, random=~1|Site, data=new.ALL1)
>
> but I still get the same error message or the model runs with all the
> Week and not the subset. Would I need to write
>         subset = (Week 1:16, >15) or similar?
>
> I am very confused as I've used subsetting before without a problem. I've
> tried as many combinations as I could think of and it still won't work.
> Can anybody shed some light on this? Full code and variables labeling
> below if this is useful.
>
> Your help is appreciated.
>
> Kate
>
> -------------
>
># full code:
>
> ALL<-read.csv("location\\filename.txt",header=T)
>
> attach(ALL)
> names(ALL)
> library(nlme)
> library(lattice)
>
> new.ALL<-na.exclude(ALL) # allowing NAs to be ignored but still keep the
> residuals and predictions padding to the correct length of the dataset
> names(new.ALL)
> attach(new.ALL)
>
># variables with correct labeling
> Site<-factor(Site_ID)
> Yr<-factor(Year)
> Week<-ordered(Weeks_rec)                #1, 2, 3, ... , 26
> MAN<-ordered(management_code)           #0,1,2
> Lep<-log(Lep_m)                         #log transformed
> BAP<-factor(UK_BAP)                     #TRUE, FALSE
> Splist<-factor(Gen_Spec)                #NA, 0 (Generalist), 1
> (Specialist)
> Mgrnt<-factor(Migrant)                  #TRUE, FALSE
> Type<-factor(Lep_type)                  #butterfly, moth
> Sun<-asin(sqrt(Mean_Sun/100))   #arcsin transformation of %
> Temp<-Mean_Temp
> Wind<-ordered(Mean_Wind)                #NA,0,1,2,3,4,5,6
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>



----------------------
Kate Pressland
Office D95
School of Biological Sciences
University of Bristol
Woodland Road
Bristol, BS8 1UG
Tel: 0117 9288918 (Internal 88918)
Kate.Pressland at bristol.ac.uk
www.bio.bris.ac.uk/people/staff.cfm?key=1137




More information about the R-sig-mixed-models mailing list