# Non-numeric argument to binary operator - Markdown

Hello everyone,

I'm new to r and taking a class where I'm using an r-markdown script. I keep getting the "non-numeric argument to binary operator" error when I try to knit my document into a pdf, which I'm not sure what is going wrong. The actual markdown was performed by my teacher, and my script is running fine on a separate console.

This is the script so far (including the assignment instructions from my teacher):

---
title: "Trends Lab (Weeks 3-4)"
author: "Student Name"
date: "04/26/2022"
output: pdf_document
---

{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)  # Part 1: Background on r,$\lambda$, and trends A population trend is a measure of how a population or population index is changing through time. Trends are often expressed as "percent per year", which is a discrete rate. Like a multiplication rate applied to the population each year, these are trends where the actual number of individuals gained or lost each year can be expressed as: N(t + 1) =$\lambda$*N(t) N is population size. t is time. Read this equation as: population size at time t+1 is equal to$\lambda$times the population size in year t. For most vertebrates, t is one year.$\lambda$is equal to next year's population (N(t+1)) divided by this year's population (N(t)).$\lambda$can be determined in a number of ways; in these simple models, an average$\lambda$is determined as an average of N(t+1)/N(t) or by a smooth line that is "fit" to the data.$\lambda$is a population multiplication rate. When$\lambda$= 1, the population is stable and does not change from year to year. When$\lambda$>1, the population is increasing, and when$\lambda$< 1 the population is decreasing. For example, if$\lambda$= 1.15, the population is increasing at a rate of 15% per year, and if$\lambda$= 0.85, the population is decreasing at a rate of 15% per year. Simple exponential trend models are usually based on "fitting" a line to the observed data, and are often used to "project" population size into the future, assuming that the current trend will continue. Naturally, the farther we extrapolate into the future, the less confident we will be in our projected estimate. Because real populations vary from year to year, it is sometimes difficult to know for sure if the population is increasing or decreasing, or simply varying randomly. This is especially true if the time series is short. The last part of this assignment uses regression analysis, a statistical procedure, to "test" the model to see if it is likely that there really is a trend in the data. ## Exercise 1. Population growth of beetles *(8 points total)* You are studying a lab beetle colony of size 300. During a one-day period you record 630 births and 517 deaths in this population. You want to project the population growth rate in 14 days #### A. (1 pt) Create two objects called N_0 and N_1 to define the initial and subsequent population sizes. {r} N_0<-300 N_1<-413  #### B. (1 pt) Create an object storing the value of$\lambda\$, and take the natural log [the log() function] to find the intrinsic rate of increase r:

{r}
lambda<-(N_1/N_0)
log(lambda)


#### C. (2 pt) Use the continuous equation for exponential growth to predict the population size for the next 14 days. What is the expected population at day 14? (Report the units). Hint: you can create a vector for time using [t<-1:14] and calculate the population size for every value of t by plugging in the vector for t into an appropriately written equation.

{r}
#289.10


#### D. (2 pt) Make a plot of population size over time. Label the axes and their units. Use the code [?plot] to see some plotting options.

{r}
k<-N_1*(t+1)/N_0*t
x<-k+300
y<-seq(from=1,to=14)
plot(x,y,xlab="population",ylab="time in days")


#### E. (2 pts). You start another beetle colony at a different temperature, because you had heard that temperature affected population growth rate in insects. Again, you started with 300 beetles. You expected fewer births, because it is 4 degrees C cooler. During a one-day period you record 361 births and 410 deaths in this population.  Make a plot of predicted population size over time using these data. What is the estimated population size after 14 days?

{r}
N_2<-251
z<-N_2*(t+1)/N_0*t
x_1 <-z+300
plot(x_1,y,xlab="Population 2",ylab="time in days")



Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.