Admixtools 2
#46
(10-14-2024, 03:22 PM)Light Wrote: AT2 qpf4ratio is garbage

I know but some people only have at2
Reply
#47
So ChatGPT and I just pushed each other to our limits...
I got it to turn the qpadm output...
Show Content

Into this...
# A tibble: 5 x 3
  target fitted                                        Fitted_z
  <chr>  <chr>                                            <dbl>
1 MA1.SG MA1.SG fitted Congo_Mbuti.DG ZlatyKun.SG      -1.18220
2 MA1.SG MA1.SG fitted Congo_Mbuti.DG Ust_Ishim.DG    -1.42942
3 MA1.SG MA1.SG fitted Congo_Mbuti.DG BachoKiro_IUP    -1.22780
4 MA1.SG MA1.SG fitted Congo_Mbuti.DG Andaman_100BP.SG -0.961409
5 MA1.SG MA1.SG fitted Congo_Mbuti.DG China_UP        -0.576480

By just multiplying the actual f4 statistics in $f4 by the weights.
That would be sufficient, however here is the code I have to put in R to do that...
Show Content

And it absolutely cannot wrap it's circuits around being told not to include the bolded (because it's going to change with every model) and instead reference it from qpadm's output.
If ChatGPT is correct, weights appears to be both a variable and a tibble? And it doesn't know how to resolve that.
Reply
#48
Works for me, call the function on the qpadm result, no need to make those weights and f4 variables: calculate_fitted_z(res$weights, res$f4)
library(dplyr) if it can't find tibble
Congrats ChatGPT (if it's actually what you were looking for) Big Grin
Reply
#49
Hmm? I mean it works in that specific instance. But if I wanted to run a different model I'd have to change the bolded parts in the second spoiler manually?
Unless you figured out something I didn't?
Reply
#50
The bolded parts are the qpadm output.
You just do
res = qpadm(...)
calculate_fitted_z(res$weights, res$f4)
Reply
#51
(10-14-2024, 07:08 PM)Kale Wrote: Hmm? I mean it works in that specific instance. But if I wanted to run a different model I'd have to change the bolded parts in the second spoiler manually?
Unless you figured out something I didn't?

Just out of curiosity why don’t you run admixtools1 I’ve seen some atrocious differences in the two
Reply
#52
(10-14-2024, 07:35 PM)kolompar Wrote: The bolded parts are the qpadm output.
You just do
res = qpadm(...)
calculate_fitted_z(res$weights, res$f4)

No the first spoiler is the qpadm output. The bolded parts in the 2nd spoiler are how chatGPT wanted to reformat the qpadm output.
The hurdle is what commands can convert the qpadm output into the bolded parts, so that the rest of chatGPT gobbledegook can do it's thing.

EDIT: Noticed that after upgrading to Admixtools 2.07, that something broke in qpgraph, involving a function/variable named 'names'?
That happens either updating all dependencies or just the necessary ones.
Reply
#53
You don't need to convert, that's the same thing, just a way to create a tibble. You just call the function on the qpadm output as I said.
For names you need to update your R.
Reply
#54
So what exactly are the commands you are running where it is working for you?
Reply
#55
(10-15-2024, 04:51 PM)Kale Wrote: So what exactly are the commands you are running where it is working for you?

Note that I modified the above function to add parameters the number of left and right populations for it to work with any numbers as the original worked only for 2 left and 6 right

-Step1: Once you open R, paste the following that's in between the pounds(#) only once:

#######

library(dplyr)

calculate_fitted_z <- function(weights, f4, nleft, nright) {
  # Initialize results tibble
  results <- tibble(target = character(), fitted = character(), Fitted_z = numeric())

  for (i in seq(1, nright - 1)) {

  tot_fitted_z = 0

  for (j in seq(1, nleft)) {

    result_weight <- weights$weight[j]
 
    result_z <- f4$z[i + (j - 1) * (nright - 1)]
 
    fitted_z <- result_z * result_weight

    tot_fitted_z <- tot_fitted_z + fitted_z
  }

    results <- results %>%
      add_row(
        target = weights$target[1],
        fitted = paste(weights$target[1], "fitted", f4$pop3[i], f4$pop4[i], sep = " "),
        Fitted_z = tot_fitted_z
      )
  }

  return(results)
}


#######

-Step2: run qpadm

qpadm_result = qpadm(data, left, right, target, allsnps=TRUE)

-step3: get your fitted z! (I put 3 left pop in my example and 9 right pops, BUT CHANGE IT AS NEEDED)

calculate_fitted_z(qpadm_result$weights, qpadm_result$f4, 3, 9)
Reply
#56
Sweeeeetttt! Big Grin
Reply
#57
Yes, I noticed now what's the problem and decided to also try ChatGPT to fix it. You can get the needed numbers from nrow(weights) and nrow(f4)/nrow(weights), and that way you wouldn't need to pass those as parameters.
This was my result but I had to correct it several times, try if it also works.
Code:
calculate_fitted_z <- function(weights, f4) {
  # Initialize results tibble
  results <- tibble(target = character(), fitted = character(), Fitted_z = numeric())
 
  n_weights <- nrow(weights)
  n_f4 <- nrow(f4)
 
  # Ensure f4 has n * k rows (where k is the number of groups)
  if (n_f4 %% n_weights != 0) {
    stop("The number of f4 rows must be a multiple of the number of weights.")
  }
 
  # Calculate the number of groups (k)
  k <- n_f4 / n_weights
 
  for (j in seq(1, k)) {  # Loop over each group
    # Initialize fitted_z for the current group
    fitted_z <- 0
   
    for (i in seq(1, n_weights)) {  # Loop over each weight
      z_index <- i + (j - 1) * n_weights  # Adjust index for each weight and group
      weight <- weights$weight[i]
      z <- f4$z[z_index]
     
      fitted_z <- fitted_z + (z * weight)
    }
   
    results <- results %>%
      add_row(
        target = weights$target[1],  # Assuming all share the same target for the group
        fitted = paste(weights$target[1], "fitted", f4$pop3[j], f4$pop4[j], sep = " "),
        Fitted_z = fitted_z
      )
  }
 
  return(results)
}
Reply
#58
I think this might be a bug with admixtools2, but maybe someone else understands the technicalities better than me...
Here's a qpadm model...
right = c('Congo_Mbuti.DG', 'ZlatyKun.SG', 'Ust_Ishim.DG', 'BachoKiro_IUP', 'China_UP', 'Andaman_100BP.SG', 'RUS_Primorsky_DevilsCave_N.SG', 'Kostenki14', 'Sunghir.SG', 'Muierii1', 'Gravettian_KremsVestonice', 'GoyetQ116_1', 'Gravettian_France_Fournol', 'BachoKiro_BK1653', 'Yana_UP.SG', 'MA1.SG', 'Peru_RioUncallane_1800BP.SG', 'Kotias_UP.SG', 'Anatolia_Epipaleolithic', 'CHG.SG', 'Iran_Wezmeh_N.SG')
allsnps=TRUE

RUS_Vologda_Minino_HG
Italy_AreneCandide_HG 0.324782 0.0281531 11.5363
AG3 0.478162 0.0206777 23.1246
RUS_Yakutia_KolymaRiver_Meso.SG 0.0261529 0.0135680 1.92754
Anatolia_Boncuklu_N 0.170903 0.0235679 7.25152
Tail: 0.20

And now because it's fun, residuals!
Show Content

From observation, AG3 has a bit of damage/artifacts which make it universally less related to everybody, and as can be seen from the residuals, that gives EHG pretty much a universal slight underfit to the right pops.

So what happens if I throw in Mota as an additional source (expecting it to come back as a small negative percentage) to 'counteract' the damage?

RUS_Vologda_Minino_HG
Italy_AreneCandide_HG 0.322127 0.0283130 11.3773
AG3 0.477256 0.0205856 23.1840
RUS_Yakutia_KolymaRiver_Meso.SG 0.0298457 0.0139813 2.13468
Anatolia_Boncuklu_N 0.180140 0.0247575 7.27620
Ethiopia_Mota_4500BP.SG -0.00936885 0.00600763 -1.55949
It takes -0.9%, kind of what I thought, and the residuals as a whole have greatly improved.
Show Content
But the tail prob is now... 3e-10!?

It seems to be a problem specifically relating to African/deep populations. No negative coefficients here, residuals are great, tail prob is garbage.
Morocco_SKH001_MN.SG
Israel_Pekiin_CA 0.561492 0.0504498 11.1297
Ethiopia_Mota_4500BP.SG 0.0576846 0.00868432 6.64239
Morocco_OUB002_Epipaleolithic.SG 0.0510571 0.0203990 2.50292
Morocco_KTG005_EN.SG 0.329766 0.0656861 5.02034
Tail: 6e-7
right = c('Congo_Mbuti.DG', 'Kenya_Naivasha_PastoralN', 'Levant_N', 'Anatolia_Barcin_N.SG', 'Anatolia_Boncuklu_N.SG', 'Iran_TepeAbdulHosein_N.SG', 'Iran_Wezmeh_N.SG', 'CHG.SG', 'Taforalt', 'Italy_GrottaContinenza_HG.SG', 'Sweden_StoraForvar_HG.SG', 'RUS_Arkhangelsk_HG.SG', 'Botai.SG', 'Andaman_100BP.SG', 'RUS_Primorsky_DevilsCave_N.SG', 'Peru_RioUncallane_1800BP.SG')
allsnps=TRUE

Residuals...
Show Content
Ran again with SouthAfrica_2000BP.SG, Neanderthal_Altai.DG, and Chimp.REF as the first right pops, same deal.
Reply
#59
(07-25-2024, 06:44 PM)masta Wrote: admixtools 2 is trash and gives false results i advice any user to use the original admixtools

I wouldn’t suggest it for Neolithic modelling but anything else it seems fine and matches up from what I can see. 

The only differences I had was running Neolithic models on both they were wildly different, when I ran iron model or a modern model it was similar 

Personally I don’t do Neolithic modelling so it doesn’t effect me
Reply
#60
v2.0.8 released two days ago
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)