-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function for multiple models #19
Comments
I've downloaded the Distance package, just to see how everything works. Looks like the output should be fine to do what you want. One issue is that
Does this give you the same error message? |
Hey Brad, Yea I assumed it would be able to look in the global environment for I changed it as per your example, but wasn't exactly sure whether when testing it I was then supposed to use distdata as the first argument or the name of the model. So I tried both. When I do
And when I try
I have also just tried to add a
Followed by But get the same error: |
Thanks @mattnuttall00 -- you're correct that Sorry, I should have specified what I was doing better! By changing to
You could also just call
But your In the redefined function you sent (including I'm not quite sure I understand what the |
Thanks @bradduthie, Right I see, the distdata bits make sense. John also mentioned to me about keeping functions self contained...it just doesn't seem to be sinking in! In terms of
So the
So for some reason the M |
No worries @mattnuttall00! I'm trying to verbalise what I think is the general function-related issue, but I'm not quite sure how to phrase it in a way that makes sense to me. I'm hoping the below will help. Your line showing
But then run the function as below.
Does that work okay? |
Eureka! That worked. I never even suspected that the culprit was the ~ Many thanks @bradduthie , much appreciated! |
It seems like it's always the most subtle possible thing that causes the most critical problem :-) -- glad that worked, @mattnuttall00! |
I'm making my first tentative steps in writing very simple functions just to help keep my scripts tidy, but have hit a snag.
I am trying to write a function that makes running lots of models a bit neater. The models I am running are to estimate the detection function for animals from line transect surveys, using the package 'distance' and the function ds(). The structure of the model call is:
mod1 <- ds(data, truncation, key, formula)
Where
data = my data,
trunctation = a truncation distance
key = the key model function to use (options are uniform, half-normal, hazard rate)
formula = simple formula for if you are adding covariates into the model (e.g. formula = ~habitat)
In my models,
data
andtruncation
will not change.I wrote the below function to make running a bunch of models slightly neater (although probably not by much!)
The idea being that I can simply write:
etc etc rather than writing the model calls out in full, and the model summary and resulting plots would be spat out.
The function seems to be struggling with the third term:
covar
though. It throws up and error (from the ds() call rather than from my function) saying that "covar" is not in my dataframe. So it doesn't seem to be recognising the third term in my function call. I tried addingcovar <- data$covar
at the top of the function to try and assign the term to a column in my dataframe but that hasn't worked.
Can someone offer any advice? If you think this is a pointless use of a function, I am open to that advice too ;)
Matt
The text was updated successfully, but these errors were encountered: