Non-linear regression with vectors as observations I'm blocking on a computational problem, that is fitting a function
$\begin{array}{lrcl}
f_{\alpha} : & \mathbb{R}^k & \longrightarrow & \mathbb{R} \end{array}$ to observations $(x_1, ..., x_n)$ that are vectors of $\mathbb{R^{m_{i}}}$ (the length of each vector is different, so that each $x_i \in \mathbb{R^{m_{i}}}$). In the following reprex my function is defined as 
$f_{\alpha}(x) = (\sum_{i = 1}^n x_i^{\alpha}$). I'm getting a type error, and I don't really know how to handle it. 
Thank you by advance
library(dplyr)
library(tidyr)
library(purrr)

dummy_fun <- function(x, alpha){
  return(sum((x)^alpha))
}



set.seed(123)
dummy_data <-
  data_frame(id =  c(rep(c(1:8), times = c(10,12,8,13,7,8,10,12))), x = runif(80)) %>%
  group_by(id) %>%
  nest() %>%
  mutate(y = map_dbl(data, dummy_fun, alpha = 2)) %>%
  rename(obs = data)

nls.test <- nls(y ~ dummy_fun(x = obs, alpha), data = dummy_data, start = list(alpha = 1.5))

 A: I did not check the dplyr code but I noticed that the dummy_data table contains tibbles  (column obs). I also encountered problems with the nls function, then I decided to use a different strategy. Below you will find a small R code.
There are 2 differences w.r.t your attempt.


*

*I defined a function dummy_fun2 which sapply trough each element of the dplyr column obs

*I used the the optimize function for the estimaiton task.
I left some comments in my code as guide. 
Hope my answer will help you.
library(dplyr)
library(tidyr)
library(purrr)

# Original piece of code---
dummy_fun <- function(x, alpha){
  return(sum((x)^alpha))
}

set.seed(123)
dummy_data <-
  data_frame(id =  c(rep(c(1:8), times = c(10,12,8,13,7,8,10,12))), x = runif(80)) %>%
  group_by(id) %>%
  nest() %>%
  mutate(y = map_dbl(data, dummy_fun, alpha = 2)) %>%
  rename(obs = data)
# End original piece of code ---

# Modified dummy function - sum(x^alpha) on each element of the cell 
dummy_fun2 = function(x, alpha){
  out = sapply(x, function(x) sum((x)^alpha))
  return(out)
}

# Obj function to be minimize
optFun = function(theta)
{
  # if needed keep pars > 0 alpha = exp(theta)
  alpha = theta

  # Mu (a vector) and rss
  mu = dummy_fun2(x = dummy_data$obs, alpha)
  res = dummy_data$y - mu
  sum(res^2)
}

# Optimization task
nls.test = optimize(f = optFun, interval = c(-5, 5))
(nls.test$minimum)

