Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Ellipse simulation
- ### Simulate X ellipses with y points and attempt to estimate the shape
- # Load library
- library("brms")
- # Set Seed
- set.seed(42)
- # Define ellipses
- nlev <- 8 # Points
- nr <- 10 # Participants
- width <- 12
- height <- 10
- # Generate n Circles
- angs <- seq(pi/2,-pi-2*pi/nlev,-2*pi/nlev)
- capture <- matrix(NA,nlev,3)
- capture[,1] <- 1
- # Add noise per meassure
- indvar <- rnorm(1)
- random <- rnorm(nlev,indvar,sd=0.1)
- capture[,2] <- cos(angs)*(width+random)
- capture[,3] <- sin(angs)*(height+random)
- captureTemp <- matrix(NA,nlev,3)
- for(i in 2:nr){
- indvar <- rnorm(1)
- random <- rnorm(nlev,indvar,sd=0.1)
- captureTemp[,1] <- i
- captureTemp[,2] <- cos(angs)*(width+random)
- captureTemp[,3] <- sin(angs)*(height+random)
- capture <- rbind(capture,captureTemp)}
- # Make data frame
- dat <- data.frame(capture)
- names(dat) <- c("part", "xpos", "ypos")
- # Plot
- limit <- max(capture)
- plot(dat$xpos,dat$ypos, xlim = c(-limit,limit), ylim = c(-limit,limit))
- # Brms (wrong method, surely)
- m1 <- brm(data = dat,
- family = gaussian,
- mvbind(xpos, ypos) ~ 1 +(1|part), chains = 2, cores = 2, iter=500)
- m1
- # Attempt at better model
- m2 <- brm(data = dat,
- family = gaussian,
- mvbind(xpos*a*(cos(t)),
- ypos*b*(sin(t))) ~ 1 +(1|part), chains = 2, cores = 2, iter=500)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement